Class DeleteAction
java.lang.Object
javax.swing.AbstractAction
org.openstreetmap.josm.actions.JosmAction
org.openstreetmap.josm.actions.mapmode.MapMode
org.openstreetmap.josm.actions.mapmode.DeleteAction
- All Implemented Interfaces:
ActionListener,MouseListener,MouseMotionListener,Serializable,Cloneable,EventListener,Action,ModifierExListener,PreferenceChangedListener,Destroyable
A map mode that enables the user to delete nodes and other objects.
The user can click on an object, which gets deleted if possible. When Ctrl is
pressed when releasing the button, the objects and all its references are deleted.
If the user did not press Ctrl and the object has any references, the user
is informed and nothing is deleted.
If the user enters the mapmode and any object is selected, all selected
objects are deleted, if possible.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static class(package private) static enumprivate static final classNested classes/interfaces inherited from class org.openstreetmap.josm.actions.JosmAction
JosmAction.ActiveLayerChangeAdapter, JosmAction.LayerChangeAdapter, JosmAction.SelectionChangeAdapter -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate booleanprivate static final HighlightHelperprivate MouseEventprivate WaySegmentelements that have been highlighted in the previous iteration.Fields inherited from class org.openstreetmap.josm.actions.mapmode.MapMode
alt, ctrl, cursor, meta, platformMenuShortcutKeyMask, shiftFields inherited from class org.openstreetmap.josm.actions.JosmAction
scFields inherited from class javax.swing.AbstractAction
changeSupport, enabledFields inherited from interface javax.swing.Action
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidCall selectMapMode(this) on the parent mapFrame.private voidaddHighlighting(MouseEvent e, int modifiers) handles everything related to highlighting primitives and way segments for the given pointer position (via MouseEvent) and modifiers.private CommandbuildDeleteCommands(MouseEvent e, int modifiers, boolean silent) This function takes any mouse event argument and builds the list of elements that should be deleted but does not actually delete them.private static booleanstatic voiddeleteRelation(OsmDataLayer layer, Relation toDelete) Deletes the relation in the context of the given layer.static voiddeleteRelations(OsmDataLayer layer, Collection<Relation> toDelete) Deletes the relations in the context of the given layer.voidInvoked when the action occurs.voidMakes this map mode active.voidexitMode()Makes this map mode inactive.private DeleteAction.DeleteParametersgetDeleteParameters(MouseEvent e, int modifiers) Returns a short translated help message describing how this map mode can be used, to be displayed in status line.private voidGives the user feedback for the action he/she is about to do.private voidgiveUserFeedback(MouseEvent e, int modifiers) Gives the user feedback for the action he/she is about to do.booleanDetermines if layerlis supported by this map mode.voidmodifiersExChanged(int modifiers) This is required to update the cursors when ctrl/shift/alt is pressedvoidvoidListen to mouse move to be able to update the cursor (and highlights)voidIf user clicked with the left button, delete the nearest object.private voidremoves any highlighting that may have been set beforehand.private voidrepaintIfRequired(Set<OsmPrimitive> newHighlights, WaySegment newHighlightedWaySegment) private voidupdateCursor(MouseEvent e, int modifiers) This function handles all work related to updating the cursor and highlightsprotected voidOverride in subclasses to update the enabled state of the action when something in the JOSM state changes, i.e.Methods inherited from class org.openstreetmap.josm.actions.mapmode.MapMode
isEditableDataLayer, isPanning, mouseClicked, mouseEntered, mouseExited, mousePressed, preferenceChanged, readPreferences, requestFocusInMapView, updateKeyModifiers, updateKeyModifiers, updateKeyModifiers, updateKeyModifiersEx, updateStatusLineMethods inherited from class org.openstreetmap.josm.actions.JosmAction
buildActiveLayerChangeAdapter, buildLayerChangeAdapter, checkAndConfirmOutlyingOperation, destroy, getLayerManager, getShortcut, initEnabledState, installAdapters, listenToLayerChange, listenToSelectionChange, setHelpId, setToolbarId, setTooltip, updateEnabledState, updateEnabledStateOnCurrentSelection, updateEnabledStateOnCurrentSelection, updateEnabledStateOnModifiableSelection, waitFutureMethods inherited from class javax.swing.AbstractAction
addPropertyChangeListener, clone, firePropertyChange, getKeys, getPropertyChangeListeners, getValue, isEnabled, putValue, removePropertyChangeListener, setEnabled
-
Field Details
-
oldEvent
-
oldHighlightedWaySegment
elements that have been highlighted in the previous iteration. Used to remove the highlight from them again as otherwise the whole data set would have to be checked. -
HIGHLIGHT_HELPER
-
drawTargetHighlight
-
-
Constructor Details
-
DeleteAction
public DeleteAction()Construct a new DeleteAction. Mnemonic is the delete - key.- Since:
- 11713
-
-
Method Details
-
enterMode
Description copied from class:MapModeMakes this map mode active. -
exitMode
Description copied from class:MapModeMakes this map mode inactive. -
actionPerformed
Description copied from class:MapModeCall selectMapMode(this) on the parent mapFrame.- Specified by:
actionPerformedin interfaceActionListener- Overrides:
actionPerformedin classMapMode
-
doActionPerformed
Invoked when the action occurs.- Parameters:
e- Action event
-
mouseDragged
- Specified by:
mouseDraggedin interfaceMouseMotionListener- Overrides:
mouseDraggedin classMapMode
-
mouseMoved
Listen to mouse move to be able to update the cursor (and highlights)- Specified by:
mouseMovedin interfaceMouseMotionListener- Overrides:
mouseMovedin classMapMode- Parameters:
e- The mouse event that has been captured
-
removeHighlighting
removes any highlighting that may have been set beforehand. -
addHighlighting
handles everything related to highlighting primitives and way segments for the given pointer position (via MouseEvent) and modifiers.- Parameters:
e- current mouse eventmodifiers- extended mouse modifiers, not necessarily taken from the given mouse event
-
repaintIfRequired
private void repaintIfRequired(Set<OsmPrimitive> newHighlights, WaySegment newHighlightedWaySegment) -
updateCursor
This function handles all work related to updating the cursor and highlights- Parameters:
e- current mouse eventmodifiers- extended mouse modifiers, not necessarily taken from the given mouse event
-
giveUserFeedback
Gives the user feedback for the action he/she is about to do. Currently calls the cursor and target highlighting routines. Allows for modifiers not taken from the given mouse event. Normally the mouse event also contains the modifiers. However, when the mouse is not moved and only modifier keys are pressed, no mouse event occurs. We can use AWTEvent to catch those but still lack a proper mouseevent. Instead we copy the previous event and only update the modifiers.- Parameters:
e- mouse eventmodifiers- mouse modifiers
-
giveUserFeedback
Gives the user feedback for the action he/she is about to do. Currently calls the cursor and target highlighting routines. Extracts modifiers from mouse event.- Parameters:
e- mouse event
-
mouseReleased
If user clicked with the left button, delete the nearest object.- Specified by:
mouseReleasedin interfaceMouseListener- Overrides:
mouseReleasedin classMapMode
-
getModeHelpText
Description copied from class:MapModeReturns a short translated help message describing how this map mode can be used, to be displayed in status line.- Overrides:
getModeHelpTextin classMapMode- Returns:
- a short translated help message describing how this map mode can be used
-
layerIsSupported
Description copied from class:MapModeDetermines if layerlis supported by this map mode. By default, all tools will work with all layers. Can be overwritten to require a special type of layer- Overrides:
layerIsSupportedin classMapMode- Parameters:
l- layer- Returns:
trueif the layer is supported by this map mode
-
updateEnabledState
Description copied from class:JosmActionOverride 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. SeeJosmAction.updateEnabledState(Collection)to respond to changes in the collection of selected primitives. Default behavior is empty.- Overrides:
updateEnabledStatein classJosmAction- See Also:
-
deleteRelation
Deletes the relation in the context of the given layer.- Parameters:
layer- the layer in whose context the relation is deleted. Must not be null.toDelete- the relation to be deleted. Must not be null.- Throws:
IllegalArgumentException- if layer is nullIllegalArgumentException- if toDelete is null
-
deleteRelations
Deletes the relations in the context of the given layer.- Parameters:
layer- the layer in whose context the relations are deleted. Must not be null.toDelete- the relations to be deleted. Must not be null.- Throws:
IllegalArgumentException- if layer is nullIllegalArgumentException- if toDelete is null
-
getDeleteParameters
-
buildDeleteCommands
This function takes any mouse event argument and builds the list of elements that should be deleted but does not actually delete them.- Parameters:
e- MouseEvent from which modifiers and position are takenmodifiers- For explanation, seeupdateCursor(java.awt.event.MouseEvent, int)silent- Set to true if the user should not be bugged with additional dialogs- Returns:
- delete command
-
modifiersExChanged
This is required to update the cursors when ctrl/shift/alt is pressed- Specified by:
modifiersExChangedin interfaceModifierExListener- Parameters:
modifiers- The new extended modifiers
-
changesHiddenWay
-