Package ucar.unidata.ui
Class BAMutil
java.lang.Object
ucar.unidata.ui.BAMutil
Button, Action and Menu utilities:
static helper methods for building ucar.unidata.UI's.
- Version:
- $Id: BAMutil.java,v 1.16 2007/07/06 20:45:29 jeffmc Exp $
- Author:
- John Caron
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
This wraps a regular action and makes it into a "toggle action", and associates it with an AbstractButton. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String
Action Property specifies menu acceleratorstatic final String
Action Property specifies menu mneumonicstatic final String
Action Property specifies Rollover icon namestatic final String
the state of "toggle" actions = Booleanstatic final String
Action Property specifies is its a toggle -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic AbstractButton
addActionToContainer
(Container c, Action act) Same as addActionToContainerPos, but add to end of Containerstatic AbstractButton
addActionToContainerPos
(Container c, Action act, int pos) creates an AbstractButton using the given Action and adds it to the given Container at the position..static JMenuItem
addActionToMenu
(JMenu menu, Action act) _more_static JMenuItem
addActionToMenu
(JMenu menu, Action act, int menuPos) creates a MenuItem using the given Action and adds it to the given Menu.static ImageIcon
Get the named Icon from the default resource (jar file).static Image
Get the named Image from the default resource (jar file).static AbstractButton
makeButtcon
(Icon icon, Icon rollover, String tooltip, boolean is_toggle) Make a "buttcon" = button with an Iconstatic Cursor
makeCursor
(String name) Make a cursor from the named Image in the default resource (jar file)static void
setActionProperties
(AbstractAction act, String icon_name, String action_name, boolean is_toggle, int mnemonic, int accel) Standard way to set Properties for Actions.
-
Field Details
-
ROLLOVER_ICON
Action Property specifies Rollover icon name- See Also:
-
TOGGLE
Action Property specifies is its a toggle- See Also:
-
MNEMONIC
Action Property specifies menu mneumonic- See Also:
-
ACCEL
Action Property specifies menu accelerator- See Also:
-
STATE
the state of "toggle" actions = Boolean- See Also:
-
-
Constructor Details
-
BAMutil
public BAMutil()
-
-
Method Details
-
getIcon
Get the named Icon from the default resource (jar file).- Parameters:
name
- name of the Icon ( will look for.gif) errMsg
- true= print error message if not found- Returns:
- the Icon or null if not found
-
getImage
Get the named Image from the default resource (jar file).- Parameters:
name
- name of the Image ( will look for.gif) - Returns:
- the Image or null if not found
-
makeCursor
Make a cursor from the named Image in the default resource (jar file)- Parameters:
name
- name of the Image ( will look for.gif) - Returns:
- the Cursor or null if failure
-
makeButtcon
public static AbstractButton makeButtcon(Icon icon, Icon rollover, String tooltip, boolean is_toggle) Make a "buttcon" = button with an Icon- Parameters:
icon
- the normal Iconrollover
- the rollover Icontooltip
- the tooltipis_toggle
- if true, make JToggleButton, else JButton- Returns:
- the buttcon (JButton or JToggleButton)
-
addActionToMenu
creates a MenuItem using the given Action and adds it to the given Menu. Uses Properties that have been set on the Action (see setActionProperties()). All are optional except for Action.SHORT_DESCRIPTION:Action.SHORT_DESCRIPTION String MenuItem text (required) Action.SMALL_ICON Icon the Icon to Use BAMutil.ROLLOVER_ICON Icon the rollover Icon BAMutil.TOGGLE Boolean true if its a toggle BAMutil.MNEMONIC Integer menu item shortcut BAMutil.ACCEL Integer menu item global keyboard accelerator
The Action is triggered when the MenuItem is selected. Enabling and disabling the Action does the same for the MenuItem. For toggles, state is maintained in the Action, and MenuItem state changes when the Action state changes.
The point of all this is that once you set it up, you work exclusively with the action object, and all changes are automatically reflected in the UI.- Parameters:
menu
- add to this menuact
- the Action to make it out ofmenuPos
-- Returns:
- the MenuItem created
-
addActionToMenu
_more_- Parameters:
menu
-act
-- Returns:
- _more_
-
addActionToContainerPos
creates an AbstractButton using the given Action and adds it to the given Container at the position.. Uses Properties that have been set on the Action (see setActionProperties()). All are optional except for Action.SMALL_ICON:Action.SMALL_ICON Icon the Icon to Use (required) BAMutil.ROLLOVER_ICON Icon the rollover Icon Action.SHORT_DESCRIPTION String tooltip BAMutil.TOGGLE Boolean true if its a toggle
The Action is triggered when the Button is selected. Enabling and disabling the Action does the same for the Button. For toggles, state is maintained in the Action, and the Button state changes when the Action state changes.
The point of all this is that once you set it up, you work exclusively with the action object, and all changes are automatically reflected in the UI.- Parameters:
c
- add to this Containeract
- the Action to make it out ofpos
- add to the container at this position (if pos invalid input: '<' 0, add at the end)- Returns:
- the AbstractButton created (JButton or JToggleButton)
-
addActionToContainer
Same as addActionToContainerPos, but add to end of Container- Parameters:
c
-act
-- Returns:
- _more_
-
setActionProperties
public static void setActionProperties(AbstractAction act, String icon_name, String action_name, boolean is_toggle, int mnemonic, int accel) Standard way to set Properties for Actions. This also looks for an Icon "Sel" and sets ROLLOVER_ICON if it exists. If is_toggle, a toggle button is created (in addActionToContainer()), default state false To get or set the state of the toggle button: Boolean state = (Boolean) action.getValue(BAMutil.STATE); action.putValue(BAMutil.STATE, new Boolean(true/false)); - Parameters:
act
- add properties to this actionicon_name
- name of icon (or null).action_name
- menu name / tooltipis_toggle
- true if its a togglemnemonic
- menu item shortcutaccel
- menu item global keyboard accelerator
-