Package org.openstreetmap.josm.command
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.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.openstreetmap.josm.command.Command
Command.OldNodeState
-
-
Field Summary
Fields Modifier and Type Field Description private double
backupX
private double
backupY
private java.util.Collection<Node>
nodes
The objects that should be moved.private java.util.List<Command.OldNodeState>
oldState
List of all old states of the objects.private EastNorth
startEN
Starting position, base command point, current (mouse-drag) position = startEN + (x,y) =private double
x
x difference movement.private double
y
y difference movement.-
Fields inherited from class org.openstreetmap.josm.command.Command
IS_INCOMPLETE, IS_OK, IS_OUTSIDE
-
-
Constructor Summary
Constructors Constructor Description MoveCommand(java.util.Collection<OsmPrimitive> objects, double x, double y)
Constructs a newMoveCommand
and assign the initial object set and movement vector.MoveCommand(java.util.Collection<OsmPrimitive> objects, EastNorth offset)
Constructs a newMoveCommand
to move a collection of primitives.MoveCommand(java.util.Collection<OsmPrimitive> objects, EastNorth start, EastNorth end)
Constructs a newMoveCommand
to move a collection of primitives.MoveCommand(DataSet ds, java.util.Collection<OsmPrimitive> objects, double x, double y)
Constructs a newMoveCommand
and assign the initial object set and movement vector.MoveCommand(DataSet ds, java.util.Collection<OsmPrimitive> objects, EastNorth start, EastNorth end)
Constructs a newMoveCommand
to move a collection of primitives.MoveCommand(DataSet ds, OsmPrimitive p, EastNorth start, EastNorth end)
Constructs a newMoveCommand
to move a primitive.MoveCommand(Node node, LatLon position)
Constructs a newMoveCommand
to move a node.MoveCommand(OsmPrimitive osm, double x, double y)
Constructs a newMoveCommand
to move a primitive.MoveCommand(OsmPrimitive p, EastNorth start, EastNorth end)
Constructs a newMoveCommand
to move a primitive.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
applyVectorTo(EastNorth currentEN)
Change the displacement vector to have endpointcurrentEN
.void
changeStartPoint(EastNorth newDraggedStartPoint)
Changes base point of movementboolean
equals(java.lang.Object obj)
boolean
executeCommand()
Executes the command on the dataset.void
fillModifiedData(java.util.Collection<OsmPrimitive> modified, java.util.Collection<OsmPrimitive> deleted, java.util.Collection<OsmPrimitive> added)
Fill in the changed data this command operates on.javax.swing.Icon
getDescriptionIcon()
Provides a descriptive icon of this command.java.lang.String
getDescriptionText()
Provides a description text representing this command.double
getDistance(java.util.function.Predicate<Node> predicate)
Computes the move distance for one node matching the specified predicateprotected EastNorth
getOffset()
Gets the current move offset.java.util.Collection<Node>
getParticipatingPrimitives()
Return the primitives that take part in this command.int
hashCode()
void
moveAgain(double x, double y)
Move the same set of objects again by the specified vector.void
moveAgainTo(double x, double y)
Move again to the specified coordinates.void
resetToCheckpoint()
Restore old displacement in case of some problemsvoid
saveCheckpoint()
Save current displacement to restore in case of some problemsvoid
undoCommand()
Undoes the command.private void
updateCoordinates()
-
Methods inherited from class org.openstreetmap.josm.command.Command
checkOutlyingOrIncompleteOperation, ensurePrimitivesAreInDataset, getAffectedDataSet, getOrig
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.openstreetmap.josm.command.PseudoCommand
getChildren
-
-
-
-
Field Detail
-
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
private final java.util.List<Command.OldNodeState> oldState
List of all old states of the objects.
-
-
Constructor Detail
-
MoveCommand
public MoveCommand(OsmPrimitive osm, double x, double y)
Constructs a newMoveCommand
to move a primitive.- Parameters:
osm
- The primitive to movex
- X difference movement. Coordinates are in northern/easterny
- Y difference movement. Coordinates are in northern/eastern
-
MoveCommand
public MoveCommand(Node node, LatLon position)
Constructs a newMoveCommand
to move a node.- Parameters:
node
- The node to moveposition
- The new location (lat/lon)
-
MoveCommand
public MoveCommand(java.util.Collection<OsmPrimitive> objects, EastNorth offset)
Constructs a newMoveCommand
to move a collection of primitives.- Parameters:
objects
- The primitives to moveoffset
- The movement vector
-
MoveCommand
public MoveCommand(java.util.Collection<OsmPrimitive> objects, double x, double y)
Constructs a newMoveCommand
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 setx
- X difference movement. Coordinates are in northern/easterny
- Y difference movement. Coordinates are in northern/eastern- Throws:
java.lang.NullPointerException
- if objects is null or contain null itemjava.util.NoSuchElementException
- if objects is empty
-
MoveCommand
public MoveCommand(DataSet ds, java.util.Collection<OsmPrimitive> objects, double x, double y)
Constructs a newMoveCommand
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/easterny
- Y difference movement. Coordinates are in northern/eastern- Throws:
java.lang.NullPointerException
- if objects is null or contain null itemjava.util.NoSuchElementException
- if objects is empty- Since:
- 12759
-
MoveCommand
public MoveCommand(DataSet ds, java.util.Collection<OsmPrimitive> objects, EastNorth start, EastNorth end)
Constructs a newMoveCommand
to move a collection of primitives.- Parameters:
ds
- the dataset context for moving these primitives. Must not be null.objects
- The primitives to movestart
- 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 newMoveCommand
to move a collection of primitives.- Parameters:
objects
- The primitives to movestart
- The starting position (northern/eastern)end
- The ending position (northern/eastern)
-
MoveCommand
public MoveCommand(DataSet ds, OsmPrimitive p, EastNorth start, EastNorth end)
Constructs a newMoveCommand
to move a primitive.- Parameters:
ds
- the dataset context for moving these primitives. Must not be null.p
- The primitive to movestart
- The starting position (northern/eastern)end
- The ending position (northern/eastern)- Since:
- 12759
-
MoveCommand
public MoveCommand(OsmPrimitive p, EastNorth start, EastNorth end)
Constructs a newMoveCommand
to move a primitive.- Parameters:
p
- The primitive to movestart
- 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/easterny
- 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 coordinatey
- Y coordinate- See Also:
moveAgain(double, double)
-
applyVectorTo
public void applyVectorTo(EastNorth currentEN)
Change the displacement vector to have endpointcurrentEN
. 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 classCommand
- 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 classCommand
-
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 classCommand
- Parameters:
modified
- The modified primitivesdeleted
- The deleted primitivesadded
- 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
-
getParticipatingPrimitives
public java.util.Collection<Node> 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 interfacePseudoCommand
- Overrides:
getParticipatingPrimitives
in classCommand
- 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(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
-
-