org.openstreetmap.josm.actions.mapmode
Class SelectAction

java.lang.Object
  extended by javax.swing.AbstractAction
      extended by org.openstreetmap.josm.actions.JosmAction
          extended by org.openstreetmap.josm.actions.mapmode.MapMode
              extended by org.openstreetmap.josm.actions.mapmode.SelectAction
All Implemented Interfaces:
java.awt.event.ActionListener, java.awt.event.AWTEventListener, java.awt.event.MouseListener, java.awt.event.MouseMotionListener, java.io.Serializable, java.lang.Cloneable, java.util.EventListener, javax.swing.Action, SelectionManager.SelectionEnded, Destroyable

public class SelectAction
extends MapMode
implements java.awt.event.AWTEventListener, SelectionManager.SelectionEnded

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)

See Also:
Serialized Form

Nested Class Summary
private  class SelectAction.CycleManager
           
(package private) static class SelectAction.Mode
           
private static class SelectAction.SelectActionCursor
           
private  class SelectAction.VirtualManager
           
 
Field Summary
private  boolean cancelDrawMode
           
(package private)  SelectAction.CycleManager cycleManager
           
private  boolean didMouseDrag
           
private  boolean drawTargetHighlight
           
private  int initialMoveDelay
          The time which needs to pass between click and release before something counts as a move, in milliseconds
private  int initialMoveThreshold
          The screen distance which needs to be travelled before something counts as a move, in pixels
private  boolean initialMoveThresholdExceeded
           
private  boolean lassoMode
           
private  java.awt.Point lastMousePos
          The last known position of the mouse.
private  SelectAction.Mode mode
           
private  int mouseDownButton
          The pressed button of the user mouse down event.
private  long mouseDownTime
          The time of the user mouse down event.
private  long mouseReleaseTime
          The time of the user mouse down event.
private  MapView mv
          The component this SelectAction is associated with.
private  java.awt.event.MouseEvent oldEvent
           
private  java.util.Set<OsmPrimitive> oldHighlights
          elements that have been highlighted in the previous iteration.
(package private)  int previousModifiers
           
private  SelectionManager selectionManager
           
(package private)  EastNorth startEN
          point where user pressed the mouse to start movement
private  java.awt.Point startingDraggingPos
          The old cursor before the user pressed the mouse button.
(package private)  SelectAction.VirtualManager virtualManager
           
 
Fields inherited from class org.openstreetmap.josm.actions.mapmode.MapMode
alt, ctrl, cursor, shift
 
Fields inherited from class org.openstreetmap.josm.actions.JosmAction
sc
 
Fields inherited from class javax.swing.AbstractAction
changeSupport, enabled
 
Fields 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
SelectAction(MapFrame mapFrame)
          Create a new SelectAction
 
Method Summary
private  void confirmOrUndoMovement(java.awt.event.MouseEvent e)
          Present warning in case of large and possibly unwanted movements and undo unwanted movements.
private  void determineMapMode(boolean hasSelectionNearby)
          sets the mapmode according to key modifiers and if there are any selectables nearby.
private  boolean dragInProgress()
          returns true whenever elements have been grabbed and moved (i.e.
 void enterMode()
           
 void eventDispatched(java.awt.AWTEvent e)
          This is called whenever the keyboard modifier status changes
 void exitMode()
           
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.
private  java.awt.Cursor getCursor(java.util.Collection<OsmPrimitive> nearbyStuff)
          works out which cursor should be displayed for most of SelectAction's features.
private  Command getLastCommand()
          Obtain command in undoRedo stack to "continue" when dragging
 java.lang.String getModeHelpText()
           
private  boolean giveUserFeedback(java.awt.event.MouseEvent e)
          handles adding highlights and updating the cursor for the given mouse event.
private  boolean giveUserFeedback(java.awt.event.MouseEvent e, int modifiers)
          handles adding highlights and updating the cursor for the given mouse event.
 boolean layerIsSupported(Layer l)
           
private  void mergePrims(java.awt.Point p)
          Merges the selected nodes to the one closest to the given mouse position iff the control key is pressed.
 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).
 void mouseExited(java.awt.event.MouseEvent e)
           
 void mouseMoved(java.awt.event.MouseEvent e)
           
 void mousePressed(java.awt.event.MouseEvent e)
          Look, whether any object is selected.
 void mouseReleased(java.awt.event.MouseEvent e)
           
private  boolean removeHighlighting()
          Removes all existing highlights.
private  boolean repaintIfRequired(java.util.HashSet<OsmPrimitive> newHighlights)
           
 void selectionEnded(java.awt.Rectangle r, java.awt.event.MouseEvent e)
          Called, when the left mouse button was released.
private  void selectPrims(java.util.Collection<OsmPrimitive> prims, boolean released, boolean area)
           
 void setLassoMode(boolean lassoMode)
           
