All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.nuiton.widget.SwingUtil Maven / Gradle / Ivy

There is a newer version: 1.1.1
Show newest version
/* *##% Graphical Widget
 * Copyright (C) 2004 - 2008 CodeLutin
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Lesser Public License for more details.
 *
 * You should have received a copy of the GNU General Lesser Public
 * License along with this program.  If not, see
 * . ##%*/

/* *
 * SwingUtil.java
 *
 * Created: Nov 19, 2004
 *
 * @author Cédric Pineau 
 * @version $Revision: 184 $
 *
 * Last update : $Date: 2009-05-16 06:01:36 +0200 (sam., 16 mai 2009) $
 * by : $Author: tchemit $
 */

package org.nuiton.widget;

import java.awt.Component;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.Window;

import javax.swing.JFrame;
import javax.swing.UIManager;

import com.jgoodies.plaf.LookUtils;
import com.jgoodies.plaf.plastic.PlasticLookAndFeel;
import com.jgoodies.plaf.plastic.PlasticXPLookAndFeel;
import com.jgoodies.plaf.plastic.theme.SkyBluerTahoma;
import com.l2fprod.common.swing.plaf.LookAndFeelAddons;
import com.l2fprod.common.swing.plaf.windows.WindowsLookAndFeelAddons;

/**
 * 
 */
public class SwingUtil {

    public static void init() throws Exception {
        UIManager.put("ClassLoader", LookUtils.class.getClassLoader());
        PlasticLookAndFeel.setMyCurrentTheme(new SkyBluerTahoma());
        UIManager.setLookAndFeel(new PlasticXPLookAndFeel());

        try {
            LookAndFeelAddons.setAddon(WindowsLookAndFeelAddons.class);
        } catch (InstantiationException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    }

    public static void configureUI(Component component) {
        if (component instanceof JFrame) {
            ((JFrame) component)
                    .setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
        }
        if (component instanceof Window) {
            ((Window) component).pack();
        }
        center(component);
    }

    /**
     * Center the widget on the screen
     */
    public static void center(Component component) {
        Toolkit tk = component.getToolkit();
        Dimension d = component.getSize();
        int x = (tk.getScreenSize().width - d.width) / 2;
        int y = (tk.getScreenSize().height - d.height) / 2;
        component.setLocation(x, y);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy