com.mucommander.ui.action
Class MuAction

java.lang.Object
  extended by javax.swing.AbstractAction
      extended by com.mucommander.ui.action.MuAction
All Implemented Interfaces:
java.awt.event.ActionListener, java.io.Serializable, java.lang.Cloneable, java.util.EventListener, javax.swing.Action
Direct Known Subclasses:
AddBookmarkAction, BringAllToFrontAction, ChangeLocationAction, CheckForUpdatesAction, CloseWindowAction, CommandAction, CompareFoldersAction, ConnectToServerAction, CycleBackwardThruFolderPanelAction, CycleForwardThruFolderPanelAction, EditBookmarksAction, EditCredentialsAction, EmptyTrashAction, ExploreBookmarksAction, FileAction, GarbageCollectAction, GoToAction, GoToHomeAction, InvertSelectionAction, MarkAllAction, MarkExtensionAction, MarkGroupAction, MarkPageDownAction, MarkPageUpAction, MarkSelectedFileAction, MarkUpToFirstRowAction, MarkUpToLastRowAction, MaximizeWindowAction, MinimizeWindowAction, MkdirAction, MkfileAction, NewWindowAction, OpenAction, OpenLocationAction, OpenNativelyAction, OpenTrashAction, OpenURLInBrowserAction, PasteClipboardFilesAction, PopupLeftDriveButtonAction, PopupRightDriveButtonAction, QuitAction, RecallNextWindowAction, RecallPreviousWindowAction, RecallWindowAction, RefreshAction, RevealInDesktopAction, ReverseSortOrderAction, RunCommandAction, SelectFirstRowAction, SelectLastRowAction, SetSameFolderAction, ShowAboutAction, ShowBookmarksQLAction, ShowKeyboardShortcutsAction, ShowParentFoldersQLAction, ShowPreferencesAction, ShowRecentExecutedFilesQLAction, ShowRecentLocationsQLAction, ShowServerConnectionsAction, SortByAction, SplitEquallyAction, SplitHorizontallyAction, SplitVerticallyAction, StopAction, SwapFoldersAction, SwitchActiveTableAction, ToggleAutoSizeAction, ToggleColumnAction, ToggleCommandBarAction, ToggleHiddenFilesAction, ToggleShowFoldersFirstAction, ToggleStatusBarAction, ToggleToolBarAction, ToggleTreeAction, UnmarkGroupAction

public abstract class MuAction
extends javax.swing.AbstractAction

MuAction extends AbstractAction to add more functionalities and make it easier to integrate within muCommander. The biggest difference with AbstractAction is that MuAction instances are bound to a specific MainFrame.
Note that by being an Action, MuAction can be used in every Swing components that accept Action instances.

The MuAction class is abstract. MuAction subclasses must implement the performAction() method to provide a response to the action trigger, and must provide a constructor with the MuAction(MainFrame, java.util.Hashtable) signature.

MuAction subclasses should not be instanciated directly, ActionManager's getActionInstance methods should be used instead. Using ActionManager to retrieve a MuAction ensures that only one instance exists for a given MainFrame. This is particularly important because actions are stateful and can be used in several components of a MainFrame at the same time; if an action's state changes, the change must be reflected everywhere the action is used. It is also important for performance reasons: sharing one action throughout a MainFrame saves some memory and also CPU cycles as some actions listen to particular events to change their state accordingly.

Author:
Maxence Bernard
See Also:
ActionManager, ActionKeymap, Serialized Form

Field Summary
static java.lang.String ALTERNATE_ACCELERATOR_PROPERTY_KEY
          Name of the alternate accelerator KeyStroke property
protected  MainFrame mainFrame
          The MainFrame associated with this MuAction
 
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
MuAction(MainFrame mainFrame, java.util.Hashtable properties)
          Convenience constructor which has the same effect as calling MuAction(MainFrame, Hashtable, boolean, boolean, boolean ) with standard labels, icon and accelerators enabled.
MuAction(MainFrame mainFrame, java.util.Hashtable properties, boolean useStandardLabels)
          Convenience constructor which has the same effect as calling MuAction(MainFrame, Hashtable, boolean, boolean, boolean) with standard icon and accelerators enabled.
