net.sf.freecol.client.gui.action
Class FreeColAction

java.lang.Object
  extended by javax.swing.AbstractAction
      extended by net.sf.freecol.client.gui.action.FreeColAction
All Implemented Interfaces:
java.awt.event.ActionListener, java.io.Serializable, java.lang.Cloneable, java.util.EventListener, javax.swing.Action, Option<FreeColAction>
Direct Known Subclasses:
AboutAction, ChatAction, ColopediaAction, ContinueAction, DebugAction, DetermineHighSeasAction, MapboardAction, MapEditorAction, NewAction, OpenAction, PreferencesAction, QuitAction, ReconnectAction, ReportCargoAction, ReportColonyAction, ReportContinentalCongressAction, ReportEducationAction, ReportExplorationAction, ReportForeignAction, ReportHighScoresAction, ReportHistoryAction, ReportIndianAction, ReportLabourAction, ReportMilitaryAction, ReportNavalAction, ReportProductionAction, ReportReligionAction, ReportRequirementsAction, ReportTradeAction, ReportTurnAction, RetireAction, SaveAction, SaveAndQuitAction, ScaleMapAction, ShowDifficultyAction, ShowGameOptionsAction, ShowMainAction, ShowMapGeneratorOptionsAction, ZoomInAction, ZoomOutAction

public abstract class FreeColAction
extends javax.swing.AbstractAction
implements Option<FreeColAction>

The super class of all actions in FreeCol. Subclasses of this object is stored in an ActionManager.

See Also:
Serialized Form

Nested Class Summary
 class FreeColAction.InnerMenuKeyListener
          A class used by Actions which have a mnemonic.
 
Field Summary
static java.lang.String ACTION_ID
           
static java.lang.String BUTTON_DISABLED_IMAGE
           
static java.lang.String BUTTON_IMAGE
           
static java.lang.String BUTTON_PRESSED_IMAGE
           
static java.lang.String BUTTON_ROLLOVER_IMAGE
           
protected  FreeColClient freeColClient
           
protected  GUI gui
           
private static java.util.logging.Logger logger
           
static java.lang.Integer NO_MNEMONIC
           
private  int orderButtonImageCount
           
 
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
protected FreeColAction(FreeColClient freeColClient, GUI gui, java.lang.String id)
          Creates a new FreeColAction.
 
Method Summary
protected  void addImageIcons(java.lang.String key)
          Adds icons for the order buttons.
 FreeColAction clone()
          Don't use this method.
 javax.swing.KeyStroke getAccelerator()
          Gets the keyboard accelerator for this option.
protected  FreeColClient getFreeColClient()
          Gets the main controller object for the client.
 java.lang.String getId()
          Returns the id of this Option.
static java.lang.String getKeyStrokeText(javax.swing.KeyStroke keyStroke)
          Creates a String that keeps the attributes given KeyStroke.
 javax.swing.event.MenuKeyListener getMenuKeyListener()
           
 java.lang.Integer getMnemonic()
          Gets the mnemonic to be used for selecting this action
 java.lang.String getName()
          Returns the name of this Option.
 java.lang.String getShortDescription()
          Gives a short description of this Option.
 FreeColAction getValue()
          Returns the action itself.
static java.lang.String getXMLElementTagName()
          Gets the tag name of the root element representing this object.
 boolean hasOrderButtons()
          Are all the order button images present?
 void readFromXML(javax.xml.stream.XMLStreamReader in)
          Initialize this object from an XML-representation of this object.
protected  void readFromXMLImpl(javax.xml.stream.XMLStreamReader in)
          Initialize this object from an XML-representation of this object.
 void setAccelerator(javax.swing.KeyStroke accelerator)
          Sets a keyboard accelerator.
 void setMnemonic(int mnemonic)
          Describe setMnemonic method here.
 void setValue(FreeColAction value)
          Does nothing except log a warning.
protected  boolean shouldBeEnabled()
          Checks if this action should be enabled.
 java.lang.String toString()
          Returns a textual representation of this object.
 void toXML(javax.xml.stream.XMLStreamWriter out)
          This method writes an XML-representation of this object to the given stream.
protected  void toXMLImpl(javax.xml.stream.XMLStreamWriter out)
          This method writes an XML-representation of this object to the given stream.
 void update()
          Updates the "enabled"-status with the value returned by shouldBeEnabled().
 
Methods inherited from class javax.swing.AbstractAction
addPropertyChangeListener, firePropertyChange, getKeys, getPropertyChangeListeners, getValue, isEnabled, putValue, removePropertyChangeListener, setEnabled
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.awt.event.ActionListener
actionPerformed
 

Field Detail

logger

private static final java.util.logging.Logger logger

ACTION_ID

public static final java.lang.String ACTION_ID
See Also:
Constant Field Values

BUTTON_IMAGE

public static final java.lang.String BUTTON_IMAGE
See Also:
Constant Field Values

BUTTON_ROLLOVER_IMAGE

public static final java.lang.String BUTTON_ROLLOVER_IMAGE
See Also:
Constant Field Values

BUTTON_PRESSED_IMAGE

public static final java.lang.String BUTTON_PRESSED_IMAGE
See Also:
Constant Field Values

BUTTON_DISABLED_IMAGE

public static final java.lang.String BUTTON_DISABLED_IMAGE
See Also:
Constant Field Values

