org.openstreetmap.josm.actions.mapmode
Class ExtrudeAction

java.lang.Object
  extended by javax.swing.AbstractAction
      extended by org.openstreetmap.josm.actions.JosmAction
          extended by org.openstreetmap.josm.actions.mapmode.MapMode
              extended by 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, Destroyable

public class ExtrudeAction
extends MapMode
implements MapViewPaintable

Makes a rectangle from a line, or modifies a rectangle.

See Also:
Serialized Form

Nested Class Summary
(package private) static class ExtrudeAction.Mode
           
 
Field Summary
private  EastNorth activeMoveDirection
          The direction that is currently active.
private  java.awt.event.AWTEventListener altKeyListener
          This listener is used to indicate the 'create_new' mode, if the Alt modifier is pressed.
private  boolean alwaysCreateNodes
          If true, when extruding create new node even if segments parallel.
private  java.awt.Cursor cursorCreateNew
          The cursor for the 'create_new' mode.
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  EastNorth initialN1en
          The initial EastNorths of node1 and node2
private  EastNorth initialN2en
           
private  ExtrudeAction.Mode mode
           
private  long mouseDownTime
           
private  MoveCommand moveCommand
          the command that performed last move.
private  EastNorth newN1en
          The new EastNorths of node1 and node2
private  EastNorth newN2en
           
private  java.util.List<EastNorth> possibleMoveDirections
          Possible directions to move to.
private  java.awt.Color selectedColor
           
private  WaySegment selectedSegment
           
 
Fields inherited from class org.openstreetmap.josm.actions.mapmode.MapMode
alt, ctrl, cursor, shift
 
Fields inherited from class org.openstreetmap.josm.actions.JosmAction
sc
 
Fields inherited from class javax.swing.AbstractAction
changeSupport, enabled
 
Fields 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
ExtrudeAction(MapFrame mapFrame)
          Create a new SelectAction
 
Method Summary
private static EastNorth calculateSegmentOffset(EastNorth segmentP1, EastNorth segmentP2, EastNorth moveDirection, EastNorth targetPos)
          This method calculates offset amount by witch to move the given segment perpendicularly for it to be in line with mouse position.
private static java.awt.geom.Line2D createSemiInfiniteLine(java.awt.geom.Point2D start, java.awt.geom.Point2D unitvector, java.awt.Graphics2D g)
          Create a new Line that extends off the edge of the viewport in one direction
 void enterMode()
           
 void exitMode()
           
 java.lang.String getModeHelpText()
           
private  Node getNextNode(int index)
          Gets a node from selected way before given index.
private  Node getPreviousNode(int index)
          Gets a node from selected way before given index.
private  boolean hasNodeOtherWays(Node node, Way myWay)
          This method tests if a node has other ways apart from the given one.
 boolean layerIsSupported(Layer l)
           
 void mouseDragged(java.awt.event.MouseEvent e)
          Perform 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, switch to either extrude, translate or create_new mode depending on whether Ctrl or Alt is held.
 void mouseReleased(java.awt.event.MouseEvent e)
          Do anything that needs to be done, then switch back to select mode
 void paint(java.awt.Graphics2D g, MapView mv, Bounds box)
          Paint the dataset using the engine set.
 
Methods inherited from class org.openstreetmap.josm.actions.mapmode.MapMode
actionPerformed, mouseClicked, mouseEntered, mouseExited, mouseMoved, updateKeyModifiers, updateKeyModifiers, updateKeyModifiers, updateStatusLine
 
Methods inherited from class org.openstreetmap.josm.actions.JosmAction
destroy, getCurrentDataSet, getEditLayer, getShortcut, initEnabledState, installAdapters, setTooltip, updateEnabledState, updateEnabledState
 
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
 

Field Detail

mode

private ExtrudeAction.Mode mode

alwaysCreateNodes

private boolean alwaysCreateNodes
If true, when extruding create new node even if segments parallel.


mouseDownTime

private long mouseDownTime

selectedSegment

private WaySegment selectedSegment

selectedColor

private java.awt.Color selectedColor

possibleMoveDirections

private java.util.List<EastNorth> possibleMoveDirections
Possible directions to move to.


activeMoveDirection

private EastNorth 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


initialN1en

private EastNorth initialN1en
The initial EastNorths of node1 and node2


initialN2en

private EastNorth initialN2en

newN1en

private EastNorth newN1en
The new EastNorths of node1 and node2


newN2en

private EastNorth newN2en

moveCommand

private MoveCommand moveCommand
the command that performed last move.


cursorCreateNew

private final java.awt.Cursor cursorCreateNew
The cursor for the 'create_new' mode.


altKeyListener

private final java.awt.event.AWTEventListener altKeyListener
This listener is used to indicate the 'create_new' mode, if the Alt modifier is pressed.

Constructor Detail

ExtrudeAction

public ExtrudeAction(MapFrame mapFrame)
Create a new SelectAction

Parameters:
mapFrame - The MapFrame this action belongs to.
Method Detail

getModeHelpText

public java.lang.String getModeHelpText()
Overrides:
getModeHelpText in class MapMode

layerIsSupported

public boolean layerIsSupported(Layer l)
Overrides:
layerIsSupported in class MapMode

enterMode

public void enterMode()
Overrides:
enterMode in class MapMode

exitMode

public void exitMode()
Overrides:
exitMode in class MapMode

mousePressed

public void mousePressed(java.awt.event.MouseEvent e)
If the left mouse button is pressed over a segment, switch to either extrude, translate or create_new mode depending on whether Ctrl or Alt is held.

Specified by:
mousePressed in interface java.awt.event.MouseListener
Overrides:
mousePressed in class MapMode

mouseDragged

public void mouseDragged(java.awt.event.MouseEvent e)
Perform action depending on what mode we're in.

Specified by:
mouseDragged in interface java.awt.event.MouseMotionListener
Overrides:
mouseDragged in class MapMode

mouseReleased

public void mouseReleased(java.awt.event.MouseEvent e)
Do anything that needs to be done, then switch back to select mode

Specified by:
mouseReleased in interface java.awt.event.MouseListener
Overrides:
mouseReleased in class MapMode

hasNodeOtherWays

private boolean hasNodeOtherWays(Node node,
                                 Way myWay)
This method tests if a node has other ways apart from the given one.

Parameters:
node -
myWay -
Returns:
true of node belongs only to myWay, false if there are more ways.

calculateSegmentOffset

private static EastNorth calculateSegmentOffset(EastNorth segmentP1,
                                                EastNorth segmentP2,
                                                EastNorth moveDirection,
                                                EastNorth targetPos)
This method calculates offset amount by witch to move the given segment perpendicularly for it to be in line with mouse position.

Parameters:
segmentP1 -
segmentP2 -
targetPos -
Returns:
offset amount of P1 and P2.

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.

getNextNode

private Node getNextNode(int index)
Gets a node from selected way before 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 interface MapViewPaintable
mv - The object that can translate GeoPoints to screen coordinates.

createSemiInfiniteLine

private static java.awt.geom.Line2D createSemiInfiniteLine(java.awt.geom.Point2D start,
                                                           java.awt.geom.Point2D unitvector,
                                                           java.awt.Graphics2D g)
Create a new Line that extends off the edge of the viewport in one direction

Parameters:
start - The start point of the line
unitvector - A unit vector denoting the direction of the line
g - the Graphics2D object it will be used on


JOSM