org.nuiton.widget.SwingUtil Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of nuiton-widgets Show documentation
Show all versions of nuiton-widgets Show documentation
Widgets graphiques utiles pour tous les développements.
/* *##% 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: 254 $
*
* Last update : $Date: 2010-04-10 01:13:11 +0200 (sam., 10 avril 2010) $
* 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);
}
}