Class SelectAction

All Implemented Interfaces:
ActionListener, MouseListener, MouseMotionListener, Serializable, Cloneable, EventListener, Action, SelectionManager.SelectionEnded, KeyPressReleaseListener, ModifierExListener, PreferenceChangedListener, Destroyable

Move is an action that can move all kind of OsmPrimitives (except keys for now).

If an selected object is under the mouse when dragging, move all selected objects. If an unselected object is under the mouse when dragging, it becomes selected and will be moved. If no object is under the mouse, move all selected objects (if any)

On Mac OS X, Ctrl + mouse button 1 simulates right click (map move), so the feature "selection remove" is disabled on this platform.

See Also:
  • Field Details

  • Constructor Details

    • SelectAction

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

    • enterMode

      public void enterMode()
      Description copied from class: MapMode
      Makes this map mode active.
      Overrides:
      enterMode in class MapMode
    • exitMode

      public void exitMode()
      Description copied from class: MapMode
      Makes this map mode inactive.
      Overrides:
      exitMode in class MapMode
    • modifiersExChanged

      public void modifiersExChanged(int modifiers)
      Description copied from interface: ModifierExListener
      Called when the extended modifiers are changed
      Specified by:
      modifiersExChanged in interface ModifierExListener
      Parameters:
      modifiers - The new extended modifiers
    • giveUserFeedback

      private boolean giveUserFeedback(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(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 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
    • repaintIfRequired

      private boolean repaintIfRequired(OsmPrimitive newHighlight)
    • mousePressed

      public void mousePressed(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 MouseListener
      Overrides:
      mousePressed in class MapMode
    • mouseMoved

      public void mouseMoved(MouseEvent e)
      Specified by:
      mouseMoved in interface MouseMotionListener
      Overrides:
      mouseMoved in class MapMode
    • mouseDragged

      public void mouseDragged(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 MouseMotionListener
      Overrides:
      mouseDragged in class MapMode
    • mouseExited

      public void mouseExited(MouseEvent e)
      Specified by:
      mouseExited in interface MouseListener
      Overrides:
      mouseExited in class MapMode
    • mouseReleased

      public void mouseReleased(MouseEvent e)
      Specified by:
      mouseReleased in interface MouseListener
      Overrides:
      mouseReleased in class MapMode
    • selectionEnded

      public void selectionEnded(Rectangle r, MouseEvent e)
      Description copied from interface: SelectionManager.SelectionEnded
      Called, when the left mouse button was released.
      Specified by:
      selectionEnded in interface SelectionManager.SelectionEnded
      Parameters:
      r - The rectangle that encloses the current selection.
      e - The mouse event.
      See Also:
    • doKeyPressed

      public void doKeyPressed(KeyEvent e)
      Description copied from interface: KeyPressReleaseListener
      This is called when key press event is actually pressed (no fake events while holding key)
      Specified by:
      doKeyPressed in interface KeyPressReleaseListener
      Parameters:
      e - key event
    • doKeyReleased

      public void doKeyReleased(KeyEvent e)
      Description copied from interface: KeyPressReleaseListener
      This is called when key press event is actually released (no fake events while holding key)
      Specified by:
      doKeyReleased in interface KeyPressReleaseListener
      Parameters:
      e - key event
    • 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(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(Collection<Node> affectedNodes, Collection<Way> selectedWays)
    • useLastMoveCommandIfPossible

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

      Obtain command in undoRedo stack to "continue" when dragging
      Parameters:
      ds - The data set the command needs to be in.
      Returns:
      last command
    • confirmOrUndoMovement

      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)
    • checkCommandForLargeDistance

      static void checkCommandForLargeDistance(Command lastCommand)
    • showConfirmMoveDialog

    • movesHiddenWay

      private boolean movesHiddenWay()
    • 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(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, 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

      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(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

      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> 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.