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:
ActionListener,MouseListener,MouseMotionListener,Serializable,Cloneable,EventListener,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:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate class(package private) static enumprivate static classNested classes/interfaces inherited from class org.openstreetmap.josm.actions.JosmAction
JosmAction.ActiveLayerChangeAdapter, JosmAction.LayerChangeAdapter, JosmAction.SelectionChangeAdapterNested classes/interfaces inherited from interface org.openstreetmap.josm.gui.layer.MapViewPaintable
MapViewPaintable.LayerPainter, MapViewPaintable.MapViewEvent, MapViewPaintable.PaintableInvalidationEvent, MapViewPaintable.PaintableInvalidationListener -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate ExtrudeAction.ReferenceSegmentThe direction that is currently active.private booleanIftrue, when extruding create new node(s) even if segments are parallel.private final CursorThe cursor for the 'create_new' mode.private final CursorThe cursor for the 'alwaysCreateNodes' submode.private final CursorThe cursor for the 'translate' mode.private booleantrue, if dual alignment is active.private final ExtrudeAction.DualAlignChangeActionprivate final JCheckBoxMenuItemprivate booleantrue, if dual alignment mode is enabled.private ExtrudeAction.ReferenceSegmentDual alignment reference segmentsprivate ExtrudeAction.ReferenceSegmentDual alignment reference segmentsprivate booleantrue, if new segment was collapsedprivate final Shortcutprivate Colordrawing settings for helper linesprivate Strokeprivate Strokeprivate booleanprivate booleansettings value whether shared nodes should be ignored or notprivate PointThe position of the mouse cursor when the drag action was initiated.private intThe time which needs to pass between click and release before something counts as a move, in millisecondsprivate intThe minimal shift of mouse (in pixels) before something counts as moveprivate EastNorthThe initial EastNorths of node1 and node2private EastNorthprivate booleanprivate Commandprivate Colorprivate Strokeprivate ExtrudeAction.Modeprivate longprivate MoveCommandthe command that performed last move.private MoveCommandThe command used for dual alignment movement.Collection of nodes that is movedprivate EastNorthThe new EastNorths of node1 and node2private EastNorthprivate booleanprivate Strokeprivate List<ExtrudeAction.ReferenceSegment>Possible directions to move to.private Nodeprivate WaySegmentprivate doubleprivate booleanFields inherited from class org.openstreetmap.josm.actions.mapmode.MapMode
alt, ctrl, cursor, meta, platformMenuShortcutKeyMask, shiftFields inherited from class org.openstreetmap.josm.actions.JosmAction
scFields inherited from class javax.swing.AbstractAction
changeSupport, enabledFields inherited from interface javax.swing.Action
ACCELERATOR_KEY, ACTION_COMMAND_KEY, DEFAULT, DISPLAYED_MNEMONIC_INDEX_KEY, LARGE_ICON_KEY, LONG_DESCRIPTION, MNEMONIC_KEY, NAME, SELECTED_KEY, SHORT_DESCRIPTION, SMALL_ICON -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate JCheckBoxMenuItemprivate static voidInserts node into nearby segment.private EastNorthcalculateBestMovement(EastNorth mouseEn) Determines best movement frominitialMousePosto current mouse position, choosing one of the directions frompossibleMoveDirections.private EastNorthCalculate newN1en, newN2en best suitable for given mouse coordinates For dual align, calculates positions of new nodes, aligning them to neighboring segments.private voidGathers possible move directions - along all adjacent segments.private voidGathers possible move directions - perpendicular to the selected segment and parallel to neighboring segments.private voidGathers 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 booleanChecks dual alignment conditions: 1.private voidCreates a new way that shares segment with selected way.private static Line2DcreateSemiInfiniteLine(Point2D start, Point2D unitvector, Graphics2D g) Creates a new Line that extends off the edge of the viewport in one directionvoiddestroy()Called when the object has been destroyed.voidThis is called when key press event is actually pressed (no fake events while holding key)voidThis is called when key press event is actually released (no fake events while holding key)private voiddrawAngleSymbol(Graphics2D g2, Point2D center, Point2D normal, boolean mirror) Draws right angle symbol at specified position.private voidDraws given reference segment.voidMakes this map mode active.voidexitMode()Makes this map mode inactive.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 Point2Dprivate 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(List<Node> changedNodes) booleanDetermines 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,voidPerforms action depending on whatmodewe're in.voidIf the left mouse button is pressed over a segment or a node, switches to appropriatemode, depending on Ctrl/Alt/Shift modifiers anddualAlignEnabled.voidDoes anything that needs to be done, then switches back to select mode.voidpaint(Graphics2D g, MapView mv, Bounds box) Paint the dataset using the engine set.private voidDoes actual extrusion ofselectedSegment.protected voidprivate voidToggles dual alignment mode.Methods inherited from class org.openstreetmap.josm.actions.mapmode.MapMode
actionPerformed, isEditableDataLayer, isPanning, mouseClicked, mouseEntered, mouseExited, mouseMoved, preferenceChanged, requestFocusInMapView, updateKeyModifiers, updateKeyModifiers, updateKeyModifiers, updateKeyModifiersEx, updateStatusLineMethods 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, waitFutureMethods inherited from class javax.swing.AbstractAction
addPropertyChangeListener, clone, firePropertyChange, getKeys, getPropertyChangeListeners, getValue, isEnabled, putValue, removePropertyChangeListener, setEnabledMethods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.openstreetmap.josm.gui.layer.MapViewPaintable
addInvalidationListener, removeInvalidationListener
-
Field Details
-
mode
-
alwaysCreateNodes
Iftrue, when extruding create new node(s) even if segments are parallel. -
nodeDragWithoutCtrl
-
mouseDownTime
-
selectedSegment
-
selectedNode
-
lastCommandOnUndoStack
-
mainColor
-
mainStroke
-
keepSegmentDirection
-
helperColor
drawing settings for helper lines -
helperStrokeDash
-
helperStrokeRA
-
oldLineStroke
-
symbolSize
-
possibleMoveDirections
Possible directions to move to. -
movingNodeList
Collection of nodes that is moved -
activeMoveDirection
The direction that is currently active. -
initialMousePos
The position of the mouse cursor when the drag action was initiated. -
initialMoveDelay
The time which needs to pass between click and release before something counts as a move, in milliseconds -
initialMoveThreshold
The minimal shift of mouse (in pixels) before something counts as move -
initialN1en
The initial EastNorths of node1 and node2 -
initialN2en
-
newN1en
The new EastNorths of node1 and node2 -
newN2en
-
moveCommand
the command that performed last move. -
moveCommand2
The command used for dual alignment movement. Needs to be separate, due to two nodes moving in different directions. -
cursorCreateNew
The cursor for the 'create_new' mode. -
cursorTranslate
The cursor for the 'translate' mode. -
cursorCreateNodes
The cursor for the 'alwaysCreateNodes' submode. -
dualAlignEnabled
true, if dual alignment mode is enabled. User wants following extrude to be dual aligned. -
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
Dual alignment reference segments -
dualAlignSegment2
Dual alignment reference segments -
dualAlignSegmentCollapsed
true, if new segment was collapsed -
dualAlignChangeAction
-
dualAlignCheckboxMenuItem
-
dualAlignShortcut
-
useRepeatedShortcut
-
ignoreNextKeyRelease
-
-
Constructor Details
-
ExtrudeAction
public ExtrudeAction()Creates a new ExtrudeAction- Since:
- 11713
-
-
Method Details
-
destroy
Description copied from interface:DestroyableCalled when the object has been destroyed.- Specified by:
destroyin interfaceDestroyable- Overrides:
destroyin classJosmAction
-
addDualAlignMenuItem
-
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
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
Description copied from class:MapModeMakes this map mode active. -
readPreferences
- Overrides:
readPreferencesin classMapMode
-
exitMode
Description copied from class:MapModeMakes this map mode inactive. -
modifiersExChanged
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
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
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
Toggles dual alignment mode. -
mousePressed
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 interfaceMouseListener- Overrides:
mousePressedin classMapMode- Parameters:
e- current mouse event
-
mouseDragged
Performs action depending on whatmodewe're in.- Specified by:
mouseDraggedin interfaceMouseMotionListener- Overrides:
mouseDraggedin classMapMode- Parameters:
e- current mouse event
-
mouseReleased
Does anything that needs to be done, then switches back to select mode.- Specified by:
mouseReleasedin interfaceMouseListener- Overrides:
mouseReleasedin classMapMode- Parameters:
e- current mouse event
-
addNewNode
Inserts node into nearby segment.- Parameters:
e- current mouse point
-
createNewRectangle
Creates a new way that shares segment with selected way. -
performExtrusion
Does actual extrusion ofselectedSegment. UsesinitialN1en,initialN2ensaved in calculatePossibleDirections* call UsesnewN1en,newN2encalculated bycalculateBestMovementAndNewNodes(org.openstreetmap.josm.data.coor.EastNorth) -
joinNodesIfCollapsed
-
hasNodeOtherWays
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
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
Gathers possible move directions - perpendicular to the selected segment and parallel to neighboring segments. -
calculatePossibleDirectionsByNode
Gathers possible move directions - along all adjacent segments. -
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
Gathers possible move directions - perpendicular to the selected segment only. Neighboring segments go todualAlignSegment1anddualAlignSegment2. -
calculateBestMovementAndNewNodes
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
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
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
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
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
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
-
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
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
Draws given reference segment.- Parameters:
g2- the Graphics2D object used to draw onmv- map viewseg- the reference segment
-
createSemiInfiniteLine
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
-