public class ExtrudeAction extends MapMode implements MapViewPaintable, KeyPressReleaseListener, ModifierExListener
Modifier and Type | Class and Description |
---|---|
private class |
ExtrudeAction.DualAlignChangeAction |
(package private) static class |
ExtrudeAction.Mode |
private static class |
ExtrudeAction.ReferenceSegment |
JosmAction.ActiveLayerChangeAdapter, JosmAction.LayerChangeAdapter, JosmAction.SelectionChangeAdapter
MapViewPaintable.LayerPainter, MapViewPaintable.MapViewEvent, MapViewPaintable.PaintableInvalidationEvent, MapViewPaintable.PaintableInvalidationListener
Modifier and Type | Field and Description |
---|---|
private ExtrudeAction.ReferenceSegment |
activeMoveDirection
The direction that is currently active.
|
private boolean |
alwaysCreateNodes
If
true , when extruding create new node(s) even if segments are parallel. |
private java.awt.Cursor |
cursorCreateNew
The cursor for the 'create_new' mode.
|
private java.awt.Cursor |
cursorCreateNodes
The cursor for the 'alwaysCreateNodes' submode.
|
private java.awt.Cursor |
cursorTranslate
The cursor for the 'translate' mode.
|
private boolean |
dualAlignActive
true , if dual alignment is active. |
private ExtrudeAction.DualAlignChangeAction |
dualAlignChangeAction |
private javax.swing.JCheckBoxMenuItem |
dualAlignCheckboxMenuItem |
private boolean |
dualAlignEnabled
true , if dual alignment mode is enabled. |
private ExtrudeAction.ReferenceSegment |
dualAlignSegment1
Dual alignment reference segments
|
private ExtrudeAction.ReferenceSegment |
dualAlignSegment2
Dual alignment reference segments
|
private boolean |
dualAlignSegmentCollapsed
true , if new segment was collapsed |
private Shortcut |
dualAlignShortcut |
private java.awt.Color |
helperColor
drawing settings for helper lines
|
private java.awt.Stroke |
helperStrokeDash |
private java.awt.Stroke |
helperStrokeRA |
private boolean |
ignoreNextKeyRelease |
private boolean |
ignoreSharedNodes
settings value whether shared nodes should be ignored or not
|
private java.awt.Point |
initialMousePos
The position of the mouse cursor when the drag action was initiated.
|
private int |
initialMoveDelay
The time which needs to pass between click and release before something
counts as a move, in milliseconds
|
private int |
initialMoveThreshold
The minimal shift of mouse (in pixels) befire something counts as move
|
private EastNorth |
initialN1en
The initial EastNorths of node1 and node2
|
private EastNorth |
initialN2en |
private boolean |
keepSegmentDirection |
private java.awt.Color |
mainColor |
private java.awt.Stroke |
mainStroke |
private ExtrudeAction.Mode |
mode |
private long |
mouseDownTime |
private MoveCommand |
moveCommand
the command that performed last move.
|
private MoveCommand |
moveCommand2
The command used for dual alignment movement.
|
private java.util.List<Node> |
movingNodeList
Collection of nodes that is moved
|
private EastNorth |
newN1en
The new EastNorths of node1 and node2
|
private EastNorth |
newN2en |
private boolean |
nodeDragWithoutCtrl |
private java.awt.Stroke |
oldLineStroke |
private java.util.List<ExtrudeAction.ReferenceSegment> |
possibleMoveDirections
Possible directions to move to.
|
private Node |
selectedNode |
private WaySegment |
selectedSegment |
private double |
symbolSize |
private boolean |
useRepeatedShortcut |
sc
Constructor and Description |
---|
ExtrudeAction()
Creates a new ExtrudeAction
|
Modifier and Type | Method and Description |
---|---|
private javax.swing.JCheckBoxMenuItem |
addDualAlignMenuItem() |
private static void |
addNewNode(java.awt.event.MouseEvent e)
Inserts node into nearby segment.
|
private EastNorth |
calculateBestMovement(EastNorth mouseEn)
Determines best movement from
initialMousePos to current mouse position,
choosing one of the directions from possibleMoveDirections . |
private EastNorth |
calculateBestMovementAndNewNodes(EastNorth mouseEn)
Calculate newN1en, newN2en best suitable for given mouse coordinates
For dual align, calculates positions of new nodes, aligning them to neighboring segments.
|
private void |
calculatePossibleDirectionsByNode()
Gathers possible move directions - along all adjacent segments.
|
private void |
calculatePossibleDirectionsBySegment()
Gathers possible move directions - perpendicular to the selected segment
and parallel to neighboring segments.
|
private void |
calculatePossibleDirectionsForDualAlign()
Gathers possible move directions - perpendicular to the selected segment only.
|
private static EastNorth |
calculateSegmentOffset(EastNorth segmentP1,
EastNorth segmentP2,
EastNorth moveDirection,
EastNorth targetPos)
This method calculates offset amount by which to move the given segment
perpendicularly for it to be in line with mouse position.
|
private boolean |
checkDualAlignConditions()
Checks dual alignment conditions:
1.
|
private void |
createNewRectangle()
Creates a new way that shares segment with selected way.
|
private static java.awt.geom.Line2D |
createSemiInfiniteLine(java.awt.geom.Point2D start,
java.awt.geom.Point2D unitvector,
java.awt.Graphics2D g)
Creates a new Line that extends off the edge of the viewport in one direction
|
void |
destroy()
Called when the object has been destroyed.
|
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)
|
private void |
drawAngleSymbol(java.awt.Graphics2D g2,
java.awt.geom.Point2D center,
java.awt.geom.Point2D normal,
boolean mirror)
Draws right angle symbol at specified position.
|
private void |
drawReferenceSegment(java.awt.Graphics2D g2,
MapView mv,
ExtrudeAction.ReferenceSegment seg)
Draws given reference segment.
|
void |
enterMode()
Makes this map mode active.
|
void |
exitMode()
Makes this map mode inactive.
|
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 Node |
getNextNode(int index)
Gets a node from selected way after given index.
|
private int |
getNextNodeIndex(int index)
Gets a node index from selected way after given index.
|
private java.awt.geom.Point2D |
getNormalUniVector() |
private Node |
getPreviousNode(int index)
Gets a node from selected way before given index.
|
private int |
getPreviousNodeIndex(int index)
Gets a node index from selected way before given index.
|
private static boolean |
hasNodeOtherWays(Node node,
Way myWay)
This method tests if
node has other ways apart from the given one. |
private static boolean |
isOppositeDirection(EastNorth from1,
EastNorth to1,
EastNorth from2,
EastNorth to2)
Determines if from1-to1 and from2-to2 vectors directions are opposite
|
private void |
joinNodesIfCollapsed(java.util.List<Node> changedNodes) |
boolean |
layerIsSupported(Layer l)
Determines if layer
l is supported by this map mode. |
void |
modifiersExChanged(int modifiers)
This method is called to indicate different modes via cursor when the Alt/Ctrl/Shift modifier is pressed,
|
void |
mouseDragged(java.awt.event.MouseEvent e)
Performs action depending on what
mode we're in. |
void |
mousePressed(java.awt.event.MouseEvent e)
If the left mouse button is pressed over a segment or a node, switches
to appropriate
mode , depending on Ctrl/Alt/Shift modifiers and
dualAlignEnabled . |
void |
mouseReleased(java.awt.event.MouseEvent e)
Does anything that needs to be done, then switches back to select mode.
|
void |
paint(java.awt.Graphics2D g,
MapView mv,
Bounds box)
Paint the dataset using the engine set.
|
private void |
performExtrusion()
Does actual extrusion of
selectedSegment . |
protected void |
readPreferences() |
private void |
toggleDualAlign()
Toggles dual alignment mode.
|
actionPerformed, isEditableDataLayer, mouseClicked, mouseEntered, mouseExited, mouseMoved, preferenceChanged, requestFocusInMapView, updateKeyModifiers, updateKeyModifiers, updateKeyModifiers, updateKeyModifiersEx, updateStatusLine
checkAndConfirmOutlyingOperation, getLayerManager, getShortcut, initEnabledState, installAdapters, listenToLayerChange, listenToSelectionChange, setHelpId, setTooltip, updateEnabledState, updateEnabledState, updateEnabledStateOnCurrentSelection, updateEnabledStateOnCurrentSelection, updateEnabledStateOnModifiableSelection, waitFuture
addPropertyChangeListener, clone, firePropertyChange, getKeys, getPropertyChangeListeners, getValue, isEnabled, putValue, removePropertyChangeListener, setEnabled
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
addInvalidationListener, removeInvalidationListener
private ExtrudeAction.Mode mode
private boolean alwaysCreateNodes
true
, when extruding create new node(s) even if segments are parallel.private boolean nodeDragWithoutCtrl
private long mouseDownTime
private transient WaySegment selectedSegment
private transient Node selectedNode
private java.awt.Color mainColor
private transient java.awt.Stroke mainStroke
private boolean ignoreSharedNodes
private boolean keepSegmentDirection
private java.awt.Color helperColor
private transient java.awt.Stroke helperStrokeDash
private transient java.awt.Stroke helperStrokeRA
private transient java.awt.Stroke oldLineStroke
private double symbolSize
private transient java.util.List<ExtrudeAction.ReferenceSegment> possibleMoveDirections
private transient java.util.List<Node> movingNodeList
private transient ExtrudeAction.ReferenceSegment activeMoveDirection
private java.awt.Point initialMousePos
private int initialMoveDelay
private int initialMoveThreshold
private EastNorth initialN1en
private EastNorth initialN2en
private transient MoveCommand moveCommand
private transient MoveCommand moveCommand2
private final java.awt.Cursor cursorCreateNew
private final java.awt.Cursor cursorTranslate
private final java.awt.Cursor cursorCreateNodes
private boolean dualAlignEnabled
true
, if dual alignment mode is enabled. User wants following extrude to be dual aligned.private boolean dualAlignActive
true
, if dual alignment is active. User is dragging the mouse, required conditions are met.
Treat mode
(extrude/translate/create_new) as dual aligned.private transient ExtrudeAction.ReferenceSegment dualAlignSegment1
private transient ExtrudeAction.ReferenceSegment dualAlignSegment2
private boolean dualAlignSegmentCollapsed
true
, if new segment was collapsedprivate final ExtrudeAction.DualAlignChangeAction dualAlignChangeAction
private final javax.swing.JCheckBoxMenuItem dualAlignCheckboxMenuItem
private final transient Shortcut dualAlignShortcut
private boolean useRepeatedShortcut
private boolean ignoreNextKeyRelease
public ExtrudeAction()
public void destroy()
Destroyable
destroy
in interface Destroyable
destroy
in class JosmAction
private javax.swing.JCheckBoxMenuItem addDualAlignMenuItem()
public java.lang.String getModeHelpText()
MapMode
getModeHelpText
in class MapMode
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 modepublic void enterMode()
MapMode
protected void readPreferences()
readPreferences
in class MapMode
public void exitMode()
MapMode
public void modifiersExChanged(int modifiers)
modifiersExChanged
in interface ModifierExListener
modifiers
- The new extended modifierspublic 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 eventprivate void toggleDualAlign()
public void mousePressed(java.awt.event.MouseEvent e)
mode
, depending on Ctrl/Alt/Shift modifiers and
dualAlignEnabled
.mousePressed
in interface java.awt.event.MouseListener
mousePressed
in class MapMode
e
- current mouse eventpublic void mouseDragged(java.awt.event.MouseEvent e)
mode
we're in.mouseDragged
in interface java.awt.event.MouseMotionListener
mouseDragged
in class MapMode
e
- current mouse eventpublic void mouseReleased(java.awt.event.MouseEvent e)
mouseReleased
in interface java.awt.event.MouseListener
mouseReleased
in class MapMode
e
- current mouse eventprivate static void addNewNode(java.awt.event.MouseEvent e)
e
- current mouse pointprivate void createNewRectangle()
private void performExtrusion()
selectedSegment
.
Uses initialN1en
, initialN2en
saved in calculatePossibleDirections* call
Uses newN1en
, newN2en
calculated by calculateBestMovementAndNewNodes(org.openstreetmap.josm.data.coor.EastNorth)
private void joinNodesIfCollapsed(java.util.List<Node> changedNodes)
private static boolean hasNodeOtherWays(Node node, Way myWay)
node
has other ways apart from the given one.node
- node to testmyWay
- way known to contain this nodetrue
if node
belongs only to myWay
, false if there are more ways.private EastNorth calculateBestMovement(EastNorth mouseEn)
initialMousePos
to current mouse position,
choosing one of the directions from possibleMoveDirections
.mouseEn
- current mouse positionprivate static EastNorth calculateSegmentOffset(EastNorth segmentP1, EastNorth segmentP2, EastNorth moveDirection, EastNorth targetPos)
segmentP1
- segment's first pointsegmentP2
- segment's second pointmoveDirection
- direction of movementtargetPos
- mouse positionprivate void calculatePossibleDirectionsBySegment()
private void calculatePossibleDirectionsByNode()
private boolean checkDualAlignConditions()
true
if dual alignment conditions are satisfiedprivate void calculatePossibleDirectionsForDualAlign()
dualAlignSegment1
and dualAlignSegment2
.private EastNorth calculateBestMovementAndNewNodes(EastNorth mouseEn)
initialN1en
, initialN2en
.mouseEn
- mouse coordinatesprivate int getPreviousNodeIndex(int index)
index
- index of current node-1
if there are no nodes there.private Node getPreviousNode(int index)
index
- index of current nodenull
if there are no nodes there.private int getNextNodeIndex(int index)
index
- index of current node-1
if there are no nodes there.private Node getNextNode(int index)
index
- index of current nodenull
if there are no nodes there.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 boxprivate java.awt.geom.Point2D getNormalUniVector()
private static boolean isOppositeDirection(EastNorth from1, EastNorth to1, EastNorth from2, EastNorth to2)
from1
- vector1 startto1
- vector1 endfrom2
- vector2 startto2
- vector2 endprivate void drawAngleSymbol(java.awt.Graphics2D g2, java.awt.geom.Point2D center, java.awt.geom.Point2D normal, boolean mirror)
g2
- the Graphics2D object used to draw oncenter
- center point of anglenormal
- vector of normalmirror
- true
if symbol should be mirrored by the normalprivate void drawReferenceSegment(java.awt.Graphics2D g2, MapView mv, ExtrudeAction.ReferenceSegment seg)
g2
- the Graphics2D object used to draw onmv
- map viewseg
- the reference segmentprivate static java.awt.geom.Line2D createSemiInfiniteLine(java.awt.geom.Point2D start, java.awt.geom.Point2D unitvector, java.awt.Graphics2D g)
start
- The start point of the lineunitvector
- A unit vector denoting the direction of the lineg
- the Graphics2D object it will be used on