ehsbe CommonsTM
Version 1.1.0rc3

com.ehsbe.commons.action
Class TriggerAction

java.lang.Object
  extended by javax.swing.AbstractAction
      extended by com.ehsbe.commons.action.AbstractActionExt
          extended by com.ehsbe.commons.action.ManagedAction
              extended by com.ehsbe.commons.action.TriggerAction
All Implemented Interfaces:
ActionListener, ItemListener, Serializable, Cloneable, EventListener, Action

public class TriggerAction
extends ManagedAction

Action, that supports different settings for tootltip, text and icons depending on its selection state.

Version:
$Revision: 456 $
Author:
Jens Elkner
See Also:
Serialized Form

Field Summary
static String SELECTED_LARGE_ICON
          The key for the large icon, when the button is selected.
static String SELECTED_LONG_DESCRIPTION
          The key used for storing a longer String description for the action, when it is selected.
static String SELECTED_MNEMONIC_KEY
          The key used for storing a the mnemonic for the action, when it is selected.
static String SELECTED_NAME
          The key used for storing the String name for the action, used for a menu or button, when it is selected.
static String SELECTED_SHORT_DESCRIPTION
          The key used for storing a short String description for the action, used for tooltip text, when it is selected.
static String SELECTED_SMALL_ICON
          The key used for storing a small Icon, such as ImageIcon, for the action, when it is selected.
static String TOGGLE_BUTTON
          UI hint to use a JToggleButton instead of a normal JButton.
 
Fields inherited from class com.ehsbe.commons.action.ManagedAction
actionListeners, itemListeners
 
Fields inherited from class com.ehsbe.commons.action.AbstractActionExt
GROUP, IS_STATE, LARGE_ICON_P_KEY, SELECT_PROPERTY_NAME, SMALL_ICON_P_KEY
 
Fields inherited from class javax.swing.AbstractAction
changeSupport, enabled
 
Fields inherited from interface javax.swing.Action
ACCELERATOR_KEY, ACTION_COMMAND_KEY, DEFAULT, DISPLAYED_MNEMONIC_INDEX_KEY, LARGE_ICON_KEY, LONG_DESCRIPTION, MNEMONIC_KEY, NAME, SELECTED_KEY, SHORT_DESCRIPTION, SMALL_ICON
 
Constructor Summary
TriggerAction()
          Default Action constructor.
TriggerAction(String name)
          Defines an Action object with the specified name and a default icon.
TriggerAction(String name, Icon icon)
          Defines an Action object with the specified name and the specified icon.
TriggerAction(String name, String command)
          Defines an Action object with the specified name, and the specified command key.
TriggerAction(String name, String command, Icon icon)
          Defines an Action object with the specified name, the specified command key and the specified icon.
TriggerAction(String name, String command, Icon icon, String selectedName, Icon selectedIcon)
          Defines an Action object with the specified name, the specified command key and the specified icon.
 
Method Summary
 Icon getLargeIcon()
          Get a large icon which represents the action wrt. its current selection state.
 Icon getLargeIcon(boolean selected)
          Get a large icon which represents the action wrt. the given selection state.
 String getLongDescription()
          Get a long desciption of the action wrt. its current selection state.
 String getLongDescription(boolean selected)
          Get a long desciption of the action wrt. the given selection state.
 int getMnemonic()
          Get the mnemonic key code for the action wrt. to the current selection state.
 int getMnemonic(boolean selected)
          Get the mnemonic key code for the action wrt. to the given selection state.
 String getName()
          Get the name of the action wrt. its current selection state.
 String getName(boolean selected)
          Get the name of the action wrt. the given selection state.
 String getShortDescription()
          Get a short description of the action wrt. its current selection state.
 String getShortDescription(boolean selected)
          Get a short description of the action wrt. the given selection state.
 Icon getSmallIcon()
          Get a small icon which represents the action wrt. to the current selection state.
 Icon getSmallIcon(boolean selected)
          Get a small icon which represents the action wrt. to the given selection state.
 Object getValue(String key)
          
 void setLargeIcon(Icon icon, boolean selected)
          Sets the large icon which represents the action depending on its selection state.
 void setLongDescription(String desc, boolean selected)
          Sets the long description of the action depending on its selection state.
 void setMnemonic(int mnemonic, boolean selected)
          Sets the mnemonic key code for the action wrt. to the given selection state.
 void setMnemonic(String mnemonic, boolean selected)
          Sets the mnemonic key code for the action wrt. to the given selection state.
 void setName(String name, boolean selected)
          Sets the display name of the action depending on its selection state.
 void setShortDescription(String desc, boolean selected)
          Sets the short description of the action.
 void setSmallIcon(Icon icon, boolean selected)
          Sets the small icon which represents the action depending on its selection state.
 
