public class BAMutil
extends java.lang.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 java.lang.String |
ACCEL
Action Property specifies menu accelerator
|
static java.lang.String |
MNEMONIC
Action Property specifies menu mneumonic
|
static java.lang.String |
SELECTED_ICON
Action Property specifies Selected icon name
|
static java.lang.String |
STATE
the state of "toggle" actions = Boolean
|
static java.lang.String |
TOGGLE
Action Property specifies is its a toggle
|
| Constructor and Description |
|---|
BAMutil() |
| Modifier and Type | Method and Description |
|---|---|
static javax.swing.AbstractButton |
addActionToContainer(java.awt.Container c,
javax.swing.Action act)
Same as addActionToContainerPos, but add to end of Container
|
static javax.swing.AbstractButton |
addActionToContainerPos(java.awt.Container c,
javax.swing.Action act,
int pos)
creates an AbstractButton using the given Action and adds it to the given Container at the position..
|
static javax.swing.JMenuItem |
addActionToMenu(javax.swing.JMenu menu,
javax.swing.Action act) |
static javax.swing.JMenuItem |
addActionToMenu(javax.swing.JMenu menu,
javax.swing.Action act,
int menuPos)
creates a MenuItem using the given Action and adds it to the given Menu.
|
static javax.swing.JMenuItem |
addActionToPopupMenu(javax.swing.JPopupMenu pmenu,
javax.swing.Action act) |
static javax.swing.ImageIcon |
getIcon(java.lang.String name,
boolean errMsg)
Get the named Icon from the default resource (jar file).
|
static java.awt.Image |
getImage(java.lang.String name)
Get the named Image from the default resource (jar file).
|
static java.lang.String |
getResourcePath() |
static javax.swing.AbstractButton |
makeButtcon(javax.swing.Icon icon,
javax.swing.Icon selected,
java.lang.String tooltip,
boolean is_toggle)
Make a "buttcon" = button with an Icon
|
static javax.swing.AbstractButton |
makeButtcon(java.lang.String iconName,
java.lang.String tooltip,
boolean is_toggle)
Make a "buttcon" = button with an Icon
|
static javax.swing.AbstractButton |
makeButtconFromAction(javax.swing.Action act) |
static java.awt.Cursor |
makeCursor(java.lang.String name)
Make a cursor from the named Image in the default resource (jar file)
|
static void |
setActionProperties(javax.swing.AbstractAction act,
java.lang.String icon_name,
java.lang.String action_name,
boolean is_toggle,
int mnemonic,
int accel)
Standard way to set Properties for Actions.
|
static void |
setActionPropertiesToggle(javax.swing.AbstractAction act,
java.lang.String icon_name,
java.lang.String action_name,
boolean toggleValue,
int mnemonic,
int accel)
Standard way to set Properties and state for "Toggle" Actions.
|
static void |
setResourcePath(java.lang.String path)
Set the resource path for icons, images, cursors.
|
public static final java.lang.String SELECTED_ICON
public static final java.lang.String TOGGLE
public static final java.lang.String MNEMONIC
public static final java.lang.String ACCEL
public static final java.lang.String STATE
public static void setResourcePath(java.lang.String path)
path - relative to the classpathpublic static java.lang.String getResourcePath()
public static javax.swing.ImageIcon getIcon(java.lang.String name,
boolean errMsg)
name - name of the Icon ( will look for errMsg - true= print error message if not foundpublic static java.awt.Image getImage(java.lang.String name)
name - name of the Image ( will look for public static java.awt.Cursor makeCursor(java.lang.String name)
name - name of the Image ( will look for public static javax.swing.AbstractButton makeButtcon(javax.swing.Icon icon,
javax.swing.Icon selected,
java.lang.String tooltip,
boolean is_toggle)
icon - the normal Iconselected - the selected Icontooltip - the tooltipis_toggle - if true, make JToggleButton, else JButtonpublic static javax.swing.AbstractButton makeButtcon(java.lang.String iconName,
java.lang.String tooltip,
boolean is_toggle)
iconName - name of the Icon ( will look for tooltip - the tooltipis_toggle - if true, make JToggleButton, else JButtonpublic static javax.swing.JMenuItem addActionToMenu(javax.swing.JMenu menu,
javax.swing.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 javax.swing.JMenuItem addActionToMenu(javax.swing.JMenu menu,
javax.swing.Action act)
public static javax.swing.JMenuItem addActionToPopupMenu(javax.swing.JPopupMenu pmenu,
javax.swing.Action act)
public static javax.swing.AbstractButton addActionToContainerPos(java.awt.Container c,
javax.swing.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 javax.swing.AbstractButton makeButtconFromAction(javax.swing.Action act)
public static javax.swing.AbstractButton addActionToContainer(java.awt.Container c,
javax.swing.Action act)
c - add to this containeract - add this actionpublic static void setActionProperties(javax.swing.AbstractAction act,
java.lang.String icon_name,
java.lang.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(javax.swing.AbstractAction act,
java.lang.String icon_name,
java.lang.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 accelerator