Class 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 Detail

      • nodes

        private java.util.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
    • Constructor Detail

      • 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​(java.util.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​(java.util.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:
        java.lang.NullPointerException - if objects is null or contain null item
        java.util.NoSuchElementException - if objects is empty
      • MoveCommand

        public MoveCommand​(DataSet ds,
                           java.util.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:
        java.lang.NullPointerException - if objects is null or contain null item
        java.util.NoSuchElementException - if objects is empty
        Since:
        12759
      • MoveCommand

        public MoveCommand​(DataSet ds,
                           java.util.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​(java.util.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 Detail

      • 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:
        moveAgain(double, double)
      • 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
      • 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

        public void fillModifiedData​(java.util.Collection<OsmPrimitive> modified,
                                     java.util.Collection<OsmPrimitive> deleted,
                                     java.util.Collection<OsmPrimitive> added)
        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

        public java.lang.String getDescriptionText()
        Description copied from interface: PseudoCommand
        Provides a description text representing this command.
        Returns:
        description text representing this command
      • getDescriptionIcon

        public javax.swing.Icon getDescriptionIcon()
        Description copied from interface: PseudoCommand
        Provides a descriptive icon of this command.
        Returns:
        descriptive icon of this command
      • getOffset

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

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

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class Command