NO_MNEMONIC

public static final java.lang.Integer NO_MNEMONIC

freeColClient

protected final FreeColClient freeColClient

orderButtonImageCount

private int orderButtonImageCount

gui

protected GUI gui
Constructor Detail

FreeColAction

protected FreeColAction(FreeColClient freeColClient,
                        GUI gui,
                        java.lang.String id)
Creates a new FreeColAction.

Parameters:
freeColClient - The main controller object for the client.
id - a String value
Method Detail

clone

public FreeColAction clone()
                    throws java.lang.CloneNotSupportedException
Don't use this method.

Specified by:
clone in interface Option<FreeColAction>
Overrides:
clone in class javax.swing.AbstractAction
Throws:
java.lang.CloneNotSupportedException

getMnemonic

public java.lang.Integer getMnemonic()
Gets the mnemonic to be used for selecting this action

Returns:
The mnemonic of the action

setMnemonic

public void setMnemonic(int mnemonic)
Describe setMnemonic method here.

Parameters:
mnemonic - an int value

getFreeColClient

protected FreeColClient getFreeColClient()
Gets the main controller object for the client.

Returns:
The main controller object for the client.

hasOrderButtons

public boolean hasOrderButtons()
Are all the order button images present?

Returns:
True if all the order button images are present.

addImageIcons

protected void addImageIcons(java.lang.String key)
Adds icons for the order buttons.

Parameters:
key - The id of the action.

update

public void update()
Updates the "enabled"-status with the value returned by shouldBeEnabled().


shouldBeEnabled

protected boolean shouldBeEnabled()
Checks if this action should be enabled.

Returns:
false if the ClientOptionsDialog is visible and true otherwise. This method should be extended by subclasses if the action should be disabled in other cases.

setAccelerator

public void setAccelerator(javax.swing.KeyStroke accelerator)
Sets a keyboard accelerator.

Parameters:
accelerator - The KeyStroke. Using null is the same as disabling the keyboard accelerator.

getAccelerator

public javax.swing.KeyStroke getAccelerator()
Gets the keyboard accelerator for this option.

Returns:
The KeyStroke or null if the keyboard accelerator is disabled.

getShortDescription

public java.lang.String getShortDescription()
Gives a short description of this Option. Can for instance be used as a tooltip text.

Returns:
A short description of this action.

toString

public java.lang.String toString()
Returns a textual representation of this object.

Specified by:
toString in interface Option<FreeColAction>
Overrides:
toString in class java.lang.Object
Returns:
The name of this Option.
See Also:
getName()

getId

public java.lang.String getId()
Returns the id of this Option.

Specified by:
getId in interface Option<FreeColAction>
Returns:
An unique identifier for this action.

getName

public java.lang.String getName()
Returns the name of this Option.

Returns:
The name as provided in the constructor.

getKeyStrokeText

public static java.lang.String getKeyStrokeText(javax.swing.KeyStroke keyStroke)
Creates a String that keeps the attributes given KeyStroke. This String can be used to store the key stroke in an XML-file.

Parameters:
keyStroke - The KeyStroke.
Returns:
A String that produces a key stroke equal to the given KeyStroke if passed as a parameter to getAWTKeyStroke(String).

getValue

public FreeColAction getValue()
Returns the action itself. TODO: at the moment, this is only necessary in order to implement Option.

Specified by:
getValue in interface Option<FreeColAction>
Returns:
an FreeColAction value

setValue

public void setValue(FreeColAction value)
Does nothing except log a warning. TODO: at the moment, this is only necessary in order to implement Option.

Specified by:
setValue in interface Option<FreeColAction>
Parameters:
value - a FreeColAction value

toXMLImpl

protected void toXMLImpl(javax.xml.stream.XMLStreamWriter out)
                  throws javax.xml.stream.XMLStreamException
This method writes an XML-representation of this object to the given stream.

Parameters:
out - The target stream.
Throws:
javax.xml.stream.XMLStreamException - if there are any problems writing to the stream.

readFromXMLImpl

protected void readFromXMLImpl(javax.xml.stream.XMLStreamReader in)
                        throws javax.xml.stream.XMLStreamException
Initialize this object from an XML-representation of this object.

Parameters:
in - The input stream with the XML.
Throws:
javax.xml.stream.XMLStreamException - if a problem was encountered during parsing.

toXML

public void toXML(javax.xml.stream.XMLStreamWriter out)
           throws javax.xml.stream.XMLStreamException
This method writes an XML-representation of this object to the given stream.

Specified by:
toXML in interface Option<FreeColAction>
Parameters:
out - The target stream.
Throws:
javax.xml.stream.XMLStreamException - if there are any problems writing to the stream.

readFromXML

public void readFromXML(javax.xml.stream.XMLStreamReader in)
                 throws javax.xml.stream.XMLStreamException
Initialize this object from an XML-representation of this object.

Specified by:
readFromXML in interface Option<FreeColAction>
Parameters:
in - The input stream with the XML.
Throws:
javax.xml.stream.XMLStreamException - if a problem was encountered during parsing.

getMenuKeyListener

public javax.swing.event.MenuKeyListener getMenuKeyListener()

getXMLElementTagName

public static java.lang.String getXMLElementTagName()
Gets the tag name of the root element representing this object.

Returns:
"integerOption".