Package org.openstreetmap.josm.command
Class Command
- java.lang.Object
-
- org.openstreetmap.josm.command.Command
-
- All Implemented Interfaces:
PseudoCommand
- Direct Known Subclasses:
AbstractNodesCommand
,AddCommand
,AddPrimitivesCommand
,ChangeCommand
,ChangeMembersCommand
,ChangePropertyCommand
,ChangePropertyKeyCommand
,ChangeRelationMemberRoleCommand
,ConflictAddCommand
,ConflictResolveCommand
,DeleteCommand
,MoveCommand
,PurgeCommand
,SelectCommand
,SequenceCommand
,TransformNodesCommand
public abstract class Command extends java.lang.Object implements PseudoCommand
Classes implementing Command modify a dataset in a specific way. A command is one atomic action on a specific dataset, such as move or delete. The command remembers theDataSet
it is operating on.- Since:
- 21 (creation), 10599 (signature)
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
Command.CloneVisitor
static class
Command.OldNodeState
Small helper for holding the interesting part of the old data state of the objects.
-
Field Summary
Fields Modifier and Type Field Description private java.util.Map<OsmPrimitive,PrimitiveData>
cloneMap
the map of OsmPrimitives in the original state to OsmPrimitives in cloned stateprivate DataSet
data
the dataset which this command is applied tostatic int
IS_INCOMPLETE
IS_INCOMPLETE: operation on incomplete targetstatic int
IS_OK
IS_OK : operation is okaystatic int
IS_OUTSIDE
IS_OUTSIDE : operation on element outside of download area
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description static int
checkOutlyingOrIncompleteOperation(java.util.Collection<? extends OsmPrimitive> primitives, java.util.Collection<? extends OsmPrimitive> ignore)
Check whether user is about to operate on data outside of the download area.protected void
ensurePrimitivesAreInDataset()
Ensures that all primitives that are participating in this command belong to the affected data set.boolean
equals(java.lang.Object obj)
boolean
executeCommand()
Executes the command on the dataset.abstract 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.DataSet
getAffectedDataSet()
Gets the data set this command affects.PrimitiveData
getOrig(OsmPrimitive osm)
Lets other commands access the original version of the object.java.util.Collection<? extends OsmPrimitive>
getParticipatingPrimitives()
Return the primitives that take part in this command.int
hashCode()
void
undoCommand()
Undoes the command.-
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, getDescriptionIcon, getDescriptionText
-
-
-
-
Field Detail
-
IS_OK
public static final int IS_OK
IS_OK : operation is okay- See Also:
- Constant Field Values
-
IS_OUTSIDE
public static final int IS_OUTSIDE
IS_OUTSIDE : operation on element outside of download area- See Also:
- Constant Field Values
-
IS_INCOMPLETE
public static final int IS_INCOMPLETE
IS_INCOMPLETE: operation on incomplete target- See Also:
- Constant Field Values
-
cloneMap
private java.util.Map<OsmPrimitive,PrimitiveData> cloneMap
the map of OsmPrimitives in the original state to OsmPrimitives in cloned state
-
-
Method Detail
-
executeCommand
public boolean executeCommand()
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.
- Returns:
- true
-
undoCommand
public void undoCommand()
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.
-
getOrig
public PrimitiveData getOrig(OsmPrimitive osm)
Lets other commands access the original version of the object. Usually for undoing.- Parameters:
osm
- The requested OSM object- Returns:
- The original version of the requested object, if any
-
getAffectedDataSet
public DataSet getAffectedDataSet()
Gets the data set this command affects.- Returns:
- The data set. May be
null
if no layer was set and no edit layer was found. - Since:
- 10467
-
fillModifiedData
public abstract 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. Add to the lists, don't clear them.- Parameters:
modified
- The modified primitivesdeleted
- The deleted primitivesadded
- The added primitives
-
getParticipatingPrimitives
public java.util.Collection<? extends OsmPrimitive> getParticipatingPrimitives()
Return the primitives that take part in this command. The collection is computed during execution.- Specified by:
getParticipatingPrimitives
in interfacePseudoCommand
- Returns:
- primitives that take part in this command
-
checkOutlyingOrIncompleteOperation
public static int checkOutlyingOrIncompleteOperation(java.util.Collection<? extends OsmPrimitive> primitives, java.util.Collection<? extends OsmPrimitive> ignore)
Check whether user is about to operate on data outside of the download area.- Parameters:
primitives
- the primitives to operate onignore
-null
or a primitive to be ignored- Returns:
- true, if operating on outlying primitives is OK; false, otherwise
-
ensurePrimitivesAreInDataset
protected void ensurePrimitivesAreInDataset()
Ensures that all primitives that are participating in this command belong to the affected data set. Commands may use this in their update methods to check the consistency of the primitives they operate on.- Throws:
java.lang.AssertionError
- if noDataSet
is set or if any primitive does not belong to that dataset.
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equals
in classjava.lang.Object
-
-