MuAction(MainFrame mainFrame, java.util.Hashtable properties, boolean useStandardLabels, boolean useStandardIcon, boolean useStandardAccelerators)
          Creates a new MuAction associated with the specified MainFrame.
 
Method Summary
 void actionPerformed(java.awt.event.ActionEvent e)
          Intercepts action events and filters them out when the MainFrame associated with this action is in 'no events' mode and honourNoEventsMode() returns true.
 javax.swing.KeyStroke getAccelerator()
          Returns the accelerator KeyStroke of this action, null if this action has no accelerator.
 java.lang.String getAcceleratorText()
          Returns a displayable String representation of this action's accelerator, in the [modifier]+[modifier]+...+key format.
 javax.swing.KeyStroke getAlternateAccelerator()
          Returns the alternate accelerator KeyStroke of this action, null if it doesn't have any.
 javax.swing.ImageIcon getIcon()
          Return the icon of this action, null if this action has no icon.
static java.lang.String getKeyStrokeRepresentation(javax.swing.KeyStroke ks)
          Returns a String representation for the given KeyStroke, in the following format:
modifier+modifier+...+key
 java.lang.String getLabel()
          Returns the label of this action, null if this action has no label.
 MainFrame getMainFrame()
          Return the MainFrame this MuAction is associated.
static java.lang.String getModifiersRepresentation(int modifiers)
          Returns a String representations of the given modifiers bitwise mask, in the following format:
modifier+...+modifier
 javax.swing.KeyStroke getStandardAccelerator()
          Shorthand for getStandardAccelerator(Class) called with the Class instance returned by Object.getClass().
static javax.swing.KeyStroke getStandardAccelerator(java.lang.Class action)
          Queries ActionKeymap for an accelerator corresponding to the specified action.
 javax.swing.KeyStroke getStandardAlternateAccelerator()
          Shorthand for getStandardAlternateAccelerator(Class) called with the Class instance returned by Object.getClass().
static javax.swing.KeyStroke getStandardAlternateAccelerator(java.lang.Class action)
          Queries ActionKeymap for an alternate accelerator corresponding to the specified action.
 javax.swing.ImageIcon getStandardIcon()
          Shorthand for getStandardIcon(Class) called with the Class instance returned by Object.getClass().
static javax.swing.ImageIcon getStandardIcon(java.lang.Class action)
          Queries IconManager for an image icon corresponding to the specified action using standard icon path conventions.
 java.lang.String getStandardIconPath()
          Shorthand for getStandardIconPath(Class) called with the Class instance returned by Object.getClass().
static java.lang.String getStandardIconPath(java.lang.Class action)
          Returns the standard path to the icon image for the specified MuAction class.
 java.lang.String getStandardLabel()
          Shorthand for getStandardLabel(Class) called with the Class instance returned by Object.getClass().
static java.lang.String getStandardLabel(java.lang.Class action)
          Queries Translator for a label corresponding to the specified action using standard naming conventions.
 java.lang.String getStandardLabelKey()
          Shorthand for getStandardLabelKey(Class) called with the Class instance returned by Object.getClass().
static java.lang.String getStandardLabelKey(java.lang.Class action)
          Returns the dictionary key for the specified action's label, using the following standard naming convention:
 java.lang.String getStandardTooltip()
          Shorthand for getStandardTooltip(Class) called with the Class instance returned by Object.getClass().
static java.lang.String getStandardTooltip(java.lang.Class action)
          Queries Translator for a tooltip corresponding to the specified action using standard naming conventions.
 java.lang.String getStandardTooltipKey()
          Shorthand for getStandardTooltipKey(Class) called with the Class instance returned by Object.getClass().
static java.lang.String getStandardTooltipKey(java.lang.Class action)
          Returns the dictionary key for the specified action's tooltip, using the following standard naming convention:
 java.lang.String getToolTipText()
          Returns the tooltip text of this action, null if this action has no tooltip.
 boolean honourNoEventsMode()
          Return true if action events are ignored while the MainFrame associated with this action is in 'no events mode' (see MainFrame for an explanation about this mode).
 boolean isAccelerator(javax.swing.KeyStroke keyStroke)
          Returns true if the given KeyStroke is one of this action's accelerators.