private  boolean updateCommandWhileDragging(EastNorth currentEN)
          Create or update data modification command while dragging mouse - implementation of continuous moving, scaling and rotation
private  void useLastMoveCommandIfPossible()
          Adapt last move command (if it is suitable) to work with next drag, started at point startEN
 
Methods inherited from class org.openstreetmap.josm.actions.mapmode.MapMode
actionPerformed, mouseClicked, mouseEntered, updateKeyModifiers, updateKeyModifiers, updateKeyModifiers, updateStatusLine
 
Methods inherited from class org.openstreetmap.josm.actions.JosmAction
destroy, getCurrentDataSet, getEditLayer, getShortcut, initEnabledState, installAdapters, setTooltip, updateEnabledState, updateEnabledState
 
Methods inherited from class javax.swing.AbstractAction
addPropertyChangeListener, clone, firePropertyChange, getKeys, getPropertyChangeListeners, getValue, isEnabled, putValue, removePropertyChangeListener, setEnabled
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.openstreetmap.josm.gui.SelectionManager.SelectionEnded
addPropertyChangeListener, removePropertyChangeListener
 

Field Detail

lassoMode

private boolean lassoMode

oldEvent

private java.awt.event.MouseEvent oldEvent

mode

private SelectAction.Mode mode

selectionManager

private SelectionManager selectionManager

cancelDrawMode

private boolean cancelDrawMode

drawTargetHighlight

private boolean drawTargetHighlight

didMouseDrag

private boolean didMouseDrag

mv

private final MapView mv
The component this SelectAction is associated with.


startingDraggingPos

private java.awt.Point startingDraggingPos
The old cursor before the user pressed the mouse button.


startEN

EastNorth startEN
point where user pressed the mouse to start movement


lastMousePos

private java.awt.Point lastMousePos
The last known position of the mouse.


mouseDownTime

private long mouseDownTime
The time of the user mouse down event.


mouseDownButton

private int mouseDownButton
The pressed button of the user mouse down event.


mouseReleaseTime

private long mouseReleaseTime
The time of the user mouse down event.


initialMoveDelay

private int initialMoveDelay
The time which needs to pass between click and release before something counts as a move, in milliseconds


initialMoveThreshold

private int initialMoveThreshold
The screen distance which needs to be travelled before something counts as a move, in pixels


initialMoveThresholdExceeded

private boolean initialMoveThresholdExceeded

oldHighlights

private java.util.Set<OsmPrimitive> oldHighlights
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.


previousModifiers

int previousModifiers

cycleManager

SelectAction.CycleManager cycleManager

virtualManager

SelectAction.VirtualManager virtualManager
Constructor Detail

SelectAction

public SelectAction(MapFrame mapFrame)
Create a new SelectAction

Parameters:
mapFrame - The MapFrame this action belongs to.
Method Detail

enterMode

public void enterMode()
Overrides:
enterMode in class MapMode

exitMode

public void exitMode()
Overrides:
exitMode in class MapMode

eventDispatched

public void eventDispatched(java.awt.AWTEvent e)
This is called whenever the keyboard modifier status changes

Specified by:
eventDispatched in interface java.awt.event.AWTEventListener

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:
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:
MouseEvent - which should be used as base for the feedback
define - custom keyboard modifiers if the ones from MouseEvent are outdated or similar
Returns:
true if repaint is required

getCursor

private java.awt.Cursor getCursor(java.util.Collection<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(java.util.HashSet<OsmPrimitive> newHighlights)

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

selectionEnded

public void selectionEnded(java.awt.Rectangle r,
                           java.awt.event.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 is currently the selection.
See Also:
InputEvent.getModifiersEx()

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 -

dragInProgress

private final boolean dragInProgress()
returns true 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)


updateCommandWhileDragging

private boolean updateCommandWhileDragging(EastNorth currentEN)
Create or update data modification command while dragging mouse - implementation of continuous moving, scaling and rotation

Parameters:
currentEN - - mouse position
Returns:
status of action (true when action was performed)

useLastMoveCommandIfPossible

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


getLastCommand

private Command getLastCommand()
Obtain command in undoRedo stack to "continue" when dragging


confirmOrUndoMovement

private void confirmOrUndoMovement(java.awt.event.MouseEvent e)
Present warning in case of large and possibly unwanted movements and undo unwanted movements.

Parameters:
e - the mouse event causing the action (mouse released)

mergePrims

private final void mergePrims(java.awt.Point p)
Merges the selected nodes to the one closest to the given mouse position iff 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.


findNodeToMergeTo

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


selectPrims

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

getModeHelpText

public java.lang.String getModeHelpText()
Overrides:
getModeHelpText in class MapMode

layerIsSupported

public boolean layerIsSupported(Layer l)
Overrides:
layerIsSupported in class MapMode

setLassoMode

public void setLassoMode(boolean lassoMode)


JOSM