Class SelectAction
- java.lang.Object
-
- javax.swing.AbstractAction
-
- org.openstreetmap.josm.actions.JosmAction
-
- org.openstreetmap.josm.actions.mapmode.MapMode
-
- org.openstreetmap.josm.actions.mapmode.SelectAction
-
- All Implemented Interfaces:
ActionListener
,MouseListener
,MouseMotionListener
,Serializable
,Cloneable
,EventListener
,Action
,SelectionManager.SelectionEnded
,KeyPressReleaseListener
,ModifierExListener
,PreferenceChangedListener
,Destroyable
public class SelectAction extends MapMode implements ModifierExListener, KeyPressReleaseListener, 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) 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:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static class
SelectAction.ConfirmMoveDialog
private class
SelectAction.CycleManager
static class
SelectAction.Mode
Select action mode.(package private) static class
SelectAction.SelectActionCursor
private class
SelectAction.VirtualManager
-
Nested classes/interfaces inherited from class org.openstreetmap.josm.actions.JosmAction
JosmAction.ActiveLayerChangeAdapter, JosmAction.LayerChangeAdapter, JosmAction.SelectionChangeAdapter
-
-
Field Summary
Fields Modifier and Type Field Description private boolean
cancelDrawMode
private Optional<OsmPrimitive>
currentHighlight
elements that have been highlighted in the previous iteration.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 millisecondsprivate int
initialMoveThreshold
The screen distance which needs to be travelled before something counts as a move, in pixelsprivate boolean
initialMoveThresholdExceeded
private boolean
lassoMode
private 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 static String
NORMAL
private MouseEvent
oldEvent
private boolean
repeatedKeySwitchLassoOption
private SelectionManager
selectionManager
private EastNorth
startEN
point where user pressed the mouse to start movementprivate Point
startingDraggingPos
The old cursor before the user pressed the mouse button.private SelectAction.VirtualManager
virtualManager
-
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
Constructors Constructor Description SelectAction(MapFrame mapFrame)
Create a new SelectAction
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected static <T> Collection<T>
asColl(T o)
Returnso
as collection ofo
's type.(package private) static void
checkCommandForLargeDistance(Command lastCommand)
private void
confirmOrUndoMovement(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 filtersprivate void
determineMapMode(boolean hasSelectionNearby)
sets the mapmode according to key modifiers and if there are any selectables nearby.private static boolean
doesImpactStatusLine(Collection<Node> affectedNodes, Collection<Way> selectedWays)
void
doKeyPressed(KeyEvent e)
This is called when key press event is actually pressed (no fake events while holding key)void
doKeyReleased(KeyEvent e)
This is called when key press event is actually released (no fake events while holding key)private boolean
dragInProgress()
Determines whenever elements have been grabbed and moved (i.e.void
enterMode()
Makes this map mode active.void
exitMode()
Makes this map mode inactive.private Node
findNodeToMergeTo(Point p)
Tries to find a node to merge to when in move-merge mode for the current mouse position.private Cursor
getCursor(OsmPrimitive nearbyStuff)
works out which cursor should be displayed for most of SelectAction's features.private static Command
getLastCommandInDataset(DataSet ds)
Obtain command in undoRedo stack to "continue" when draggingSelectAction.Mode
getMode()
Returns the current select mode.String
getModeHelpText()
Returns a short translated help message describing how this map mode can be used, to be displayed in status line.private boolean
giveUserFeedback(MouseEvent e)
handles adding highlights and updating the cursor for the given mouse event.private boolean
giveUserFeedback(MouseEvent e, int modifiers)
handles adding highlights and updating the cursor for the given mouse event.boolean
layerIsSupported(Layer l)
Determines if layerl
is supported by this map mode.void
mergeNodes(OsmDataLayer layer, Collection<Node> nodes, Node targetLocationNode)
Merge nodes usingMergeNodesAction
.private void
mergePrims(Point p)
Merges the selected nodes to the one closest to the given mouse position if the control key is pressed.void
modifiersExChanged(int modifiers)
Called when the extended modifiers are changedvoid
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).void
mouseExited(MouseEvent e)
void
mouseMoved(MouseEvent e)
void
mousePressed(MouseEvent e)
Look, whether any object is selected.void
mouseReleased(MouseEvent e)
private boolean
movesHiddenWay()
private boolean
removeHighlighting()
Removes all existing highlights.private boolean
repaintIfRequired(Optional<OsmPrimitive> newHighlight)
void
selectionEnded(Rectangle r, MouseEvent e)
Called, when the left mouse button was released.private void
selectPrims(Collection<OsmPrimitive> prims, boolean released, boolean area)
void
setLassoMode(boolean lassoMode)
Enable or diable the lasso modeprivate static void
showConfirmMoveDialog(SelectAction.ConfirmMoveDialog ed)
private boolean
updateCommandWhileDragging(EastNorth currentEN)
Create or update data modification command while dragging mouse - implementation of continuous moving, scaling and rotationprivate 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, isEditableDataLayer, mouseClicked, mouseEntered, preferenceChanged, readPreferences, requestFocusInMapView, updateKeyModifiers, updateKeyModifiers, updateKeyModifiers, updateKeyModifiersEx, updateStatusLine
-
Methods inherited from class org.openstreetmap.josm.actions.JosmAction
buildActiveLayerChangeAdapter, buildLayerChangeAdapter, checkAndConfirmOutlyingOperation, destroy, getLayerManager, getShortcut, initEnabledState, installAdapters, listenToLayerChange, listenToSelectionChange, setHelpId, setToolbarId, setTooltip, updateEnabledState, updateEnabledState, updateEnabledStateOnCurrentSelection, updateEnabledStateOnCurrentSelection, updateEnabledStateOnModifiableSelection, waitFuture
-
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 javax.swing.Action
accept, addPropertyChangeListener, getValue, isEnabled, putValue, removePropertyChangeListener, setEnabled
-
Methods inherited from interface java.awt.event.ActionListener
actionPerformed
-
-
-
-
Field Detail
-
NORMAL
private static final String NORMAL
- See Also:
- Constant Field Values
-
lassoMode
private boolean lassoMode
-
repeatedKeySwitchLassoOption
private boolean repeatedKeySwitchLassoOption
-
oldEvent
private MouseEvent oldEvent
-
mode
private SelectAction.Mode mode
-
selectionManager
private final transient SelectionManager selectionManager
-
cancelDrawMode
private boolean cancelDrawMode
-
drawTargetHighlight
private boolean drawTargetHighlight
-
didMouseDrag
private boolean didMouseDrag
-
startingDraggingPos
private Point startingDraggingPos
The old cursor before the user pressed the mouse button.
-
lastMousePos
private 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
-
currentHighlight
private transient Optional<OsmPrimitive> currentHighlight
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.
-
cycleManager
private final transient SelectAction.CycleManager cycleManager
-
virtualManager
private final transient 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()
Description copied from class:MapMode
Makes this map mode active.
-
exitMode
public void exitMode()
Description copied from class:MapMode
Makes this map mode inactive.
-
modifiersExChanged
public void modifiersExChanged(int modifiers)
Description copied from interface:ModifierExListener
Called when the extended modifiers are changed- Specified by:
modifiersExChanged
in interfaceModifierExListener
- 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 feedbackmodifiers
- 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(Optional<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 interfaceMouseListener
- Overrides:
mousePressed
in classMapMode
-
mouseMoved
public void mouseMoved(MouseEvent e)
- Specified by:
mouseMoved
in interfaceMouseMotionListener
- Overrides:
mouseMoved
in classMapMode
-
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 interfaceMouseMotionListener
- Overrides:
mouseDragged
in classMapMode
-
mouseExited
public void mouseExited(MouseEvent e)
- Specified by:
mouseExited
in interfaceMouseListener
- Overrides:
mouseExited
in classMapMode
-
mouseReleased
public void mouseReleased(MouseEvent e)
- Specified by:
mouseReleased
in interfaceMouseListener
- Overrides:
mouseReleased
in classMapMode
-
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 interfaceSelectionManager.SelectionEnded
- Parameters:
r
- The rectangle that encloses the current selection.e
- The mouse event.- See Also:
InputEvent.getModifiersEx()
,SelectionManager.getSelectedObjects(boolean)
-
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 interfaceKeyPressReleaseListener
- 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 interfaceKeyPressReleaseListener
- 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(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)
-
doesImpactStatusLine
private static boolean doesImpactStatusLine(Collection<Node> affectedNodes, 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(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)
-
checkCommandForLargeDistance
static void checkCommandForLargeDistance(Command lastCommand)
-
showConfirmMoveDialog
private static void showConfirmMoveDialog(SelectAction.ConfirmMoveDialog ed)
-
movesHiddenWay
private boolean movesHiddenWay()
-
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 usingMergeNodesAction
. Can be overridden for testing purpose.- Parameters:
layer
- layer the reference data layer. Must not be nullnodes
- the collection of nodes. Ignored if nulltargetLocationNode
- this node's location will be used for the target node
-
findNodeToMergeTo
private Node findNodeToMergeTo(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(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 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 classMapMode
- 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 layerl
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 classMapMode
- 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)
Returnso
as collection ofo
's type.- Type Parameters:
T
- object type- Parameters:
o
- any object- Returns:
o
as collection ofo
's type.
-
-