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:
java.awt.event.ActionListener,java.awt.event.MouseListener,java.awt.event.MouseMotionListener,java.io.Serializable,java.lang.Cloneable,java.util.EventListener,javax.swing.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 classSelectAction.ConfirmMoveDialogprivate classSelectAction.CycleManagerstatic classSelectAction.ModeSelect action mode.(package private) static classSelectAction.SelectActionCursorprivate classSelectAction.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 booleancancelDrawModeprivate OsmPrimitivecurrentHighlightelements that have been highlighted in the previous iteration.private SelectAction.CycleManagercycleManagerprivate booleandidMouseDragprivate booleandrawTargetHighlightprivate intinitialMoveDelayThe time which needs to pass between click and release before something counts as a move, in millisecondsprivate intinitialMoveThresholdThe screen distance which needs to be travelled before something counts as a move, in pixelsprivate booleaninitialMoveThresholdExceededprivate booleanlassoModeprivate java.awt.PointlastMousePosThe last known position of the mouse.private static CachingProperty<java.lang.Boolean>MERGE_BY_DEFAULTWhether nodes should be merged with other primitives by default when they are being draggedprivate SelectAction.Modemodeprivate intmouseDownButtonThe pressed button of the user mouse down event.private longmouseDownTimeThe time of the user mouse down event.private longmouseReleaseTimeThe time of the user mouse down event.private MapViewmvThe component this SelectAction is associated with.private static java.lang.StringNORMALprivate java.awt.event.MouseEventoldEventprivate booleanrepeatedKeySwitchLassoOptionprivate SelectionManagerselectionManagerprivate EastNorthstartENpoint where user pressed the mouse to start movementprivate java.awt.PointstartingDraggingPosThe old cursor before the user pressed the mouse button.private SelectAction.VirtualManagervirtualManager-
Fields inherited from class org.openstreetmap.josm.actions.mapmode.MapMode
alt, ctrl, cursor, meta, platformMenuShortcutKeyMask, shift
-
Fields inherited from class org.openstreetmap.josm.actions.JosmAction
sc
-
-
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> java.util.Collection<T>asColl(T o)Returnsoas collection ofo's type.(package private) static voidcheckCommandForLargeDistance(Command lastCommand)private voidconfirmOrUndoMovement(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 filtersprivate voiddetermineMapMode(boolean hasSelectionNearby)sets the mapmode according to key modifiers and if there are any selectables nearby.private static booleandoesImpactStatusLine(java.util.Collection<Node> affectedNodes, java.util.Collection<Way> selectedWays)voiddoKeyPressed(java.awt.event.KeyEvent e)This is called when key press event is actually pressed (no fake events while holding key)voiddoKeyReleased(java.awt.event.KeyEvent e)This is called when key press event is actually released (no fake events while holding key)private booleandragInProgress()Determines whenever elements have been grabbed and moved (i.e.voidenterMode()Makes this map mode active.voidexitMode()Makes this map mode inactive.private NodefindNodeToMergeTo(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.CursorgetCursor(OsmPrimitive nearbyStuff)works out which cursor should be displayed for most of SelectAction's features.private static CommandgetLastCommandInDataset(DataSet ds)Obtain command in undoRedo stack to "continue" when draggingSelectAction.ModegetMode()Returns the current select mode.java.lang.StringgetModeHelpText()Returns a short translated help message describing how this map mode can be used, to be displayed in status line.private booleangiveUserFeedback(java.awt.event.MouseEvent e)handles adding highlights and updating the cursor for the given mouse event.private booleangiveUserFeedback(java.awt.event.MouseEvent e, int modifiers)handles adding highlights and updating the cursor for the given mouse event.private booleanisMergeRequested()Check if dragged node should be merged when moving it over another primitivebooleanlayerIsSupported(Layer l)Determines if layerlis supported by this map mode.voidmergeNodes(OsmDataLayer layer, java.util.Collection<Node> nodes, Node targetLocationNode)Merge nodes usingMergeNodesAction.private voidmergePrims(java.awt.Point p)Merges the selected nodes to the one closest to the given mouse position if the control key is pressed.voidmodifiersExChanged(int modifiers)Called when the extended modifiers are changedvoidmouseDragged(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).voidmouseExited(java.awt.event.MouseEvent e)voidmouseMoved(java.awt.event.MouseEvent e)voidmousePressed(java.awt.event.MouseEvent e)Look, whether any object is selected.voidmouseReleased(java.awt.event.MouseEvent e)private booleanmovesHiddenWay()private booleanremoveHighlighting()Removes all existing highlights.private booleanrepaintIfRequired(OsmPrimitive newHighlight)voidselectionEnded(java.awt.Rectangle r, java.awt.event.MouseEvent e)Called, when the left mouse button was released.private voidselectPrims(java.util.Collection<OsmPrimitive> prims, boolean released, boolean area)voidsetLassoMode(boolean lassoMode)Enable or diable the lasso modeprivate static voidshowConfirmMoveDialog(SelectAction.ConfirmMoveDialog ed)private booleanupdateCommandWhileDragging(java.awt.event.MouseEvent mouseEvent, EastNorth currentEN)Create or update data modification command while dragging mouse - implementation of continuous moving, scaling and rotationprivate voiduseLastMoveCommandIfPossible()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
-
-
-
-
Field Detail
-
NORMAL
private static final java.lang.String NORMAL
- See Also:
- Constant Field Values
-
MERGE_BY_DEFAULT
private static final CachingProperty<java.lang.Boolean> MERGE_BY_DEFAULT
Whether nodes should be merged with other primitives by default when they are being dragged
-
lassoMode
private boolean lassoMode
-
repeatedKeySwitchLassoOption
private boolean repeatedKeySwitchLassoOption
-
oldEvent
private java.awt.event.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 java.awt.Point startingDraggingPos
The old cursor before the user pressed the mouse button.
-
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
-
currentHighlight
private transient 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:MapModeMakes this map mode active.
-
exitMode
public void exitMode()
Description copied from class:MapModeMakes this map mode inactive.
-
modifiersExChanged
public void modifiersExChanged(int modifiers)
Description copied from interface:ModifierExListenerCalled when the extended modifiers are changed- Specified by:
modifiersExChangedin interfaceModifierExListener- Parameters:
modifiers- The new extended modifiers
-
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-MouseEventwhich should be used as base for the feedback- Returns:
trueif 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-MouseEventwhich should be used as base for the feedbackmodifiers- define custom keyboard extended modifiers if the ones from MouseEvent are outdated or similar- Returns:
trueif 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
-
repaintIfRequired
private boolean repaintIfRequired(OsmPrimitive newHighlight)
-
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:
mousePressedin interfacejava.awt.event.MouseListener- Overrides:
mousePressedin classMapMode
-
mouseMoved
public void mouseMoved(java.awt.event.MouseEvent e)
- Specified by:
mouseMovedin interfacejava.awt.event.MouseMotionListener- Overrides:
mouseMovedin classMapMode
-
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:
mouseDraggedin interfacejava.awt.event.MouseMotionListener- Overrides:
mouseDraggedin classMapMode
-
mouseExited
public void mouseExited(java.awt.event.MouseEvent e)
- Specified by:
mouseExitedin interfacejava.awt.event.MouseListener- Overrides:
mouseExitedin classMapMode
-
mouseReleased
public void mouseReleased(java.awt.event.MouseEvent e)
- Specified by:
mouseReleasedin interfacejava.awt.event.MouseListener- Overrides:
mouseReleasedin classMapMode
-
selectionEnded
public void selectionEnded(java.awt.Rectangle r, java.awt.event.MouseEvent e)
Description copied from interface:SelectionManager.SelectionEndedCalled, when the left mouse button was released.- Specified by:
selectionEndedin 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(java.awt.event.KeyEvent e)
Description copied from interface:KeyPressReleaseListenerThis is called when key press event is actually pressed (no fake events while holding key)- Specified by:
doKeyPressedin interfaceKeyPressReleaseListener- Parameters:
e- key event
-
doKeyReleased
public void doKeyReleased(java.awt.event.KeyEvent e)
Description copied from interface:KeyPressReleaseListenerThis is called when key press event is actually released (no fake events while holding key)- Specified by:
doKeyReleasedin 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-trueif 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 eventcurrentEN- - mouse position- Returns:
- status of action (
truewhen 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)
-
checkCommandForLargeDistance
static void checkCommandForLargeDistance(Command lastCommand)
-
showConfirmMoveDialog
private static void showConfirmMoveDialog(SelectAction.ConfirmMoveDialog ed)
-
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(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 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(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:MapModeReturns a short translated help message describing how this map mode can be used, to be displayed in status line.- Overrides:
getModeHelpTextin 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:MapModeDetermines if layerlis 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:
layerIsSupportedin classMapMode- Parameters:
l- layer- Returns:
trueif 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)
Returnsoas collection ofo's type.- Type Parameters:
T- object type- Parameters:
o- any object- Returns:
oas collection ofo's type.
-
-