/*
* (c) Copyright 2006 by Heng Yuan
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* ITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
package cookxml.cookswing;
import java.awt.*;
import java.awt.event.*;
import java.beans.ExceptionListener;
import java.beans.VetoableChangeListener;
import java.text.DateFormat;
import java.text.Format;
import java.text.NumberFormat;
import java.util.Calendar;
import javax.swing.*;
import javax.swing.border.BevelBorder;
import javax.swing.border.Border;
import javax.swing.border.EtchedBorder;
import javax.swing.border.TitledBorder;
import javax.swing.event.*;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;
import javax.swing.text.*;
import cookxml.common.CommonLib;
import cookxml.common.setter.ObjectOrHookVariableSetter;
import cookxml.common.util.Utils;
import cookxml.cookswing.adder.*;
import cookxml.cookswing.converter.*;
import cookxml.cookswing.creator.*;
import cookxml.cookswing.helper.*;
import cookxml.cookswing.setter.DecoratedWindowSetter;
import cookxml.cookswing.setter.LabelForSetter;
import cookxml.cookswing.setter.ListSelectionListenerSetter;
import cookxml.core.adder.CallFunctionAdder;
import cookxml.core.adder.DefaultAdder;
import cookxml.core.adder.DoNothingAdder;
import cookxml.core.creator.DefaultCreator;
import cookxml.core.creator.HelperCreator;
import cookxml.core.exception.CookXmlException;
import cookxml.core.interfaces.Adder;
import cookxml.core.interfaces.Converter;
import cookxml.core.interfaces.Setter;
import cookxml.core.setter.ConstantSetter;
import cookxml.core.setter.DefaultSetter;
import cookxml.core.setter.DoNothingSetter;
import cookxml.core.taglibrary.InheritableTagLibrary;
/**
* @author Heng Yuan
* @version $Id: CookSwingLib.java 270 2007-06-10 20:42:10Z coconut $
* @since CookSwing 1.5
*/
public class CookSwingLib
{
/** this is the namespace for CookSwing tags */
public static String NAMESPACE = "http://cookxml.sf.net/cookswing/";
public final static String UI_PREFIX = "ui:";
//
// internal tags
//
public static String WINDOW_GROUP = "window-constants";
public static String ABSTRACT_BUTTON = "abstractbutton";
//
// tags that are being inherited
//
public final static String COMPONENT = "component";
public final static String TEXTCOMPONENT = "textcomponent";
public final static String TEXTFIELD = "textfield";
/**
* Setup the Swing tag library.
* <p>
* Call this function if you intend to setup the Swing tag library manually.
*
* @param tagLibrary
* the tag library to be setup
* @param commonTagLibrary
* the CookXml Common library to be setup. Some listener setters will be added.
* @throws cookxml.core.exception.CookXmlException
* exception is thrown if any errors occurred.
*/
public static void setupTags (InheritableTagLibrary tagLibrary, InheritableTagLibrary commonTagLibrary) throws CookXmlException
{
tagLibrary.setSetter (null, null, DefaultSetter.getInstance ());
tagLibrary.addAdder (null, DefaultAdder.getInstance ());
// replace the following with a different creator because we want to be able
// to be able to retrieve UIManager values
// Boolean
commonTagLibrary.setCreator ("boolean", HelperCreator.getCreator (BooleanHelper.class));
// Integer
commonTagLibrary.setCreator ("int", HelperCreator.getCreator (IntegerHelper.class));
// String
commonTagLibrary.setCreator ("string", HelperCreator.getCreator (StringHelper.class));
////////////////////////////////////////////////////////////////////////////
//
// AWT/Swing Specific
//
////////////////////////////////////////////////////////////////////////////
ConstantSetter mnemonicConstantSetter = new ConstantSetter (KeyEvent.class);
ConstantSetter inputEventConstantSetter = new ConstantSetter (InputEvent.class);
ConstantSetter swingConstantsSetter = new ConstantSetter (SwingConstants.class);
ConstantSetter listSelectionModeConstantsSetter = new ConstantSetter (ListSelectionModel.class);
ConstantSetter componentOrientationConstantsSetter = new ConstantSetter (ComponentOrientation.class);
Adder contentPaneAdder = CallFunctionAdder.getAdder ("setContentPane", RootPaneContainer.class, Container.class);
Adder menuBarAdder = CallFunctionAdder.getAdder ("setJMenuBar", null, JMenuBar.class);
// Cursor
tagLibrary.setCreator ("cursor", HelperCreator.getCreator (CursorHelper.class));
tagLibrary.setConverter (Cursor.class, new CursorConverter ());
// Font
tagLibrary.setCreator ("font", HelperCreator.getCreator (FontHelper.class));
tagLibrary.setConverter (Font.class, new FontConverter ());
// KeyStroke
tagLibrary.setCreator ("keystroke", HelperCreator.getCreator (KeyStrokeHelper.class));
tagLibrary.setConverter (KeyStroke.class, new KeyStrokeConverter ());
tagLibrary.setSetter ("keystroke", "keycode", mnemonicConstantSetter);
tagLibrary.setSetter ("keystroke", "modifiers", inputEventConstantSetter);
// Insets
tagLibrary.setCreator ("insets", new InsetsCreator ());
tagLibrary.setConverter (Insets.class, new InsetsConverter ());
// Dimension
tagLibrary.setCreator ("dimension", DefaultCreator.getCreator (Dimension.class, true));
tagLibrary.setConverter (Dimension.class, new DimensionConverter ());
// Rectangle
tagLibrary.setCreator ("rectangle", DefaultCreator.getCreator (Rectangle.class, true));
tagLibrary.setConverter (Rectangle.class, new RectangleConverter ());
// Image
tagLibrary.setCreator ("image", HelperCreator.getCreator (ImageHelper.class));
tagLibrary.setConverter (Image.class, new ImageConverter ());
// ImageIcon
Converter iconConverter = new ImageIconConverter ();
tagLibrary.setCreator ("imageicon", HelperCreator.getCreator (ImageIconHelper.class));
tagLibrary.setConverter (ImageIcon.class, iconConverter);
// Icon
tagLibrary.setCreator ("icon", HelperCreator.getCreator (IconHelper.class));
tagLibrary.setConverter (Icon.class, iconConverter);
// Color
tagLibrary.setCreator ("color", HelperCreator.getCreator (ColorHelper.class));
tagLibrary.setConverter (Color.class, new ColorConverter ());
// Point
tagLibrary.setCreator ("point", DefaultCreator.getCreator (Point.class, true));
tagLibrary.setConverter (Point.class, new PointConverter ());
//
// Swing Components
//
Setter decoratedWindowSetter = new DecoratedWindowSetter ();
// UIManager
tagLibrary.setCreator ("uimanager", new UIManagerCreator ());
// JApplet
tagLibrary.setCreator ("applet", new AppletCreator ());
tagLibrary.inheritTag (WINDOW_GROUP, "applet");
// JDialog
tagLibrary.setCreator ("dialog", new DialogCreator ());
tagLibrary.inheritTag (WINDOW_GROUP, "dialog");
tagLibrary.setSetter ("dialog", "ctor", DoNothingSetter.getInstance ());
tagLibrary.setSetter ("dialog", "decorated", decoratedWindowSetter);
// JFrame
tagLibrary.setCreator ("frame", new FrameCreator ());
tagLibrary.inheritTag (WINDOW_GROUP, "frame");
tagLibrary.setSetter ("frame", "decorated", decoratedWindowSetter);
// JInternalFrame
tagLibrary.setCreator ("internalframe", new InternalFrameCreator ());
tagLibrary.inheritTag (WINDOW_GROUP, "internalframe");
// JWindow
tagLibrary.setCreator ("window", new WindowCreator ());
tagLibrary.inheritTag (WINDOW_GROUP, "window");
// JMenuBar
tagLibrary.setCreator ("menubar", DefaultCreator.getCreator (JMenuBar.class));
tagLibrary.inheritTag (COMPONENT, "menubar");
// JPopupMenu
tagLibrary.setCreator ("popupmenu", DefaultCreator.getCreator (JPopupMenu.class));
tagLibrary.inheritTag (COMPONENT, "popupmenu");
// JMenu
tagLibrary.setCreator ("menu", DefaultCreator.getCreator (JMenu.class));
tagLibrary.inheritTag (ABSTRACT_BUTTON, "menu");
tagLibrary.setSetter ("menu", "componentorientation", componentOrientationConstantsSetter);
// JMenuItem
tagLibrary.setCreator ("menuitem", DefaultCreator.getCreator (JMenuItem.class));
tagLibrary.inheritTag (ABSTRACT_BUTTON, "menuitem");
// menu split
tagLibrary.setCreator ("menusplit", new MenuSplitCreator ());
// JRadioButtonMenuItem
tagLibrary.setCreator ("radiobuttonmenuitem", DefaultCreator.getCreator (JRadioButtonMenuItem.class));
tagLibrary.inheritTag (ABSTRACT_BUTTON, "radiobuttonmenuitem");
// JCheckBoxMenuItem
tagLibrary.setCreator ("checkboxmenuitem", DefaultCreator.getCreator (JCheckBoxMenuItem.class));
tagLibrary.inheritTag (ABSTRACT_BUTTON, "checkboxmenuitem");
// JSeparator
tagLibrary.setCreator ("separator", DefaultCreator.getCreator (JSeparator.class));
tagLibrary.inheritTag (COMPONENT, "separator");
tagLibrary.setSetter ("separator", "orientation", swingConstantsSetter);
// JToolBar
tagLibrary.setCreator ("toolbar", DefaultCreator.getCreator (JToolBar.class));
tagLibrary.inheritTag (COMPONENT, "toolbar");
tagLibrary.setSetter ("toolbar", "orientation", swingConstantsSetter);
// JToolBar.Separator
tagLibrary.setCreator ("toolbar-separator", DefaultCreator.getCreator (JToolBar.Separator.class));
tagLibrary.inheritTag (COMPONENT, "toolbar-separator");
// JButton
tagLibrary.setCreator ("button", DefaultCreator.getCreator (JButton.class));
tagLibrary.inheritTag (ABSTRACT_BUTTON, "button");
// JToggleButton
tagLibrary.setCreator ("togglebutton", DefaultCreator.getCreator (JToggleButton.class));
tagLibrary.inheritTag (ABSTRACT_BUTTON, "togglebutton");
// JRadioButton
tagLibrary.setCreator ("radiobutton", DefaultCreator.getCreator (JRadioButton.class));
tagLibrary.inheritTag (ABSTRACT_BUTTON, "radiobutton");
// JCheckBox
tagLibrary.setCreator ("checkbox", DefaultCreator.getCreator (JCheckBox.class));
tagLibrary.inheritTag (ABSTRACT_BUTTON, "checkbox");
// ButtonGroup
tagLibrary.setCreator ("buttongroup", DefaultCreator.getCreator (ButtonGroup.class));
// syncbuttonstate
tagLibrary.setCreator ("syncbuttonstate", HelperCreator.getCreator (SyncButtonStateHelper.class));
// JLabel
tagLibrary.setCreator ("label", DefaultCreator.getCreator (JLabel.class));
tagLibrary.inheritTag (COMPONENT, "label");
tagLibrary.setSetter ("label", "horizontalalignment", swingConstantsSetter);
tagLibrary.setSetter ("label", "horizontaltextposition", swingConstantsSetter);
tagLibrary.setSetter ("label", "displayedmnemonic", mnemonicConstantSetter);
tagLibrary.setSetter ("label", "verticalalignment", swingConstantsSetter);
tagLibrary.setSetter ("label", "verticaltextposition", swingConstantsSetter);
tagLibrary.setSetter ("label", "labelfor", new LabelForSetter ());
// JTextField
tagLibrary.setCreator (TEXTFIELD, DefaultCreator.getCreator (JTextField.class));
tagLibrary.inheritTag (TEXTCOMPONENT, TEXTFIELD);
tagLibrary.setSetter (TEXTFIELD, "horizontalalignment", swingConstantsSetter);
// JFormattedTextField
tagLibrary.setCreator ("formattedtextfield", new FormattedTextFieldCreator ());
tagLibrary.addAdder ("formattedtextfield", new FormatterAdder ());
tagLibrary.inheritTag (TEXTFIELD, "formattedtextfield");
tagLibrary.setSetter ("formattedtextfield", "focuslostbehavior", new ConstantSetter (JFormattedTextField.class));
// JPasswordField
tagLibrary.setCreator ("passwordfield", DefaultCreator.getCreator (JPasswordField.class));
tagLibrary.inheritTag (TEXTFIELD, "passwordfield");
// JTextArea
tagLibrary.setCreator ("textarea", DefaultCreator.getCreator (JTextArea.class));
tagLibrary.inheritTag (TEXTCOMPONENT, "textarea");
// JTextPane
tagLibrary.setCreator ("textpane", DefaultCreator.getCreator (JTextPane.class));
tagLibrary.inheritTag (TEXTCOMPONENT, "textpane");
// JEditorPane
tagLibrary.setCreator ("editorpane", DefaultCreator.getCreator (JEditorPane.class));
tagLibrary.inheritTag (TEXTCOMPONENT, "editorpane");
// JPanel
tagLibrary.setCreator ("panel", DefaultCreator.getCreator (JPanel.class));
tagLibrary.inheritTag (COMPONENT, "panel");
// JDesktopPane
tagLibrary.setCreator ("desktoppane", DefaultCreator.getCreator (JDesktopPane.class));
tagLibrary.inheritTag (COMPONENT, "desktoppane");
// JSplitPane
tagLibrary.setCreator ("splitpane", DefaultCreator.getCreator (JSplitPane.class));
tagLibrary.inheritTag (COMPONENT, "splitpane");
tagLibrary.setSetter ("splitpane", "orientation", new ConstantSetter (JSplitPane.class));
tagLibrary.addAdder ("splitpane", new SplitPaneAdder ());
// JScrollPane
tagLibrary.setCreator ("scrollpane", DefaultCreator.getCreator (JScrollPane.class));
tagLibrary.inheritTag (COMPONENT, "scrollpane");
tagLibrary.addAdder ("scrollpane", CallFunctionAdder.getAdder ("setViewportView", JScrollPane.class, Component.class));
ConstantSetter scrollPaneConstantSetter = new ConstantSetter (ScrollPaneConstants.class);
tagLibrary.setSetter ("scrollpane", "horizontalscrollbarpolicy", scrollPaneConstantSetter);
tagLibrary.setSetter ("scrollpane", "verticalscrollbarpolicy", scrollPaneConstantSetter);
// JRootPane
tagLibrary.setCreator ("rootpane", DefaultCreator.getCreator (JRootPane.class));
tagLibrary.inheritTag (COMPONENT, "rootpane");
tagLibrary.addAdder ("rootpane", contentPaneAdder);
tagLibrary.addAdder ("rootpane", menuBarAdder);
// JTabbedPane
tagLibrary.inheritTag (COMPONENT, "tabbedpane");
tagLibrary.setCreator ("tabbedpane", DefaultCreator.getCreator (JTabbedPane.class));
tagLibrary.setSetter ("tabbedpane", "tablayoutpolicy", new ConstantSetter (JTabbedPane.class));
tagLibrary.setSetter ("tabbedpane", "tabplacement", swingConstantsSetter);
// tab in JTabbedPane
tagLibrary.setCreator ("tab", DefaultCreator.getCreator (TabHelper.class));
tagLibrary.addAdder ("tab", new TabAdder ());
tagLibrary.setSetter ("tab", "mnemonic", mnemonicConstantSetter);
// JFileChooser
tagLibrary.setCreator ("filechooser", DefaultCreator.getCreator (JFileChooser.class));
tagLibrary.inheritTag (COMPONENT, "filechooser");
ConstantSetter fileChooserConstantSetter = new ConstantSetter (JFileChooser.class);
tagLibrary.setSetter ("filechooser", "fileselectionmode", fileChooserConstantSetter);
tagLibrary.setSetter ("filechooser", "dialogtype", fileChooserConstantSetter);
tagLibrary.setSetter ("filechooser", "approvedbuttonmnemonic", mnemonicConstantSetter);
// JColorChooser
tagLibrary.setCreator ("colorchooser", DefaultCreator.getCreator (JColorChooser.class));
tagLibrary.inheritTag (COMPONENT, "colorchooser");
// JTable
// The reason that table is added to parent object after everything inside table has
// been set up is because TableModel can affect the table header, which would in turn
// affect the parent object if it scrollpane.
tagLibrary.setCreator ("table", DefaultCreator.getCreator (JTable.class, true));
tagLibrary.inheritTag (COMPONENT, "table");
tagLibrary.setSetter ("table", "autoresizemode", new ConstantSetter (JTable.class));
tagLibrary.setSetter ("table", "selectionmode", listSelectionModeConstantsSetter);
tagLibrary.setSetter ("table", "listselectionlistener", new ListSelectionListenerSetter ());
tagLibrary.addAdder ("table", CallFunctionAdder.getAdder ("setModel", JTable.class, TableModel.class));
tagLibrary.setCreator ("defaulttablemodel", DefaultCreator.getCreator (DefaultTableModel.class));
Utils.addListenerSetter (tagLibrary, "defaulttablemodel", TableModelListener.class);
tagLibrary.setAdder ("defaulttablemodel", new DefaultTableModelAdder ());
// JTableHeader
tagLibrary.setCreator ("tableheader", new TableHeaderCreator ());
tagLibrary.inheritTag (COMPONENT, "tableheader");
// JList
tagLibrary.setCreator ("list", DefaultCreator.getCreator (JList.class));
tagLibrary.inheritTag (COMPONENT, "list");
tagLibrary.setSetter ("list", "layoutorientation", new ConstantSetter (JList.class));
tagLibrary.setSetter ("list", "selectionmode", listSelectionModeConstantsSetter);
tagLibrary.addAdder ("list", CallFunctionAdder.getAdder ("setModel", JList.class, ListModel.class));
tagLibrary.setCreator ("defaultlistmodel", DefaultCreator.getCreator (DefaultListModel.class));
Utils.addListenerSetter (tagLibrary, "defaultlistmodel", ListDataListener.class);
tagLibrary.addAdder ("defaultlistmodel", CallFunctionAdder.getAdder ("addElement", DefaultListModel.class, null));
// JTree
tagLibrary.setCreator ("tree", DefaultCreator.getCreator (JTree.class));
tagLibrary.inheritTag (COMPONENT, "tree");
// JComboBox
tagLibrary.setCreator ("combobox", DefaultCreator.getCreator (JComboBox.class));
tagLibrary.inheritTag (COMPONENT, "combobox");
tagLibrary.addAdder ("combobox", CallFunctionAdder.getAdder ("addItem", JComboBox.class, null));
tagLibrary.addAdder ("combobox", CallFunctionAdder.getAdder ("setModel", JComboBox.class, ComboBoxModel.class));
tagLibrary.setCreator ("defaultcomboboxmodel", DefaultCreator.getCreator (DefaultComboBoxModel.class));
tagLibrary.addAdder ("defaultcomboboxmodel", CallFunctionAdder.getAdder ("addElement", DefaultComboBoxModel.class, null));
Utils.addListenerSetter (tagLibrary, "defaultcomboboxmodel", ListDataListener.class);
// JProgressBar
tagLibrary.setCreator ("progressbar", DefaultCreator.getCreator (JProgressBar.class));
tagLibrary.inheritTag (COMPONENT, "progressbar");
tagLibrary.setSetter ("progressbar", "orientation", swingConstantsSetter);
// JScrollBar
tagLibrary.setCreator ("scrollbar", DefaultCreator.getCreator (JScrollBar.class));
tagLibrary.inheritTag (COMPONENT, "scrollbar");
tagLibrary.setSetter ("scrollbar", "orientation", swingConstantsSetter);
// JSlider
tagLibrary.setCreator ("slider", DefaultCreator.getCreator (JSlider.class));
tagLibrary.inheritTag (COMPONENT, "slider");
tagLibrary.setSetter ("slider", "orientation", swingConstantsSetter);
// JSpinner
tagLibrary.setCreator ("spinner", DefaultCreator.getCreator (JSpinner.class));
tagLibrary.inheritTag (COMPONENT, "spinner");
tagLibrary.addAdder ("spinner", CallFunctionAdder.getAdder ("setModel", JSpinner.class, SpinnerModel.class));
tagLibrary.addAdder ("spinner", CallFunctionAdder.getAdder ("setEditor", JSpinner.class, JComponent.class));
tagLibrary.setCreator ("spinner-defaulteditor", new SpinnerEditorCreator (JSpinner.DefaultEditor.class));
tagLibrary.setCreator ("spinner-listeditor", new SpinnerEditorCreator (JSpinner.ListEditor.class));
tagLibrary.setCreator ("spinner-dateeditor", new SpinnerEditorCreator (JSpinner.DateEditor.class));
tagLibrary.setSetter ("spinner-dateeditor", "format", DoNothingSetter.getInstance ());
tagLibrary.setCreator ("spinner-numbereditor", new SpinnerEditorCreator (JSpinner.NumberEditor.class));
tagLibrary.setSetter ("spinner-numbereditor", "format", DoNothingSetter.getInstance ());
// SpinnerModel
tagLibrary.setCreator ("spinnerdatemodel", DefaultCreator.getCreator (SpinnerDateModel.class));
tagLibrary.setSetter ("spinnerdatemodel", "calendarfield", new ConstantSetter (Calendar.class));
tagLibrary.setCreator ("spinnerlistmodel", DefaultCreator.getCreator (SpinnerListModel.class));
tagLibrary.addAdder ("spinnerlistmodel", new CallFunctionAdder ("setList", SpinnerListModel.class, java.util.List.class));
tagLibrary.setCreator ("spinnernumbermodel", DefaultCreator.getCreator (SpinnerNumberModel.class));
// JToolTip
tagLibrary.setCreator ("tooltip", DefaultCreator.getCreator (JToolTip.class));
tagLibrary.inheritTag (COMPONENT, "tooltip");
//
// Misc
//
// BevelBorder
tagLibrary.setCreator ("bevelborder", HelperCreator.getCreator (BevelBorderHelper.class));
tagLibrary.setSetter ("bevelborder", "type", new ConstantSetter (BevelBorder.class));
// CompoundBorder
tagLibrary.setCreator ("compoundborder", HelperCreator.getCreator (CompoundBorderHelper.class));
// EmptyBorder
tagLibrary.setCreator ("emptyborder", HelperCreator.getCreator (EmptyBorderHelper.class));
// EtchedBorder
tagLibrary.setCreator ("etchedborder", HelperCreator.getCreator (EtchedBorderHelper.class));
tagLibrary.setSetter ("etchedborder", "type", new ConstantSetter (EtchedBorder.class));
// LineBorder
tagLibrary.setCreator ("lineborder", HelperCreator.getCreator (LineBorderHelper.class));
// MatteBorder
tagLibrary.setCreator ("matteborder", HelperCreator.getCreator (MatteBorderHelper.class));
// TitledBorder
tagLibrary.setCreator ("titledborder", HelperCreator.getCreator (TitledBorderHelper.class));
ConstantSetter titledBorderConstantsSetter = new ConstantSetter (TitledBorder.class);
tagLibrary.setSetter ("titledborder", "titlejustification", titledBorderConstantsSetter);
tagLibrary.setSetter ("titledborder", "titleposition", titledBorderConstantsSetter);
tagLibrary.setCreator ("clientproperty", DefaultCreator.getCreator (ClientPropertyHelper.class, true));
Adder layoutComponentAdder = new LayoutComponentAdder ();
// BorderLayout
tagLibrary.setCreator ("borderlayout", DefaultCreator.getCreator (BorderLayout.class));
// BoxLayout
tagLibrary.setCreator ("boxlayout", new BoxLayoutCreator ());
tagLibrary.addAdder ("boxlayout", layoutComponentAdder);
tagLibrary.setSetter ("boxlayout", "ctor", DoNothingSetter.getInstance ());
// Cardlayout
tagLibrary.setCreator ("cardlayout", DefaultCreator.getCreator (CardLayout.class));
// constraint for BorderLayout, CardLayout and OverlayLayout
tagLibrary.setCreator ("constraint", DefaultCreator.getCreator (Constraint.class));
tagLibrary.addAdder ("constraint", new LayoutConstraintAdder ());
// FLowLayout
tagLibrary.setCreator ("flowlayout", DefaultCreator.getCreator (FlowLayout.class));
tagLibrary.addAdder ("flowlayout", layoutComponentAdder);
tagLibrary.setSetter ("flowlayout", "alignment", new ConstantSetter (FlowLayout.class));
// GridBagLayout
tagLibrary.setCreator ("gridbaglayout", DefaultCreator.getCreator (GridBagLayout.class));
tagLibrary.addAdder ("gridbaglayout", DoNothingAdder.getInstance());
tagLibrary.setCreator ("gridbagconstraints", DefaultCreator.getCreator (GridBagConstraints.class));
ConstantSetter gridbagConstantsSetter = new ConstantSetter (GridBagConstraints.class);
tagLibrary.setSetter ("gridbagconstraints", "fill", gridbagConstantsSetter);
tagLibrary.setSetter ("gridbagconstraints", "anchor", gridbagConstantsSetter);
tagLibrary.setSetter ("gridbagconstraints", "gridwidth", gridbagConstantsSetter);
tagLibrary.addAdder ("gridbagconstraints", new GridBagLayoutConstraintsAdder ());
// GridLayout
tagLibrary.setCreator ("gridlayout", DefaultCreator.getCreator (GridLayout.class));
tagLibrary.addAdder ("gridlayout", layoutComponentAdder);
// OverlayLayout
tagLibrary.setCreator ("overlaylayout", new OverlayLayoutCreator ());
// SpringLayout
tagLibrary.setCreator ("springlayout", DefaultCreator.getCreator (SpringLayout.class));
tagLibrary.addAdder ("springlayout", new SpringLayoutAdder ());
tagLibrary.setCreator ("springconstraint", DefaultCreator.getCreator (SpringConstraintHelper.class, true));
tagLibrary.setCreator ("spring", new SpringCreator ());
tagLibrary.setConverter (Spring.class, new SpringConverter ());
tagLibrary.setCreator ("springgridlayout", new SpringGridCreator ());
// formatters for JFormattedTextField
tagLibrary.setCreator ("defaultformatterfactory", DefaultCreator.getCreator (DefaultFormatterFactory.class, true));
tagLibrary.setCreator ("defaultformatter", DefaultCreator.getCreator (DefaultFormatter.class, true));
tagLibrary.setCreator ("maskformatter", DefaultCreator.getCreator (MaskFormatter.class, true));
tagLibrary.setCreator ("internationalformatter", DefaultCreator.getCreator (InternationalFormatter.class, true));
tagLibrary.addAdder ("internationalformatter", CallFunctionAdder.getAdder ("setFormat", InternationalFormatter.class, Format.class));
tagLibrary.setCreator ("dateformatter", DefaultCreator.getCreator (DateFormatter.class, true));
tagLibrary.addAdder ("dateformatter", CallFunctionAdder.getAdder ("setFormat", DateFormatter.class, DateFormat.class));
tagLibrary.setCreator ("numberformatter", DefaultCreator.getCreator (NumberFormatter.class, true));
tagLibrary.addAdder ("numberformatter", CallFunctionAdder.getAdder ("setFormat", NumberFormatter.class, NumberFormat.class));
//
// listeners
//
// there are too many damn listeners around, it is not possible find out what each does.
// it may be tedious for custom tags to consider them as well, so put them all under
// one internal tag
//
// awt listeners
Utils.addListenerSetter (commonTagLibrary, CommonLib.LISTENERS, ActionListener.class);
Utils.addListenerSetter (commonTagLibrary, CommonLib.LISTENERS, AdjustmentListener.class);
Utils.addListenerSetter (commonTagLibrary, CommonLib.LISTENERS, AWTEventListener.class);
Utils.addListenerSetter (commonTagLibrary, CommonLib.LISTENERS, ComponentListener.class);
Utils.addListenerSetter (commonTagLibrary, CommonLib.LISTENERS, ContainerListener.class);
Utils.addListenerSetter (commonTagLibrary, CommonLib.LISTENERS, FocusListener.class);
Utils.addListenerSetter (commonTagLibrary, CommonLib.LISTENERS, HierarchyBoundsListener.class);
Utils.addListenerSetter (commonTagLibrary, CommonLib.LISTENERS, HierarchyListener.class);
Utils.addListenerSetter (commonTagLibrary, CommonLib.LISTENERS, InputMethodListener.class);
Utils.addListenerSetter (commonTagLibrary, CommonLib.LISTENERS, ItemListener.class);
Utils.addListenerSetter (commonTagLibrary, CommonLib.LISTENERS, KeyListener.class);
Utils.addListenerSetter (commonTagLibrary, CommonLib.LISTENERS, MouseListener.class);
Utils.addListenerSetter (commonTagLibrary, CommonLib.LISTENERS, MouseMotionListener.class);
Utils.addListenerSetter (commonTagLibrary, CommonLib.LISTENERS, MouseWheelListener.class);
Utils.addListenerSetter (commonTagLibrary, CommonLib.LISTENERS, TextListener.class);
Utils.addListenerSetter (commonTagLibrary, CommonLib.LISTENERS, WindowFocusListener.class);
Utils.addListenerSetter (commonTagLibrary, CommonLib.LISTENERS, WindowListener.class);
Utils.addListenerSetter (commonTagLibrary, CommonLib.LISTENERS, WindowStateListener.class);
// bean listeners
Utils.addListenerSetter (commonTagLibrary, CommonLib.LISTENERS, ExceptionListener.class);
Utils.addListenerSetter (commonTagLibrary, CommonLib.LISTENERS, VetoableChangeListener.class);
// swing listeners
Utils.addListenerSetter (commonTagLibrary, CommonLib.LISTENERS, AncestorListener.class);
Utils.addListenerSetter (commonTagLibrary, CommonLib.LISTENERS, CaretListener.class);
Utils.addListenerSetter (commonTagLibrary, CommonLib.LISTENERS, CellEditorListener.class);
Utils.addListenerSetter (commonTagLibrary, CommonLib.LISTENERS, ChangeListener.class);
Utils.addListenerSetter (commonTagLibrary, CommonLib.LISTENERS, DocumentListener.class);
Utils.addListenerSetter (commonTagLibrary, CommonLib.LISTENERS, HyperlinkListener.class);
Utils.addListenerSetter (commonTagLibrary, CommonLib.LISTENERS, InternalFrameListener.class);
Utils.addListenerSetter (commonTagLibrary, CommonLib.LISTENERS, ListDataListener.class);
Utils.addListenerSetter (commonTagLibrary, CommonLib.LISTENERS, ListSelectionListener.class);
Utils.addListenerSetter (commonTagLibrary, CommonLib.LISTENERS, MenuDragMouseListener.class);
Utils.addListenerSetter (commonTagLibrary, CommonLib.LISTENERS, MenuKeyListener.class);
Utils.addListenerSetter (commonTagLibrary, CommonLib.LISTENERS, MenuListener.class);
Utils.addListenerSetter (commonTagLibrary, CommonLib.LISTENERS, MouseInputListener.class);
Utils.addListenerSetter (commonTagLibrary, CommonLib.LISTENERS, PopupMenuListener.class);
Utils.addListenerSetter (commonTagLibrary, CommonLib.LISTENERS, TableColumnModelListener.class);
Utils.addListenerSetter (commonTagLibrary, CommonLib.LISTENERS, TableModelListener.class);
Utils.addListenerSetter (commonTagLibrary, CommonLib.LISTENERS, TreeExpansionListener.class);
Utils.addListenerSetter (commonTagLibrary, CommonLib.LISTENERS, TreeModelListener.class);
Utils.addListenerSetter (commonTagLibrary, CommonLib.LISTENERS, TreeSelectionListener.class);
Utils.addListenerSetter (commonTagLibrary, CommonLib.LISTENERS, TreeWillExpandListener.class);
Utils.addListenerSetter (commonTagLibrary, CommonLib.LISTENERS, UndoableEditListener.class);
// window_group
tagLibrary.setSetter (WINDOW_GROUP, "defaultcloseoperation", new ConstantSetter (WindowConstants.class));
tagLibrary.setSetter (WINDOW_GROUP, "packed", DoNothingSetter.getInstance ());
tagLibrary.setSetter (WINDOW_GROUP, "locationrelativeto", DoNothingSetter.getInstance ());
tagLibrary.addAdder (WINDOW_GROUP, contentPaneAdder);
tagLibrary.addAdder (WINDOW_GROUP, menuBarAdder);
tagLibrary.inheritTag (CommonLib.NAMESPACE, CommonLib.LISTENERS, WINDOW_GROUP);
// JComponent
tagLibrary.setCreator (COMPONENT, DefaultCreator.getCreator (JComponent.class));
tagLibrary.inheritTag (CommonLib.NAMESPACE, CommonLib.LISTENERS, COMPONENT);
tagLibrary.addAdder (COMPONENT, CallFunctionAdder.getAdder ("add", Container.class, Component.class));
tagLibrary.addAdder (COMPONENT, CallFunctionAdder.getAdder ("setLayout", Container.class, LayoutManager.class));
tagLibrary.addAdder (COMPONENT, CallFunctionAdder.getAdder ("setBorder", JComponent.class, Border.class));
tagLibrary.addAdder (COMPONENT, new ClientPropertyAdder ());
// AbstractButton
tagLibrary.inheritTag (COMPONENT, ABSTRACT_BUTTON);
tagLibrary.setSetter (ABSTRACT_BUTTON, "horizontalalignment", swingConstantsSetter);
tagLibrary.setSetter (ABSTRACT_BUTTON, "horizontaltextposition", swingConstantsSetter);
tagLibrary.setSetter (ABSTRACT_BUTTON, "mnemonic", mnemonicConstantSetter);
tagLibrary.setSetter (ABSTRACT_BUTTON, "verticalalignment", swingConstantsSetter);
tagLibrary.setSetter (ABSTRACT_BUTTON, "verticaltextposition", swingConstantsSetter);
tagLibrary.setSetter (ABSTRACT_BUTTON, "action", new ObjectOrHookVariableSetter ("setAction", Action.class));
// JTextComponent
tagLibrary.setSetter (TEXTCOMPONENT, "componentorientation", componentOrientationConstantsSetter);
tagLibrary.inheritTag (COMPONENT, TEXTCOMPONENT);
}
/**
* This function creates the Swing tag library in http://cookxml.sf.net/cookswing/ namespace,
* with CookXml CommonLib tag library as its parent. This is necessary because "component" tag
* inherits "listener" tag of CookXml CommonLib. This function also inserts some additional
* setters for commonTagLibrary.
*
* @param commonTagLibrary
* The CookXml CommonLib tag library.
* @return the created CookSwing tag library.
*/
public static InheritableTagLibrary createTagLibrary (InheritableTagLibrary commonTagLibrary)
{
InheritableTagLibrary tagLibrary = new InheritableTagLibrary (commonTagLibrary);
tagLibrary.setNameSpace (NAMESPACE);
setupTags (tagLibrary, commonTagLibrary);
return tagLibrary;
}
}