org.nuiton.widget.SwingWidgetFactory 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
* . ##%*/
/* *
* SwingWidgetFactory.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.text.DateFormat;
import javax.swing.AbstractAction;
import javax.swing.AbstractButton;
import javax.swing.JButton;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JSplitPane;
import javax.swing.JToolBar;
import javax.swing.border.Border;
import javax.swing.border.CompoundBorder;
import javax.swing.border.EmptyBorder;
import javax.swing.border.EtchedBorder;
import com.jgoodies.plaf.Options;
import com.jgoodies.plaf.plastic.PlasticLookAndFeel;
import com.jgoodies.plaf.windows.ExtWindowsLookAndFeel;
import com.l2fprod.common.swing.JLinkButton;
/**
*
*/
public class SwingWidgetFactory {
/**
* Creates and returns a AbstractButton
*/
public static AbstractButton createMenuButton(ApplicationAction action) {
JButton button = new JButton(action);
button.setText(null);
return button;
}
/**
* Creates and returns a AbstractButton
*/
public static AbstractButton createButton(ApplicationAction action) {
JButton button = new JButton(action);
button.setText(action.getShortText());
return button;
}
/**
* Creates and returns a AbstractButton
*/
public static AbstractButton createHyperLinkButton(ApplicationAction action) {
JLinkButton button = new JLinkButton(action);
button.setText((String) action.getValue(AbstractAction.NAME));
button.setIcon(null);// IconFactory.getIcon(IconFactory.LINK));
return button;
}
/**
* Creates and returns a JSplitPane
*/
public static JSplitPane createSplitPane() {
return new UIFSplitPane();
}
/**
* Creates and returns a JPanel
*/
public static JPanel createPanel() {
return new SimpleInternalFrame();
}
/**
* Creates and returns a JPanel
*/
public static JPanel createNamedPanel(String title) {
return new SimpleInternalFrame(title);
}
public static void setPanelTitle(JPanel panel, String title) {
if (panel instanceof SimpleInternalFrame) {
((SimpleInternalFrame) panel).setTitle(title);
}
}
/**
* Creates and returns a JToolBar
*/
public static JToolBar createToolBar() {
JToolBar toolBar = new JToolBar();
Settings settings = Settings.createDefault();
toolBar.setFloatable(false);
toolBar.putClientProperty("JToolBar.isRollover", Boolean.TRUE);
// Swing
toolBar.putClientProperty(Options.HEADER_STYLE_KEY, settings
.getToolBarHeaderStyle());
toolBar.putClientProperty(PlasticLookAndFeel.BORDER_STYLE_KEY, settings
.getToolBarPlasticBorderStyle());
toolBar.putClientProperty(ExtWindowsLookAndFeel.BORDER_STYLE_KEY,
settings.getToolBarWindowsBorderStyle());
toolBar.putClientProperty(PlasticLookAndFeel.IS_3D_KEY, settings
.getToolBar3DHint());
toolBar.setFloatable(false);
Border marginBorder = new EmptyBorder(0, 2, 0, 2);
EtchedBorder etchedBorder = new EtchedBorder();
Border compoundBorder = new CompoundBorder(etchedBorder, marginBorder);
toolBar.setBorder(compoundBorder);
return toolBar;
}
/**
* Creates and returns a JMenuBar
*/
public static JMenuBar createMenuBar() {
JMenuBar menuBar = new JMenuBar();
Settings settings = Settings.createDefault();
menuBar.putClientProperty(Options.HEADER_STYLE_KEY, settings
.getMenuBarHeaderStyle());
menuBar.putClientProperty(PlasticLookAndFeel.BORDER_STYLE_KEY, settings
.getMenuBarPlasticBorderStyle());
menuBar.putClientProperty(ExtWindowsLookAndFeel.BORDER_STYLE_KEY,
settings.getMenuBarWindowsBorderStyle());
menuBar.putClientProperty(PlasticLookAndFeel.IS_3D_KEY, settings
.getMenuBar3DHint());
Border marginBorder = new EmptyBorder(0, 2, 0, 2);
EtchedBorder etchedBorder = new EtchedBorder();
Border compoundBorder = new CompoundBorder(etchedBorder, marginBorder);
menuBar.setBorder(compoundBorder);
return menuBar;
}
public static JMenu createMenu(String text, char mnemonic) {
JMenu menu = new JMenu(text);
menu.setMnemonic(mnemonic);
return menu;
}
public static JMenuItem createMenuItem(ApplicationAction action) {
JMenuItem menuItem = new JMenuItem();
menuItem.setAction(action);
menuItem.setText(action.getShortText());
return menuItem;
}
public static DatePicker createDatePicker(DateFormat dateFormat) {
return new DatePicker(dateFormat);
}
}