public class DrawAction extends MapMode implements MapViewPaintable, SelectionChangedListener, AWTEventListener
| Modifier and Type | Class and Description |
|---|---|
class |
DrawAction.BackSpaceAction |
private class |
DrawAction.SnapChangeAction |
private class |
DrawAction.SnapHelper |
scchangeSupport, enabledACCELERATOR_KEY, ACTION_COMMAND_KEY, DEFAULT, DISPLAYED_MNEMONIC_INDEX_KEY, LARGE_ICON_KEY, LONG_DESCRIPTION, MNEMONIC_KEY, NAME, SELECTED_KEY, SHORT_DESCRIPTION, SMALL_ICON| Constructor and Description |
|---|
DrawAction(MapFrame mapFrame) |
| 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 JCheckBoxMenuItem |
addMenuItem() |
private static void |
adjustNode(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 @param way is given @param 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(Collection<OsmPrimitive> selection)
Helper function that sets fields currentBaseNode and previousNode
|
private void |
doKeyPressEvent(KeyEvent e) |
private void |
doKeyReleaseEvent(KeyEvent e) |
void |
enterMode()
Makes this map mode active.
|
void |
eventDispatched(AWTEvent event)
redraw to (possibly) get rid of helper line if selection changes.
|
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() |
Collection<OsmPrimitive> |
getInProgressSelection()
Get selected primitives, while draw action is in progress.
|
String |
getModeHelpText() |
static Way |
getWayForNode(Node n) |
private void |
insertNodeIntoAllNearbySegments(List<WaySegment> wss,
Node n,
Collection<OsmPrimitive> newSelection,
Collection<Command> cmds,
List<Way> replacedWays,
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) |
void |
mouseDragged(MouseEvent e) |
void |
mouseExited(MouseEvent e)
Repaint on mouse exit so that the helper line goes away.
|
void |
mouseMoved(MouseEvent e) |
void |
mousePressed(MouseEvent e) |
void |
mouseReleased(MouseEvent e)
If user clicked with the left button, add a node at the current mouse
position.
|
void |
paint(Graphics2D g,
MapView mv,
Bounds box)
Paint the dataset using the engine set.
|
(package private) void |
processKeyEvent(KeyEvent e) |
private static void |
pruneSuccsAndReverse(List<Integer> is) |
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(Collection<? extends OsmPrimitive> newSelection)
redraw to (possibly) get rid of helper line if selection changes.
|
private void |
showStatusInfo(double angle,
double hdg,
double distance,
boolean activeFlag) |
private void |
tryAgain(MouseEvent e) |
private void |
tryToMoveNodeOnIntersection(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. when a layer is removed or added.
|
actionPerformed, mouseClicked, mouseEntered, requestFocusInMapView, updateKeyModifiers, updateKeyModifiers, updateKeyModifiers, updateStatusLinegetCurrentDataSet, getEditLayer, getShortcut, initEnabledState, installAdapters, setTooltip, updateEnabledStateaddPropertyChangeListener, clone, firePropertyChange, getKeys, getPropertyChangeListeners, getValue, isEnabled, putValue, removePropertyChangeListener, setEnabledprivate final Cursor cursorJoinNode
private final Cursor cursorJoinWay
private Node lastUsedNode
private double PHI
private double toleranceMultiplier
private Node mouseOnExistingNode
private Set<Way> mouseOnExistingWays
private Set<OsmPrimitive> oldHighlights
private Set<OsmPrimitive> newHighlights
private boolean drawHelperLine
private boolean wayIsFinished
private boolean drawTargetHighlight
private Point oldMousePos
private Color rubberLineColor
private Node currentBaseNode
private Node previousNode
private EastNorth currentMouseEastNorth
private final DrawAction.SnapHelper snapHelper
private Shortcut backspaceShortcut
private DrawAction.BackSpaceAction backspaceAction
private final Shortcut snappingShortcut
private final DrawAction.SnapChangeAction snapChangeAction
private final JCheckBoxMenuItem snapCheckboxMenuItem
private boolean useRepeatedShortcut
private Stroke rubberLineStroke
private static final BasicStroke BASIC_STROKE
private KeyEvent releaseEvent
private Point rightClickPressPos
public DrawAction(MapFrame mapFrame)
private JCheckBoxMenuItem addMenuItem()
private boolean redrawIfRequired()
public void enterMode()
MapModepublic void exitMode()
MapModepublic void eventDispatched(AWTEvent event)
eventDispatched in interface AWTEventListenervoid processKeyEvent(KeyEvent e)
private void doKeyPressEvent(KeyEvent e)
private void doKeyReleaseEvent(KeyEvent e)
public void selectionChanged(Collection<? extends OsmPrimitive> newSelection)
selectionChanged in interface SelectionChangedListenernewSelection - The new selection.private void tryAgain(MouseEvent e)
private void finishDrawing()
public void mousePressed(MouseEvent e)
mousePressed in interface MouseListenermousePressed in class MapModepublic void mouseReleased(MouseEvent e)
mouseReleased in interface MouseListenermouseReleased in class MapModeprivate void insertNodeIntoAllNearbySegments(List<WaySegment> wss, Node n, Collection<OsmPrimitive> newSelection, Collection<Command> cmds, List<Way> replacedWays, 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(MouseEvent e)
mouseDragged in interface MouseMotionListenermouseDragged in class MapModepublic void mouseMoved(MouseEvent e)
mouseMoved in interface MouseMotionListenermouseMoved in class MapModeprivate void tryToSetBaseSegmentForAngleSnap()
private void computeHelperLine()
private void showStatusInfo(double angle, double hdg, double distance, boolean activeFlag)
private void determineCurrentBaseNodeAndPreviousNode(Collection<OsmPrimitive> selection)
selection - uses also lastUsedNode fieldprivate void continueWayFromNode(Way way, Node node)
public void mouseExited(MouseEvent e)
mouseExited in interface MouseListenermouseExited in class MapModepublic static Way getWayForNode(Node n)
null otherwise.public Node getCurrentBaseNode()
private static void pruneSuccsAndReverse(List<Integer> is)
private static void adjustNode(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(List<WaySegment> wss, Node n)
private void addHighlighting()
private boolean removeHighlighting()
public void paint(Graphics2D g, MapView mv, Bounds box)
MapViewPaintablepaint in interface MapViewPaintablemv - The object that can translate GeoPoints to screen coordinates.public String getModeHelpText()
getModeHelpText in class MapModepublic Collection<OsmPrimitive> getInProgressSelection()
public boolean layerIsSupported(Layer l)
layerIsSupported in class MapModeprotected 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()public void destroy()
Destroyabledestroy in interface Destroyabledestroy in class JosmAction