abstract  void performAction()
          Called when this action has been triggered.
 boolean performActionInSeparateThread()
          Returns true if performAction() is called from a separate thread (and not from the event thread) when this action is performed.
protected  void reportError(java.lang.String message)
          Opens a dialog with the specified error message.
protected  void reportError(java.lang.String title, java.lang.String message)
          Opens an error dialog with the specified title and message.
protected  void reportGenericError()
          Opens a dialog with a generic error message.
 void setAccelerator(javax.swing.KeyStroke keyStroke)
          Sets the accelerator KeyStroke for this action, null for no accelerator.
 void setAlternateAccelerator(javax.swing.KeyStroke keyStroke)
          Sets the alternate accelerator KeyStroke for this action, null for none.
 void setHonourNoEventsMode(boolean honourNoEventsMode)
          Sets whether action events are to be ignored while the MainFrame associated with this action is in 'no events mode' (see MainFrame for an explanation about this mode).
 void setIcon(javax.swing.ImageIcon icon)
          Sets the icon for this action, null if this action has no icon.
 void setLabel(java.lang.String label)
          Sets the label for this action, null for no label.
 void setPerformActionInSeparateThread(boolean performActionInSeparateThread)
          Sets whether performAction() is called from a separate thread (and not from the event thread) when this action is performed.
 void setToolTipText(java.lang.String toolTipText)
          Sets the tooltip for this action, null for no tooltip.
 
Methods inherited from class javax.swing.AbstractAction
addPropertyChangeListener, clone, firePropertyChange, getKeys, getPropertyChangeListeners, getValue, isEnabled, putValue, removePropertyChangeListener, setEnabled
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

mainFrame

protected MainFrame mainFrame
The MainFrame associated with this MuAction


ALTERNATE_ACCELERATOR_PROPERTY_KEY

public static final java.lang.String ALTERNATE_ACCELERATOR_PROPERTY_KEY
Name of the alternate accelerator KeyStroke property

See Also:
Constant Field Values
Constructor Detail

MuAction

public MuAction(MainFrame mainFrame,
                java.util.Hashtable properties)
Convenience constructor which has the same effect as calling MuAction(MainFrame, Hashtable, boolean, boolean, boolean ) with standard labels, icon and accelerators enabled.

Parameters:
mainFrame - the MainFrame to associate with this new MuAction
properties - the initial properties to use in this action. The Hashtable may simply be empty if no initial properties are specified.

MuAction

public MuAction(MainFrame mainFrame,
                java.util.Hashtable properties,
                boolean useStandardLabels)
Convenience constructor which has the same effect as calling MuAction(MainFrame, Hashtable, boolean, boolean, boolean) with standard icon and accelerators enabled.

Parameters:
mainFrame - the MainFrame to associate with this new MuAction
properties - the initial properties to use in this action. The Hashtable may simply be empty if no initial properties are specified.
useStandardLabels - if true, standard label and tooltip (if any) will be retrieved with getStandardLabel(Class) and getStandardTooltip(Class) and used

MuAction

public MuAction(MainFrame mainFrame,
                java.util.Hashtable properties,
                boolean useStandardLabels,
                boolean useStandardIcon,
                boolean useStandardAccelerators)
Creates a new MuAction associated with the specified MainFrame. The properties contained by the given Hashtable are used to initialize this action's property map.

The useStandardLabels, useStandardIcon and useStandardAccelerators parameters control whether standard property values are automatically retrieved and used. These should be disabled if custom values are used.

Parameters:
mainFrame - the MainFrame to associate with this new MuAction
properties - the initial properties to use in this action. The Hashtable may simply be empty if no initial properties are specified.
useStandardLabels - if true, standard label and tooltip (if any) will be retrieved with getStandardLabel() and getStandardTooltip() and used
useStandardIcon - if true, standard icon (if any) will be retrieved using getStandardIcon() and used
useStandardAccelerators - if true, standard accelerator and alternate accelerator (if any) will be retrieved with getStandardAccelerator() and getStandardAlternateAccelerator() and used
Method Detail

