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 classExtrudeAction.DualAlignChangeAction(package private) static classExtrudeAction.Modeprivate static classExtrudeAction.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.ReferenceSegmentactiveMoveDirectionThe direction that is currently active.private booleanalwaysCreateNodesIftrue, when extruding create new node(s) even if segments are parallel.private java.awt.CursorcursorCreateNewThe cursor for the 'create_new' mode.private java.awt.CursorcursorCreateNodesThe cursor for the 'alwaysCreateNodes' submode.private java.awt.CursorcursorTranslateThe cursor for the 'translate' mode.private booleandualAlignActivetrue, if dual alignment is active.private ExtrudeAction.DualAlignChangeActiondualAlignChangeActionprivate javax.swing.JCheckBoxMenuItemdualAlignCheckboxMenuItemprivate booleandualAlignEnabledtrue, if dual alignment mode is enabled.private ExtrudeAction.ReferenceSegmentdualAlignSegment1Dual alignment reference segmentsprivate ExtrudeAction.ReferenceSegmentdualAlignSegment2Dual alignment reference segmentsprivate booleandualAlignSegmentCollapsedtrue, if new segment was collapsedprivate ShortcutdualAlignShortcutprivate java.awt.ColorhelperColordrawing settings for helper linesprivate java.awt.StrokehelperStrokeDashprivate java.awt.StrokehelperStrokeRAprivate booleanignoreNextKeyReleaseprivate booleanignoreSharedNodessettings value whether shared nodes should be ignored or notprivate java.awt.PointinitialMousePosThe position of the mouse cursor when the drag action was initiated.private intinitialMoveDelayThe time which needs to pass between click and release before something counts as a move, in millisecondsprivate intinitialMoveThresholdThe minimal shift of mouse (in pixels) before something counts as moveprivate EastNorthinitialN1enThe initial EastNorths of node1 and node2private EastNorthinitialN2enprivate booleankeepSegmentDirectionprivate CommandlastCommandOnUndoStackprivate java.awt.ColormainColorprivate java.awt.StrokemainStrokeprivate ExtrudeAction.Modemodeprivate longmouseDownTimeprivate MoveCommandmoveCommandthe command that performed last move.private MoveCommandmoveCommand2The command used for dual alignment movement.private java.util.List<Node>movingNodeListCollection of nodes that is movedprivate EastNorthnewN1enThe new EastNorths of node1 and node2private EastNorthnewN2enprivate booleannodeDragWithoutCtrlprivate java.awt.StrokeoldLineStrokeprivate java.util.List<ExtrudeAction.ReferenceSegment>possibleMoveDirectionsPossible directions to move to.private NodeselectedNodeprivate WaySegmentselectedSegmentprivate doublesymbolSizeprivate booleanuseRepeatedShortcut-
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.JCheckBoxMenuItemaddDualAlignMenuItem()private static voidaddNewNode(java.awt.event.MouseEvent e)Inserts node into nearby segment.private EastNorthcalculateBestMovement(EastNorth mouseEn)Determines best movement frominitialMousePosto current mouse position, choosing one of the directions frompossibleMoveDirections.private EastNorthcalculateBestMovementAndNewNodes(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 voidcalculatePossibleDirectionsByNode()Gathers possible move directions - along all adjacent segments.private voidcalculatePossibleDirectionsBySegment()Gathers possible move directions - perpendicular to the selected segment and parallel to neighboring segments.private voidcalculatePossibleDirectionsForDualAlign()Gathers possible move directions - perpendicular to the selected segment only.private static EastNorthcalculateSegmentOffset(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 booleancheckDualAlignConditions()Checks dual alignment conditions: 1.private voidcreateNewRectangle()Creates a new way that shares segment with selected way.private static java.awt.geom.Line2DcreateSemiInfiniteLine(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 directionvoiddestroy()Called when the object has been destroyed.voiddoKeyPressed(java.awt.event.KeyEvent e)This is called when key press event is actually pressed (no fake events while holding key)voiddoKeyReleased(java.awt.event.KeyEvent e)This is called when key press event is actually released (no fake events while holding key)private voiddrawAngleSymbol(java.awt.Graphics2D g2, java.awt.geom.Point2D center, java.awt.geom.Point2D normal, boolean mirror)Draws right angle symbol at specified position.private voiddrawReferenceSegment(java.awt.Graphics2D g2, MapView mv, ExtrudeAction.ReferenceSegment seg)Draws given reference segment.voidenterMode()Makes this map mode active.voidexitMode()Makes this map mode inactive.java.lang.StringgetModeHelpText()Returns a short translated help message describing how this map mode can be used, to be displayed in status line.private NodegetNextNode(int index)Gets a node from selected way after given index.private intgetNextNodeIndex(int index)Gets a node index from selected way after given index.private java.awt.geom.Point2DgetNormalUniVector()private NodegetPreviousNode(int index)Gets a node from selected way before given index.private intgetPreviousNodeIndex(int index)Gets a node index from selected way before given index.private static booleanhasNodeOtherWays(Node node, Way myWay)This method tests ifnodehas other ways apart from the given one.private static booleanisOppositeDirection(EastNorth from1, EastNorth to1, EastNorth from2, EastNorth to2)Determines if from1-to1 and from2-to2 vectors directions are oppositeprivate voidjoinNodesIfCollapsed(java.util.List<Node> changedNodes)booleanlayerIsSupported(Layer l)Determines if layerlis supported by this map mode.voidmodifiersExChanged(int modifiers)This method is called to indicate different modes via cursor when the Alt/Ctrl/Shift modifier is pressed,voidmouseDragged(java.awt.event.MouseEvent e)Performs action depending on whatmodewe're in.voidmousePressed(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.voidmouseReleased(java.awt.event.MouseEvent e)Does anything that needs to be done, then switches back to select mode.voidpaint(java.awt.Graphics2D g, MapView mv, Bounds box)Paint the dataset using the engine set.private voidperformExtrusion()Does actual extrusion ofselectedSegment.protected voidreadPreferences()private voidtoggleDualAlign()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:DestroyableCalled when the object has been destroyed.- Specified by:
destroyin interfaceDestroyable- Overrides:
destroyin classJosmAction
-
addDualAlignMenuItem
private javax.swing.JCheckBoxMenuItem addDualAlignMenuItem()
-
getModeHelpText
public java.lang.String getModeHelpText()
Description copied from class:MapModeReturns a short translated help message describing how this map mode can be used, to be displayed in status line.- Overrides:
getModeHelpTextin 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:MapModeDetermines if layerlis 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:
layerIsSupportedin classMapMode- Parameters:
l- layer- Returns:
trueif the layer is supported by this map mode
-
enterMode
public void enterMode()
Description copied from class:MapModeMakes this map mode active.
-
readPreferences
protected void readPreferences()
- Overrides:
readPreferencesin classMapMode
-
exitMode
public void exitMode()
Description copied from class:MapModeMakes 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:
modifiersExChangedin interfaceModifierExListener- Parameters:
modifiers- The new extended modifiers
-
doKeyPressed
public void doKeyPressed(java.awt.event.KeyEvent e)
Description copied from interface:KeyPressReleaseListenerThis is called when key press event is actually pressed (no fake events while holding key)- Specified by:
doKeyPressedin interfaceKeyPressReleaseListener- Parameters:
e- key event
-
doKeyReleased
public void doKeyReleased(java.awt.event.KeyEvent e)
Description copied from interface:KeyPressReleaseListenerThis is called when key press event is actually released (no fake events while holding key)- Specified by:
doKeyReleasedin 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:
mousePressedin interfacejava.awt.event.MouseListener- Overrides:
mousePressedin classMapMode- Parameters:
e- current mouse event
-
mouseDragged
public void mouseDragged(java.awt.event.MouseEvent e)
Performs action depending on whatmodewe're in.- Specified by:
mouseDraggedin interfacejava.awt.event.MouseMotionListener- Overrides:
mouseDraggedin 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:
mouseReleasedin interfacejava.awt.event.MouseListener- Overrides:
mouseReleasedin 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,initialN2ensaved in calculatePossibleDirections* call UsesnewN1en,newN2encalculated 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 ifnodehas other ways apart from the given one.- Parameters:
node- node to testmyWay- way known to contain this node- Returns:
trueifnodebelongs only tomyWay, false if there are more ways.
-
calculateBestMovement
private EastNorth calculateBestMovement(EastNorth mouseEn)
Determines best movement frominitialMousePosto 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:
trueif dual alignment conditions are satisfied
-
calculatePossibleDirectionsForDualAlign
private void calculatePossibleDirectionsForDualAlign()
Gathers possible move directions - perpendicular to the selected segment only. Neighboring segments go todualAlignSegment1anddualAlignSegment2.
-
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
-1if 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
nullif 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
-1if 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
nullif there are no nodes there.
-
paint
public void paint(java.awt.Graphics2D g, MapView mv, Bounds box)
Description copied from interface:MapViewPaintablePaint the dataset using the engine set.- Specified by:
paintin 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-trueif 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
-
-