Methods inherited from class com.ehsbe.commons.action.ManagedAction
actionPerformed, addActionListener, addItemListener, clone, itemStateChanged, removeActionListener, removeItemListener
 
Methods inherited from class com.ehsbe.commons.action.AbstractActionExt
dispose, getAccelerator, getActionCommand, getGroup, getLargePressedIcon, getSmallPressedIcon, isSelected, isStateAction, setAccelerator, setActionCommand, setGroup, setLargeIcon, setLargePressedIcon, setLongDescription, setMnemonic, setMnemonic, setName, setSelected, setShortDescription, setSmallIcon, setSmallPressedIcon, setStateAction, setStateAction, toString
 
Methods inherited from class javax.swing.AbstractAction
addPropertyChangeListener, firePropertyChange, getKeys, getPropertyChangeListeners, isEnabled, putValue, removePropertyChangeListener, setEnabled
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

SELECTED_LARGE_ICON

public static final String SELECTED_LARGE_ICON
The key for the large icon, when the button is selected. Used for toolbar buttons.

See Also:
Constant Field Values

SELECTED_NAME

public static final String SELECTED_NAME
The key used for storing the String name for the action, used for a menu or button, when it is selected.

See Also:
Constant Field Values

SELECTED_SHORT_DESCRIPTION

public static final String SELECTED_SHORT_DESCRIPTION
The key used for storing a short String description for the action, used for tooltip text, when it is selected.

See Also:
Constant Field Values

SELECTED_LONG_DESCRIPTION

public static final String SELECTED_LONG_DESCRIPTION
The key used for storing a longer String description for the action, when it is selected. Could be used for context-sensitive help.

See Also:
Constant Field Values

SELECTED_SMALL_ICON

public static final String SELECTED_SMALL_ICON
The key used for storing a small Icon, such as ImageIcon, for the action, when it is selected. Used for menu items.

See Also:
Constant Field Values

SELECTED_MNEMONIC_KEY

public static final String SELECTED_MNEMONIC_KEY
The key used for storing a the mnemonic for the action, when it is selected. Used for menu items.

See Also:
Constant Field Values

TOGGLE_BUTTON

public static final String TOGGLE_BUTTON
UI hint to use a JToggleButton instead of a normal JButton. Boolean value.

See Also:
Constant Field Values
Constructor Detail

TriggerAction

public TriggerAction()
Default Action constructor.


TriggerAction

public TriggerAction(String name)
Defines an Action object with the specified name and a default icon.

Parameters:
name - display name of the action

TriggerAction

public TriggerAction(String name,
                     Icon icon)
Defines an Action object with the specified name and the specified icon.

Parameters:
name - display name of the action
icon - the action's icon

TriggerAction

public TriggerAction(String name,
                     String command)
Defines an Action object with the specified name, and the specified command key.

Parameters:
name - display name of the action
command - the value of the action command key

TriggerAction

public TriggerAction(String name,
                     String command,
                     Icon icon)
Defines an Action object with the specified name, the specified command key and the specified icon.

Parameters:
name - display name of the action
command - the value of the action command key
icon - icon to display

TriggerAction

public TriggerAction(String name,
                     String command,
                     Icon icon,
                     String selectedName,
                     Icon selectedIcon)
Defines an Action object with the specified name, the specified command key and the specified icon.

Parameters:
name - display name of the action
command - the value of the action command key
icon - icon to display
selectedName - display name of the action, when selected
selectedIcon - icon to display, when selected
Method Detail

setName

public void setName(String name,
                    boolean selected)
Sets the display name of the action depending on its selection state.

This is a convenience method for putValue with the Action.NAME and SELECTED_NAMEkey.

Parameters:
name - the name of the action; can be null
selected - if true, the icon will be used, when selected, otherwise when unselected.
See Also:
Action.NAME, SELECTED_NAME, Action.putValue(java.lang.String, java.lang.Object)

getName

public String getName()
Get the name of the action wrt. its current selection state.

Overrides:
getName in class AbstractActionExt
Returns:
the name of the action or null if not set.

getName

public String getName(boolean selected)
Get the name of the action wrt. the given selection state.

Parameters:
selected - selection state
Returns:
the name of the action or null if not set.

setSmallIcon

public void setSmallIcon(Icon icon,
                         boolean selected)
Sets the small icon which represents the action depending on its selection state.

This is a convenience method for putValue with the Action.SMALL_ICON and SELECTED_SMALL_ICON key.

Also sets its counter part's icon to the given icon, if it has no icon set (i.e. null).

Parameters:
icon - the small icon; can be null
selected - if true, the icon will be used, when selected, otherwise when unselected.
See Also:
Action.SMALL_ICON, SELECTED_SMALL_ICON, Action.putValue(java.lang.String, java.lang.Object)

