public abstract class JosmAction extends AbstractAction implements Destroyable
MapView.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 getCurrentDataSet()
and the current layers
(see also getEditLayer()
).
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 |
---|---|
private class |
JosmAction.LayerChangeAdapter
Adapter for layer change events
|
private class |
JosmAction.SelectionChangeAdapter
Adapter for selection change events
|
Modifier and Type | Field and Description |
---|---|
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
Constructor and Description |
---|
JosmAction() |
JosmAction(boolean installAdapters) |
JosmAction(String name,
Icon icon,
String tooltip,
Shortcut shortcut,
boolean registerInToolbar,
String toolbarId,
boolean installAdapters)
Constructs a
JosmAction . |
JosmAction(String name,
String iconName,
String tooltip,
Shortcut shortcut,
boolean registerInToolbar) |
JosmAction(String name,
String iconName,
String tooltip,
Shortcut shortcut,
boolean registerInToolbar,
boolean installAdapters) |
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 |
---|---|
void |
destroy()
Called when the object has been destroyed.
|
protected static DataSet |
getCurrentDataSet()
Replies the current dataset
|
protected static OsmDataLayer |
getEditLayer()
Replies the current edit layer
|
Shortcut |
getShortcut() |
protected void |
initEnabledState()
Override in subclasses to init the enabled state of an action when it is
created.
|
protected void |
installAdapters() |
private void |
setHelpId() |
void |
setTooltip(String tooltip) |
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.
|
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.
|
addPropertyChangeListener, clone, firePropertyChange, getKeys, getPropertyChangeListeners, getValue, isEnabled, putValue, removePropertyChangeListener, setEnabled
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
actionPerformed
private JosmAction.LayerChangeAdapter layerChangeAdapter
private JosmAction.SelectionChangeAdapter selectionChangeAdapter
public JosmAction(String name, Icon 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 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(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 adapterspublic JosmAction(String name, String iconName, String tooltip, Shortcut shortcut, boolean registerInToolbar, boolean installAdapters)
public JosmAction(String name, String iconName, String tooltip, Shortcut shortcut, boolean registerInToolbar)
public JosmAction()
public JosmAction(boolean installAdapters)
public Shortcut getShortcut()
public void destroy()
Destroyable
destroy
in interface Destroyable
private void setHelpId()
public void setTooltip(String tooltip)
protected static OsmDataLayer getEditLayer()
protected static DataSet getCurrentDataSet()
protected void installAdapters()
protected void initEnabledState()
updateEnabledState()
protected void updateEnabledState()
updateEnabledState(Collection)
to respond to changes in the collection
of selected primitives.
Default behavior is empty.updateEnabledState(Collection)
,
initEnabledState()
protected void updateEnabledState(Collection<? extends OsmPrimitive> selection)
selection
- the collection of selected primitives; may be empty, but not nullupdateEnabledState()
,
initEnabledState()