Class SelectAction

    • Constructor Detail

      • SelectAction

        public SelectAction​(MapFrame mapFrame)
        Create a new SelectAction
        Parameters:
        mapFrame - The MapFrame this action belongs to.
    • Method Detail

      • giveUserFeedback

        private boolean giveUserFeedback​(java.awt.event.MouseEvent e)
        handles adding highlights and updating the cursor for the given mouse event. Please note that the highlighting for merging while moving is handled via mouseDragged.
        Parameters:
        e - MouseEvent which should be used as base for the feedback
        Returns:
        true if repaint is required
      • giveUserFeedback

        private boolean giveUserFeedback​(java.awt.event.MouseEvent e,
                                         int modifiers)
        handles adding highlights and updating the cursor for the given mouse event. Please note that the highlighting for merging while moving is handled via mouseDragged.
        Parameters:
        e - MouseEvent which should be used as base for the feedback
        modifiers - define custom keyboard extended modifiers if the ones from MouseEvent are outdated or similar
        Returns:
        true if repaint is required
      • getCursor

        private java.awt.Cursor getCursor​(OsmPrimitive nearbyStuff)
        works out which cursor should be displayed for most of SelectAction's features. The only exception is the "move" cursor when actually dragging primitives.
        Parameters:
        nearbyStuff - primitives near the cursor
        Returns:
        the cursor that should be displayed
      • removeHighlighting

        private boolean removeHighlighting()
        Removes all existing highlights.
        Returns:
        true if a repaint is required
      • mousePressed

        public void mousePressed​(java.awt.event.MouseEvent e)
        Look, whether any object is selected. If not, select the nearest node. If there are no nodes in the dataset, do nothing.

        If the user did not press the left mouse button, do nothing.

        Also remember the starting position of the movement and change the mouse cursor to movement.

        Specified by:
        mousePressed in interface java.awt.event.MouseListener
        Overrides:
        mousePressed in class MapMode
      • mouseMoved

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

        public void mouseDragged​(java.awt.event.MouseEvent e)
        If the left mouse button is pressed, move all currently selected objects (if one of them is under the mouse) or the current one under the mouse (which will become selected).
        Specified by:
        mouseDragged in interface java.awt.event.MouseMotionListener
        Overrides:
        mouseDragged in class MapMode
      • mouseExited

        public void mouseExited​(java.awt.event.MouseEvent e)
        Specified by:
        mouseExited in interface java.awt.event.MouseListener
        Overrides:
        mouseExited in class MapMode
      • mouseReleased

        public void mouseReleased​(java.awt.event.MouseEvent e)
        Specified by:
        mouseReleased in interface java.awt.event.MouseListener
        Overrides:
        mouseReleased in class MapMode
      • determineMapMode

        private void determineMapMode​(boolean hasSelectionNearby)
        sets the mapmode according to key modifiers and if there are any selectables nearby. Everything has to be pre-determined for this function; its main purpose is to centralize what the modifiers do.
        Parameters:
        hasSelectionNearby - true if some primitves are selectable nearby
      • dragInProgress

        private boolean dragInProgress()
        Determines whenever elements have been grabbed and moved (i.e. the initial thresholds have been exceeded) and is still in progress (i.e. mouse button still pressed)
        Returns:
        true if a drag is in progress
      • updateCommandWhileDragging

        private boolean updateCommandWhileDragging​(java.awt.event.MouseEvent mouseEvent,
                                                   EastNorth currentEN)
        Create or update data modification command while dragging mouse - implementation of continuous moving, scaling and rotation
        Parameters:
        mouseEvent - The triggering mouse event
        currentEN - - mouse position
        Returns:
        status of action (true when action was performed)
      • doesImpactStatusLine

        private static boolean doesImpactStatusLine​(java.util.Collection<Node> affectedNodes,
                                                    java.util.Collection<Way> selectedWays)
      • useLastMoveCommandIfPossible

        private void useLastMoveCommandIfPossible()
        Adapt last move command (if it is suitable) to work with next drag, started at point startEN
      • getLastCommandInDataset

        private static Command getLastCommandInDataset​(DataSet ds)
        Obtain command in undoRedo stack to "continue" when dragging
        Parameters:
        ds - The data set the command needs to be in.
        Returns:
        last command
      • confirmOrUndoMovement

        private void confirmOrUndoMovement​(java.awt.event.MouseEvent e)
        Present warning in the following cases and undo unwanted movements:
        • large and possibly unwanted movements
        • movement of node with attached ways that are hidden by filters
        Parameters:
        e - the mouse event causing the action (mouse released)
      • isMergeRequested

        private boolean isMergeRequested()
        Check if dragged node should be merged when moving it over another primitive
        Returns:
        true if merge is requested
      • mergePrims

        private void mergePrims​(java.awt.Point p)
        Merges the selected nodes to the one closest to the given mouse position if the control key is pressed. If there is no such node, no action will be done and no error will be reported. If there is, it will execute the merge and add it to the undo buffer.
        Parameters:
        p - mouse position
      • mergeNodes

        public void mergeNodes​(OsmDataLayer layer,
                               java.util.Collection<Node> nodes,
                               Node targetLocationNode)
        Merge nodes using MergeNodesAction. Can be overridden for testing purpose.
        Parameters:
        layer - layer the reference data layer. Must not be null
        nodes - the collection of nodes. Ignored if null
        targetLocationNode - this node's location will be used for the target node
      • findNodeToMergeTo

        private Node findNodeToMergeTo​(java.awt.Point p)
        Tries to find a node to merge to when in move-merge mode for the current mouse position. Either returns the node or null, if no suitable one is nearby.
        Parameters:
        p - mouse position
        Returns:
        node to merge to, or null
      • selectPrims

        private void selectPrims​(java.util.Collection<OsmPrimitive> prims,
                                 boolean released,
                                 boolean area)
      • getMode

        public final SelectAction.Mode getMode()
        Returns the current select mode.
        Returns:
        the select mode
        Since:
        7543
      • 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
      • setLassoMode

        public void setLassoMode​(boolean lassoMode)
        Enable or diable the lasso mode
        Parameters:
        lassoMode - true to enable the lasso mode, false otherwise
      • asColl

        protected static <T> java.util.Collection<T> asColl​(T o)
        Returns o as collection of o's type.
        Type Parameters:
        T - object type
        Parameters:
        o - any object
        Returns:
        o as collection of o's type.