public abstract class JosmAction extends javax.swing.AbstractAction implements Destroyable
updateEnabledState()
whenever the global context is changed.
A JosmAction can register a LayerManager.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 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 |
Constructor and Description |
---|
JosmAction()
Constructs a new
JosmAction . |
JosmAction(boolean installAdapters)
Constructs a new
JosmAction . |
JosmAction(java.lang.String name,
ImageProvider 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 registerInToolbar)
Constructs a new
JosmAction . |
JosmAction(java.lang.String name,
java.lang.String iconName,
java.lang.String tooltip,
Shortcut shortcut,
boolean registerInToolbar,
boolean installAdapters)
Constructs a new
JosmAction . |
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.
|
Modifier and Type | Method and Description |
---|---|
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 / availabe layers change. |
protected boolean |
listenToSelectionChange()
Overwrite this if
updateEnabledState() should be called when the selection changed. |
private void |
setHelpId() |
void |
setTooltip(java.lang.String tooltip)
Sets the tooltip text of this action.
|
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 static void |
waitFuture(java.util.concurrent.Future<?> future,
PleaseWaitProgressMonitor monitor) |
addPropertyChangeListener, clone, firePropertyChange, getKeys, getPropertyChangeListeners, getValue, isEnabled, putValue, removePropertyChangeListener, setEnabled
private transient JosmAction.LayerChangeAdapter layerChangeAdapter
private transient JosmAction.ActiveLayerChangeAdapter activeLayerChangeAdapter
private transient JosmAction.SelectionChangeAdapter selectionChangeAdapter
public JosmAction(java.lang.String name, ImageProvider icon, java.lang.String tooltip, Shortcut shortcut, boolean registerInToolbar, java.lang.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 preferences. The iconName is used, if this parameter is nullinstallAdapters
- false, if you don't want to install layer changed and selection changed adapterspublic JosmAction(java.lang.String name, java.lang.String iconName, java.lang.String tooltip, Shortcut shortcut, boolean registerInToolbar, java.lang.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 adapterspublic JosmAction(java.lang.String name, java.lang.String iconName, java.lang.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 adapterspublic JosmAction(java.lang.String name, java.lang.String iconName, java.lang.String tooltip, Shortcut shortcut, boolean registerInToolbar)
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?public JosmAction()
JosmAction
.public JosmAction(boolean installAdapters)
JosmAction
.installAdapters
- false, if you don't want to install layer changed and selection changed adaptersprotected 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 boolean listenToLayerChange()
updateEnabledState()
should be called when the active / availabe 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 SelectionChangedListener
should be registered.public void destroy()
Destroyable
destroy
in interface Destroyable
private void setHelpId()
public Shortcut getShortcut()
public final void setTooltip(java.lang.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(java.util.concurrent.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(java.util.Collection<? extends OsmPrimitive> selection)
selection
- the collection of selected primitives; may be empty, but not nullupdateEnabledState()
,
initEnabledState()
,
listenToSelectionChange()
protected final void updateEnabledStateOnCurrentSelection()
updateEnabledState()
implementations.