org.openstreetmap.josm.actions
Class JosmAction

java.lang.Object
  extended by javax.swing.AbstractAction
      extended by org.openstreetmap.josm.actions.JosmAction
All Implemented Interfaces:
java.awt.event.ActionListener, java.io.Serializable, java.lang.Cloneable, java.util.EventListener, javax.swing.Action, Destroyable
Direct Known Subclasses:
AboutAction, AbstractInfoAction, AbstractMergeAction, AddImageryLayerAction, AddNodeAction, AlignInCircleAction, AlignInLineAction, AudioBackAction, AudioFastSlowAction, AudioFwdAction, AudioNextAction, AudioPlayPauseAction, AudioPrevAction, AutoScaleAction, ChangesetManagerToggleAction, CloseChangesetAction, CombineWayAction, CopyAction, CopyCoordinatesAction, CreateCircleAction, CreateMultipolygonAction, DeleteAction, DiskAccessAction, DistributeAction, DownloadAction, DownloadPrimitiveAction, DownloadReferrersAction, DrawAction.SnapChangeAction, DuplicateAction, ExitAction, ExpertToggleAction, FollowLineAction, FullscreenToggleAction, HistoryInfoAction, InfoAction, JoinAreasAction, JoinNodeWayAction, JumpToAction, MainApplet.UploadPreferencesAction, Map_Rectifier_WMSmenuAction, MapMode, MapPaintMenu.MapPaintAction, MergeNodesAction, MirrorAction, MoveAction, MoveNodeAction, NewAction, OpenLocationAction, OrthogonalizeAction, OrthogonalizeAction.Undo, PasteAction, PasteTagsAction, PreferencesAction, PreferenceToggleAction, PropertiesDialog.AddAction, PropertiesDialog.DeleteAction, PropertiesDialog.EditAction, PurgeAction, RedoAction, ReverseWayAction, SearchAction, SelectAllAction, ShowStatusReportAction, SimplifyWayAction, SplitWayAction, TaggingPresetSearchAction, ToggleDialog.ToggleDialogAction, ToggleGPXLinesAction, ToggleUploadDiscouragedLayerAction, UndoAction, UnGlueAction, UnselectAllAction, UpdateDataAction, UpdateSelectionAction, UploadAction, UploadSelectionAction, ValidateAction, ViewportFollowToggleAction, WireframeToggleAction, ZoomInAction, ZoomOutAction

public abstract class JosmAction
extends javax.swing.AbstractAction
implements Destroyable

Base class helper for all Actions in JOSM. Just to make the life easier. A JosmAction is a MapView.LayerChangeListener and a SelectionChangedListener. Upon a layer change event or a selection change event it invokes updateEnabledState(). Subclasses can override updateEnabledState() in order to update the AbstractAction.isEnabled()-state of a JosmAction depending on the getCurrentDataSet() and the current layers (see also getEditLayer()). destroy() from interface Destroyable is called e.g. for MapModes, when the last layer has been removed and so the mapframe will be destroyed. For other JosmActions, destroy() may never be called (currently).

See Also:
Serialized Form

Nested Class Summary
private  class JosmAction.LayerChangeAdapter
          Adapter for layer change events
private  class JosmAction.SelectionChangeAdapter
          Adapter for selection change events
 
Field Summary
private  JosmAction.LayerChangeAdapter layerChangeAdapter
           
protected  Shortcut sc
           
private  JosmAction.SelectionChangeAdapter selectionChangeAdapter
           
 
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
JosmAction()
           
JosmAction(boolean installAdapters)
           
JosmAction(java.lang.String name, javax.swing.Icon icon, java.lang.String tooltip, Shortcut shortcut, boolean registerInToolbar, java.lang.String toolbarId, boolean installAdapters)
          Constructs a JosmAction.
JosmAction(java.lang.String name, java.lang.String iconName, java.lang.String tooltip, Shortcut shortcut, boolean register)
           
JosmAction(java.lang.String name, java.lang.String iconName, java.lang.String tooltip, Shortcut shortcut, boolean register, boolean installAdapters)
           
JosmAction(java.lang.String name, java.lang.String iconName, java.lang.String tooltip, Shortcut shortcut, boolean register, java.lang.String toolbarId, boolean installAdapters)
          The new super for all actions.
 
Method Summary
 void destroy()
          Called when the object has been destroyed.
protected static DataSet getCurrentDataSet()
          Replies the current dataset
protected static OsmDataLayer getEditLayer()
          Replies the current edit layer
 Shortcut getShortcut()
           
protected  void initEnabledState()
          Override in subclasses to init the enabled state of an action when it is created.
protected  void installAdapters()
           