getSmallIcon

public Icon getSmallIcon()
Get a small icon which represents the action wrt. to the current selection state.

Overrides:
getSmallIcon in class AbstractActionExt
Returns:
the small icon or null if not set.

getSmallIcon

public Icon getSmallIcon(boolean selected)
Get a small icon which represents the action wrt. to the given selection state.

Parameters:
selected - selection state
Returns:
the small icon or null if not set.
See Also:
setSmallIcon(Icon, boolean)

setLargeIcon

public void setLargeIcon(Icon icon,
                         boolean selected)
Sets the large icon which represents the action depending on its selection state.

This is a convenience method for putValue with the LARGE_ICON and SELECTED_LARGE_ICON key.

Also sets its counter part's icon to the given icon, if it has no icon set (i.e. null).

Parameters:
icon - the large icon; can be null
selected - if true, the icon will be used, when selected, otherwise when unselected.
See Also:
Action.LARGE_ICON_KEY, SELECTED_LARGE_ICON, Action.putValue(java.lang.String, java.lang.Object)

getLargeIcon

public Icon getLargeIcon()
Get a large icon which represents the action wrt. its current selection state.

Overrides:
getLargeIcon in class AbstractActionExt
Returns:
the large icon or null if not set.

getLargeIcon

public Icon getLargeIcon(boolean selected)
Get a large icon which represents the action wrt. the given selection state.

Parameters:
selected - selection state
Returns:
the large icon or null if not set.

setShortDescription

public void setShortDescription(String desc,
                                boolean selected)
Sets the short description of the action. This will also set the long description value is it is null.

This is a convenience method for putValue with the Action.SHORT_DESCRIPTION and SELECTED_SHORT_DESCRIPTIONkey.

Parameters:
desc - the short description; can be nullw
selected - if true, the description will be used, when selected, otherwise when unselected.
See Also:
Action.SHORT_DESCRIPTION, SELECTED_SHORT_DESCRIPTION, Action.putValue(java.lang.String, java.lang.Object)

getShortDescription

public String getShortDescription()
Get a short description of the action wrt. its current selection state.

Overrides:
getShortDescription in class AbstractActionExt
Returns:
the short description or null if not set.

getShortDescription

public String getShortDescription(boolean selected)
Get a short description of the action wrt. the given selection state.

Parameters:
selected - selection state
Returns:
the short description or null if not set.

setLongDescription

public void setLongDescription(String desc,
                               boolean selected)
Sets the long description of the action depending on its selection state. This will also set the value of the short description if that value is null.

This is a convenience method for putValue with the Action.LONG_DESCRIPTION||SELECTED_LONG_DESCRIPTION key.

Parameters:
desc - the long description; can be null
selected - if true, the icon will be used, when selected, otherwise when unselected.
See Also:
Action.LONG_DESCRIPTION, SELECTED_LONG_DESCRIPTION, Action.putValue(java.lang.String, java.lang.Object)

getLongDescription

public String getLongDescription()
Get a long desciption of the action wrt. its current selection state.

Overrides:
getLongDescription in class AbstractActionExt
Returns:
the long description or null if not set.

getLongDescription

public String getLongDescription(boolean selected)
Get a long desciption of the action wrt. the given selection state.

Parameters:
selected - selection state
Returns:
the long description or null if not set.

setMnemonic

public void setMnemonic(int mnemonic,
                        boolean selected)
Sets the mnemonic key code for the action wrt. to the given selection state.

Parameters:
mnemonic - an int key code mnemonic or 0
selected - selection state
See Also:
AbstractActionExt.setMnemonic(int)

setMnemonic

public void setMnemonic(String mnemonic,
                        boolean selected)
Sets the mnemonic key code for the action wrt. to the given selection state.

Parameters:
mnemonic - the first character of this parameter will be used to get the mnemonic value. Ignored if null or empty.
selected - selection state
See Also:
setMnemonic(int, boolean)

getMnemonic

public int getMnemonic()
Get the mnemonic key code for the action wrt. to the current selection state.

Overrides:
getMnemonic in class AbstractActionExt
Returns:
the mnemonic or 0

getMnemonic

public int getMnemonic(boolean selected)
Get the mnemonic key code for the action wrt. to the given selection state.

Parameters:
selected - selection state
Returns:
the mnemonic or 0

getValue

public Object getValue(String key)

Specified by:
getValue in interface Action
Overrides:
getValue in class AbstractAction

ehsbe CommonsTM
Version 1.1.0rc3

Copyright ©2005-2009 EHSBE, Walther-Rathenau-Str. 58, 39104 Magdeburg, Sachsen-Anhalt, Germany. All Rights Reserved.