|
| Components |
|
| |||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||||||
java.lang.Object | +--com.sas.swing.visuals.util.ActionUIFactory
Creates user-interface components based on action definitions. The ui-components register listeners with the actions, so that as actions are, for example, enabled and disabled, the ui-components will update accordingly, thus freeing the application from having to enable/disable multiple components per action.
A separate factory method is provided for the instantiation of each
ui-component, so that applications have the ability to use their own
ui-component subclasses. See newMenuBar() et al.
Methods that map ui-components back to the actions that they were created
from are provided, so that applications can readily resync views with
models. See getAction(JMenuBar) et al.
Sample usage:
import java.awt.*;
import javax.swing.*;
public class Test
{
public static void main (String[] args)
{
JFrame app = new JFrame();
// load actions for menu bar
ActionList menuActions = ActionResourceLoader.getActionList ("Menu");
// load actions for tool bar
ActionList toolActions = ActionResourceLoader.getActionList ("Toolbar");
// set application context on our actions, so that we can find
// ourselves from command handlers
setAppContext (menuActions, app);
setAppContext (toolActions, app);
// create menu and tool bar
ActionUIFactory auf = new ActionUIFactory ();
JMenuBar menuBar = auf.getMenuBar (menuActions);
JToolBar toolBar = auf.getToolBar (toolActions);
// add menu and toolbar to app and display it
app.setJMenuBar (menuBar);
app.getContentPane().setLayout (new BorderLayout ());
app.getContentPane().add (toolBar, BorderLayout.NORTH);
app.setSize (new Dimension (400, 400));
app.setVisible (true);
}
private static final String APP_CONTEXT = "Test";
private static void setAppContext (Action action, Object app)
{
action.putValue (APP_CONTEXT, app);
if (action instanceof ActionList)
{
java.util.List actions = ((ActionList)action).getActions();
for (int i = 0, iCount = actions.size(); i < iCount; i++)
{
if (actions.get(i) == ActionList.SEPARATOR)
continue;
setAppContext ((Action)actions.get(i), app);
}
}
}
}
public class ExitCommand extends com.sas.util.AbstractCommand
{
public void execute (Object arg)
{
Action action = (Action)arg;
System.out.println (action.getValue("TestApp"));
System.exit (0);
}
public Object clone ()
{
return null;
}
}
TODO: show dynamic example like MRU list
| Fields inherited from interface com.sas.swing.visuals.util.LayoutConstants |
DOTS_BUTTON_INSETS, EMPTY_INSETS, HGAP, HMARGIN, INDENTED_BORDER, TAB_BORDER, TEXTFIELD_INSETS, VGAP, VMARGIN |
| Fields inherited from interface javax.swing.SwingConstants |
BOTTOM, CENTER, EAST, HORIZONTAL, LEADING, LEFT, NEXT, NORTH, NORTH_EAST, NORTH_WEST, PREVIOUS, RIGHT, SOUTH, SOUTH_EAST, SOUTH_WEST, TOP, TRAILING, VERTICAL, WEST |
| Constructor Summary | |
ActionUIFactory()
|
|
| Method Summary | |
Action |
getAction(AbstractButton toolItem)
Returns the action that serves as a model to a given tool item. |
Action |
getAction(JMenuItem menuItem)
Returns the action that serves as a model to a given menu item. |
ActionList |
getActionList(JMenu menu)
Returns the list of actions that serve as a model to a given menu. |
ActionList |
getActionList(JMenuBar menuBar)
Returns the list of actions that serve as a model to a given menu bar. |
ActionList |
getActionList(JPopupMenu popupMenu)
Returns the list of actions that serve as a model to a given popup menu. |
ActionList |
getActionList(JToolBar toolBar)
Returns the list of actions that serve as a model to a given tool bar. |
AbstractButton |
getButton(Action action)
Returns a button on the given action. |
IconMap |
getIconMap()
Returns the map for accessing icons that are associated with actions. |
JMenu |
getMenu(Action action)
Returns a menu representation of the given actions. |
JMenu |
getMenu(ActionList actionList)
Returns a menu representation of the given actions. |
JMenuBar |
getMenuBar(ActionList actionList)
Returns a menu bar representation of the given actions. |
JMenuItem |
getMenuItem(Action action)
Returns a menu item based on the given action. |
JPopupMenu |
getPopupMenu(ActionList actionList)
Returns a popup menu representation of the given actions. |
ResourceLocatorInterface |
getResourceLocator()
Returns the handler for locating resources, such as images, that are associated with actions. |
AbstractButton |
getShortcutItem(Action action)
|
AbstractButton |
getShortcutItem(Action action,
boolean smallIcons)
|
AbstractButton |
getTaskItem(Action action)
Returns a task item based on the given action. |
JToolBar |
getToolBar(ActionList actionList)
Returns a tool bar representation of the given actions. |
AbstractButton |
getToolItem(Action action)
Returns a tool item based on the given action. |
void |
loadActionResources(Action action)
|
protected AbstractButton |
newButton()
Creates a new button. |
protected AbstractButton |
newButton(Action action)
Creates a new button based on a given action. |
protected AbstractButton |
newCheckBox()
Creates a new check box. |
protected JMenuItem |
newCheckBoxMenuItem()
Creates a new check box menu item. |
protected JMenu |
newMenu()
Creates a new menu. |
protected JMenuBar |
newMenuBar()
Creates a new menu bar. |
protected JMenuItem |
newMenuItem()
Creates a new menu item. |
protected JMenuItem |
newMenuItem(Action action)
Creates a new menu item based on a given action. |
protected JPopupMenu |
newPopupMenu()
Creates a new popup menu. |
protected AbstractButton |
newRadioButton()
Creates a new radio button. |
protected JMenuItem |
newRadioButtonMenuItem()
Creates a new radio button menu item. |
protected AbstractButton |
newShortcutItem(Action action)
Creates a new shortcut item based on a given action. |
protected AbstractButton |
newShortcutItem(Action action,
boolean smallIcons)
Creates a new shortcut item based on a given action. |
protected AbstractButton |
newTaskItem(Action action)
Creates a new task item based on a given action. |
protected AbstractButton |
newToggleButton()
Creates a new toggle button. |
protected JToolBar |
newToolBar()
Creates a new tool bar. |
protected AbstractButton |
newToolItem(Action action)
Creates a new tool item based on a given action. |
void |
populateMenuBar(JMenuBar menuBar,
ActionList actionList)
Populates a JMenuBar with the actions from the given ActionList. |
void |
populatePopupMenu(JPopupMenu menu,
ActionList actionList)
Populates a JPopupMenu with the action from the given ActionList. |
void |
populateToolBar(JToolBar toolBar,
ActionList actionList)
Populates a JToolBar with the action from the given ActionList. |
void |
setIconMap(IconMap iconMap)
Sets the map for accessing icons that are associated with actions. |
void |
setResourceLocator(ResourceLocatorInterface resourceLocator)
Returns the handler for locating resources, such as images, that are associated with actions. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
public ActionUIFactory()
| Method Detail |
public void populateMenuBar(JMenuBar menuBar,
ActionList actionList)
JMenuBar with the actions from the given ActionList.menuBar - the instance of the JMenuBar to have the action added toactionList - the list of actions to add to the menu bar;
each top-level item in actionList.getActions() must
itself be an ActionListpublic JMenuBar getMenuBar(ActionList actionList)
New JMenuBar instances are created using the factory method
newMenuBar() so that an application may override and
create a JMenuBar subclass.
actionList - the list of actions to add to the menu bar;
each top-level item in actionList.getActions() must
itself be an ActionListJMenuBar; will never be nullnewMenuBar()public JMenu getMenu(ActionList actionList)
New JMenu instances are created using the factory method
newMenu() so that an application may override and
create a JMenu subclass.
actionList - the list of actions to add to the menuJMenu; will never be nullnewMenu()public JMenu getMenu(Action action)
New JMenu instances are created using the factory method
newMenu() so that an application may override and
create a JMenu subclass.
actionList - the list of actions to add to the menuJMenu; will never be nullnewMenu()
public void populatePopupMenu(JPopupMenu menu,
ActionList actionList)
JPopupMenu with the action from the given ActionList.menu - the instance of the JPopupMenu to have the action added toactionList - the list of actions to add to the menu bar;
each top-level item in actionList.getActions() must
itself be an ActionListpublic JPopupMenu getPopupMenu(ActionList actionList)
New JPopupMenu instances are created using the factory method
newPopupMenu() so that an application may override and
create a JPopupMenu subclass.
actionList - the list of actions to add to the menuJPopupMenu; will never be nullnewPopupMenu()public JMenuItem getMenuItem(Action action)
The determination, creation, and customization of the menu item is
delegated to the factory method newMenuItem(Action).
action - the action to create a menu item forJMenuItem; will never be nullnewMenuItem(Action)
public void populateToolBar(JToolBar toolBar,
ActionList actionList)
JToolBar with the action from the given ActionList.toolBar - the instance of the JToolBar to have the action added toactionList - the list of actions to add to the menu bar;
each top-level item in actionList.getActions() must
itself be an ActionListpublic JToolBar getToolBar(ActionList actionList)
New JToolBar instances are created using the factory method
newToolBar() so that an application may override and
create a JToolBar subclass.
actionList - the list of actions to add to the tool barJToolBar; will never be nullnewToolBar()public AbstractButton getButton(Action action)
The determination, creation, and customization of the button is
delegated to the factory method newButton(Action).
action - the action to create a button forAbstractButton; will never be nullnewButton(Action)public AbstractButton getToolItem(Action action)
The determination, creation, and customization of the tool item is
delegated to the factory method newToolItem(Action).
action - the action to create a tool item forAbstractButton; will never be nullnewToolItem(Action)public AbstractButton getTaskItem(Action action)
The determination, creation, and customization of the task item is
delegated to the factory method newTaskItem(Action).
action - the action to create a tool item forAbstractButton; will never be nullnewTaskItem(Action)public AbstractButton getShortcutItem(Action action)
public AbstractButton getShortcutItem(Action action,
boolean smallIcons)
public ActionList getActionList(JMenuBar menuBar)
menuBar - a JMenuBar from getMenuBar()ActionList or null if the menu bar
is not from getMenuBar()public ActionList getActionList(JPopupMenu popupMenu)
popupMenu - a JPopupMenu from getPopupMenu()ActionList or null if the menu
is not from getPopupMenu()public ActionList getActionList(JMenu menu)
Convenience method for (ActionList)menu.getAction().
menu - a JMenu from getMenu()ActionList or null if the menu
is not from getMenu()public Action getAction(JMenuItem menuItem)
Convenience method for (Action)menuItem.getAction().
menuItem - a JMenuItem from getMenuItem()Action or null if the menu item
is not from getMenuItem()public ActionList getActionList(JToolBar toolBar)
toolBar - a JToolBar from getToolBar()ActionList or null if the tool bar
is not from getToolBar()public Action getAction(AbstractButton toolItem)
Convenience method for (Action)toolItem.getAction().
toolItem - a AbstractButton from getToolItem()Action or null if the tool item
is not from getToolItem()public ResourceLocatorInterface getResourceLocator()
ResourceLocatorInterface or nullsetResourceLocator(com.sas.net.ResourceLocatorInterface)public IconMap getIconMap()
IconMap or nullsetIconMap(com.sas.swing.visuals.util.IconMap)public void setIconMap(IconMap iconMap)
iconMap - an instance of IconMap or nullgetIconMap()public void setResourceLocator(ResourceLocatorInterface resourceLocator)
Action.getValue(Action.SMALL_ICON_NAME), for example,
returns the name of an icon. The resource locator will be used to
locate and load the image identified by the name, so that a
javax.swing.Icon can be created for the corresponding
menu or tool item.
resourceLocator - an instance of ResourceLocatorInterface or nullgetResourceLocator()protected JMenuBar newMenuBar()
JMenuBarprotected JPopupMenu newPopupMenu()
JPopupMenuprotected JMenu newMenu()
JMenuprotected JMenuItem newMenuItem(Action action)
If the action's type property, Action.TYPE, is
set to Action.TYPE_BOOLEAN, then
a check box menu item is created instead of a regular menu item.
If in addition to the type being boolean, the action's group name
property, Action.GROUP_NAME, is set, then a
radio button menu item is created instead of a check box menu item.
New regular menu items, check box menu items, and radio button menu
items are created using the factory methods newMenuItem(),
newCheckBoxMenuItem and newRadioButtonMenuItem,
respectively, so that an application may override and
create subclasses of those.
action - the action to create a menu item forJMenuItemnewMenuItem(com.sas.swing.util.Action),
newCheckBoxMenuItem(),
newRadioButtonMenuItem()protected JMenuItem newMenuItem()
JMenuItemprotected JMenuItem newCheckBoxMenuItem()
javax.swing.JCheckBoxMenuItemprotected JMenuItem newRadioButtonMenuItem()
javax.swing.JRadioButtonMenuItemprotected JToolBar newToolBar()
JToolBarprotected AbstractButton newTaskItem(Action action)
If the action's type property, Action.TYPE, is
set to Action.TYPE_BOOLEAN, then
a check box is created instead of a regular button.
If in addition to the type being boolean, the action's group name
property, Action.GROUP_NAME, is set, then a
radio button is created instead of a check box.
The item's text will be set from Action.LONG_NAME,
if available, and from Action.NAME otherwise.
New buttons, check boxes, and radio buttons
are created using the factory methods newButton(),
newCheckBox and newRadioButton,
respectively, so that an application may override and
create subclasses of those.
action - the action to create a task item forAbstractButtonnewButton(com.sas.swing.util.Action),
newCheckBox(),
newRadioButton()protected AbstractButton newToolItem(Action action)
If the action's type property, Action.TYPE, is
set to Action.TYPE_BOOLEAN, then
a check box is created instead of a regular button.
If in addition to the type being boolean, the action's group name
property, Action.GROUP_NAME, is set, then a
radio button is created instead of a check box.
New buttons, check boxes, and radio buttons
are created using the factory methods newButton(),
newCheckBox and newRadioButton,
respectively, so that an application may override and
create subclasses of those.
action - the action to create a tool item forAbstractButtonnewButton(com.sas.swing.util.Action),
newCheckBox(),
newRadioButton()protected AbstractButton newButton(Action action)
If the action's type property, Action.TYPE, is
set to Action.TYPE_BOOLEAN, then
a toggle button is created instead of a regular button.
New buttons and toggle buttons
are created using the factory methods newButton() and
newToggleBox.
respectively, so that an application may override and
create subclasses of those.
action - the action to create a tool item forAbstractButtonnewButton(com.sas.swing.util.Action),
newToggleButton()protected AbstractButton newButton()
javax.swing.JButtonprotected AbstractButton newCheckBox()
javax.swing.JCheckBoxprotected AbstractButton newRadioButton()
javax.swing.JRadioButtonprotected AbstractButton newToggleButton()
javax.swing.JToggleButtonprotected AbstractButton newShortcutItem(Action action)
The item's text will be set from Action.LARGE_ICON,
if available, and from Action.SMALL_ICON otherwise.
New buttons
are created using the factory method newButton(),
so that an application may override and
create a button subclass.
action - the action to create a shortcut item forAbstractButtonnewButton(com.sas.swing.util.Action)
protected AbstractButton newShortcutItem(Action action,
boolean smallIcons)
The item's text will be set from Action.LARGE_ICON,
if available, and from Action.SMALL_ICON otherwise.
New buttons
are created using the factory method newButton(),
so that an application may override and
create a button subclass.
action - the action to create a shortcut item forAbstractButtonnewButton(com.sas.swing.util.Action)public void loadActionResources(Action action)
action -
|
| Components |
|
| |||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||||||