Class DrawAction
java.lang.Object
javax.swing.AbstractAction
org.openstreetmap.josm.actions.JosmAction
org.openstreetmap.josm.actions.mapmode.MapMode
org.openstreetmap.josm.actions.mapmode.DrawAction
- All Implemented Interfaces:
ActionListener,MouseListener,MouseMotionListener,Serializable,Cloneable,EventListener,Action,DataSelectionListener,MapViewPaintable,KeyPressReleaseListener,ModifierExListener,PreferenceChangedListener,Destroyable
public class DrawAction
extends MapMode
implements MapViewPaintable, DataSelectionListener, KeyPressReleaseListener, ModifierExListener
Mapmode to add nodes, create and extend ways.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclassUndo the last command.private classNested classes/interfaces inherited from class org.openstreetmap.josm.actions.JosmAction
JosmAction.ActiveLayerChangeAdapter, JosmAction.LayerChangeAdapter, JosmAction.SelectionChangeAdapterNested classes/interfaces inherited from interface org.openstreetmap.josm.data.osm.DataSelectionListener
DataSelectionListener.AbstractSelectionEvent, DataSelectionListener.SelectionAddEvent, DataSelectionListener.SelectionChangeEvent, DataSelectionListener.SelectionRemoveEvent, DataSelectionListener.SelectionReplaceEvent, DataSelectionListener.SelectionToggleEventNested classes/interfaces inherited from interface org.openstreetmap.josm.gui.layer.MapViewPaintable
MapViewPaintable.LayerPainter, MapViewPaintable.MapViewEvent, MapViewPaintable.PaintableInvalidationEvent, MapViewPaintable.PaintableInvalidationListener -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final DrawAction.BackSpaceActionprivate final Shortcutprivate static final BasicStrokeprivate Nodeprivate EastNorthprivate final Cursorprivate final Cursor(package private) static final CachingProperty<Boolean>(package private) static final CachingProperty<Boolean>(package private) static final CachingProperty<Boolean>(package private) static final CachingProperty<BasicStroke>(package private) static final CachingProperty<Color>(package private) static final CachingProperty<BasicStroke>private booleanprivate Nodeprivate Nodeprivate Pointprivate Set<OsmPrimitive>private Set<OsmPrimitive>private Pointprivate static final Colorprivate Nodeprivate Point(package private) static final AbstractProperty<Color>(package private) static final CachingProperty<BasicStroke>(package private) static final CachingProperty<Boolean>(package private) static final CachingProperty<Boolean>(package private) static final CachingProperty<Double>(package private) static final CachingProperty<Color>(package private) static final CachingProperty<Double>(package private) static final CachingProperty<Boolean>private final DrawAction.SnapChangeActionprivate final JCheckBoxMenuItemprivate final DrawSnapHelperprivate final Shortcutprivate static final ArrowPaintHelperprivate double(package private) static final CachingProperty<Boolean>static final CachingProperty<Boolean>If this property is set, the draw action moves the viewport when adding new points.private booleanFields 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 TypeMethodDescriptionprivate voidaddHighlighting(Object event) Takes the data from computeHelperLine to determine which ways/nodes should be highlighted (if feature enabled).private JCheckBoxMenuItemprivate static voidaddRemoveSelection(DataSet ds, OsmPrimitive toAdd, OsmPrimitive toRemove) private static voidaddSelection(DataSet ds, OsmPrimitive toAdd) private static voidadjustNode(Collection<Pair<Node, Node>> segs, Node n) Adjusts the position of a node to lie on a segment (or a segment intersection).private static voidadjustNodeDefault(Collection<Pair<Node, Node>> segs, Node n) private static voidadjustNodeTwoSegments(Collection<Pair<Node, Node>> segs, Node n) private static voidclearSelection(DataSet ds, OsmPrimitive toRemove) private voidThis method prepares data required for painting the "helper line" from the last used position to the mouse cursor.private voidcontinueWayFromNode(Way way, Node node) if one of the ends ofwayis givennode, then set currentBaseNode = node and previousNode = adjacent node of wayvoiddestroy()Called when the object has been destroyed.(package private) static doubledet(double a, double b, double c, double d) private voidHelper function that sets fields currentBaseNode and previousNodevoidThis 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)voidMakes this map mode active.voidexitMode()Makes this map mode inactive.private NodefindNodeToContinueFrom(Node selectedNode, Way selectedWay) Finds a node to continue drawing from.private voidThis function should be called when the user wishes to finish his current draw action.Replies the current base node, after having checked it is still usable (see #11105).Get selected primitives, while draw action is in progress.Returns a short translated help message describing how this map mode can be used, to be displayed in status line.private static StringgetTitle(boolean newNode, Node n, Collection<OsmPrimitive> newSelection, Map<Way, List<Node>> reuseWays, boolean extendedWay) static WayReplies the parent way of a node, if it is the end of exactly one usable way.private voidinsertNodeIntoAllNearbySegments(List<WaySegment> wss, Node n, Collection<OsmPrimitive> newSelection, Collection<Command> cmds, Map<Way, List<Node>> reuseWays) private booleanisSelfContainedWay(Way selectedWay, Node currentNode, Node targetNode) Prevent creation of ways that look like this: <----> This happens if users want to draw a no-exit-sideway from the main way like this: ^ |<----> | The solution isn't ideal because the main way will end in the side way, which is bad for navigation software ("drive straight on") but at least easier to fix.booleanDetermines if layerlis supported by this map mode.voidmodifiersExChanged(int modifiers) redraw to (possibly) get rid of helper line if selection changes.voidvoidRepaint on mouse exit so that the helper line goes away.voidvoidvoidIf user clicked with the left button, add a node at the current mouse position.voidpaint(Graphics2D g, MapView mv, Bounds box) Paint the dataset using the engine set.private voidprivate static voidprivate booleanChecks if a map redraw is required and does so if needed.private booleanremoveHighlighting(Object event) Removes target highlighting from primitives.voidredraw to (possibly) get rid of helper line if selection changes.private static voidsetSelection(DataSet ds, Collection<OsmPrimitive> toSet) private static voidsetSelection(DataSet ds, OsmPrimitive toSet) (package private) static voidshowStatusInfo(double angle, double hdg, double distance, boolean activeFlag) private voidprivate voidtryToMoveNodeOnIntersection(List<WaySegment> wss, Node n) private voidThis method is used to detect segment under mouse and use it as reference for angle snappingprotected voidOverride in subclasses to update the enabled state of the action when something in the JOSM state changes, i.e.private static voidupdatePreservedFlag(OsmPrimitive osm, boolean state) Methods 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, getLayerManager, getShortcut, initEnabledState, installAdapters, listenToLayerChange, listenToSelectionChange, setHelpId, setToolbarId, setTooltip, 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 org.openstreetmap.josm.gui.layer.MapViewPaintable
addInvalidationListener, removeInvalidationListener
-
Field Details
-
VIEWPORT_FOLLOWING
If this property is set, the draw action moves the viewport when adding new points.- Since:
- 12182
-
ORANGE_TRANSPARENT
-
START_WAY_INDICATOR
-
USE_REPEATED_SHORTCUT
-
RUBBER_LINE_STROKE
-
HIGHLIGHT_STROKE
-
HELPER_STROKE
-
SNAP_ANGLE_TOLERANCE
-
DRAW_CONSTRUCTION_GEOMETRY
-
SHOW_PROJECTED_POINT
-
SNAP_TO_PROJECTIONS
-
SHOW_ANGLE
-
SNAP_HELPER_COLOR
-
HIGHLIGHT_COLOR
-
RUBBER_LINE_COLOR
-
DRAW_HELPER_LINE
-
DRAW_TARGET_HIGHLIGHT
-
SNAP_TO_INTERSECTION_THRESHOLD
-
cursorJoinNode
-
cursorJoinWay
-
lastUsedNode
-
toleranceMultiplier
-
mouseOnExistingNode
-
mouseOnExistingWays
-
oldHighlights
-
newHighlights
-
wayIsFinished
-
mousePos
-
oldMousePos
-
currentBaseNode
-
previousNode
-
currentMouseEastNorth
-
snapHelper
-
backspaceShortcut
-
backspaceAction
-
snappingShortcut
-
ignoreNextKeyRelease
-
snapChangeAction
-
snapCheckboxMenuItem
-
BASIC_STROKE
-
rightClickPressPos
-
-
Constructor Details
-
DrawAction
public DrawAction()Constructs a newDrawAction.- Since:
- 11713
-
-
Method Details
-
addMenuItem
-
redrawIfRequired
Checks if a map redraw is required and does so if needed. Also updates the status bar.- Parameters:
e- event, can be null- Returns:
- true if a repaint is needed
-
addRemoveSelection
-
updatePreservedFlag
-
setSelection
-
setSelection
-
addSelection
-
clearSelection
-
enterMode
Description copied from class:MapModeMakes this map mode active. -
exitMode
Description copied from class:MapModeMakes this map mode inactive. -
modifiersExChanged
redraw to (possibly) get rid of helper line if selection changes.- Specified by:
modifiersExChangedin interfaceModifierExListener- Parameters:
modifiers- The new extended modifiers
-
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
-
selectionChanged
redraw to (possibly) get rid of helper line if selection changes.- Specified by:
selectionChangedin interfaceDataSelectionListener- Parameters:
event- The selection change event.- See Also:
-
tryAgain
-
finishDrawing
This function should be called when the user wishes to finish his current draw action. If Potlatch Style is enabled, it will switch to select tool, otherwise simply disable the helper line until the user chooses to draw something else. -
mousePressed
- Specified by:
mousePressedin interfaceMouseListener- Overrides:
mousePressedin classMapMode
-
mouseReleased
If user clicked with the left button, add a node at the current mouse position. If in nodeway mode, insert the node into the way.- Specified by:
mouseReleasedin interfaceMouseListener- Overrides:
mouseReleasedin classMapMode
-
getTitle
private static String getTitle(boolean newNode, Node n, Collection<OsmPrimitive> newSelection, Map<Way, List<Node>> reuseWays, boolean extendedWay) -
insertNodeIntoAllNearbySegments
private void insertNodeIntoAllNearbySegments(List<WaySegment> wss, Node n, Collection<OsmPrimitive> newSelection, Collection<Command> cmds, Map<Way, List<Node>> reuseWays) -
isSelfContainedWay
Prevent creation of ways that look like this: <----> This happens if users want to draw a no-exit-sideway from the main way like this: ^ |<----> | The solution isn't ideal because the main way will end in the side way, which is bad for navigation software ("drive straight on") but at least easier to fix. Maybe users will fix it on their own, too. At least it's better than producing an error.- Parameters:
selectedWay- the way to checkcurrentNode- the current node (i.e. the one the connection will be made from)targetNode- the target node (i.e. the one the connection will be made to)- Returns:
trueif this would create a selfcontaining way,falseotherwise.
-
findNodeToContinueFrom
Finds a node to continue drawing from. Decision is based upon given node and way.- Parameters:
selectedNode- Currently selected node, may be nullselectedWay- Currently selected way, may be null- Returns:
- Node if a suitable node is found, null otherwise
-
mouseDragged
- Specified by:
mouseDraggedin interfaceMouseMotionListener- Overrides:
mouseDraggedin classMapMode
-
mouseMoved
- Specified by:
mouseMovedin interfaceMouseMotionListener- Overrides:
mouseMovedin classMapMode
-
tryToSetBaseSegmentForAngleSnap
This method is used to detect segment under mouse and use it as reference for angle snapping -
computeHelperLine
This method prepares data required for painting the "helper line" from the last used position to the mouse cursor. It duplicates some code from mouseReleased() (FIXME). -
showStatusInfo
-
determineCurrentBaseNodeAndPreviousNode
Helper function that sets fields currentBaseNode and previousNode- Parameters:
selection- uses also lastUsedNode field
-
continueWayFromNode
if one of the ends ofwayis givennode, then set currentBaseNode = node and previousNode = adjacent node of way- Parameters:
way- way to continuenode- starting node
-
mouseExited
Repaint on mouse exit so that the helper line goes away.- Specified by:
mouseExitedin interfaceMouseListener- Overrides:
mouseExitedin classMapMode
-
getWayForNode
Replies the parent way of a node, if it is the end of exactly one usable way.- Parameters:
n- node- Returns:
- If the node is the end of exactly one way, return this.
nullotherwise.
-
getCurrentBaseNode
Replies the current base node, after having checked it is still usable (see #11105).- Returns:
- the current base node (can be null). If not-null, it's guaranteed the node is usable
-
pruneSuccsAndReverse
-
adjustNode
Adjusts the position of a node to lie on a segment (or a segment intersection). If one or more than two segments are passed, the node is adjusted to lie on the first segment that is passed. If two segments are passed, the node is adjusted to be at their intersection. No action is taken if no segments are passed.- Parameters:
segs- the segments to use as a reference when adjustingn- the node to adjust
-
adjustNodeTwoSegments
-
adjustNodeDefault
-
det
-
tryToMoveNodeOnIntersection
-
addHighlighting
Takes the data from computeHelperLine to determine which ways/nodes should be highlighted (if feature enabled). Also sets the target cursor if appropriate. It adds the to-be- highlighted primitives to newHighlights but does not actually highlight them. This work is done in redrawIfRequired. This means, calling addHighlighting() without redrawIfRequired() will leave the data in an inconsistent state. The status bar derives its information from oldHighlights, so in order to update the status bar both addHighlighting() and repaintIfRequired() are needed, since former fills newHighlights and latter processes them into oldHighlights.- Parameters:
event- event, can be null
-
removeHighlighting
Removes target highlighting from primitives. Issues repaint if required.- Parameters:
event- event, can be null- Returns:
- true if a repaint has been issued.
-
paint
Description copied from interface:MapViewPaintablePaint the dataset using the engine set.- Specified by:
paintin interfaceMapViewPaintable- Parameters:
g- Graphicsmv- The object that can translate GeoPoints to screen coordinates.box- Bounding box
-
paintConstructionGeometry
-
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
-
getInProgressSelection
Get selected primitives, while draw action is in progress. While drawing a way, technically the last node is selected. This is inconvenient when the user tries to add/edit tags to the way. For this case, this method returns the current way as selection, to work around this issue. Otherwise the normal selection of the current data layer is returned.- Returns:
- selected primitives, while draw action is in progress
-
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
-
updateEnabledState
Description copied from class:JosmActionOverride in subclasses to update the enabled state of the action when something in the JOSM state changes, i.e. when a layer is removed or added. SeeJosmAction.updateEnabledState(Collection)to respond to changes in the collection of selected primitives. Default behavior is empty.- Overrides:
updateEnabledStatein classJosmAction- See Also:
-
destroy
Description copied from interface:DestroyableCalled when the object has been destroyed.- Specified by:
destroyin interfaceDestroyable- Overrides:
destroyin classJosmAction
-