public class ExtrudeAction extends MapMode implements MapViewPaintable, KeyPressReleaseListener, ModifierListener
Modifier and Type | Class and Description |
---|---|
private class |
ExtrudeAction.DualAlignChangeAction |
(package private) static class |
ExtrudeAction.Mode |
private static class |
ExtrudeAction.ReferenceSegment |
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.ArrayList<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(MapFrame mapFrame)
Creates a new ExtrudeAction
|
Modifier and Type | Method and Description |
---|---|
private javax.swing.JCheckBoxMenuItem |
addDualAlignMenuItem() |
private 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() |
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 boolean |
isOppositeDirection(EastNorth from1,
EastNorth to1,
EastNorth from2,
EastNorth to2)
Returns true if from1-to1 and from2-to2 vertors directions are opposite
|
private void |
joinNodesIfCollapsed(java.util.List<Node> changedNodes) |
boolean |
layerIsSupported(Layer l) |
void |
modifiersChanged(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 . |
private void |
readPreferences() |
private void |
toggleDualAlign()
Toggles dual alignment mode.
|
actionPerformed, mouseClicked, mouseEntered, mouseExited, mouseMoved, requestFocusInMapView, updateKeyModifiers, updateKeyModifiers, updateKeyModifiers, updateStatusLine
getCurrentDataSet, getEditLayer, getShortcut, initEnabledState, installAdapters, setTooltip, updateEnabledState, updateEnabledState
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 WaySegment selectedSegment
private Node selectedNode
private java.awt.Color mainColor
private java.awt.Stroke mainStroke
private boolean ignoreSharedNodes
private boolean keepSegmentDirection
private java.awt.Color helperColor
private java.awt.Stroke helperStrokeDash
private java.awt.Stroke helperStrokeRA
private java.awt.Stroke oldLineStroke
private double symbolSize
private java.util.List<ExtrudeAction.ReferenceSegment> possibleMoveDirections
private java.util.ArrayList<Node> movingNodeList
private ExtrudeAction.ReferenceSegment activeMoveDirection
private java.awt.Point initialMousePos
private int initialMoveDelay
private int initialMoveThreshold
private EastNorth initialN1en
private EastNorth initialN2en
private MoveCommand moveCommand
private 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 ExtrudeAction.ReferenceSegment dualAlignSegment1
private ExtrudeAction.ReferenceSegment dualAlignSegment2
private boolean dualAlignSegmentCollapsed
true
, if new segment was collapsedprivate final ExtrudeAction.DualAlignChangeAction dualAlignChangeAction
private final javax.swing.JCheckBoxMenuItem dualAlignCheckboxMenuItem
private final Shortcut dualAlignShortcut
private boolean useRepeatedShortcut
private boolean ignoreNextKeyRelease
public ExtrudeAction(MapFrame mapFrame)
mapFrame
- The MapFrame this action belongs to.public void destroy()
Destroyable
destroy
in interface Destroyable
destroy
in class JosmAction
private javax.swing.JCheckBoxMenuItem addDualAlignMenuItem()
public java.lang.String getModeHelpText()
getModeHelpText
in class MapMode
public boolean layerIsSupported(Layer l)
layerIsSupported
in class MapMode
public void enterMode()
MapMode
private void readPreferences()
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
public void doKeyReleased(java.awt.event.KeyEvent e)
KeyPressReleaseListener
doKeyReleased
in interface KeyPressReleaseListener
private 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
- public void mouseDragged(java.awt.event.MouseEvent e)
mode
we're in.mouseDragged
in interface java.awt.event.MouseMotionListener
mouseDragged
in class MapMode
e
- public void mouseReleased(java.awt.event.MouseEvent e)
mouseReleased
in interface java.awt.event.MouseListener
mouseReleased
in class MapMode
e
- private 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
- myWay
- true
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
.private 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
mv
- The object that can translate GeoPoints to screen coordinates.private java.awt.geom.Point2D getNormalUniVector()
private boolean isOppositeDirection(EastNorth from1, EastNorth to1, EastNorth from2, EastNorth to2)
private 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
- p1en
- segment's first pointp2en
- segment's second pointprivate 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