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:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static classprivate final classstatic enumSelect action mode.(package private) static enumprivate final classNested classes/interfaces inherited from class org.openstreetmap.josm.actions.JosmAction
JosmAction.ActiveLayerChangeAdapter, JosmAction.LayerChangeAdapter, JosmAction.SelectionChangeAdapter -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate booleanprivate OsmPrimitiveelements that have been highlighted in the previous iteration.private final SelectAction.CycleManagerprivate booleanprivate booleanprivate intThe time which needs to pass between click and release before something counts as a move, in millisecondsprivate intThe screen distance which needs to be travelled before something counts as a move, in pixelsprivate booleanprivate booleanprivate PointThe last known position of the mouse.private static final CachingProperty<Boolean>Whether nodes should be merged with other primitives by default when they are being draggedprivate SelectAction.Modeprivate intThe pressed button of the user mouse down event.private longThe time of the user mouse down event.private longThe time of the user mouse down event.private final MapViewThe component this SelectAction is associated with.private static final Stringprivate MouseEventprivate booleanprivate final SelectionManagerprivate EastNorthpoint where user pressed the mouse to start movementprivate PointThe old cursor before the user pressed the mouse button.private final SelectAction.VirtualManagerFields inherited from class org.openstreetmap.josm.actions.mapmode.MapMode
alt, ctrl, cursor, meta, platformMenuShortcutKeyMask, shiftFields inherited from class org.openstreetmap.josm.actions.JosmAction
scFields inherited from class javax.swing.AbstractAction
changeSupport, enabledFields 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 -
Method Summary
Modifier and TypeMethodDescriptionprotected static <T> Collection<T>asColl(T o) Returnsoas collection ofo's type.(package private) static voidcheckCommandForLargeDistance(Command lastCommand) private voidPresent 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(Collection<Node> affectedNodes, Collection<Way> selectedWays) voidThis is called when key press event is actually pressed (no fake events while holding key)voidThis is called when key press event is actually released (no fake events while holding key)private booleanDetermines whenever elements have been grabbed and moved (i.e.voidMakes this map mode active.voidexitMode()Makes this map mode inactive.private NodeTries to find a node to merge to when in move-merge mode for the current mouse position.private CursorgetCursor(OsmPrimitive nearbyStuff) works out which cursor should be displayed for most of SelectAction's features.private static CommandObtain command in undoRedo stack to "continue" when draggingfinal SelectAction.ModegetMode()Returns the current select mode.Returns a short translated help message describing how this map mode can be used, to be displayed in status line.private booleanhandles adding highlights and updating the cursor for the given mouse event.private booleangiveUserFeedback(MouseEvent e, int modifiers) handles adding highlights and updating the cursor for the given mouse event.private booleanCheck if dragged node should be merged when moving it over another primitivebooleanDetermines if layerlis supported by this map mode.voidmergeNodes(OsmDataLayer layer, Collection<Node> nodes, Node targetLocationNode) Merge nodes usingMergeNodesAction.private voidmergePrims(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 changedvoidIf 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).voidvoidvoidLook, whether any object is selected.voidprivate booleanprivate booleanRemoves all existing highlights.private booleanrepaintIfRequired(OsmPrimitive newHighlight) voidCalled, when the left mouse button was released.private voidselectPrims(Collection<OsmPrimitive> prims, boolean released, boolean area) voidsetLassoMode(boolean lassoMode) Enable or diable the lasso modeprivate static voidprivate booleanupdateCommandWhileDragging(MouseEvent mouseEvent, EastNorth currentEN) Create or update data modification command while dragging mouse - implementation of continuous moving, scaling and rotationprivate voidAdapt last move command (if it is suitable) to work with next drag, started at point startENMethods inherited from class org.openstreetmap.josm.actions.mapmode.MapMode
actionPerformed, isEditableDataLayer, mouseClicked, mouseEntered, preferenceChanged, readPreferences, requestFocusInMapView, updateKeyModifiers, updateKeyModifiers, updateKeyModifiers, updateKeyModifiersEx, updateStatusLineMethods 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, waitFutureMethods inherited from class javax.swing.AbstractAction
addPropertyChangeListener, clone, firePropertyChange, getKeys, getPropertyChangeListeners, getValue, isEnabled, putValue, removePropertyChangeListener, setEnabledMethods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface javax.swing.Action
accept, addPropertyChangeListener, getValue, isEnabled, putValue, removePropertyChangeListener, setEnabledMethods inherited from interface java.awt.event.ActionListener
actionPerformed
-
Field Details
-
NORMAL
- See Also:
-
MERGE_BY_DEFAULT
Whether nodes should be merged with other primitives by default when they are being dragged -
lassoMode
-
repeatedKeySwitchLassoOption
-
oldEvent
-
mode
-
selectionManager
-
cancelDrawMode
-
drawTargetHighlight
-
didMouseDrag
-
mv
The component this SelectAction is associated with. -
startingDraggingPos
The old cursor before the user pressed the mouse button. -
startEN
point where user pressed the mouse to start movement -
lastMousePos
The last known position of the mouse. -
mouseDownTime
The time of the user mouse down event. -
mouseDownButton
The pressed button of the user mouse down event. -
mouseReleaseTime
The time of the user mouse down event. -
initialMoveDelay
The time which needs to pass between click and release before something counts as a move, in milliseconds -
initialMoveThreshold
The screen distance which needs to be travelled before something counts as a move, in pixels -
initialMoveThresholdExceeded
-
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
-
virtualManager
-
-
Constructor Details
-
SelectAction
Create a new SelectAction- Parameters:
mapFrame- The MapFrame this action belongs to.
-
-
Method Details
-
enterMode
Description copied from class:MapModeMakes this map mode active. -
exitMode
Description copied from class:MapModeMakes this map mode inactive. -
modifiersExChanged
Description copied from interface:ModifierExListenerCalled when the extended modifiers are changed- Specified by:
modifiersExChangedin interfaceModifierExListener- Parameters:
modifiers- The new extended modifiers
-
giveUserFeedback
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
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
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
Removes all existing highlights.- Returns:
- true if a repaint is required
-
repaintIfRequired
-
mousePressed
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 interfaceMouseListener- Overrides:
mousePressedin classMapMode
-
mouseMoved
- Specified by:
mouseMovedin interfaceMouseMotionListener- Overrides:
mouseMovedin classMapMode
-
mouseDragged
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 interfaceMouseMotionListener- Overrides:
mouseDraggedin classMapMode
-
mouseExited
- Specified by:
mouseExitedin interfaceMouseListener- Overrides:
mouseExitedin classMapMode
-
mouseReleased
- Specified by:
mouseReleasedin interfaceMouseListener- Overrides:
mouseReleasedin classMapMode
-
selectionEnded
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:
-
doKeyPressed
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
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
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
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
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(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
-
showConfirmMoveDialog
-
movesHiddenWay
-
isMergeRequested
Check if dragged node should be merged when moving it over another primitive- Returns:
- true if merge is requested
-
mergePrims
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
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
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
-
getMode
Returns the current select mode.- Returns:
- the select mode
- Since:
- 7543
-
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
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
Enable or diable the lasso mode- Parameters:
lassoMode- true to enable the lasso mode, false otherwise
-
asColl
Returnsoas collection ofo's type.- Type Parameters:
T- object type- Parameters:
o- any object- Returns:
oas collection ofo's type.
-