ucar.unidata.ui
Class BAMutil

java.lang.Object
  extended by ucar.unidata.ui.BAMutil

public class BAMutil
extends Object

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
static class BAMutil.ActionToggle
          This wraps a regular action and makes it into a "toggle action", and associates it with an AbstractButton.
 
Field Summary
static String ACCEL
          Action Property specifies menu accelerator
static String MNEMONIC
          Action Property specifies menu mneumonic
static String ROLLOVER_ICON
          Action Property specifies Rollover icon name
static String STATE
          the state of "toggle" actions = Boolean
static String TOGGLE
          Action Property specifies is its a toggle
 
Constructor Summary
BAMutil()
           
 
Method Summary
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)
          _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 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 AbstractButton makeButtcon(Icon icon, Icon rollover, String tooltip, boolean is_toggle)
          Make a "buttcon" = button with an Icon
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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ROLLOVER_ICON

public static final String ROLLOVER_ICON
Action Property specifies Rollover 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
Constructor Detail

BAMutil

public BAMutil()
Method Detail

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 rollover,
                                         String tooltip,
                                         boolean is_toggle)
Make a "buttcon" = button with an Icon

Parameters:
icon - the normal Icon
rollover - the rollover Icon
tooltip - the tooltip
is_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.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 menu
act - the Action to make it out of
menuPos -
Returns:
the MenuItem created

addActionToMenu

public static JMenuItem addActionToMenu(JMenu menu,
                                        Action act)
_more_

Parameters:
menu -
act -
Returns:
_more_

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.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 Container
act - the Action to make it out of
pos - add to the container at this position (if pos < 0, add at the end)
Returns:
the AbstractButton created (JButton or JToggleButton)

addActionToContainer

public static AbstractButton addActionToContainer(Container c,
                                                  Action act)
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 action
icon_name - name of icon (or null).
action_name - menu name / tooltip
is_toggle - true if its a toggle
mnemonic - menu item shortcut
accel - menu item global keyboard accelerator