public abstract class JosmAction extends javax.swing.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 |
Constructor and Description |
---|
JosmAction()
Constructs a new
JosmAction . |
JosmAction(boolean installAdapters)
Constructs a new
JosmAction . |
JosmAction(java.lang.String name,
javax.swing.Icon 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.
|
protected static DataSet |
getCurrentDataSet()
Replies the current dataset
|
protected static OsmDataLayer |
getEditLayer()
Replies the current edit layer
|
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() |
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.
|
addPropertyChangeListener, clone, firePropertyChange, getKeys, getPropertyChangeListeners, getValue, isEnabled, putValue, removePropertyChangeListener, setEnabled
private JosmAction.LayerChangeAdapter layerChangeAdapter
private JosmAction.SelectionChangeAdapter selectionChangeAdapter
public JosmAction(java.lang.String name, javax.swing.Icon 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 adapterspublic Shortcut getShortcut()
public void destroy()
Destroyable
destroy
in interface Destroyable
private void setHelpId()
public final void setTooltip(java.lang.String tooltip)
tooltip
- The text to display in tooltip. Can be null
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(java.util.Collection<? extends OsmPrimitive> selection)
selection
- the collection of selected primitives; may be empty, but not nullupdateEnabledState()
,
initEnabledState()