Package org.openstreetmap.josm.command
Class TransformNodesCommand
- java.lang.Object
-
- org.openstreetmap.josm.command.Command
-
- org.openstreetmap.josm.command.TransformNodesCommand
-
- All Implemented Interfaces:
PseudoCommand
- Direct Known Subclasses:
RotateCommand
,ScaleCommand
public abstract class TransformNodesCommand extends Command
Abstract class with common services for nodes rotation and scaling commands.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.openstreetmap.josm.command.Command
Command.OldNodeState
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.Collection<Node>
nodes
The nodes to transform.protected java.util.Map<Node,Command.OldNodeState>
oldStates
List of all old states of the nodes.-
Fields inherited from class org.openstreetmap.josm.command.Command
IS_INCOMPLETE, IS_OK, IS_OUTSIDE
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
TransformNodesCommand(java.util.Collection<? extends OsmPrimitive> objects)
Creates a TransformNodesObject.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description boolean
equals(java.lang.Object obj)
boolean
executeCommand()
Finally apply the transformation of the nodes.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.void
flagNodesAsModified()
Flag all nodes as modified.javax.swing.Icon
getDescriptionIcon()
Provides a descriptive icon of this command.java.lang.String
getDescriptionText()
Provides a description text representing this command.EastNorth
getNodesCenter()
Get the center of the nodes under modification.java.util.Collection<? extends OsmPrimitive>
getParticipatingPrimitives()
Return the primitives that take part in this command.java.util.Collection<Node>
getTransformedNodes()
Get the nodes with the current transformation applied.abstract void
handleEvent(EastNorth currentEN)
Handling of a mouse event (e.g.int
hashCode()
protected void
storeOldState()
Stores the state of the nodes before the command.protected abstract void
transformNodes()
Implementation for the nodes transformation.void
undoCommand()
Restore the state of the nodes from the backup.-
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
-
oldStates
protected final java.util.Map<Node,Command.OldNodeState> oldStates
List of all old states of the nodes.
-
-
Constructor Detail
-
TransformNodesCommand
protected TransformNodesCommand(java.util.Collection<? extends OsmPrimitive> objects)
Creates a TransformNodesObject. Find out the impacted nodes and store their initial state.- Parameters:
objects
- objects to fetch nodes from. Must neither be null nor empty. Items must belong to a data set- Throws:
java.lang.NullPointerException
- if objects is null or contain null itemjava.util.NoSuchElementException
- if objects is empty
-
-
Method Detail
-
storeOldState
protected final void storeOldState()
Stores the state of the nodes before the command.
-
handleEvent
public abstract void handleEvent(EastNorth currentEN)
Handling of a mouse event (e.g. dragging event).- Parameters:
currentEN
- the current world position of the mouse
-
transformNodes
protected abstract void transformNodes()
Implementation for the nodes transformation. No parameters are given here, you should handle the user input in handleEvent() and store it internally.
-
executeCommand
public boolean executeCommand()
Finally apply the transformation of the nodes. This is called when the user is happy with the current state of the command and its effects.- Overrides:
executeCommand
in classCommand
- Returns:
- true
-
flagNodesAsModified
public void flagNodesAsModified()
Flag all nodes as modified.
-
undoCommand
public void undoCommand()
Restore the state of the nodes from the backup.- 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
-
getParticipatingPrimitives
public java.util.Collection<? extends OsmPrimitive> 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
-
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
-
getTransformedNodes
public java.util.Collection<Node> getTransformedNodes()
Get the nodes with the current transformation applied.- Returns:
- nodes with the current transformation applied
-
getNodesCenter
public EastNorth getNodesCenter()
Get the center of the nodes under modification. It's just the barycenter.- Returns:
- center east/north of the nodes under modification
- See Also:
Geometry.getCentroid(java.util.List)
-
-