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 doublebackupXprivate doublebackupYprivate java.util.Collection<Node>nodesThe objects that should be moved.private java.util.List<Command.OldNodeState>oldStateList of all old states of the objects.private EastNorthstartENStarting position, base command point, current (mouse-drag) position = startEN + (x,y) =private doublexx difference movement.private doubleyy 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 newMoveCommandand assign the initial object set and movement vector.MoveCommand(java.util.Collection<OsmPrimitive> objects, EastNorth offset)Constructs a newMoveCommandto move a collection of primitives.MoveCommand(java.util.Collection<OsmPrimitive> objects, EastNorth start, EastNorth end)Constructs a newMoveCommandto move a collection of primitives.MoveCommand(DataSet ds, java.util.Collection<OsmPrimitive> objects, double x, double y)Constructs a newMoveCommandand assign the initial object set and movement vector.MoveCommand(DataSet ds, java.util.Collection<OsmPrimitive> objects, EastNorth start, EastNorth end)Constructs a newMoveCommandto move a collection of primitives.MoveCommand(DataSet ds, OsmPrimitive p, EastNorth start, EastNorth end)Constructs a newMoveCommandto move a primitive.MoveCommand(Node node, LatLon position)Constructs a newMoveCommandto move a node.MoveCommand(OsmPrimitive osm, double x, double y)Constructs a newMoveCommandto move a primitive.MoveCommand(OsmPrimitive p, EastNorth start, EastNorth end)Constructs a newMoveCommandto move a primitive.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidapplyVectorTo(EastNorth currentEN)Change the displacement vector to have endpointcurrentEN.voidchangeStartPoint(EastNorth newDraggedStartPoint)Changes base point of movementbooleanequals(java.lang.Object obj)booleanexecuteCommand()Executes the command on the dataset.voidfillModifiedData(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.IcongetDescriptionIcon()Provides a descriptive icon of this command.java.lang.StringgetDescriptionText()Provides a description text representing this command.doublegetDistance(java.util.function.Predicate<Node> predicate)Computes the move distance for one node matching the specified predicateprotected EastNorthgetOffset()Gets the current move offset.java.util.Collection<Node>getParticipatingPrimitives()Return the primitives that take part in this command.inthashCode()voidmoveAgain(double x, double y)Move the same set of objects again by the specified vector.voidmoveAgainTo(double x, double y)Move again to the specified coordinates.voidresetToCheckpoint()Restore old displacement in case of some problemsvoidsaveCheckpoint()Save current displacement to restore in case of some problemsvoidundoCommand()Undoes the command.private voidupdateCoordinates()-
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 newMoveCommandto 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 newMoveCommandto 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 newMoveCommandto 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 newMoveCommandand 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 newMoveCommandand 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 newMoveCommandto 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 newMoveCommandto 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 newMoveCommandto 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 newMoveCommandto 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:CommandExecutes 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:
executeCommandin classCommand- Returns:
- true
-
undoCommand
public void undoCommand()
Description copied from class:CommandUndoes 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:
undoCommandin classCommand
-
fillModifiedData
public void fillModifiedData(java.util.Collection<OsmPrimitive> modified, java.util.Collection<OsmPrimitive> deleted, java.util.Collection<OsmPrimitive> added)
Description copied from class:CommandFill in the changed data this command operates on. Add to the lists, don't clear them.- Specified by:
fillModifiedDatain classCommand- Parameters:
modified- The modified primitivesdeleted- The deleted primitivesadded- The added primitives
-
getDescriptionText
public java.lang.String getDescriptionText()
Description copied from interface:PseudoCommandProvides a description text representing this command.- Returns:
- description text representing this command
-
getDescriptionIcon
public javax.swing.Icon getDescriptionIcon()
Description copied from interface:PseudoCommandProvides a descriptive icon of this command.- Returns:
- descriptive icon of this command
-
getParticipatingPrimitives
public java.util.Collection<Node> getParticipatingPrimitives()
Description copied from class:CommandReturn the primitives that take part in this command. The collection is computed during execution.- Specified by:
getParticipatingPrimitivesin interfacePseudoCommand- Overrides:
getParticipatingPrimitivesin 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
-
-