public class DrawAction extends MapMode implements MapViewPaintable, SelectionChangedListener, KeyPressReleaseListener, ModifierListener
Modifier and Type | Class and Description |
---|---|
class |
DrawAction.BackSpaceAction |
private class |
DrawAction.SnapChangeAction |
private class |
DrawAction.SnapHelper |
JosmAction.ActiveLayerChangeAdapter, JosmAction.LayerChangeAdapter, JosmAction.SelectionChangeAdapter
MapViewPaintable.LayerPainter, MapViewPaintable.MapViewEvent, MapViewPaintable.PaintableInvalidationEvent, MapViewPaintable.PaintableInvalidationListener
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 |
private boolean |
drawHelperLine |
private boolean |
drawTargetHighlight |
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 static double |
PHI |
private Node |
previousNode |
private java.awt.Point |
rightClickPressPos |
private java.awt.Color |
rubberLineColor |
private java.awt.Stroke |
rubberLineStroke |
private DrawAction.SnapChangeAction |
snapChangeAction |
private javax.swing.JCheckBoxMenuItem |
snapCheckboxMenuItem |
private DrawAction.SnapHelper |
snapHelper |
private Shortcut |
snappingShortcut |
private static int |
snapToIntersectionThreshold |
private double |
toleranceMultiplier |
private boolean |
useRepeatedShortcut |
private boolean |
wayIsFinished |
sc
Constructor and Description |
---|
DrawAction(MapFrame mapFrame)
Constructs a new
DrawAction . |
Modifier and Type | Method and Description |
---|---|
private void |
addHighlighting()
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 |
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 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() |
static Way |
getWayForNode(Node n) |
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 |
modifiersChanged(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 static void |
pruneSuccsAndReverse(java.util.List<java.lang.Integer> is) |
protected void |
readPreferences() |
private boolean |
redrawIfRequired()
Checks if a map redraw is required and does so if needed.
|
private boolean |
removeHighlighting()
Removes target highlighting from primitives.
|
void |
selectionChanged(java.util.Collection<? extends OsmPrimitive> newSelection)
redraw to (possibly) get rid of helper line if selection changes.
|
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.
|
actionPerformed, mouseClicked, mouseEntered, preferenceChanged, requestFocusInMapView, updateKeyModifiers, updateKeyModifiers, updateKeyModifiers, updateStatusLine
getCurrentDataSet, getEditLayer, getLayerManager, getShortcut, initEnabledState, installAdapters, listenToLayerChange, listenToSelectionChange, setTooltip, updateEnabledState, updateEnabledStateOnCurrentSelection, waitFuture
private static final java.awt.Color ORANGE_TRANSPARENT
private static final double PHI
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 drawHelperLine
private boolean wayIsFinished
private boolean drawTargetHighlight
private java.awt.Point mousePos
private java.awt.Point oldMousePos
private java.awt.Color rubberLineColor
private transient Node currentBaseNode
private transient Node previousNode
private EastNorth currentMouseEastNorth
private final transient DrawAction.SnapHelper 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 boolean useRepeatedShortcut
private transient java.awt.Stroke rubberLineStroke
private static final java.awt.BasicStroke BASIC_STROKE
private static int snapToIntersectionThreshold
private java.awt.Point rightClickPressPos
public DrawAction(MapFrame mapFrame)
DrawAction
.mapFrame
- Map frameprivate javax.swing.JCheckBoxMenuItem addMenuItem()
private boolean redrawIfRequired()
private static void addRemoveSelection(DataSet ds, OsmPrimitive toAdd, OsmPrimitive toRemove)
public void enterMode()
MapMode
protected void readPreferences()
readPreferences
in class MapMode
public void exitMode()
MapMode
public void modifiersChanged(int modifiers)
modifiersChanged
in interface ModifierListener
public void doKeyPressed(java.awt.event.KeyEvent e)
KeyPressReleaseListener
doKeyPressed
in interface KeyPressReleaseListener
e
- key eventpublic void doKeyReleased(java.awt.event.KeyEvent e)
KeyPressReleaseListener
doKeyReleased
in interface KeyPressReleaseListener
e
- key eventpublic void selectionChanged(java.util.Collection<? extends OsmPrimitive> newSelection)
selectionChanged
in interface SelectionChangedListener
newSelection
- The new selection.private void tryAgain(java.awt.event.MouseEvent e)
private void finishDrawing()
public void mousePressed(java.awt.event.MouseEvent e)
mousePressed
in interface java.awt.event.MouseListener
mousePressed
in class MapMode
public void mouseReleased(java.awt.event.MouseEvent e)
mouseReleased
in interface java.awt.event.MouseListener
mouseReleased
in class MapMode
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.MouseMotionListener
mouseDragged
in class MapMode
public void mouseMoved(java.awt.event.MouseEvent e)
mouseMoved
in interface java.awt.event.MouseMotionListener
mouseMoved
in class MapMode
private void tryToSetBaseSegmentForAngleSnap()
private void computeHelperLine()
private 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.MouseListener
mouseExited
in class MapMode
public 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 adjuststatic double det(double a, double b, double c, double d)
private void tryToMoveNodeOnIntersection(java.util.List<WaySegment> wss, Node n)
private void addHighlighting()
private boolean removeHighlighting()
public void paint(java.awt.Graphics2D g, MapView mv, Bounds box)
MapViewPaintable
paint
in interface MapViewPaintable
g
- Graphicsmv
- The object that can translate GeoPoints to screen coordinates.box
- Bounding boxpublic java.lang.String getModeHelpText()
getModeHelpText
in class MapMode
public java.util.Collection<OsmPrimitive> getInProgressSelection()
public boolean layerIsSupported(Layer l)
MapMode
l
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 MapMode
l
- layertrue
if the layer is supported by this map modeprotected void updateEnabledState()
JosmAction
JosmAction.updateEnabledState(Collection)
to respond to changes in the collection
of selected primitives.
Default behavior is empty.updateEnabledState
in class JosmAction
JosmAction.updateEnabledState(Collection)
,
JosmAction.initEnabledState()
,
JosmAction.listenToLayerChange()
public void destroy()
Destroyable
destroy
in interface Destroyable
destroy
in class JosmAction