Class ExtrudeAction
- java.lang.Object
-
- javax.swing.AbstractAction
-
- org.openstreetmap.josm.actions.JosmAction
-
- org.openstreetmap.josm.actions.mapmode.MapMode
-
- org.openstreetmap.josm.actions.mapmode.ExtrudeAction
-
- All Implemented Interfaces:
java.awt.event.ActionListener
,java.awt.event.MouseListener
,java.awt.event.MouseMotionListener
,java.io.Serializable
,java.lang.Cloneable
,java.util.EventListener
,javax.swing.Action
,MapViewPaintable
,KeyPressReleaseListener
,ModifierExListener
,PreferenceChangedListener
,Destroyable
public class ExtrudeAction extends MapMode implements MapViewPaintable, KeyPressReleaseListener, ModifierExListener
Makes a rectangle from a line, or modifies a rectangle.- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private class
ExtrudeAction.DualAlignChangeAction
(package private) static class
ExtrudeAction.Mode
private static class
ExtrudeAction.ReferenceSegment
-
Nested classes/interfaces inherited from class org.openstreetmap.josm.actions.JosmAction
JosmAction.ActiveLayerChangeAdapter, JosmAction.LayerChangeAdapter, JosmAction.SelectionChangeAdapter
-
Nested classes/interfaces inherited from interface org.openstreetmap.josm.gui.layer.MapViewPaintable
MapViewPaintable.LayerPainter, MapViewPaintable.MapViewEvent, MapViewPaintable.PaintableInvalidationEvent, MapViewPaintable.PaintableInvalidationListener
-
-
Field Summary
Fields Modifier and Type Field Description private ExtrudeAction.ReferenceSegment
activeMoveDirection
The direction that is currently active.private boolean
alwaysCreateNodes
Iftrue
, 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 segmentsprivate ExtrudeAction.ReferenceSegment
dualAlignSegment2
Dual alignment reference segmentsprivate boolean
dualAlignSegmentCollapsed
true
, if new segment was collapsedprivate Shortcut
dualAlignShortcut
private java.awt.Color
helperColor
drawing settings for helper linesprivate java.awt.Stroke
helperStrokeDash
private java.awt.Stroke
helperStrokeRA
private boolean
ignoreNextKeyRelease
private boolean
ignoreSharedNodes
settings value whether shared nodes should be ignored or notprivate 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 millisecondsprivate int
initialMoveThreshold
The minimal shift of mouse (in pixels) before something counts as moveprivate EastNorth
initialN1en
The initial EastNorths of node1 and node2private EastNorth
initialN2en
private boolean
keepSegmentDirection
private Command
lastCommandOnUndoStack
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 movedprivate EastNorth
newN1en
The new EastNorths of node1 and node2private 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
-
Fields inherited from class org.openstreetmap.josm.actions.mapmode.MapMode
alt, ctrl, cursor, meta, platformMenuShortcutKeyMask, shift
-
Fields inherited from class org.openstreetmap.josm.actions.JosmAction
sc
-
-
Constructor Summary
Constructors Constructor Description ExtrudeAction()
Creates a new ExtrudeAction
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method 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 frominitialMousePos
to current mouse position, choosing one of the directions frompossibleMoveDirections
.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 directionvoid
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 ifnode
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 oppositeprivate void
joinNodesIfCollapsed(java.util.List<Node> changedNodes)
boolean
layerIsSupported(Layer l)
Determines if layerl
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 whatmode
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 appropriatemode
, depending on Ctrl/Alt/Shift modifiers anddualAlignEnabled
.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 ofselectedSegment
.protected void
readPreferences()
private void
toggleDualAlign()
Toggles dual alignment mode.-
Methods inherited from class org.openstreetmap.josm.actions.mapmode.MapMode
actionPerformed, isEditableDataLayer, mouseClicked, mouseEntered, mouseExited, mouseMoved, preferenceChanged, requestFocusInMapView, updateKeyModifiers, updateKeyModifiers, updateKeyModifiers, updateKeyModifiersEx, updateStatusLine
-
Methods inherited from class org.openstreetmap.josm.actions.JosmAction
buildActiveLayerChangeAdapter, buildLayerChangeAdapter, checkAndConfirmOutlyingOperation, getLayerManager, getShortcut, initEnabledState, installAdapters, listenToLayerChange, listenToSelectionChange, setHelpId, setToolbarId, setTooltip, updateEnabledState, updateEnabledState, updateEnabledStateOnCurrentSelection, updateEnabledStateOnCurrentSelection, updateEnabledStateOnModifiableSelection, waitFuture
-
Methods inherited from class javax.swing.AbstractAction
addPropertyChangeListener, clone, firePropertyChange, getKeys, getPropertyChangeListeners, getValue, isEnabled, putValue, removePropertyChangeListener, setEnabled
-
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.openstreetmap.josm.gui.layer.MapViewPaintable
addInvalidationListener, removeInvalidationListener
-
-
-
-
Field Detail
-
mode
private ExtrudeAction.Mode mode
-
alwaysCreateNodes
private boolean alwaysCreateNodes
Iftrue
, when extruding create new node(s) even if segments are parallel.
-
nodeDragWithoutCtrl
private boolean nodeDragWithoutCtrl
-
mouseDownTime
private long mouseDownTime
-
selectedSegment
private transient WaySegment selectedSegment
-
selectedNode
private transient Node selectedNode
-
lastCommandOnUndoStack
private transient Command lastCommandOnUndoStack
-
mainColor
private java.awt.Color mainColor
-
mainStroke
private transient java.awt.Stroke mainStroke
-
ignoreSharedNodes
private boolean ignoreSharedNodes
settings value whether shared nodes should be ignored or not
-
keepSegmentDirection
private boolean keepSegmentDirection
-
helperColor
private java.awt.Color helperColor
drawing settings for helper lines
-
helperStrokeDash
private transient java.awt.Stroke helperStrokeDash
-
helperStrokeRA
private transient java.awt.Stroke helperStrokeRA
-
oldLineStroke
private transient java.awt.Stroke oldLineStroke
-
symbolSize
private double symbolSize
-
possibleMoveDirections
private transient java.util.List<ExtrudeAction.ReferenceSegment> possibleMoveDirections
Possible directions to move to.
-
movingNodeList
private transient java.util.List<Node> movingNodeList
Collection of nodes that is moved
-
activeMoveDirection
private transient ExtrudeAction.ReferenceSegment activeMoveDirection
The direction that is currently active.
-
initialMousePos
private java.awt.Point initialMousePos
The position of the mouse cursor when the drag action was initiated.
-
initialMoveDelay
private int initialMoveDelay
The time which needs to pass between click and release before something counts as a move, in milliseconds
-
initialMoveThreshold
private int initialMoveThreshold
The minimal shift of mouse (in pixels) before something counts as move
-
initialN1en
private EastNorth initialN1en
The initial EastNorths of node1 and node2
-
initialN2en
private EastNorth initialN2en
-
moveCommand
private transient MoveCommand moveCommand
the command that performed last move.
-
moveCommand2
private transient MoveCommand moveCommand2
The command used for dual alignment movement. Needs to be separate, due to two nodes moving in different directions.
-
cursorCreateNew
private final java.awt.Cursor cursorCreateNew
The cursor for the 'create_new' mode.
-
cursorTranslate
private final java.awt.Cursor cursorTranslate
The cursor for the 'translate' mode.
-
cursorCreateNodes
private final java.awt.Cursor cursorCreateNodes
The cursor for the 'alwaysCreateNodes' submode.
-
dualAlignEnabled
private boolean dualAlignEnabled
true
, if dual alignment mode is enabled. User wants following extrude to be dual aligned.
-
dualAlignActive
private boolean dualAlignActive
true
, if dual alignment is active. User is dragging the mouse, required conditions are met. Treatmode
(extrude/translate/create_new) as dual aligned.
-
dualAlignSegment1
private transient ExtrudeAction.ReferenceSegment dualAlignSegment1
Dual alignment reference segments
-
dualAlignSegment2
private transient ExtrudeAction.ReferenceSegment dualAlignSegment2
Dual alignment reference segments
-
dualAlignSegmentCollapsed
private boolean dualAlignSegmentCollapsed
true
, if new segment was collapsed
-
dualAlignChangeAction
private final ExtrudeAction.DualAlignChangeAction dualAlignChangeAction
-
dualAlignCheckboxMenuItem
private final javax.swing.JCheckBoxMenuItem dualAlignCheckboxMenuItem
-
dualAlignShortcut
private final transient Shortcut dualAlignShortcut
-
useRepeatedShortcut
private boolean useRepeatedShortcut
-
ignoreNextKeyRelease
private boolean ignoreNextKeyRelease
-
-
Constructor Detail
-
ExtrudeAction
public ExtrudeAction()
Creates a new ExtrudeAction- Since:
- 11713
-
-
Method Detail
-
destroy
public void destroy()
Description copied from interface:Destroyable
Called when the object has been destroyed.- Specified by:
destroy
in interfaceDestroyable
- Overrides:
destroy
in classJosmAction
-
addDualAlignMenuItem
private javax.swing.JCheckBoxMenuItem addDualAlignMenuItem()
-
getModeHelpText
public java.lang.String getModeHelpText()
Description copied from class:MapMode
Returns a short translated help message describing how this map mode can be used, to be displayed in status line.- Overrides:
getModeHelpText
in classMapMode
- Returns:
- a short translated help message describing how this map mode can be used
-
layerIsSupported
public boolean layerIsSupported(Layer l)
Description copied from class:MapMode
Determines if layerl
is supported by this map mode. By default, all tools will work with all layers. Can be overwritten to require a special type of layer- Overrides:
layerIsSupported
in classMapMode
- Parameters:
l
- layer- Returns:
true
if the layer is supported by this map mode
-
enterMode
public void enterMode()
Description copied from class:MapMode
Makes this map mode active.
-
readPreferences
protected void readPreferences()
- Overrides:
readPreferences
in classMapMode
-
exitMode
public void exitMode()
Description copied from class:MapMode
Makes this map mode inactive.
-
modifiersExChanged
public void modifiersExChanged(int modifiers)
This method is called to indicate different modes via cursor when the Alt/Ctrl/Shift modifier is pressed,- Specified by:
modifiersExChanged
in interfaceModifierExListener
- Parameters:
modifiers
- The new extended modifiers
-
doKeyPressed
public void doKeyPressed(java.awt.event.KeyEvent e)
Description copied from interface:KeyPressReleaseListener
This is called when key press event is actually pressed (no fake events while holding key)- Specified by:
doKeyPressed
in interfaceKeyPressReleaseListener
- Parameters:
e
- key event
-
doKeyReleased
public void doKeyReleased(java.awt.event.KeyEvent e)
Description copied from interface:KeyPressReleaseListener
This is called when key press event is actually released (no fake events while holding key)- Specified by:
doKeyReleased
in interfaceKeyPressReleaseListener
- Parameters:
e
- key event
-
toggleDualAlign
private void toggleDualAlign()
Toggles dual alignment mode.
-
mousePressed
public void mousePressed(java.awt.event.MouseEvent e)
If the left mouse button is pressed over a segment or a node, switches to appropriatemode
, depending on Ctrl/Alt/Shift modifiers anddualAlignEnabled
.- Specified by:
mousePressed
in interfacejava.awt.event.MouseListener
- Overrides:
mousePressed
in classMapMode
- Parameters:
e
- current mouse event
-
mouseDragged
public void mouseDragged(java.awt.event.MouseEvent e)
Performs action depending on whatmode
we're in.- Specified by:
mouseDragged
in interfacejava.awt.event.MouseMotionListener
- Overrides:
mouseDragged
in classMapMode
- Parameters:
e
- current mouse event
-
mouseReleased
public void mouseReleased(java.awt.event.MouseEvent e)
Does anything that needs to be done, then switches back to select mode.- Specified by:
mouseReleased
in interfacejava.awt.event.MouseListener
- Overrides:
mouseReleased
in classMapMode
- Parameters:
e
- current mouse event
-
addNewNode
private static void addNewNode(java.awt.event.MouseEvent e)
Inserts node into nearby segment.- Parameters:
e
- current mouse point
-
createNewRectangle
private void createNewRectangle()
Creates a new way that shares segment with selected way.
-
performExtrusion
private void performExtrusion()
Does actual extrusion ofselectedSegment
. UsesinitialN1en
,initialN2en
saved in calculatePossibleDirections* call UsesnewN1en
,newN2en
calculated bycalculateBestMovementAndNewNodes(org.openstreetmap.josm.data.coor.EastNorth)
-
joinNodesIfCollapsed
private void joinNodesIfCollapsed(java.util.List<Node> changedNodes)
-
hasNodeOtherWays
private static boolean hasNodeOtherWays(Node node, Way myWay)
This method tests ifnode
has other ways apart from the given one.- Parameters:
node
- node to testmyWay
- way known to contain this node- Returns:
true
ifnode
belongs only tomyWay
, false if there are more ways.
-
calculateBestMovement
private EastNorth calculateBestMovement(EastNorth mouseEn)
Determines best movement frominitialMousePos
to current mouse position, choosing one of the directions frompossibleMoveDirections
.- Parameters:
mouseEn
- current mouse position- Returns:
- movement vector
-
calculateSegmentOffset
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.- Parameters:
segmentP1
- segment's first pointsegmentP2
- segment's second pointmoveDirection
- direction of movementtargetPos
- mouse position- Returns:
- offset amount of P1 and P2.
-
calculatePossibleDirectionsBySegment
private void calculatePossibleDirectionsBySegment()
Gathers possible move directions - perpendicular to the selected segment and parallel to neighboring segments.
-
calculatePossibleDirectionsByNode
private void calculatePossibleDirectionsByNode()
Gathers possible move directions - along all adjacent segments.
-
checkDualAlignConditions
private boolean checkDualAlignConditions()
Checks dual alignment conditions: 1. selected segment has both neighboring segments, 2. selected segment is not parallel with neighboring segments.- Returns:
true
if dual alignment conditions are satisfied
-
calculatePossibleDirectionsForDualAlign
private void calculatePossibleDirectionsForDualAlign()
Gathers possible move directions - perpendicular to the selected segment only. Neighboring segments go todualAlignSegment1
anddualAlignSegment2
.
-
calculateBestMovementAndNewNodes
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. Elsewhere, just adds the vetor returned by calculateBestMovement toinitialN1en
,initialN2en
.- Parameters:
mouseEn
- mouse coordinates- Returns:
- best movement vector
-
getPreviousNodeIndex
private int getPreviousNodeIndex(int index)
Gets a node index from selected way before given index.- Parameters:
index
- index of current node- Returns:
- index of previous node or
-1
if there are no nodes there.
-
getPreviousNode
private Node getPreviousNode(int index)
Gets a node from selected way before given index.- Parameters:
index
- index of current node- Returns:
- previous node or
null
if there are no nodes there.
-
getNextNodeIndex
private int getNextNodeIndex(int index)
Gets a node index from selected way after given index.- Parameters:
index
- index of current node- Returns:
- index of next node or
-1
if there are no nodes there.
-
getNextNode
private Node getNextNode(int index)
Gets a node from selected way after given index.- Parameters:
index
- index of current node- Returns:
- next node or
null
if there are no nodes there.
-
paint
public void paint(java.awt.Graphics2D g, MapView mv, Bounds box)
Description copied from interface:MapViewPaintable
Paint the dataset using the engine set.- Specified by:
paint
in interfaceMapViewPaintable
- Parameters:
g
- Graphicsmv
- The object that can translate GeoPoints to screen coordinates.box
- Bounding box
-
getNormalUniVector
private java.awt.geom.Point2D getNormalUniVector()
-
isOppositeDirection
private static boolean isOppositeDirection(EastNorth from1, EastNorth to1, EastNorth from2, EastNorth to2)
Determines if from1-to1 and from2-to2 vectors directions are opposite- Parameters:
from1
- vector1 startto1
- vector1 endfrom2
- vector2 startto2
- vector2 end- Returns:
- true if from1-to1 and from2-to2 vectors directions are opposite
-
drawAngleSymbol
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.- Parameters:
g2
- the Graphics2D object used to draw oncenter
- center point of anglenormal
- vector of normalmirror
-true
if symbol should be mirrored by the normal
-
drawReferenceSegment
private void drawReferenceSegment(java.awt.Graphics2D g2, MapView mv, ExtrudeAction.ReferenceSegment seg)
Draws given reference segment.- Parameters:
g2
- the Graphics2D object used to draw onmv
- map viewseg
- the reference segment
-
createSemiInfiniteLine
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- Parameters:
start
- The start point of the lineunitvector
- A unit vector denoting the direction of the lineg
- the Graphics2D object it will be used on- Returns:
- created line
-
-