Class MoveCommand

java.lang.Object
org.openstreetmap.josm.command.Command
org.openstreetmap.josm.command.MoveCommand
All Implemented Interfaces:
PseudoCommand

public class MoveCommand extends Command
MoveCommand moves a set of OsmPrimitives along the map. It can be moved again to collect several MoveCommands into one command.
  • Field Details

    • nodes

      private Collection<Node> nodes
      The objects that should be moved.
    • startEN

      private EastNorth startEN
      Starting position, base command point, current (mouse-drag) position = startEN + (x,y) =
    • x

      private double x
      x difference movement. Coordinates are in northern/eastern
    • y

      private double y
      y difference movement. Coordinates are in northern/eastern
    • backupX

      private double backupX
    • backupY

      private double backupY
    • oldState

      List of all old states of the objects.
  • Constructor Details

    • MoveCommand

      public MoveCommand(OsmPrimitive osm, double x, double y)
      Constructs a new MoveCommand to move a primitive.
      Parameters:
      osm - The primitive to move
      x - X difference movement. Coordinates are in northern/eastern
      y - Y difference movement. Coordinates are in northern/eastern
    • MoveCommand

      public MoveCommand(Node node, LatLon position)
      Constructs a new MoveCommand to move a node.
      Parameters:
      node - The node to move
      position - The new location (lat/lon)
    • MoveCommand

      public MoveCommand(Collection<OsmPrimitive> objects, EastNorth offset)
      Constructs a new MoveCommand to move a collection of primitives.
      Parameters:
      objects - The primitives to move
      offset - The movement vector
    • MoveCommand

      public MoveCommand(Collection<OsmPrimitive> objects, double x, double y)
      Constructs a new MoveCommand and assign the initial object set and movement vector.
      Parameters:
      objects - The primitives to move. Must neither be null nor empty. Objects must belong to a data set
      x - X difference movement. Coordinates are in northern/eastern
      y - Y difference movement. Coordinates are in northern/eastern
      Throws:
      NullPointerException - if objects is null or contain null item
      NoSuchElementException - if objects is empty
    • MoveCommand

      public MoveCommand(DataSet ds, Collection<OsmPrimitive> objects, double x, double y)
      Constructs a new MoveCommand and assign the initial object set and movement vector.
      Parameters:
      ds - the dataset context for moving these primitives. Must not be null.
      objects - The primitives to move. Must neither be null.
      x - X difference movement. Coordinates are in northern/eastern
      y - Y difference movement. Coordinates are in northern/eastern
      Throws:
      NullPointerException - if objects is null or contain null item
      NoSuchElementException - if objects is empty
      Since:
      12759
    • MoveCommand

      public MoveCommand(DataSet ds, Collection<OsmPrimitive> objects, EastNorth start, EastNorth end)
      Constructs a new MoveCommand to move a collection of primitives.
      Parameters:
      ds - the dataset context for moving these primitives. Must not be null.
      objects - The primitives to move
      start - The starting position (northern/eastern)
      end - The ending position (northern/eastern)
      Since:
      12759
    • MoveCommand

      public MoveCommand(Collection<OsmPrimitive> objects, EastNorth start, EastNorth end)
      Constructs a new MoveCommand to move a collection of primitives.
      Parameters:
      objects - The primitives to move
      start - The starting position (northern/eastern)
      end - The ending position (northern/eastern)
    • MoveCommand

      public MoveCommand(DataSet ds, OsmPrimitive p, EastNorth start, EastNorth end)
      Constructs a new MoveCommand to move a primitive.
      Parameters:
      ds - the dataset context for moving these primitives. Must not be null.
      p - The primitive to move
      start - The starting position (northern/eastern)
      end - The ending position (northern/eastern)
      Since:
      12759
    • MoveCommand

      public MoveCommand(OsmPrimitive p, EastNorth start, EastNorth end)
      Constructs a new MoveCommand to move a primitive.
      Parameters:
      p - The primitive to move
      start - The starting position (northern/eastern)
      end - The ending position (northern/eastern)
  • Method Details

    • moveAgain

      public void moveAgain(double x, double y)
      Move the same set of objects again by the specified vector. The vectors are added together and so the resulting will be moved to the previous vector plus this one. The move is immediately executed and any undo will undo both vectors to the original position the objects had before first moving.
      Parameters:
      x - X difference movement. Coordinates are in northern/eastern
      y - Y difference movement. Coordinates are in northern/eastern
    • moveAgainTo

      public void moveAgainTo(double x, double y)
      Move again to the specified coordinates.
      Parameters:
      x - X coordinate
      y - Y coordinate
      See Also:
    • applyVectorTo

      public void applyVectorTo(EastNorth currentEN)
      Change the displacement vector to have endpoint currentEN. starting point is startEN
      Parameters:
      currentEN - the new endpoint
    • changeStartPoint

      public void changeStartPoint(EastNorth newDraggedStartPoint)
      Changes base point of movement
      Parameters:
      newDraggedStartPoint - - new starting point after movement (where user clicks to start new drag)
    • saveCheckpoint

      public final void saveCheckpoint()
      Save current displacement to restore in case of some problems
    • resetToCheckpoint

      public void resetToCheckpoint()
      Restore old displacement in case of some problems
    • updateCoordinates

      private void updateCoordinates()
    • executeCommand

      public boolean executeCommand()
      Description copied from class: Command
      Executes the command on the dataset. This implementation will remember all primitives returned by fillModifiedData for restoring them on undo.

      The layer should be invalidated after execution so that it can be re-painted.

      Overrides:
      executeCommand in class Command
      Returns:
      true
    • undoCommand

      public void undoCommand()
      Description copied from class: Command
      Undoes the command. It can be assumed that all objects are in the same state they were before. It can also be assumed that executeCommand was called exactly once before. This implementation undoes all objects stored by a former call to executeCommand.
      Overrides:
      undoCommand in class Command
    • fillModifiedData

      Description copied from class: Command
      Fill in the changed data this command operates on. Add to the lists, don't clear them.
      Specified by:
      fillModifiedData in class Command
      Parameters:
      modified - The modified primitives
      deleted - The deleted primitives
      added - The added primitives
    • getDescriptionText

      Description copied from interface: PseudoCommand
      Provides a description text representing this command.
      Returns:
      description text representing this command
    • getDescriptionIcon

      Description copied from interface: PseudoCommand
      Provides a descriptive icon of this command.
      Returns:
      descriptive icon of this command
    • getParticipatingPrimitives

      Description copied from class: Command
      Return the primitives that take part in this command. The collection is computed during execution.
      Specified by:
      getParticipatingPrimitives in interface PseudoCommand
      Overrides:
      getParticipatingPrimitives in class Command
      Returns:
      primitives that take part in this command
    • getOffset

      protected EastNorth getOffset()
      Gets the current move offset.
      Returns:
      The current move offset.
    • getDistance

      public double getDistance(Predicate<Node> predicate)
      Computes the move distance for one node matching the specified predicate
      Parameters:
      predicate - predicate to match
      Returns:
      distance in metres
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Command
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Command