getMainFrame

public MainFrame getMainFrame()
Return the MainFrame this MuAction is associated.

Returns:
the MainFrame this action is associated with

getLabel

public java.lang.String getLabel()
Returns the label of this action, null if this action has no label. The label value is stored in the Action.NAME property.

Returns:
the label of this action, null if this action has no label

setLabel

public void setLabel(java.lang.String label)
Sets the label for this action, null for no label. The label value is stored in the Action.NAME property.

Parameters:
label - the new text label for this action, replacing the previous one (if any)

getToolTipText

public java.lang.String getToolTipText()
Returns the tooltip text of this action, null if this action has no tooltip. The tooltip value is stored in the Action.SHORT_DESCRIPTION property.

Returns:
the tooltip text of this action, null if this action has no tooltip

setToolTipText

public void setToolTipText(java.lang.String toolTipText)
Sets the tooltip for this action, null for no tooltip. The tooltip value is stored in the Action.SHORT_DESCRIPTION property.

Parameters:
toolTipText - the new tooltip text for this action replacing the previous one (if any)

getIcon

public javax.swing.ImageIcon getIcon()
Return the icon of this action, null if this action has no icon. The icon value is stored in the Action.SMALL_ICON property.

Returns:
the icon of this action, null if this action has no icon

setIcon

public void setIcon(javax.swing.ImageIcon icon)
Sets the icon for this action, null if this action has no icon. The icon value is stored in the Action.SMALL_ICON property.

Parameters:
icon - the new image icon for this action, replacing the previous one (if any)

getAccelerator

public javax.swing.KeyStroke getAccelerator()
Returns the accelerator KeyStroke of this action, null if this action has no accelerator. The accelerator value is stored in the Action.ACCELERATOR_KEY property.

Returns:
the accelerator KeyStroke of this action, null if this action has no accelerator

setAccelerator

public void setAccelerator(javax.swing.KeyStroke keyStroke)
Sets the accelerator KeyStroke for this action, null for no accelerator. The tooltip value is stored in the Action.ACCELERATOR_KEY property.

Parameters:
keyStroke - the new accelerator KeyStroke for this action, replacing the previous one (if any)

getAlternateAccelerator

public javax.swing.KeyStroke getAlternateAccelerator()
Returns the alternate accelerator KeyStroke of this action, null if it doesn't have any. The accelerator accelerator value is stored in the ALTERNATE_ACCELERATOR_PROPERTY_KEY property.

Returns:
the alternate accelerator KeyStroke of this action, null if it doesn't have any

setAlternateAccelerator

public void setAlternateAccelerator(javax.swing.KeyStroke keyStroke)
Sets the alternate accelerator KeyStroke for this action, null for none. The accelerator accelerator value is stored in the ALTERNATE_ACCELERATOR_PROPERTY_KEY property.

Parameters:
keyStroke - the new alternate accelerator KeyStroke for this action, replacing the previous one (if any)

isAccelerator

public boolean isAccelerator(javax.swing.KeyStroke keyStroke)
Returns true if the given KeyStroke is one of this action's accelerators. This method always returns false if this method has no accelerator.

Parameters:
keyStroke - the KeyStroke to test against this action's acccelerators
Returns:
true if the given KeyStroke is one of this action's accelerators

getAcceleratorText

public java.lang.String getAcceleratorText()
Returns a displayable String representation of this action's accelerator, in the [modifier]+[modifier]+...+key format. This method returns null if this action has no accelerator.

Returns:
a String representation of the accelerator, or null if this action has no accelerator.

honourNoEventsMode

public boolean honourNoEventsMode()
Return true if action events are ignored while the MainFrame associated with this action is in 'no events mode' (see MainFrame for an explanation about this mode). By default, this method returns true.

Returns:
true if action events are ignored while the MainFrame associated with this action is in 'no events' mode

setHonourNoEventsMode

