be.ugent.caagt.swirl.actions
Class Description

java.lang.Object
  extended by be.ugent.caagt.swirl.actions.Description

public class Description
extends java.lang.Object

An object of this class describes caption, mnemonic and accelerator key of a GUI component. It is initialized by a single description string (either at construction time or by calling setDescription(java.lang.String)) which is then internally split into different parts. For example, the description string "Javadoc inde&x search [shift F1]" will be split into the caption 'Javadoc index search', mnemonic 'X' and accelerator key shift-F1.

Accelerator keys, if present, are written between square brackets as the last part of the description string and use the conventions of method KeyStroke.getKeyStroke(String). Mnemonics are indicated by placing an ampersand in front of the first occurrence of that letter in the string. The name of the action is obtained by removing from the description string the bracketed accelerator key, any surrounding white space and all ampersands. Two consecutive ampersands are not interpreted as a mnemonic, but result in a single ampersand in the name.

In most cases this class should not be used directly, for buttons and menu items can most easily be internationalized using actions that extend SimpleAction.


Constructor Summary
  Description(java.lang.String description)
          Create a new object based on the given description string.
protected Description(java.lang.String caption, int mnemonic, int mnemonicIndex, javax.swing.KeyStroke acceleratorKey)
          Create a new description with the given subconstituents.
 
Method Summary
 javax.swing.KeyStroke getAcceleratorKey()
          Return the accelerator key for this description, or 0 when no key was given.
static Description getCancelButtonDescription()
          Return a default description for a Cancel-button.
 java.lang.String getCaption()
          Return the caption for this description.
 int getMnemonic()
          Return the mnemonic for this description
 int getMnemonicIndex()
          Return the index of the mnemonic for this description, or -1 when no mnemonic was given.
static Description getNoButtonDescription()
          Return a default description for a No-button.
static Description getOkButtonDescription()
          Return a default description for an OK-button.
static Description getYesButtonDescription()
          Return a default description for a Yes-button.
 void init(javax.swing.AbstractButton button)
          Initialize caption and mnemonic for the given button, according to this description.
 void init(javax.swing.Action action)
          Initialize caption, mnemonic and accelerator key for the given action, according to this description.
 void initApproveButton(javax.swing.JFileChooser chooser)
          Initialize the approve button and title of the given file chooser, according to this description.
 void setDescription(java.lang.String newDescription)
          (Re)initialize this object based on the given description string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Description

public Description(java.lang.String description)
Create a new object based on the given description string.


Description

protected Description(java.lang.String caption,
                      int mnemonic,
                      int mnemonicIndex,
                      javax.swing.KeyStroke acceleratorKey)
Create a new description with the given subconstituents.

Method Detail

getOkButtonDescription

public static Description getOkButtonDescription()
Return a default description for an OK-button. The caption and mnemonics are the same as those used for an option pane in the look-and-feel of the application, and are therefore internationalized.


getCancelButtonDescription

public static Description getCancelButtonDescription()
Return a default description for a Cancel-button. The caption and mnemonics are the same as those used for an option pane in the look-and-feel of the application, and are therefore internationalized.


getYesButtonDescription

public static Description getYesButtonDescription()
Return a default description for a Yes-button. The caption and mnemonics are the same as those used for an option pane in the look-and-feel of the application, and therefore internationalized.


getNoButtonDescription

public static Description getNoButtonDescription()
Return a default description for a No-button. The caption and mnemonics are the same as those used for an option pane in the look-and-feel of the application, and therefore internationalized.


setDescription

public final void setDescription(java.lang.String newDescription)
(Re)initialize this object based on the given description string.


getCaption

public java.lang.String getCaption()
Return the caption for this description.


getMnemonic

public int getMnemonic()
Return the mnemonic for this description


getMnemonicIndex

public int getMnemonicIndex()
Return the index of the mnemonic for this description, or -1 when no mnemonic was given.


getAcceleratorKey

public javax.swing.KeyStroke getAcceleratorKey()
Return the accelerator key for this description, or 0 when no key was given.


init

public void init(javax.swing.Action action)
Initialize caption, mnemonic and accelerator key for the given action, according to this description.


init

public void init(javax.swing.AbstractButton button)
Initialize caption and mnemonic for the given button, according to this description. If the button is a menu item, also set the accelerator key.


initApproveButton

public void initApproveButton(javax.swing.JFileChooser chooser)
Initialize the approve button and title of the given file chooser, according to this description.