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.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,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.LayerChangeListenerand 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 classJosmAction.ActiveLayerChangeAdapterAdapter for layer change events.protected classJosmAction.LayerChangeAdapterAdapter for layer change events.protected classJosmAction.SelectionChangeAdapterAdapter for selection change events.
-
Field Summary
Fields Modifier and Type Field Description private JosmAction.ActiveLayerChangeAdapteractiveLayerChangeAdapterprivate JosmAction.LayerChangeAdapterlayerChangeAdapterprotected Shortcutscprivate JosmAction.SelectionChangeAdapterselectionChangeAdapter
-
Constructor Summary
Constructors Modifier Constructor Description protectedJosmAction()Constructs a newJosmAction.protectedJosmAction(boolean installAdapters)Constructs a newJosmAction.protectedJosmAction(java.lang.String name, java.lang.String iconName, java.lang.String tooltip, java.util.List<Shortcut> shortcuts)Constructs a newJosmAction.protectedJosmAction(java.lang.String name, java.lang.String iconName, java.lang.String tooltip, Shortcut shortcut, boolean registerInToolbar)Constructs a newJosmActionand installs layer changed and selection changed adapters.protectedJosmAction(java.lang.String name, java.lang.String iconName, java.lang.String tooltip, Shortcut shortcut, boolean registerInToolbar, boolean installAdapters)Constructs a newJosmAction.protectedJosmAction(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.protectedJosmAction(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.ActiveLayerChangeAdapterbuildActiveLayerChangeAdapter()Override this if callingupdateEnabledState()on active layer change event is not enough.protected JosmAction.LayerChangeAdapterbuildLayerChangeAdapter()Override this if callingupdateEnabledState()on layer change events is not enough.static booleancheckAndConfirmOutlyingOperation(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.voiddestroy()Called when the object has been destroyed.MainLayerManagergetLayerManager()Gets the layer manager used for this action.ShortcutgetShortcut()Returns the shortcut for this action.protected voidinitEnabledState()Override in subclasses to init the enabled state of an action when it is created.protected voidinstallAdapters()Installs the listeners to this action.protected booleanlistenToLayerChange()Overwrite this ifupdateEnabledState()should be called when the active / available layers change.protected booleanlistenToSelectionChange()Overwrite this ifupdateEnabledState()should be called when the selection changed.private voidsetHelpId()protected voidsetHelpId(java.lang.String helpId)Sets the help topic id.protected voidsetToolbarId(java.lang.String toolbarId)Sets the toolbar id.voidsetTooltip(java.lang.String tooltip)Sets the tooltip text of this action.private static booleanshowConfirmOutlyingOperationDialog(java.lang.String preferenceKey, java.lang.String dialogMessage, java.lang.String dialogTitle)protected voidupdateEnabledState()Override in subclasses to update the enabled state of the action when something in the JOSM state changes, i.e.protected voidupdateEnabledState(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 voidupdateEnabledStateOnCurrentSelection()Updates enabled state according to primitives currently selected in edit data set, if any.protected voidupdateEnabledStateOnCurrentSelection(boolean allowReadOnly)Updates enabled state according to primitives currently selected in active data set, if any.protected voidupdateEnabledStateOnModifiableSelection(java.util.Collection<? extends OsmPrimitive> selection)Updates enabled state according to selected primitives, if any.protected static voidwaitFuture(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 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
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.LayerChangeAdapterthat 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.LayerChangeAdapterthat 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:
trueif aLayerManager.LayerChangeListenerand aMainLayerManager.ActiveLayerChangeListenershould be registered.- Since:
- 10353
-
listenToSelectionChange
protected boolean listenToSelectionChange()
Overwrite this ifupdateEnabledState()should be called when the selection changed. Default is true.- Returns:
trueif aDataSelectionListenershould be registered.- Since:
- 10353
-
destroy
public void destroy()
Description copied from interface:DestroyableCalled when the object has been destroyed.- Specified by:
destroyin 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-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(java.lang.String preferenceKey, java.lang.String dialogMessage, java.lang.String dialogTitle)
-
-