public class BAMutil extends Object
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());
| Modifier and Type | Class and Description |
|---|---|
static class |
BAMutil.ActionToggle
This wraps a regular action and makes it into a "toggle action",
and associates it with an AbstractButton.
|
| Modifier and Type | Field and Description |
|---|---|
static String |
ACCEL
Action Property specifies menu accelerator
|
static String |
MNEMONIC
Action Property specifies menu mneumonic
|
static String |
SELECTED_ICON
Action Property specifies Selected icon name
|
static String |
STATE
the state of "toggle" actions = Boolean
|
static String |
TOGGLE
Action Property specifies is its a toggle
|
| Constructor and Description |
|---|
BAMutil() |
| Modifier and Type | Method and Description |
|---|---|
static AbstractButton |
addActionToContainer(Container c,
Action act)
Same as addActionToContainerPos, but add to end of Container
|
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..
|
static JMenuItem |
addActionToMenu(JMenu menu,
Action act) |
static JMenuItem |
addActionToMenu(JMenu menu,
Action act,
int menuPos)
creates a MenuItem using the given Action and adds it to the given Menu.
|
static JMenuItem |
addActionToPopupMenu(JPopupMenu pmenu,
Action act) |
static ImageIcon |
getIcon(String name,
boolean errMsg)
Get the named Icon from the default resource (jar file).
|
static Image |
getImage(String name)
Get the named Image from the default resource (jar file).
|
static String |
getResourcePath() |
static AbstractButton |
makeButtcon(Icon icon,
Icon selected,
String tooltip,
boolean is_toggle)
Make a "buttcon" = button with an Icon
|
static AbstractButton |
makeButtcon(String iconName,
String tooltip,
boolean is_toggle)
Make a "buttcon" = button with an Icon
|
static AbstractButton |
makeButtconFromAction(Action act) |
static 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.
|
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.
|
static void |
setResourcePath(String path)
Set the resource path for icons, images, cursors.
|
public static final String SELECTED_ICON
public static final String TOGGLE
public static final String MNEMONIC
public static final String ACCEL
public static final String STATE
public static void setResourcePath(String path)
path - reletive to the classpathpublic static String getResourcePath()
public static ImageIcon getIcon(String name, boolean errMsg)
name - name of the Icon ( will look for errMsg - true= print error message if not foundpublic static Image getImage(String name)
name - name of the Image ( will look for public static Cursor makeCursor(String name)
name - name of the Image ( will look for public static AbstractButton makeButtcon(Icon icon, Icon selected, String tooltip, boolean is_toggle)
icon - the normal Iconselected - the selected Icontooltip - the tooltipis_toggle - if true, make JToggleButton, else JButtonpublic static AbstractButton makeButtcon(String iconName, String tooltip, boolean is_toggle)
iconName - name of the Icon ( will look for tooltip - the tooltipis_toggle - if true, make JToggleButton, else JButtonpublic static JMenuItem addActionToMenu(JMenu menu, Action act, int menuPos)
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
menu - add to this menuact - the Action to make it out ofmenuPos - if >= 0, add at this position, otherwise appendpublic static JMenuItem addActionToPopupMenu(JPopupMenu pmenu, Action act)
public static AbstractButton addActionToContainerPos(Container c, Action act, int pos)
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
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)public static AbstractButton makeButtconFromAction(Action act)
public static AbstractButton addActionToContainer(Container c, Action act)
c - add to this containeract - add this actionpublic static void setActionProperties(AbstractAction act, String icon_name, String action_name, boolean is_toggle, int mnemonic, int accel)
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 acceleratorpublic static void setActionPropertiesToggle(AbstractAction act, String icon_name, String action_name, boolean toggleValue, int mnemonic, int accel)
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 acceleratorCopyright © 1999–2015 UCAR/Unidata. All rights reserved.