public class DrawAction extends MapMode implements MapViewPaintable, DataSelectionListener, KeyPressReleaseListener, ModifierExListener
| Modifier and Type | Class and Description |
|---|---|
class |
DrawAction.BackSpaceAction
Undo the last command.
|
private class |
DrawAction.SnapChangeAction |
JosmAction.ActiveLayerChangeAdapter, JosmAction.LayerChangeAdapter, JosmAction.SelectionChangeAdapterMapViewPaintable.LayerPainter, MapViewPaintable.MapViewEvent, MapViewPaintable.PaintableInvalidationEvent, MapViewPaintable.PaintableInvalidationListenerDataSelectionListener.AbstractSelectionEvent, DataSelectionListener.SelectionAddEvent, DataSelectionListener.SelectionChangeEvent, DataSelectionListener.SelectionRemoveEvent, DataSelectionListener.SelectionReplaceEvent, DataSelectionListener.SelectionToggleEvent| Modifier and Type | Field and Description |
|---|---|
private DrawAction.BackSpaceAction |
backspaceAction |
private Shortcut |
backspaceShortcut |
private static java.awt.BasicStroke |
BASIC_STROKE |
private Node |
currentBaseNode |
private EastNorth |
currentMouseEastNorth |
private java.awt.Cursor |
cursorJoinNode |
private java.awt.Cursor |
cursorJoinWay |
(package private) static CachingProperty<java.lang.Boolean> |
DRAW_CONSTRUCTION_GEOMETRY |
(package private) static CachingProperty<java.lang.Boolean> |
DRAW_HELPER_LINE |
(package private) static CachingProperty<java.lang.Boolean> |
DRAW_TARGET_HIGHLIGHT |
(package private) static CachingProperty<java.awt.BasicStroke> |
HELPER_STROKE |
(package private) static CachingProperty<java.awt.Color> |
HIGHLIGHT_COLOR |
(package private) static CachingProperty<java.awt.BasicStroke> |
HIGHLIGHT_STROKE |
private boolean |
ignoreNextKeyRelease |
private Node |
lastUsedNode |
private Node |
mouseOnExistingNode |
private java.util.Set<Way> |
mouseOnExistingWays |
private java.awt.Point |
mousePos |
private java.util.Set<OsmPrimitive> |
newHighlights |
private java.util.Set<OsmPrimitive> |
oldHighlights |
private java.awt.Point |
oldMousePos |
private static java.awt.Color |
ORANGE_TRANSPARENT |
private Node |
previousNode |
private java.awt.Point |
rightClickPressPos |
(package private) static AbstractProperty<java.awt.Color> |
RUBBER_LINE_COLOR |
(package private) static CachingProperty<java.awt.BasicStroke> |
RUBBER_LINE_STROKE |
(package private) static CachingProperty<java.lang.Boolean> |
SHOW_ANGLE |
(package private) static CachingProperty<java.lang.Boolean> |
SHOW_PROJECTED_POINT |
(package private) static CachingProperty<java.lang.Double> |
SNAP_ANGLE_TOLERANCE |
(package private) static CachingProperty<java.awt.Color> |
SNAP_HELPER_COLOR |
(package private) static CachingProperty<java.lang.Double> |
SNAP_TO_INTERSECTION_THRESHOLD |
(package private) static CachingProperty<java.lang.Boolean> |
SNAP_TO_PROJECTIONS |
private DrawAction.SnapChangeAction |
snapChangeAction |
private javax.swing.JCheckBoxMenuItem |
snapCheckboxMenuItem |
private DrawSnapHelper |
snapHelper |
private Shortcut |
snappingShortcut |
private static ArrowPaintHelper |
START_WAY_INDICATOR |
private double |
toleranceMultiplier |
(package private) static CachingProperty<java.lang.Boolean> |
USE_REPEATED_SHORTCUT |
static CachingProperty<java.lang.Boolean> |
VIEWPORT_FOLLOWING
If this property is set, the draw action moves the viewport when adding new points.
|
private boolean |
wayIsFinished |
sc| Constructor and Description |
|---|
DrawAction()
Constructs a new
DrawAction. |
| Modifier and Type | Method and Description |
|---|---|
private void |
addHighlighting(java.lang.Object event)
Takes the data from computeHelperLine to determine which ways/nodes should be highlighted
(if feature enabled).
|
private javax.swing.JCheckBoxMenuItem |
addMenuItem() |
private static void |
addRemoveSelection(DataSet ds,
OsmPrimitive toAdd,
OsmPrimitive toRemove) |
private static void |
addSelection(DataSet ds,
OsmPrimitive toAdd) |
private static void |
adjustNode(java.util.Collection<Pair<Node,Node>> segs,
Node n)
Adjusts the position of a node to lie on a segment (or a segment intersection).
|
private static void |
adjustNodeDefault(java.util.Collection<Pair<Node,Node>> segs,
Node n) |
private static void |
adjustNodeTwoSegments(java.util.Collection<Pair<Node,Node>> segs,
Node n) |
private static void |
clearSelection(DataSet ds,
OsmPrimitive toRemove) |
private void |
computeHelperLine()
This method prepares data required for painting the "helper line" from
the last used position to the mouse cursor.
|
private void |
continueWayFromNode(Way way,
Node node)
if one of the ends of
way is given node,
then set currentBaseNode = node and previousNode = adjacent node of way |
void |
destroy()
Called when the object has been destroyed.
|
(package private) static double |
det(double a,
double b,
double c,
double d) |
private void |
determineCurrentBaseNodeAndPreviousNode(java.util.Collection<OsmPrimitive> selection)
Helper function that sets fields currentBaseNode and previousNode
|
void |
doKeyPressed(java.awt.event.KeyEvent e)
This is called when key press event is actually pressed
(no fake events while holding key)
|
void |
doKeyReleased(java.awt.event.KeyEvent e)
This is called when key press event is actually released
(no fake events while holding key)
|
void |
enterMode()
Makes this map mode active.
|
void |
exitMode()
Makes this map mode inactive.
|
private Node |
findNodeToContinueFrom(Node selectedNode,
Way selectedWay)
Finds a node to continue drawing from.
|
private void |
finishDrawing()
This function should be called when the user wishes to finish his current draw action.
|
Node |
getCurrentBaseNode()
Replies the current base node, after having checked it is still usable (see #11105).
|
java.util.Collection<OsmPrimitive> |
getInProgressSelection()
Get selected primitives, while draw action is in progress.
|
java.lang.String |
getModeHelpText()
Returns a short translated help message describing how this map mode can be used, to be displayed in status line.
|
private static java.lang.String |
getTitle(boolean newNode,
Node n,
java.util.Collection<OsmPrimitive> newSelection,
java.util.List<Way> reuseWays,
boolean extendedWay) |
static Way |
getWayForNode(Node n)
Replies the parent way of a node, if it is the end of exactly one usable way.
|
private void |
insertNodeIntoAllNearbySegments(java.util.List<WaySegment> wss,
Node n,
java.util.Collection<OsmPrimitive> newSelection,
java.util.Collection<Command> cmds,
java.util.List<Way> replacedWays,
java.util.List<Way> reuseWays) |
private boolean |
isSelfContainedWay(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.
|
boolean |
layerIsSupported(Layer l)
Determines if layer
l is supported by this map mode. |
void |
modifiersExChanged(int modifiers)
redraw to (possibly) get rid of helper line if selection changes.
|
void |
mouseDragged(java.awt.event.MouseEvent e) |
void |
mouseExited(java.awt.event.MouseEvent e)
Repaint on mouse exit so that the helper line goes away.
|
void |
mouseMoved(java.awt.event.MouseEvent e) |
void |
mousePressed(java.awt.event.MouseEvent e) |
void |
mouseReleased(java.awt.event.MouseEvent e)
If user clicked with the left button, add a node at the current mouse
position.
|
void |
paint(java.awt.Graphics2D g,
MapView mv,
Bounds box)
Paint the dataset using the engine set.
|
private void |
paintConstructionGeometry(MapView mv,
java.awt.Graphics2D g2) |
private static void |
pruneSuccsAndReverse(java.util.List<java.lang.Integer> is) |
private boolean |
redrawIfRequired(java.lang.Object e)
Checks if a map redraw is required and does so if needed.
|
private boolean |
removeHighlighting(java.lang.Object event)
Removes target highlighting from primitives.
|
void |
selectionChanged(DataSelectionListener.SelectionChangeEvent event)
redraw to (possibly) get rid of helper line if selection changes.
|
private static void |
setSelection(DataSet ds,
java.util.Collection<OsmPrimitive> toSet) |
private static void |
setSelection(DataSet ds,
OsmPrimitive toSet) |
(package private) static void |
showStatusInfo(double angle,
double hdg,
double distance,
boolean activeFlag) |
private void |
tryAgain(java.awt.event.MouseEvent e) |
private void |
tryToMoveNodeOnIntersection(java.util.List<WaySegment> wss,
Node n) |
private void |
tryToSetBaseSegmentForAngleSnap()
This method is used to detect segment under mouse and use it as reference for angle snapping
|
protected void |
updateEnabledState()
Override in subclasses to update the enabled state of the action when
something in the JOSM state changes, i.e.
|
private static void |
updatePreservedFlag(OsmPrimitive osm,
boolean state) |
actionPerformed, isEditableDataLayer, mouseClicked, mouseEntered, preferenceChanged, readPreferences, requestFocusInMapView, updateKeyModifiers, updateKeyModifiers, updateKeyModifiers, updateKeyModifiersEx, updateStatusLinebuildActiveLayerChangeAdapter, buildLayerChangeAdapter, checkAndConfirmOutlyingOperation, getLayerManager, getShortcut, initEnabledState, installAdapters, listenToLayerChange, listenToSelectionChange, setHelpId, setTooltip, updateEnabledState, updateEnabledStateOnCurrentSelection, updateEnabledStateOnCurrentSelection, updateEnabledStateOnModifiableSelection, waitFutureaddPropertyChangeListener, clone, firePropertyChange, getKeys, getPropertyChangeListeners, getValue, isEnabled, putValue, removePropertyChangeListener, setEnabledequals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitaddInvalidationListener, removeInvalidationListenerpublic static final CachingProperty<java.lang.Boolean> VIEWPORT_FOLLOWING
private static final java.awt.Color ORANGE_TRANSPARENT
private static final ArrowPaintHelper START_WAY_INDICATOR
static final CachingProperty<java.lang.Boolean> USE_REPEATED_SHORTCUT
static final CachingProperty<java.awt.BasicStroke> RUBBER_LINE_STROKE
static final CachingProperty<java.awt.BasicStroke> HIGHLIGHT_STROKE
static final CachingProperty<java.awt.BasicStroke> HELPER_STROKE
static final CachingProperty<java.lang.Double> SNAP_ANGLE_TOLERANCE
static final CachingProperty<java.lang.Boolean> DRAW_CONSTRUCTION_GEOMETRY
static final CachingProperty<java.lang.Boolean> SHOW_PROJECTED_POINT
static final CachingProperty<java.lang.Boolean> SNAP_TO_PROJECTIONS
static final CachingProperty<java.lang.Boolean> SHOW_ANGLE
static final CachingProperty<java.awt.Color> SNAP_HELPER_COLOR
static final CachingProperty<java.awt.Color> HIGHLIGHT_COLOR
static final AbstractProperty<java.awt.Color> RUBBER_LINE_COLOR
static final CachingProperty<java.lang.Boolean> DRAW_HELPER_LINE
static final CachingProperty<java.lang.Boolean> DRAW_TARGET_HIGHLIGHT
static final CachingProperty<java.lang.Double> SNAP_TO_INTERSECTION_THRESHOLD
private final java.awt.Cursor cursorJoinNode
private final java.awt.Cursor cursorJoinWay
private transient Node lastUsedNode
private double toleranceMultiplier
private transient Node mouseOnExistingNode
private transient java.util.Set<Way> mouseOnExistingWays
private transient java.util.Set<OsmPrimitive> oldHighlights
private transient java.util.Set<OsmPrimitive> newHighlights
private boolean wayIsFinished
private java.awt.Point mousePos
private java.awt.Point oldMousePos
private transient Node currentBaseNode
private transient Node previousNode
private EastNorth currentMouseEastNorth
private final transient DrawSnapHelper snapHelper
private final transient Shortcut backspaceShortcut
private final DrawAction.BackSpaceAction backspaceAction
private final transient Shortcut snappingShortcut
private boolean ignoreNextKeyRelease
private final DrawAction.SnapChangeAction snapChangeAction
private final javax.swing.JCheckBoxMenuItem snapCheckboxMenuItem
private static final java.awt.BasicStroke BASIC_STROKE
private java.awt.Point rightClickPressPos
public DrawAction()
DrawAction.private javax.swing.JCheckBoxMenuItem addMenuItem()
private boolean redrawIfRequired(java.lang.Object e)
e - event, can be nullprivate static void addRemoveSelection(DataSet ds, OsmPrimitive toAdd, OsmPrimitive toRemove)
private static void updatePreservedFlag(OsmPrimitive osm, boolean state)
private static void setSelection(DataSet ds, java.util.Collection<OsmPrimitive> toSet)
private static void setSelection(DataSet ds, OsmPrimitive toSet)
private static void addSelection(DataSet ds, OsmPrimitive toAdd)
private static void clearSelection(DataSet ds, OsmPrimitive toRemove)
public void enterMode()
MapModepublic void exitMode()
MapModepublic void modifiersExChanged(int modifiers)
modifiersExChanged in interface ModifierExListenermodifiers - The new extended modifierspublic void doKeyPressed(java.awt.event.KeyEvent e)
KeyPressReleaseListenerdoKeyPressed in interface KeyPressReleaseListenere - key eventpublic void doKeyReleased(java.awt.event.KeyEvent e)
KeyPressReleaseListenerdoKeyReleased in interface KeyPressReleaseListenere - key eventpublic void selectionChanged(DataSelectionListener.SelectionChangeEvent event)
selectionChanged in interface DataSelectionListenerevent - The selection change event.DataSelectionListener.SelectionChangeEventprivate void tryAgain(java.awt.event.MouseEvent e)
private void finishDrawing()
public void mousePressed(java.awt.event.MouseEvent e)
mousePressed in interface java.awt.event.MouseListenermousePressed in class MapModepublic void mouseReleased(java.awt.event.MouseEvent e)
mouseReleased in interface java.awt.event.MouseListenermouseReleased in class MapModeprivate static java.lang.String getTitle(boolean newNode, Node n, java.util.Collection<OsmPrimitive> newSelection, java.util.List<Way> reuseWays, boolean extendedWay)
private void insertNodeIntoAllNearbySegments(java.util.List<WaySegment> wss, Node n, java.util.Collection<OsmPrimitive> newSelection, java.util.Collection<Command> cmds, java.util.List<Way> replacedWays, java.util.List<Way> reuseWays)
private boolean isSelfContainedWay(Way selectedWay, Node currentNode, Node targetNode)
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)true if this would create a selfcontaining way, false otherwise.private Node findNodeToContinueFrom(Node selectedNode, Way selectedWay)
selectedNode - Currently selected node, may be nullselectedWay - Currently selected way, may be nullpublic void mouseDragged(java.awt.event.MouseEvent e)
mouseDragged in interface java.awt.event.MouseMotionListenermouseDragged in class MapModepublic void mouseMoved(java.awt.event.MouseEvent e)
mouseMoved in interface java.awt.event.MouseMotionListenermouseMoved in class MapModeprivate void tryToSetBaseSegmentForAngleSnap()
private void computeHelperLine()
static void showStatusInfo(double angle, double hdg, double distance, boolean activeFlag)
private void determineCurrentBaseNodeAndPreviousNode(java.util.Collection<OsmPrimitive> selection)
selection - uses also lastUsedNode fieldprivate void continueWayFromNode(Way way, Node node)
way is given node,
then set currentBaseNode = node and previousNode = adjacent node of wayway - way to continuenode - starting nodepublic void mouseExited(java.awt.event.MouseEvent e)
mouseExited in interface java.awt.event.MouseListenermouseExited in class MapModepublic static Way getWayForNode(Node n)
n - nodenull otherwise.public Node getCurrentBaseNode()
private static void pruneSuccsAndReverse(java.util.List<java.lang.Integer> is)
private static void adjustNode(java.util.Collection<Pair<Node,Node>> segs, Node n)
segs - the segments to use as a reference when adjustingn - the node to adjustprivate static void adjustNodeTwoSegments(java.util.Collection<Pair<Node,Node>> segs, Node n)
private static void adjustNodeDefault(java.util.Collection<Pair<Node,Node>> segs, Node n)
static double det(double a, double b, double c, double d)
private void tryToMoveNodeOnIntersection(java.util.List<WaySegment> wss, Node n)
private void addHighlighting(java.lang.Object event)
event - event, can be nullprivate boolean removeHighlighting(java.lang.Object event)
event - event, can be nullpublic void paint(java.awt.Graphics2D g, MapView mv, Bounds box)
MapViewPaintablepaint in interface MapViewPaintableg - Graphicsmv - The object that can translate GeoPoints to screen coordinates.box - Bounding boxprivate void paintConstructionGeometry(MapView mv, java.awt.Graphics2D g2)
public java.lang.String getModeHelpText()
MapModegetModeHelpText in class MapModepublic java.util.Collection<OsmPrimitive> getInProgressSelection()
public boolean layerIsSupported(Layer l)
MapModel is supported by this map mode.
By default, all tools will work with all layers.
Can be overwritten to require a special type of layerlayerIsSupported in class MapModel - layertrue if the layer is supported by this map modeprotected void updateEnabledState()
JosmActionJosmAction.updateEnabledState(Collection) to respond to changes in the collection
of selected primitives.
Default behavior is empty.updateEnabledState in class JosmActionJosmAction.updateEnabledState(Collection),
JosmAction.initEnabledState(),
JosmAction.listenToLayerChange()public void destroy()
Destroyabledestroy in interface Destroyabledestroy in class JosmAction