public abstract class JosmAction extends AbstractAction implements Destroyable
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).Modifier and Type | Class and 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.
|
Modifier and Type | Field and Description |
---|---|
private JosmAction.ActiveLayerChangeAdapter |
activeLayerChangeAdapter |
private JosmAction.LayerChangeAdapter |
layerChangeAdapter |
protected Shortcut |
sc |
private JosmAction.SelectionChangeAdapter |
selectionChangeAdapter |
changeSupport, enabled
ACCELERATOR_KEY, ACTION_COMMAND_KEY, DEFAULT, DISPLAYED_MNEMONIC_INDEX_KEY, LARGE_ICON_KEY, LONG_DESCRIPTION, MNEMONIC_KEY, NAME, SELECTED_KEY, SHORT_DESCRIPTION, SMALL_ICON
Modifier | Constructor and Description |
---|---|
protected |
JosmAction()
Constructs a new
JosmAction . |
protected |
JosmAction(boolean installAdapters)
Constructs a new
JosmAction . |
protected |
JosmAction(String name,
ImageProvider icon,
String tooltip,
Shortcut shortcut,
boolean registerInToolbar,
String toolbarId,
boolean installAdapters)
Constructs a
JosmAction . |
protected |
JosmAction(String name,
String iconName,
String tooltip,
List<Shortcut> shortcuts)
Constructs a new
JosmAction . |
protected |
JosmAction(String name,
String iconName,
String tooltip,
Shortcut shortcut,
boolean registerInToolbar)
Constructs a new
JosmAction and installs layer changed and selection changed adapters. |
protected |
JosmAction(String name,
String iconName,
String tooltip,
Shortcut shortcut,
boolean registerInToolbar,
boolean installAdapters)
Constructs a new
JosmAction . |
protected |
JosmAction(String name,
String iconName,
String tooltip,
Shortcut shortcut,
boolean registerInToolbar,
String toolbarId,
boolean installAdapters)
The new super for all actions.
|
Modifier and Type | Method and Description |
---|---|
protected JosmAction.ActiveLayerChangeAdapter |
buildActiveLayerChangeAdapter()
Override this if calling
updateEnabledState() on active layer change event is not enough. |
protected JosmAction.LayerChangeAdapter |
buildLayerChangeAdapter()
Override this if calling
updateEnabledState() on layer change events is not enough. |
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.
|
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 if
updateEnabledState() should be called when the active / available layers change. |
protected boolean |
listenToSelectionChange()
Overwrite this if
updateEnabledState() should be called when the selection changed. |
private void |
setHelpId() |
protected void |
setHelpId(String helpId)
Sets the help topic id.
|
protected void |
setToolbarId(String toolbarId)
Sets the toolbar id.
|
void |
setTooltip(String tooltip)
Sets the tooltip text of this action.
|
private static boolean |
showConfirmOutlyingOperationDialog(String preferenceKey,
String dialogMessage,
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(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(Collection<? extends OsmPrimitive> selection)
Updates enabled state according to selected primitives, if any.
|
protected static void |
waitFuture(Future<?> future,
PleaseWaitProgressMonitor monitor) |
addPropertyChangeListener, clone, firePropertyChange, getKeys, getPropertyChangeListeners, getValue, isEnabled, putValue, removePropertyChangeListener, setEnabled
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
actionPerformed
private transient JosmAction.LayerChangeAdapter layerChangeAdapter
private transient JosmAction.ActiveLayerChangeAdapter activeLayerChangeAdapter
private transient JosmAction.SelectionChangeAdapter selectionChangeAdapter
protected JosmAction(String name, ImageProvider icon, String tooltip, Shortcut shortcut, boolean registerInToolbar, String toolbarId, boolean installAdapters)
JosmAction
.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 adaptersprotected JosmAction(String name, String iconName, String tooltip, Shortcut shortcut, boolean registerInToolbar, String toolbarId, boolean installAdapters)
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 adaptersprotected JosmAction(String name, String iconName, String tooltip, Shortcut shortcut, boolean registerInToolbar, boolean installAdapters)
JosmAction
.
Use this super constructor to setup your action.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 adaptersprotected JosmAction(String name, String iconName, String tooltip, Shortcut shortcut, boolean registerInToolbar)
JosmAction
and installs layer changed and selection changed adapters.
Use this super constructor to setup your action.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?protected JosmAction()
JosmAction
.protected JosmAction(boolean installAdapters)
JosmAction
.installAdapters
- false, if you don't want to install layer changed and selection changed adaptersprotected JosmAction(String name, String iconName, String tooltip, List<Shortcut> shortcuts)
JosmAction
.
Use this super constructor to setup your action.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 objectsprotected void installAdapters()
This should either never be called or only called in the constructor of this action.
All registered adapters should be removed in destroy()
protected JosmAction.LayerChangeAdapter buildLayerChangeAdapter()
updateEnabledState()
on layer change events is not enough.JosmAction.LayerChangeAdapter
that will be called on layer change eventsprotected JosmAction.ActiveLayerChangeAdapter buildActiveLayerChangeAdapter()
updateEnabledState()
on active layer change event is not enough.JosmAction.LayerChangeAdapter
that will be called on active layer change eventprotected boolean listenToLayerChange()
updateEnabledState()
should be called when the active / available layers change. Default is true.true
if a LayerManager.LayerChangeListener
and a MainLayerManager.ActiveLayerChangeListener
should be registered.protected boolean listenToSelectionChange()
updateEnabledState()
should be called when the selection changed. Default is true.true
if a DataSelectionListener
should be registered.public void destroy()
Destroyable
destroy
in interface Destroyable
private void setHelpId()
protected void setHelpId(String helpId)
helpId
- help topic id (result of HelpUtil.ht(java.lang.String)
)protected void setToolbarId(String toolbarId)
toolbarId
- toolbar idpublic Shortcut getShortcut()
public final void setTooltip(String tooltip)
tooltip
- The text to display in tooltip. Can be null
public MainLayerManager getLayerManager()
The layer manager must be available when installAdapters()
is called and must not change.
protected static void waitFuture(Future<?> future, PleaseWaitProgressMonitor monitor)
protected void initEnabledState()
updateEnabledState()
protected void updateEnabledState()
updateEnabledState(Collection)
to respond to changes in the collection
of selected primitives.
Default behavior is empty.protected void updateEnabledState(Collection<? extends OsmPrimitive> selection)
selection
- the collection of selected primitives; may be empty, but not nullupdateEnabledState()
,
initEnabledState()
,
listenToSelectionChange()
protected final void updateEnabledStateOnCurrentSelection()
updateEnabledState()
implementations.updateEnabledStateOnCurrentSelection(boolean)
protected final void updateEnabledStateOnCurrentSelection(boolean allowReadOnly)
updateEnabledState()
implementations.allowReadOnly
- if true
, read-only data sets are consideredprotected final void updateEnabledStateOnModifiableSelection(Collection<? extends OsmPrimitive> selection)
updateEnabledState(Collection)
implementations.selection
- the collection of selected primitivespublic static boolean checkAndConfirmOutlyingOperation(String operation, String dialogTitle, String outsideDialogMessage, String incompleteDialogMessage, Collection<? extends OsmPrimitive> primitives, Collection<? extends OsmPrimitive> ignore)
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 ignoredprivate static boolean showConfirmOutlyingOperationDialog(String preferenceKey, String dialogMessage, String dialogTitle)