Package ucar.ui.widget
Class BAMutil
- java.lang.Object
-
- ucar.ui.widget.BAMutil
-
public class BAMutil extends Object
Button, Action and Menu utilities: static stationHelper methods for building ucar.unidata.UI's.Example for Toggle Action
AbstractAction dsAction = new AbstractAction() { public void actionPerformed(ActionEvent e) { Boolean state = (Boolean) getValue( BAMutil.STATE); addCoords = state.booleanValue(); String tooltip = addCoords ? "add Coordinates in ON" : "add Coordinates is OFF"; dsButt.setToolTipText(tooltip); } }; BAMutil.setActionProperties( dsAction, "Dataset", "add Coordinates is OFF", true, 'D', -1); addCoords = prefs.getBoolean( "dsState", false); dsAction.putValue(BAMutil.STATE, new Boolean(addCoords)); AbstractButton dsButt = BAMutil.addActionToContainer(buttPanel, dsAction); ... prefs.putBoolean("dsState", dsButt.getModel().isSelected());
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classBAMutil.ActionToggleThis wraps a regular action and makes it into a "toggle action", and associates it with an AbstractButton.
-
Field Summary
Fields Modifier and Type Field Description static StringACCELAction Property specifies menu acceleratorstatic StringMNEMONICAction Property specifies menu mneumonicstatic StringSELECTED_ICONAction Property specifies Selected icon namestatic StringSTATEthe state of "toggle" actions = Booleanstatic StringTOGGLEAction Property specifies is its a toggle
-
Constructor Summary
Constructors Constructor Description BAMutil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static AbstractButtonaddActionToContainer(Container c, Action act)Same as addActionToContainerPos, but add to end of Containerstatic AbstractButtonaddActionToContainerPos(Container c, Action act, int pos)creates an AbstractButton using the given Action and adds it to the given Container at the position..static JMenuItemaddActionToMenu(JMenu menu, Action act)static JMenuItemaddActionToMenu(JMenu menu, Action act, int menuPos)creates a MenuItem using the given Action and adds it to the given Menu.static JMenuItemaddActionToPopupMenu(JPopupMenu pmenu, Action act)static ImageIcongetIcon(String name, boolean errMsg)Get the named Icon from the default resource (jar file).static ImagegetImage(String name)Get the named Image from the default resource (jar file).static StringgetResourcePath()static AbstractButtonmakeButtcon(String iconName, String tooltip, boolean is_toggle)Make a "buttcon" = button with an Iconstatic AbstractButtonmakeButtcon(Icon icon, Icon selected, String tooltip, boolean is_toggle)Make a "buttcon" = button with an Iconstatic AbstractButtonmakeButtconFromAction(Action act)static CursormakeCursor(String name)Make a cursor from the named Image in the default resource (jar file)static voidsetActionProperties(AbstractAction act, String icon_name, String action_name, boolean is_toggle, int mnemonic, int accel)Standard way to set Properties for Actions.static voidsetActionPropertiesToggle(AbstractAction act, String icon_name, String action_name, boolean toggleValue, int mnemonic, int accel)Standard way to set Properties and state for "Toggle" Actions.static voidsetResourcePath(String path)Set the resource path for icons, images, cursors.
-
-
-
Field Detail
-
SELECTED_ICON
public static final String SELECTED_ICON
Action Property specifies Selected icon name- See Also:
- Constant Field Values
-
TOGGLE
public static final String TOGGLE
Action Property specifies is its a toggle- See Also:
- Constant Field Values
-
MNEMONIC
public static final String MNEMONIC
Action Property specifies menu mneumonic- See Also:
- Constant Field Values
-
ACCEL
public static final String ACCEL
Action Property specifies menu accelerator- See Also:
- Constant Field Values
-
STATE
public static final String STATE
the state of "toggle" actions = Boolean- See Also:
- Constant Field Values
-
-
Method Detail
-
setResourcePath
public static void setResourcePath(String path)
Set the resource path for icons, images, cursors.- Parameters:
path- relative to the classpath
-
getResourcePath
public static String getResourcePath()
-
getIcon
public static ImageIcon getIcon(String name, boolean errMsg)
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
public static Image getImage(String name)
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
public static Cursor makeCursor(String name)
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 selected, String tooltip, boolean is_toggle)
Make a "buttcon" = button with an Icon- Parameters:
icon- the normal Iconselected- the selected Icontooltip- the tooltipis_toggle- if true, make JToggleButton, else JButton- Returns:
- the buttcon (JButton or JToggleButton)
-
makeButtcon
public static AbstractButton makeButtcon(String iconName, String tooltip, boolean is_toggle)
Make a "buttcon" = button with an Icon- Parameters:
iconName- name of the Icon ( will look for.gif) tooltip- the tooltipis_toggle- if true, make JToggleButton, else JButton- Returns:
- the buttcon (JButton or JToggleButton)
-
addActionToMenu
public static JMenuItem addActionToMenu(JMenu menu, Action act, int menuPos)
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.SELECTED_ICON Icon the Icon when selected (optional) 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- if >= 0, add at this position, otherwise append- Returns:
- the MenuItem created
-
addActionToPopupMenu
public static JMenuItem addActionToPopupMenu(JPopupMenu pmenu, Action act)
-
addActionToContainerPos
public static 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.. 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.SELECTED_ICON Icon the Icon when selected (optional) 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 < 0, add at the end)- Returns:
- the AbstractButton created (JButton or JToggleButton)
-
makeButtconFromAction
public static AbstractButton makeButtconFromAction(Action act)
-
addActionToContainer
public static AbstractButton addActionToContainer(Container c, Action act)
Same as addActionToContainerPos, but add to end of Container- Parameters:
c- add to this containeract- add this action- Returns:
- the Button that triggers this action, in case you want to decorate it
-
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 if it exists: 1) sets SelectedIcon if its a toggle, or 2) sets the Icon when selected (optional) if its not a toggle 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
-
setActionPropertiesToggle
public static void setActionPropertiesToggle(AbstractAction act, String icon_name, String action_name, boolean toggleValue, int mnemonic, int accel)
Standard way to set Properties and state for "Toggle" Actions. *- Parameters:
act- add properties to this actionicon_name- name of icon (or null).action_name- menu name / tooltiptoggleValue- default value of togglemnemonic- menu item shortcutaccel- menu item global keyboard accelerator
-
-