public void setHonourNoEventsMode(boolean honourNoEventsMode)
Sets whether action events are to be ignored while the MainFrame associated with this action is in 'no events mode' (see MainFrame for an explanation about this mode). By default (unless this method has been called), 'no events mode' is honoured.

Parameters:
honourNoEventsMode - if true, actions events will be ignored while the MainFrame associated with this action is in 'no events mode'

performActionInSeparateThread

public boolean performActionInSeparateThread()
Returns true if performAction() is called from a separate thread (and not from the event thread) when this action is performed. By default, false is returned, i.e. actions are performed from the main event thread.

Actions that have the potential to hold the caller thread for a substantial amount of time should perform the action in a separate thread, to avoid locking the event thread.

Returns:
true if performAction() is called from a separate thread (and not from the event thread) when this action is performed

setPerformActionInSeparateThread

public void setPerformActionInSeparateThread(boolean performActionInSeparateThread)
Sets whether performAction() is called from a separate thread (and not from the event thread) when this action is performed. By default (unless this method has been called), actions are performed from the main event thread.

Actions that have the potential to hold the caller thread for a substantial amount of time should perform the action in a separate thread, to avoid locking the event thread.

Parameters:
performActionInSeparateThread - true to have performAction() called from a separate thread (and not from the event thread) when this action is performed

getStandardLabel

public java.lang.String getStandardLabel()
Shorthand for getStandardLabel(Class) called with the Class instance returned by Object.getClass().

Returns:
the standard label corresponding to this MuAction class, null if none was found

getStandardLabelKey

public java.lang.String getStandardLabelKey()
Shorthand for getStandardLabelKey(Class) called with the Class instance returned by Object.getClass().

Returns:
the standard dictionary key for this action's label

getStandardTooltip

public java.lang.String getStandardTooltip()
Shorthand for getStandardTooltip(Class) called with the Class instance returned by Object.getClass().

Returns:
the standard tooltip corresponding to this MuAction class, null if none was found

getStandardTooltipKey

public java.lang.String getStandardTooltipKey()
Shorthand for getStandardTooltipKey(Class) called with the Class instance returned by Object.getClass().

Returns:
the standard dictionary key for this action's tooltip

getStandardAccelerator

public javax.swing.KeyStroke getStandardAccelerator()
Shorthand for getStandardAccelerator(Class) called with the Class instance returned by Object.getClass().

Returns:
the standard accelerator corresponding to this MuAction class, null if none was found

getStandardAlternateAccelerator

public javax.swing.KeyStroke getStandardAlternateAccelerator()
Shorthand for getStandardAlternateAccelerator(Class) called with the Class instance returned by Object.getClass().

Returns:
the standard alternate accelerator corresponding to this MuAction class, null if none was found

getStandardIcon

public javax.swing.ImageIcon getStandardIcon()
Shorthand for getStandardIcon(Class) called with the Class instance returned by Object.getClass().

Returns:
the standard icon corresponding to this MuAction class, null if none was found

getStandardIconPath

public java.lang.String getStandardIconPath()
Shorthand for getStandardIconPath(Class) called with the Class instance returned by Object.getClass().

Returns:
the standard path for this action's image icon

getStandardLabel

public static java.lang.String getStandardLabel(java.lang.Class action)
Queries Translator for a label corresponding to the specified action using standard naming conventions. Returns the label or null if no corresponding entry was found in the dictionary.

Parameters:
action - a MuAction class descriptor
Returns:
the standard label corresponding to the specified MuAction class, null if none was found

getStandardLabelKey

public static java.lang.String getStandardLabelKey(java.lang.Class action)
Returns the dictionary key for the specified action's label, using the following standard naming convention:
      action_classname.label
 
where action_classname is the fully qualified action class's name, as returned by Class.getName().

Parameters:
action - a MuAction class descriptor
Returns:
the standard dictionary key for the specified action's label

getStandardTooltip

public static java.lang.String getStandardTooltip(java.lang.Class action)
Queries Translator for a tooltip corresponding to the specified action using standard naming conventions. Returns the tooltip or null if no corresponding entry was found in the dictionary.