private  void setHelpId()
           
 void setTooltip(java.lang.String tooltip)
           
protected  void updateEnabledState()
          Override in subclasses to update the enabled state of the action when something in the JOSM state changes, i.e.
protected  void updateEnabledState(java.util.Collection<? extends OsmPrimitive> selection)
          Override in subclasses to update the enabled state of the action if the collection of selected primitives changes.
 
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
 
Methods inherited from interface java.awt.event.ActionListener
actionPerformed
 

Field Detail

sc

protected Shortcut sc

layerChangeAdapter

private JosmAction.LayerChangeAdapter layerChangeAdapter

selectionChangeAdapter

private JosmAction.SelectionChangeAdapter selectionChangeAdapter
Constructor Detail

JosmAction

public JosmAction(java.lang.String name,
                  javax.swing.Icon icon,
                  java.lang.String tooltip,
                  Shortcut shortcut,
                  boolean registerInToolbar,
                  java.lang.String toolbarId,
                  boolean installAdapters)
Constructs a JosmAction.

Parameters:
name - the action's text as displayed on the menu (if it is added to a menu)
icon - the icon to use
tooltip - a longer description of the action that will be displayed in the tooltip. Please note that html is not supported for menu actions on some platforms.
shortcut - a ready-created shortcut object or null if you don't want a shortcut. But you always do want a shortcut, remember you can always register it with group=none, so you won't be assigned a shortcut unless the user configures one. If you pass null here, the user CANNOT configure a shortcut for your action.
registerInToolbar - register this action for the toolbar preferences?
toolbarId - identifier for the toolbar preferences. The iconName is used, if this parameter is null
installAdapters - false, if you don't want to install layer changed and selection changed adapters

JosmAction

public JosmAction(java.lang.String name,
                  java.lang.String iconName,
                  java.lang.String tooltip,
                  Shortcut shortcut,
                  boolean register,
                  java.lang.String toolbarId,
                  boolean installAdapters)
The new super for all actions. Use this super constructor to setup your action.

Parameters:
name - the action's text as displayed on the menu (if it is added to a menu)
iconName - the filename of the icon to use
tooltip - a longer description of the action that will be displayed in the tooltip. Please note that html is not supported for menu actions on some platforms.
shortcut - a ready-created shortcut object or null if you don't want a shortcut. But you always do want a shortcut, remember you can always register it with group=none, so you won't be assigned a shortcut unless the user configures one. If you pass null here, the user CANNOT configure a shortcut for your action.
register - register this action for the toolbar preferences?
toolbarId - identifier for the toolbar preferences. The iconName is used, if this parameter is null
installAdapters - false, if you don't want to install layer changed and selection changed adapters

JosmAction

public JosmAction(java.lang.String name,
                  java.lang.String iconName,
                  java.lang.String tooltip,
                  Shortcut shortcut,
                  boolean register,
                  boolean installAdapters)

JosmAction

public JosmAction(java.lang.String name,
                  java.lang.String iconName,
                  java.lang.String tooltip,
                  Shortcut shortcut,
                  boolean register)

JosmAction

public JosmAction()

JosmAction

public JosmAction(boolean installAdapters)
Method Detail

getShortcut

public Shortcut getShortcut()

destroy

public void destroy()
Description copied from interface: Destroyable
Called when the object has been destroyed.

Specified by:
destroy in interface Destroyable

setHelpId

private void setHelpId()

setTooltip

public void setTooltip(java.lang.String tooltip)

getEditLayer

protected static OsmDataLayer getEditLayer()
Replies the current edit layer

Returns:
the current edit layer. null, if no edit layer exists

getCurrentDataSet

protected static DataSet getCurrentDataSet()
Replies the current dataset

Returns:
the current dataset. null, if no current dataset exists

installAdapters

protected void installAdapters()

initEnabledState

protected void initEnabledState()
Override in subclasses to init the enabled state of an action when it is created. Default behaviour is to call updateEnabledState()

See Also:
updateEnabledState(), updateEnabledState(Collection)

updateEnabledState

protected void updateEnabledState()
Override in subclasses to update the enabled state of the action when something in the JOSM state changes, i.e. when a layer is removed or added. See updateEnabledState(Collection) to respond to changes in the collection of selected primitives. Default behavior is empty.

See Also:
updateEnabledState(Collection), initEnabledState()

updateEnabledState

protected void updateEnabledState(java.util.Collection<? extends OsmPrimitive> selection)
Override in subclasses to update the enabled state of the action if the collection of selected primitives changes. This method is called with the new selection.

Parameters:
selection - the collection of selected primitives; may be empty, but not null
See Also:
updateEnabledState(), initEnabledState()


JOSM