Class DeleteAction

  • All Implemented Interfaces:
    java.awt.event.ActionListener, java.awt.event.MouseListener, java.awt.event.MouseMotionListener, java.io.Serializable, java.lang.Cloneable, java.util.EventListener, javax.swing.Action, ModifierExListener, PreferenceChangedListener, Destroyable

    public class DeleteAction
    extends MapMode
    implements ModifierExListener
    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:
    Serialized Form
    • Constructor Detail

      • DeleteAction

        public DeleteAction()
        Construct a new DeleteAction. Mnemonic is the delete - key.
        Since:
        11713
    • Method Detail

      • actionPerformed

        public void actionPerformed​(java.awt.event.ActionEvent e)
        Description copied from class: MapMode
        Call selectMapMode(this) on the parent mapFrame.
        Specified by:
        actionPerformed in interface java.awt.event.ActionListener
        Overrides:
        actionPerformed in class MapMode
      • doActionPerformed

        public void doActionPerformed​(java.awt.event.ActionEvent e)
        Invoked when the action occurs.
        Parameters:
        e - Action event
      • mouseDragged

        public void mouseDragged​(java.awt.event.MouseEvent e)
        Specified by:
        mouseDragged in interface java.awt.event.MouseMotionListener
        Overrides:
        mouseDragged in class MapMode
      • mouseMoved

        public void mouseMoved​(java.awt.event.MouseEvent e)
        Listen to mouse move to be able to update the cursor (and highlights)
        Specified by:
        mouseMoved in interface java.awt.event.MouseMotionListener
        Overrides:
        mouseMoved in class MapMode
        Parameters:
        e - The mouse event that has been captured
      • removeHighlighting

        private void removeHighlighting()
        removes any highlighting that may have been set beforehand.
      • addHighlighting

        private void addHighlighting​(java.awt.event.MouseEvent e,
                                     int modifiers)
        handles everything related to highlighting primitives and way segments for the given pointer position (via MouseEvent) and modifiers.
        Parameters:
        e - current mouse event
        modifiers - extended mouse modifiers, not necessarily taken from the given mouse event
      • updateCursor

        private void updateCursor​(java.awt.event.MouseEvent e,
                                  int modifiers)
        This function handles all work related to updating the cursor and highlights
        Parameters:
        e - current mouse event
        modifiers - extended mouse modifiers, not necessarily taken from the given mouse event
      • giveUserFeedback

        private void giveUserFeedback​(java.awt.event.MouseEvent e,
                                      int modifiers)
        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 event
        modifiers - mouse modifiers
      • giveUserFeedback

        private void giveUserFeedback​(java.awt.event.MouseEvent e)
        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

        public void mouseReleased​(java.awt.event.MouseEvent e)
        If user clicked with the left button, delete the nearest object.
        Specified by:
        mouseReleased in interface java.awt.event.MouseListener
        Overrides:
        mouseReleased in class MapMode
      • getModeHelpText

        public java.lang.String getModeHelpText()
        Description copied from class: MapMode
        Returns a short translated help message describing how this map mode can be used, to be displayed in status line.
        Overrides:
        getModeHelpText in class MapMode
        Returns:
        a short translated help message describing how this map mode can be used
      • layerIsSupported

        public boolean layerIsSupported​(Layer l)
        Description copied from class: MapMode
        Determines if layer l is 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:
        layerIsSupported in class MapMode
        Parameters:
        l - layer
        Returns:
        true if the layer is supported by this map mode
      • deleteRelation

        public static void deleteRelation​(OsmDataLayer layer,
                                          Relation toDelete)
        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:
        java.lang.IllegalArgumentException - if layer is null
        java.lang.IllegalArgumentException - if toDelete is null
      • deleteRelations

        public static void deleteRelations​(OsmDataLayer layer,
                                           java.util.Collection<Relation> toDelete)
        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:
        java.lang.IllegalArgumentException - if layer is null
        java.lang.IllegalArgumentException - if toDelete is null
      • buildDeleteCommands

        private Command buildDeleteCommands​(java.awt.event.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.
        Parameters:
        e - MouseEvent from which modifiers and position are taken
        modifiers - For explanation, see updateCursor(java.awt.event.MouseEvent, int)
        silent - Set to true if the user should not be bugged with additional dialogs
        Returns:
        delete command