|
Components |
|
| |||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
com.sas.swing.visuals.util.ActionUIFactory
public class 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
Field Summary |
---|
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 |
Constructor Summary | |
---|---|
ActionUIFactory()
|
Method Summary | |
---|---|
com.sas.swing.util.Action |
getAction(javax.swing.AbstractButton toolItem)
Returns the action that serves as a model to a given tool item. |
com.sas.swing.util.Action |
getAction(javax.swing.JMenuItem menuItem)
Returns the action that serves as a model to a given menu item. |
com.sas.swing.util.ActionList |
getActionList(javax.swing.JMenu menu)
Returns the list of actions that serve as a model to a given menu. |
com.sas.swing.util.ActionList |
getActionList(javax.swing.JMenuBar menuBar)
Returns the list of actions that serve as a model to a given menu bar. |
com.sas.swing.util.ActionList |
getActionList(javax.swing.JPopupMenu popupMenu)
Returns the list of actions that serve as a model to a given popup menu. |
com.sas.swing.util.ActionList |
getActionList(javax.swing.JToolBar toolBar)
Returns the list of actions that serve as a model to a given tool bar. |
javax.swing.AbstractButton |
getButton(com.sas.swing.util.Action action)
Returns a button on the given action. |
IconMap |
getIconMap()
Returns the map for accessing icons that are associated with actions. |
javax.swing.JMenu |
getMenu(com.sas.swing.util.Action action)
Returns a menu representation of the given actions. |
javax.swing.JMenu |
getMenu(com.sas.swing.util.ActionList actionList)
Returns a menu representation of the given actions. |
javax.swing.JMenuBar |
getMenuBar(com.sas.swing.util.ActionList actionList)
Returns a menu bar representation of the given actions. |
javax.swing.JMenuItem |
getMenuItem(com.sas.swing.util.Action action)
Returns a menu item based on the given action. |
javax.swing.JPopupMenu |
getPopupMenu(com.sas.swing.util.ActionList actionList)
Returns a popup menu representation of the given actions. |
com.sas.net.ResourceLocatorInterface |
getResourceLocator()
Returns the handler for locating resources, such as images, that are associated with actions. |
javax.swing.AbstractButton |
getShortcutItem(com.sas.swing.util.Action action)
|
javax.swing.AbstractButton |
getShortcutItem(com.sas.swing.util.Action action,
boolean smallIcons)
|
javax.swing.AbstractButton |
getTaskItem(com.sas.swing.util.Action action)
Returns a task item based on the given action. |
javax.swing.JToolBar |
getToolBar(com.sas.swing.util.ActionList actionList)
Returns a tool bar representation of the given actions. |
javax.swing.AbstractButton |
getToolItem(com.sas.swing.util.Action action)
Returns a tool item based on the given action. |
void |
loadActionResources(com.sas.swing.util.Action action)
|
protected javax.swing.AbstractButton |
newButton()
Creates a new button. |
protected javax.swing.AbstractButton |
newButton(com.sas.swing.util.Action action)
Creates a new button based on a given action. |
protected javax.swing.AbstractButton |
newCheckBox()
Creates a new check box. |
protected javax.swing.JMenuItem |
newCheckBoxMenuItem()
Creates a new check box menu item. |
protected javax.swing.JMenu |
newMenu()
Creates a new menu. |
protected javax.swing.JMenuBar |
newMenuBar()
Creates a new menu bar. |
protected javax.swing.JMenuItem |
newMenuItem()
Creates a new menu item. |
protected javax.swing.JMenuItem |
newMenuItem(com.sas.swing.util.Action action)
Creates a new menu item based on a given action. |
protected javax.swing.JPopupMenu |
newPopupMenu()
Creates a new popup menu. |
protected javax.swing.AbstractButton |
newRadioButton()
Creates a new radio button. |
protected javax.swing.JMenuItem |
newRadioButtonMenuItem()
Creates a new radio button menu item. |
protected javax.swing.AbstractButton |
newShortcutItem(com.sas.swing.util.Action action)
Creates a new shortcut item based on a given action. |
protected javax.swing.AbstractButton |
newShortcutItem(com.sas.swing.util.Action action,
boolean smallIcons)
Creates a new shortcut item based on a given action. |
protected javax.swing.AbstractButton |
newTaskItem(com.sas.swing.util.Action action)
Creates a new task item based on a given action. |
protected javax.swing.AbstractButton |
newToggleButton()
Creates a new toggle button. |
protected javax.swing.JToolBar |
newToolBar()
Creates a new tool bar. |
protected javax.swing.AbstractButton |
newToolItem(com.sas.swing.util.Action action)
Creates a new tool item based on a given action. |
void |
populateMenuBar(javax.swing.JMenuBar menuBar,
com.sas.swing.util.ActionList actionList)
Populates a JMenuBar with the actions from the given ActionList . |
void |
populatePopupMenu(javax.swing.JPopupMenu menu,
com.sas.swing.util.ActionList actionList)
Populates a JPopupMenu with the action from the given ActionList . |
void |
populateToolBar(javax.swing.JToolBar toolBar,
com.sas.swing.util.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(com.sas.net.ResourceLocatorInterface resourceLocator)
Returns the handler for locating resources, such as images, that are associated with actions. |
Constructor Detail |
---|
public ActionUIFactory()
Method Detail |
---|
public void populateMenuBar(javax.swing.JMenuBar menuBar, com.sas.swing.util.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 ActionList
public javax.swing.JMenuBar getMenuBar(com.sas.swing.util.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 ActionList
JMenuBar
; will never be null
newMenuBar()
public javax.swing.JMenu getMenu(com.sas.swing.util.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 menu
JMenu
; will never be null
newMenu()
public javax.swing.JMenu getMenu(com.sas.swing.util.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 menu
JMenu
; will never be null
newMenu()
public void populatePopupMenu(javax.swing.JPopupMenu menu, com.sas.swing.util.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 ActionList
public javax.swing.JPopupMenu getPopupMenu(com.sas.swing.util.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 menu
JPopupMenu
; will never be null
newPopupMenu()
public javax.swing.JMenuItem getMenuItem(com.sas.swing.util.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 for
JMenuItem
; will never be null
newMenuItem(Action)
public void populateToolBar(javax.swing.JToolBar toolBar, com.sas.swing.util.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 ActionList
public javax.swing.JToolBar getToolBar(com.sas.swing.util.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 bar
JToolBar
; will never be null
newToolBar()
public javax.swing.AbstractButton getButton(com.sas.swing.util.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 for
AbstractButton
; will never be null
newButton(Action)
public javax.swing.AbstractButton getToolItem(com.sas.swing.util.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 for
AbstractButton
; will never be null
newToolItem(Action)
public javax.swing.AbstractButton getTaskItem(com.sas.swing.util.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 for
AbstractButton
; will never be null
newTaskItem(Action)
public javax.swing.AbstractButton getShortcutItem(com.sas.swing.util.Action action)
public javax.swing.AbstractButton getShortcutItem(com.sas.swing.util.Action action, boolean smallIcons)
public com.sas.swing.util.ActionList getActionList(javax.swing.JMenuBar menuBar)
menuBar
- a JMenuBar
from getMenuBar()
ActionList
or null
if the menu bar
is not from getMenuBar()
public com.sas.swing.util.ActionList getActionList(javax.swing.JPopupMenu popupMenu)
popupMenu
- a JPopupMenu
from getPopupMenu()
ActionList
or null
if the menu
is not from getPopupMenu()
public com.sas.swing.util.ActionList getActionList(javax.swing.JMenu menu)
Convenience method for (ActionList)menu.getAction()
.
menu
- a JMenu
from getMenu()
ActionList
or null
if the menu
is not from getMenu()
public com.sas.swing.util.Action getAction(javax.swing.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 com.sas.swing.util.ActionList getActionList(javax.swing.JToolBar toolBar)
toolBar
- a JToolBar
from getToolBar()
ActionList
or null
if the tool bar
is not from getToolBar()
public com.sas.swing.util.Action getAction(javax.swing.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 com.sas.net.ResourceLocatorInterface getResourceLocator()
ResourceLocatorInterface
or null
setResourceLocator(com.sas.net.ResourceLocatorInterface)
public IconMap getIconMap()
IconMap
or null
setIconMap(com.sas.swing.visuals.util.IconMap)
public void setIconMap(IconMap iconMap)
iconMap
- an instance of IconMap
or null
getIconMap()
public void setResourceLocator(com.sas.net.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 null
getResourceLocator()
protected javax.swing.JMenuBar newMenuBar()
JMenuBar
protected javax.swing.JPopupMenu newPopupMenu()
JPopupMenu
protected javax.swing.JMenu newMenu()
JMenu
protected javax.swing.JMenuItem newMenuItem(com.sas.swing.util.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 for
JMenuItem
newMenuItem(com.sas.swing.util.Action)
,
newCheckBoxMenuItem()
,
newRadioButtonMenuItem()
protected javax.swing.JMenuItem newMenuItem()
JMenuItem
protected javax.swing.JMenuItem newCheckBoxMenuItem()
javax.swing.JCheckBoxMenuItem
protected javax.swing.JMenuItem newRadioButtonMenuItem()
javax.swing.JRadioButtonMenuItem
protected javax.swing.JToolBar newToolBar()
JToolBar
protected javax.swing.AbstractButton newTaskItem(com.sas.swing.util.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 for
AbstractButton
newButton(com.sas.swing.util.Action)
,
newCheckBox()
,
newRadioButton()
protected javax.swing.AbstractButton newToolItem(com.sas.swing.util.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 for
AbstractButton
newButton(com.sas.swing.util.Action)
,
newCheckBox()
,
newRadioButton()
protected javax.swing.AbstractButton newButton(com.sas.swing.util.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 for
AbstractButton
newButton(com.sas.swing.util.Action)
,
newToggleButton()
protected javax.swing.AbstractButton newButton()
javax.swing.JButton
protected javax.swing.AbstractButton newCheckBox()
javax.swing.JCheckBox
protected javax.swing.AbstractButton newRadioButton()
javax.swing.JRadioButton
protected javax.swing.AbstractButton newToggleButton()
javax.swing.JToggleButton
protected javax.swing.AbstractButton newShortcutItem(com.sas.swing.util.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 for
AbstractButton
newButton(com.sas.swing.util.Action)
protected javax.swing.AbstractButton newShortcutItem(com.sas.swing.util.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 for
AbstractButton
newButton(com.sas.swing.util.Action)
public void loadActionResources(com.sas.swing.util.Action action)
action
-
|
Components |
|
| |||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |