Package org.openstreetmap.josm.actions
Class JosmAction
java.lang.Object
javax.swing.AbstractAction
org.openstreetmap.josm.actions.JosmAction
- All Implemented Interfaces:
ActionListener,Serializable,Cloneable,EventListener,Action,Destroyable
- Direct Known Subclasses:
AboutAction,AbstractAudioAction,AbstractInfoAction,AbstractMergeAction,AbstractPasteAction,AbstractUploadAction,AddImageryLayerAction,AddNodeAction,AlignGridRotationAction,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.CloseOtherTabsAction,ImageViewerDialog.ImageAction,ImageViewerDialog.ImageCenterViewAction,ImageViewerDialog.ImageCollapseAction,ImageViewerDialog.ImageCopyPathAction,ImageViewerDialog.ImageExtendedInfoAction,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,NewLocalAction,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,SetGridOriginAction,ShowStatusReportAction,SimplifyWayAction,SplitWayAction,TaggingPresetSearchAction,TaggingPresetSearchPrimitiveDialog.Action,ToggleAction,ToggleDialog.ToggleDialogAction,UndoAction,UnGlueAction,UnJoinNodeWayAction,UnselectAllAction,UpdateDataAction,UpdateSelectionAction,UploadNotesAction,UserListDialog.SelectUsersPrimitivesAction,ValidateAction,WikimediaCommonsLoader.WikimediaCommonsLoadImagesAction,ZoomInAction,ZoomOutAction
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 call
updateEnabledState() whenever the global context is changed.
A JosmAction can register a LayerManager.LayerChangeListener and a DataSelectionListener. 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 getLayerManager() 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:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected classAdapter for layer change events.protected classAdapter for layer change events.protected classAdapter for selection change events. -
Field Summary
FieldsFields inherited from class javax.swing.AbstractAction
changeSupport, enabledFields 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
ConstructorsModifierConstructorDescriptionprotectedConstructs a newJosmAction.protectedJosmAction(boolean installAdapters) Constructs a newJosmAction.protectedConstructs a newJosmAction.protectedJosmAction(String name, String iconName, String tooltip, Shortcut shortcut, boolean registerInToolbar) Constructs a newJosmActionand installs layer changed and selection changed adapters.protectedJosmAction(String name, String iconName, String tooltip, Shortcut shortcut, boolean registerInToolbar, boolean installAdapters) Constructs a newJosmAction.protectedJosmAction(String name, String iconName, String tooltip, Shortcut shortcut, boolean registerInToolbar, String toolbarId, boolean installAdapters) The new super for all actions.protectedJosmAction(String name, ImageProvider icon, String tooltip, Shortcut shortcut, boolean registerInToolbar, String toolbarId, boolean installAdapters) Constructs aJosmAction. -
Method Summary
Modifier and TypeMethodDescriptionprotected JosmAction.ActiveLayerChangeAdapterOverride this if callingupdateEnabledState()on active layer change event is not enough.protected JosmAction.LayerChangeAdapterOverride this if callingupdateEnabledState()on layer change events is not enough.static booleancheckAndConfirmOutlyingOperation(String operation, String dialogTitle, String outsideDialogMessage, String incompleteDialogMessage, Collection<? extends OsmPrimitive> primitives, Collection<? extends OsmPrimitive> ignore) Check whether user is about to operate on data outside of the download area.voiddestroy()Called when the object has been destroyed.Gets the layer manager used for this action.Returns the shortcut for this action.protected voidOverride in subclasses to init the enabled state of an action when it is created.protected voidInstalls the listeners to this action.protected booleanOverwrite this ifupdateEnabledState()should be called when the active / available layers change.protected booleanOverwrite this ifupdateEnabledState()should be called when the selection changed.private voidprotected voidSets the help topic id.protected voidsetToolbarId(String toolbarId) Sets the toolbar id.final voidsetTooltip(String tooltip) Sets the tooltip text of this action.private static booleanshowConfirmOutlyingOperationDialog(String preferenceKey, String dialogMessage, String dialogTitle) protected voidOverride in subclasses to update the enabled state of the action when something in the JOSM state changes, i.e.protected voidupdateEnabledState(Collection<? extends OsmPrimitive> selection) Override in subclasses to update the enabled state of the action if the collection of selected primitives changes.protected final voidUpdates enabled state according to primitives currently selected in edit data set, if any.protected final voidupdateEnabledStateOnCurrentSelection(boolean allowReadOnly) Updates enabled state according to primitives currently selected in active data set, if any.protected final voidupdateEnabledStateOnModifiableSelection(Collection<? extends OsmPrimitive> selection) Updates enabled state according to selected primitives, if any.protected static voidwaitFuture(Future<?> future, PleaseWaitProgressMonitor monitor) Methods inherited from class javax.swing.AbstractAction
addPropertyChangeListener, clone, firePropertyChange, getKeys, getPropertyChangeListeners, getValue, isEnabled, putValue, removePropertyChangeListener, setEnabledMethods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.awt.event.ActionListener
actionPerformed
-
Field Details
-
sc
-
layerChangeAdapter
-
activeLayerChangeAdapter
-
selectionChangeAdapter
-
-
Constructor Details
-
JosmAction
protected JosmAction(String name, ImageProvider icon, String tooltip, Shortcut shortcut, boolean registerInToolbar, 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(String name, String iconName, String tooltip, Shortcut shortcut, boolean registerInToolbar, 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(String name, String iconName, 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(String name, String iconName, String tooltip, Shortcut shortcut, boolean registerInToolbar) Constructs a newJosmActionand 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
Constructs a newJosmAction.- Parameters:
installAdapters- false, if you don't want to install layer changed and selection changed adapters
-
JosmAction
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 Details
-
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
Override this if callingupdateEnabledState()on layer change events is not enough.- Returns:
- the
JosmAction.LayerChangeAdapterthat will be called on layer change events - Since:
- 15404
-
buildActiveLayerChangeAdapter
Override this if callingupdateEnabledState()on active layer change event is not enough.- Returns:
- the
JosmAction.LayerChangeAdapterthat will be called on active layer change event - Since:
- 15404
-
listenToLayerChange
Overwrite this ifupdateEnabledState()should be called when the active / available layers change. Default is true.- Returns:
trueif aLayerManager.LayerChangeListenerand aMainLayerManager.ActiveLayerChangeListenershould be registered.- Since:
- 10353
-
listenToSelectionChange
Overwrite this ifupdateEnabledState()should be called when the selection changed. Default is true.- Returns:
trueif aDataSelectionListenershould be registered.- Since:
- 10353
-
destroy
Description copied from interface:DestroyableCalled when the object has been destroyed.- Specified by:
destroyin interfaceDestroyable
-
setHelpId
-
setHelpId
Sets the help topic id.- Parameters:
helpId- help topic id (result ofHelpUtil.ht(java.lang.String))- Since:
- 14397
-
setToolbarId
Sets the toolbar id.- Parameters:
toolbarId- toolbar id- Since:
- 16138
-
getShortcut
Returns the shortcut for this action.- Returns:
- the shortcut for this action, or "No shortcut" if none is defined
-
setTooltip
Sets the tooltip text of this action.- Parameters:
tooltip- The text to display in tooltip. Can benull
-
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
-
initEnabledState
Override in subclasses to init the enabled state of an action when it is created. Default behaviour is to callupdateEnabledState() -
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
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:
-
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
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(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(String operation, String dialogTitle, String outsideDialogMessage, String incompleteDialogMessage, Collection<? extends OsmPrimitive> primitives, 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-nullor 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(String preferenceKey, String dialogMessage, String dialogTitle)
-