Package org.openstreetmap.josm.actions
Class JosmAction
- java.lang.Object
-
- javax.swing.AbstractAction
-
- 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
,AbstractAudioAction
,AbstractInfoAction
,AbstractMergeAction
,AbstractPasteAction
,AbstractUploadAction
,AddImageryLayerAction
,AddNodeAction
,AlignInCircleAction
,AlignInLineAction
,AutoScaleAction
,ChangesetDialog.CloseOpenChangesetsAction
,ChangesetDialog.LaunchChangesetManagerAction
,ChangesetDialog.ReadChangesetsAction
,ChangesetDialog.SelectObjectsAction
,ChangesetDialog.ShowChangesetInfoAction
,CloseChangesetAction
,CombineWayAction
,CommandStackDialog.SelectAction
,CommandStackDialog.UndoRedoAction
,CopyAction
,CopyCoordinatesAction
,CopyUrlAction
,CreateCircleAction
,CreateMultipolygonAction
,CycleLayerDownAction
,CycleLayerUpAction
,DeleteAction
,DeleteLayerAction
,DiskAccessAction
,DistributeAction
,DownloadAction
,DownloadAlongAction
,DownloadNotesInViewAction
,DownloadOsmInViewAction
,DownloadPrimitiveAction
,DownloadReferrersAction
,DrawAction.SnapChangeAction
,EditImagesSequenceAction
,ExitAction
,ExtrudeAction.DualAlignChangeAction
,FilterDialog.FilterAction
,FollowLineAction
,HelpAction
,HelpAwareOptionPane.HelpAction
,HistoryInfoAction
,ImageryMenu.AdjustImageryOffsetAction
,ImageViewerDialog.ImageAction
,ImageViewerDialog.ImageCenterViewAction
,ImageViewerDialog.ImageCollapseAction
,ImageViewerDialog.ImageCopyPathAction
,ImageViewerDialog.ImageOpenExternalAction
,ImageViewerDialog.ImageRemoveAction
,ImageViewerDialog.ImageRemoveFromDiskAction
,ImageViewerDialog.ImageZoomAction
,InfoAction
,InvertSelectionAction
,JoinAreasAction
,JoinNodeWayAction
,JumpToAction
,MapMode
,MapPaintDialog.MoveUpDownAction
,MapPaintDialog.OnOffAction
,MapPaintMenu.MapPaintAction
,MapRectifierWMSmenuAction
,MenuItemSearchDialog.Action
,MergeNodesAction
,MirrorAction
,MoveAction
,MoveNodeAction
,NewAction
,NotesDialog.AddCommentAction
,NotesDialog.CloseAction
,NotesDialog.NewAction
,NotesDialog.OpenInBrowserAction
,NotesDialog.ReopenAction
,NotesDialog.SortAction
,OpenLocationAction
,OrthogonalizeAction
,OrthogonalizeAction.Undo
,PasteTagsAction
,PreferencesAction
,PropertiesDialog.AddAction
,PropertiesDialog.DeleteAction
,PropertiesDialog.EditAction
,PurgeAction
,RecentRelationsAction
,RedoAction
,RelationListDialog.NewAction
,ReorderImageryLayersAction
,ReportBugAction
,RestartAction
,ReverseWayAction
,SaveLayersDialog.SaveSessionButtonAction
,SearchAction
,SearchNotesDownloadAction
,SelectAllAction
,SelectNonBranchingWaySequencesAction
,SelectSharedChildObjectsAction
,ShowStatusReportAction
,SimplifyWayAction
,SplitWayAction
,TaggingPresetSearchAction
,TaggingPresetSearchPrimitiveDialog.Action
,ToggleAction
,ToggleDialog.ToggleDialogAction
,UndoAction
,UnGlueAction
,UnJoinNodeWayAction
,UnselectAllAction
,UpdateDataAction
,UpdateSelectionAction
,UploadNotesAction
,UserListDialog.SelectUsersPrimitivesAction
,ValidateAction
,WikimediaCommonsLoader.WikimediaCommonsLoadImagesAction
,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. This action allows you to set up an icon, a tooltip text, a globally registered shortcut, register it in the main toolbar and set up layer/selection listeners that callupdateEnabledState()
whenever the global context is changed. A JosmAction can register aLayerManager.LayerChangeListener
and aDataSelectionListener
. Upon a layer change event or a selection change event it invokesupdateEnabledState()
. Subclasses can overrideupdateEnabledState()
in order to update theAbstractAction.isEnabled()
-state of a JosmAction depending on thegetLayerManager()
state. 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
Nested Classes Modifier and Type Class Description protected class
JosmAction.ActiveLayerChangeAdapter
Adapter for layer change events.protected class
JosmAction.LayerChangeAdapter
Adapter for layer change events.protected class
JosmAction.SelectionChangeAdapter
Adapter for selection change events.
-
Field Summary
Fields Modifier and Type Field Description private JosmAction.ActiveLayerChangeAdapter
activeLayerChangeAdapter
private JosmAction.LayerChangeAdapter
layerChangeAdapter
protected Shortcut
sc
private JosmAction.SelectionChangeAdapter
selectionChangeAdapter
-
Constructor Summary
Constructors Modifier Constructor Description protected
JosmAction()
Constructs a newJosmAction
.protected
JosmAction(boolean installAdapters)
Constructs a newJosmAction
.protected
JosmAction(java.lang.String name, java.lang.String iconName, java.lang.String tooltip, java.util.List<Shortcut> shortcuts)
Constructs a newJosmAction
.protected
JosmAction(java.lang.String name, java.lang.String iconName, java.lang.String tooltip, Shortcut shortcut, boolean registerInToolbar)
Constructs a newJosmAction
and installs layer changed and selection changed adapters.protected
JosmAction(java.lang.String name, java.lang.String iconName, java.lang.String tooltip, Shortcut shortcut, boolean registerInToolbar, boolean installAdapters)
Constructs a newJosmAction
.protected
JosmAction(java.lang.String name, java.lang.String iconName, java.lang.String tooltip, Shortcut shortcut, boolean registerInToolbar, java.lang.String toolbarId, boolean installAdapters)
The new super for all actions.protected
JosmAction(java.lang.String name, ImageProvider icon, java.lang.String tooltip, Shortcut shortcut, boolean registerInToolbar, java.lang.String toolbarId, boolean installAdapters)
Constructs aJosmAction
.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected JosmAction.ActiveLayerChangeAdapter
buildActiveLayerChangeAdapter()
Override this if callingupdateEnabledState()
on active layer change event is not enough.protected JosmAction.LayerChangeAdapter
buildLayerChangeAdapter()
Override this if callingupdateEnabledState()
on layer change events is not enough.static boolean
checkAndConfirmOutlyingOperation(java.lang.String operation, java.lang.String dialogTitle, java.lang.String outsideDialogMessage, java.lang.String incompleteDialogMessage, java.util.Collection<? extends OsmPrimitive> primitives, java.util.Collection<? extends OsmPrimitive> ignore)
Check whether user is about to operate on data outside of the download area.void
destroy()
Called when the object has been destroyed.MainLayerManager
getLayerManager()
Gets the layer manager used for this action.Shortcut
getShortcut()
Returns the shortcut for this action.protected void
initEnabledState()
Override in subclasses to init the enabled state of an action when it is created.protected void
installAdapters()
Installs the listeners to this action.protected boolean
listenToLayerChange()
Overwrite this ifupdateEnabledState()
should be called when the active / available layers change.protected boolean
listenToSelectionChange()
Overwrite this ifupdateEnabledState()
should be called when the selection changed.private void
setHelpId()
protected void
setHelpId(java.lang.String helpId)
Sets the help topic id.protected void
setToolbarId(java.lang.String toolbarId)
Sets the toolbar id.void
setTooltip(java.lang.String tooltip)
Sets the tooltip text of this action.private static boolean
showConfirmOutlyingOperationDialog(java.lang.String preferenceKey, java.lang.String dialogMessage, java.lang.String dialogTitle)
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.protected void
updateEnabledStateOnCurrentSelection()
Updates enabled state according to primitives currently selected in edit data set, if any.protected void
updateEnabledStateOnCurrentSelection(boolean allowReadOnly)
Updates enabled state according to primitives currently selected in active data set, if any.protected void
updateEnabledStateOnModifiableSelection(java.util.Collection<? extends OsmPrimitive> selection)
Updates enabled state according to selected primitives, if any.protected static void
waitFuture(java.util.concurrent.Future<?> future, PleaseWaitProgressMonitor monitor)
-
Methods inherited from class javax.swing.AbstractAction
addPropertyChangeListener, clone, firePropertyChange, getKeys, getPropertyChangeListeners, getValue, isEnabled, putValue, removePropertyChangeListener, setEnabled
-
-
-
-
Field Detail
-
layerChangeAdapter
private transient JosmAction.LayerChangeAdapter layerChangeAdapter
-
activeLayerChangeAdapter
private transient JosmAction.ActiveLayerChangeAdapter activeLayerChangeAdapter
-
selectionChangeAdapter
private transient JosmAction.SelectionChangeAdapter selectionChangeAdapter
-
-
Constructor Detail
-
JosmAction
protected JosmAction(java.lang.String name, ImageProvider icon, java.lang.String tooltip, Shortcut shortcut, boolean registerInToolbar, java.lang.String toolbarId, boolean installAdapters)
Constructs aJosmAction
.- Parameters:
name
- the action's text as displayed on the menu (if it is added to a menu)icon
- the icon to usetooltip
- 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 preferencesinstallAdapters
- false, if you don't want to install layer changed and selection changed adapters
-
JosmAction
protected JosmAction(java.lang.String name, java.lang.String iconName, java.lang.String tooltip, Shortcut shortcut, boolean registerInToolbar, 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 usetooltip
- 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 nullinstallAdapters
- false, if you don't want to install layer changed and selection changed adapters
-
JosmAction
protected JosmAction(java.lang.String name, java.lang.String iconName, java.lang.String tooltip, Shortcut shortcut, boolean registerInToolbar, boolean installAdapters)
Constructs a newJosmAction
. 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 usetooltip
- 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?installAdapters
- false, if you don't want to install layer changed and selection changed adapters
-
JosmAction
protected JosmAction(java.lang.String name, java.lang.String iconName, java.lang.String tooltip, Shortcut shortcut, boolean registerInToolbar)
Constructs a newJosmAction
and installs layer changed and selection changed adapters. 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 usetooltip
- 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?
-
JosmAction
protected JosmAction()
Constructs a newJosmAction
.
-
JosmAction
protected JosmAction(boolean installAdapters)
Constructs a newJosmAction
.- Parameters:
installAdapters
- false, if you don't want to install layer changed and selection changed adapters
-
JosmAction
protected JosmAction(java.lang.String name, java.lang.String iconName, java.lang.String tooltip, java.util.List<Shortcut> shortcuts)
Constructs a newJosmAction
. 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 usetooltip
- 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.shortcuts
- ready-created shortcut objects- Since:
- 14012
-
-
Method Detail
-
installAdapters
protected void installAdapters()
Installs the listeners to this action.This should either never be called or only called in the constructor of this action.
All registered adapters should be removed in
destroy()
-
buildLayerChangeAdapter
protected JosmAction.LayerChangeAdapter buildLayerChangeAdapter()
Override this if callingupdateEnabledState()
on layer change events is not enough.- Returns:
- the
JosmAction.LayerChangeAdapter
that will be called on layer change events - Since:
- 15404
-
buildActiveLayerChangeAdapter
protected JosmAction.ActiveLayerChangeAdapter buildActiveLayerChangeAdapter()
Override this if callingupdateEnabledState()
on active layer change event is not enough.- Returns:
- the
JosmAction.LayerChangeAdapter
that will be called on active layer change event - Since:
- 15404
-
listenToLayerChange
protected boolean listenToLayerChange()
Overwrite this ifupdateEnabledState()
should be called when the active / available layers change. Default is true.- Returns:
true
if aLayerManager.LayerChangeListener
and aMainLayerManager.ActiveLayerChangeListener
should be registered.- Since:
- 10353
-
listenToSelectionChange
protected boolean listenToSelectionChange()
Overwrite this ifupdateEnabledState()
should be called when the selection changed. Default is true.- Returns:
true
if aDataSelectionListener
should be registered.- Since:
- 10353
-
destroy
public void destroy()
Description copied from interface:Destroyable
Called when the object has been destroyed.- Specified by:
destroy
in interfaceDestroyable
-
setHelpId
private void setHelpId()
-
setHelpId
protected void setHelpId(java.lang.String helpId)
Sets the help topic id.- Parameters:
helpId
- help topic id (result ofHelpUtil.ht(java.lang.String)
)- Since:
- 14397
-
setToolbarId
protected void setToolbarId(java.lang.String toolbarId)
Sets the toolbar id.- Parameters:
toolbarId
- toolbar id- Since:
- 16138
-
getShortcut
public Shortcut getShortcut()
Returns the shortcut for this action.- Returns:
- the shortcut for this action, or "No shortcut" if none is defined
-
setTooltip
public final void setTooltip(java.lang.String tooltip)
Sets the tooltip text of this action.- Parameters:
tooltip
- The text to display in tooltip. Can benull
-
getLayerManager
public MainLayerManager getLayerManager()
Gets the layer manager used for this action. Defaults to the main layer manager but you can overwrite this.The layer manager must be available when
installAdapters()
is called and must not change.- Returns:
- The layer manager.
- Since:
- 10353
-
waitFuture
protected static void waitFuture(java.util.concurrent.Future<?> future, PleaseWaitProgressMonitor monitor)
-
initEnabledState
protected void initEnabledState()
Override in subclasses to init the enabled state of an action when it is created. Default behaviour is to callupdateEnabledState()
-
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. SeeupdateEnabledState(Collection)
to respond to changes in the collection of selected primitives. Default behavior is empty.
-
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()
,listenToSelectionChange()
-
updateEnabledStateOnCurrentSelection
protected final void updateEnabledStateOnCurrentSelection()
Updates enabled state according to primitives currently selected in edit data set, if any. Can be called inupdateEnabledState()
implementations.- Since:
- 10409
- See Also:
updateEnabledStateOnCurrentSelection(boolean)
-
updateEnabledStateOnCurrentSelection
protected final void updateEnabledStateOnCurrentSelection(boolean allowReadOnly)
Updates enabled state according to primitives currently selected in active data set, if any. Can be called inupdateEnabledState()
implementations.- Parameters:
allowReadOnly
- iftrue
, read-only data sets are considered- Since:
- 13434
-
updateEnabledStateOnModifiableSelection
protected final void updateEnabledStateOnModifiableSelection(java.util.Collection<? extends OsmPrimitive> selection)
Updates enabled state according to selected primitives, if any. Enables action if the collection is not empty and references primitives in a modifiable data layer. Can be called inupdateEnabledState(Collection)
implementations.- Parameters:
selection
- the collection of selected primitives- Since:
- 13434
-
checkAndConfirmOutlyingOperation
public static boolean checkAndConfirmOutlyingOperation(java.lang.String operation, java.lang.String dialogTitle, java.lang.String outsideDialogMessage, java.lang.String incompleteDialogMessage, java.util.Collection<? extends OsmPrimitive> primitives, java.util.Collection<? extends OsmPrimitive> ignore)
Check whether user is about to operate on data outside of the download area. Request confirmation if he is. Also handles the case that there is no download area.- Parameters:
operation
- the operation name which is used for setting some preferencesdialogTitle
- the title of the dialog being displayedoutsideDialogMessage
- the message text to be displayed when data is outside of the download area or no download area existsincompleteDialogMessage
- the message text to be displayed when data is incompleteprimitives
- the primitives to operate onignore
-null
or a primitive to be ignored- Returns:
- true, if operating on outlying primitives is OK; false, otherwise
- Since:
- 12749 (moved from Command)
-
showConfirmOutlyingOperationDialog
private static boolean showConfirmOutlyingOperationDialog(java.lang.String preferenceKey, java.lang.String dialogMessage, java.lang.String dialogTitle)
-
-