Parameters:
action - a MuAction class descriptor
Returns:
the standard tooltip corresponding to the specified MuAction class, null if none was found

getStandardTooltipKey

public static java.lang.String getStandardTooltipKey(java.lang.Class action)
Returns the dictionary key for the specified action's tooltip, using the following standard naming convention:
      action_classname.tooltip
 
where action_classname is the fully qualified action class's name, as returned by Class.getName().

Parameters:
action - a MuAction class descriptor
Returns:
the standard dictionary key for the specified action's tooltip

getStandardAccelerator

public static javax.swing.KeyStroke getStandardAccelerator(java.lang.Class action)
Queries ActionKeymap for an accelerator corresponding to the specified action. Returns the accelerator's KeyStroke or null if no corresponding accelerator was found.

Parameters:
action - a MuAction class descriptor
Returns:
the standard accelerator corresponding to the specified MuAction class, null if none was found

getStandardAlternateAccelerator

public static javax.swing.KeyStroke getStandardAlternateAccelerator(java.lang.Class action)
Queries ActionKeymap for an alternate accelerator corresponding to the specified action. Returns the accelerator's KeyStroke or null if no corresponding accelerator was found.

Parameters:
action - a MuAction class descriptor
Returns:
the standard alternate accelerator corresponding to the specified MuAction class, null if none was found

getStandardIcon

public static javax.swing.ImageIcon getStandardIcon(java.lang.Class action)
Queries IconManager for an image icon corresponding to the specified action using standard icon path conventions. Returns the image icon, null if none was found.

Parameters:
action - a MuAction class descriptor
Returns:
the standard icon image corresponding to the specified MuAction class, null if none was found

getStandardIconPath

public static java.lang.String getStandardIconPath(java.lang.Class action)
Returns the standard path to the icon image for the specified MuAction class. The returned path is relative to the application's JAR file.

Parameters:
action - a MuAction class descriptor
Returns:
the standard path to the icon image corresponding to the specified MuAction class

getKeyStrokeRepresentation

public static java.lang.String getKeyStrokeRepresentation(javax.swing.KeyStroke ks)
Returns a String representation for the given KeyStroke, in the following format:
modifier+modifier+...+key

For example, KeyStroke.getKeyStroke(KeyEvent.VK_C, InputEvent.CTRL_MASK|InputEvent.ALT_MASK) will return Ctrl+Alt+C.

Parameters:
ks - the KeyStroke for which to return a String representation
Returns:
a String representation of the given KeyStroke, in the [modifier]+[modifier]+...+key format

getModifiersRepresentation

public static java.lang.String getModifiersRepresentation(int modifiers)
Returns a String representations of the given modifiers bitwise mask, in the following format:
modifier+...+modifier

The modifiers' order in the returned String tries to mimick the keyboard layout of the current platform as much as possible:

  • Under Mac OS X, the order is: Shift, Ctrl, Alt, Meta
  • Under other platforms, the order is Shift, Ctrl, Meta, Alt

Parameters:
modifiers - a modifiers bitwise mask
Returns:
a String representations of the given modifiers bitwise mask

reportGenericError

protected void reportGenericError()
Opens a dialog with a generic error message.

This is a convenience method and is strictly equivalent to calling reportError(Translator.get(("error"), Translator.get(("generic_error"))


reportError

protected void reportError(java.lang.String message)
Opens a dialog with the specified error message.

This is a convenience method and is strictly equivalent to calling reportError(Translator.get(("error"), message)

Parameters:
message - error message to display.

reportError

protected void reportError(java.lang.String title,
                           java.lang.String message)
Opens an error dialog with the specified title and message.

Parameters:
title - title for the error dialog.
message - message contained by the error dialog.

actionPerformed

public void actionPerformed(java.awt.event.ActionEvent e)
Intercepts action events and filters them out when the MainFrame associated with this action is in 'no events' mode and honourNoEventsMode() returns true. If the action event is not filtered out, performAction() is called to provide a response to the action event.


performAction

public abstract void performAction()
Called when this action has been triggered. This method provides a response to the action trigger.



This file is part of muCommander - Copyright (C) 2002-2008 Maxence Bernard