org.openstreetmap.josm.command
Class Command

java.lang.Object
  extended by org.openstreetmap.josm.command.PseudoCommand
      extended by org.openstreetmap.josm.command.Command
Direct Known Subclasses:
AddCommand, AddPrimitivesCommand, ChangeCommand, ChangeNodesCommand, ChangePropertyCommand, ChangePropertyKeyCommand, ChangeRelationMemberRoleCommand, ConflictAddCommand, ConflictResolveCommand, DeleteCommand, MoveCommand, PurgeCommand, RelationMemberConflictResolverCommand, SequenceCommand, TransformNodesCommand

public abstract class Command
extends 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 the OsmDataLayer it is operating on.


Nested Class Summary
private static class Command.CloneVisitor
           
 
Field Summary
private  java.util.Map<OsmPrimitive,PrimitiveData> cloneMap
          the map of OsmPrimitives in the original state to OsmPrimitives in cloned state
private  OsmDataLayer layer
          the layer which this command is applied to
 
Constructor Summary
Command()
           
Command(OsmDataLayer layer)
          Creates a new command in the context of a specific data layer
 
Method Summary
static boolean checkAndConfirmOutlyingOperation(java.lang.String operation, java.lang.String dialogTitle, java.lang.String outsideDialogMessage, java.lang.String incompleteDialogMessage, java.awt.geom.Area area, 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.
 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.
protected  OsmDataLayer getLayer()
          Replies the layer this command is (or was) applied to.
 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.
 boolean invalidBecauselayerRemoved(Layer oldLayer)
          Called when a layer has been removed to have the command remove itself from any buffer if it is not longer applicable to the dataset (e.g.
private static boolean isOutlying(OsmPrimitive osm, java.awt.geom.Area area)
           
 void undoCommand()
          Undoes the command.
 
Methods inherited from class org.openstreetmap.josm.command.PseudoCommand
getChildren, getDescriptionIcon, getDescriptionText
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

cloneMap

private java.util.Map<OsmPrimitive,PrimitiveData> cloneMap
the map of OsmPrimitives in the original state to OsmPrimitives in cloned state


layer

private OsmDataLayer layer
the layer which this command is applied to

Constructor Detail

Command

public Command()

Command

public Command(OsmDataLayer layer)
        throws java.lang.IllegalArgumentException
Creates a new command in the context of a specific data layer

Parameters:
layer - the data layer. Must not be null.
Throws:
java.lang.IllegalArgumentException - thrown if layer is null
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.


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.


invalidBecauselayerRemoved

public boolean invalidBecauselayerRemoved(Layer oldLayer)
Called when a layer has been removed to have the command remove itself from any buffer if it is not longer applicable to the dataset (e.g. it was part of the removed layer)

Parameters:
oldLayer - the old layer
Returns:
true if this command

getOrig

public PrimitiveData getOrig(OsmPrimitive osm)
Lets other commands access the original version of the object. Usually for undoing.


getLayer

protected OsmDataLayer getLayer()
Replies the layer this command is (or was) applied to.


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 primitives
deleted - The deleted primitives
added - The added primitives

getParticipatingPrimitives

public java.util.Collection<? extends OsmPrimitive> getParticipatingPrimitives()
Return the primitives that take part in this command.

Specified by:
getParticipatingPrimitives in class PseudoCommand

checkAndConfirmOutlyingOperation

public static boolean checkAndConfirmOutlyingOperation(java.lang.String operation,
                                                       java.lang.String dialogTitle,
                                                       java.lang.String outsideDialogMessage,
                                                       java.lang.String incompleteDialogMessage,
                                                       java.awt.geom.Area area,
                                                       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. Request confirmation if he is.

Parameters:
operation - the operation name which is used for setting some preferences
dialogTitle - the title of the dialog being displayed
outsideDialogMessage - the message text to be displayed when data is outside of the download area
incompleteDialogMessage - the message text to be displayed when data is incomplete
area - the area used to determine whether data is outlying
primitives - the primitives to operate on
ignore - null or a primitive to be ignored
Returns:
true, if operating on outlying primitives is OK; false, otherwise

isOutlying

private static boolean isOutlying(OsmPrimitive osm,
                                  java.awt.geom.Area area)


JOSM