Changeset 31 in josm for src/org/openstreetmap/josm/command
- Timestamp:
- 2005-12-06T23:23:20+01:00 (20 years ago)
- Location:
- src/org/openstreetmap/josm/command
- Files:
-
- 1 added
- 1 deleted
- 5 edited
-
AddCommand.java (modified) (3 diffs)
-
ChangeKeyValueCommand.java (modified) (3 diffs)
-
CombineAndDeleteCommand.java (deleted)
-
Command.java (modified) (2 diffs)
-
DeleteCommand.java (modified) (3 diffs)
-
MoveCommand.java (modified) (6 diffs)
-
SequenceCommand.java (added)
Legend:
- Unmodified
- Added
- Removed
-
src/org/openstreetmap/josm/command/AddCommand.java
r30 r31 1 1 package org.openstreetmap.josm.command; 2 2 3 import java.awt.Component;4 3 import java.util.Collection; 5 4 6 import javax.swing.JLabel;7 8 5 import org.openstreetmap.josm.data.osm.DataSet; 9 import org.openstreetmap.josm.data.osm.Key;10 import org.openstreetmap.josm.data.osm.LineSegment;11 import org.openstreetmap.josm.data.osm.Node;12 6 import org.openstreetmap.josm.data.osm.OsmPrimitive; 13 import org.openstreetmap.josm.data.osm.Track; 14 import org.openstreetmap.josm.data.osm.visitor.SelectionComponentVisitor; 15 import org.openstreetmap.josm.data.osm.visitor.Visitor; 7 import org.openstreetmap.josm.data.osm.visitor.AddVisitor; 8 import org.openstreetmap.josm.data.osm.visitor.DeleteVisitor; 16 9 17 10 /** … … 26 19 * The dataset this command operates on. 27 20 */ 28 DataSet ds; 21 private DataSet ds; 29 22 30 /**31 * Helper that adds the object32 * @author imi33 */34 private final class AddVisitor implements Visitor {35 public void visit(Node n) {ds.nodes.add(n);}36 public void visit(LineSegment ls) {ds.lineSegments.add(ls);}37 public void visit(Track t) {ds.tracks.add(t);}38 public void visit(Key k) {throw new IllegalStateException("Keys are added by using ChangeKeyValueCommand");}39 }40 41 /**42 * Helper that deletes the object (for undo)43 * @author imi44 */45 private final class RemoveVisitor implements Visitor {46 public void visit(Node n) {ds.nodes.remove(n);}47 public void visit(LineSegment ls) {ds.lineSegments.remove(ls);}48 public void visit(Track t) {ds.tracks.remove(t);}49 public void visit(Key k) {throw new IllegalStateException("Keys are added by using ChangeKeyValueCommand");}50 }51 52 23 /** 53 24 * The primitive to add to the dataset. … … 64 35 65 36 public void executeCommand() { 66 osm.visit(new AddVisitor()); 37 osm.visit(new AddVisitor(ds)); 67 38 } 68 39 69 40 public void undoCommand() { 70 osm.visit(new RemoveVisitor());41 osm.visit(new DeleteVisitor(ds)); 71 42 } 72 43 73 public Component commandDescription() {74 SelectionComponentVisitor v = new SelectionComponentVisitor();75 osm.visit(v);76 return new JLabel("Add "+v.name, v.icon, JLabel.LEADING);77 }78 79 44 public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted, Collection<OsmPrimitive> added) { 80 45 added.add(osm); -
src/org/openstreetmap/josm/command/ChangeKeyValueCommand.java
r30 r31 1 1 package org.openstreetmap.josm.command; 2 2 3 import java.awt.Component;4 3 import java.util.Collection; 5 4 import java.util.HashMap; … … 8 7 import java.util.List; 9 8 import java.util.Map; 10 11 import javax.swing.JLabel;12 9 13 10 import org.openstreetmap.josm.data.osm.Key; … … 77 74 } 78 75 79 public Component commandDescription() {80 String objStr = objects.size()+" object" + (objects.size()==1?"":"s");81 if (value == null)82 return new JLabel("Delete the key '"+key+"' of "+objStr);83 return new JLabel("Change the key '"+key+"' of "+objStr+" to '"+value+"'");84 }85 86 76 public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted, Collection<OsmPrimitive> added) { 87 77 modified.addAll(objects); -
src/org/openstreetmap/josm/command/Command.java
r30 r31 1 1 package org.openstreetmap.josm.command; 2 2 3 import java.awt.Component;4 3 import java.util.Collection; 5 4 … … 32 31 33 32 /** 34 * Give a description of the command as component to draw35 */36 Component commandDescription();37 38 /**39 33 * Fill in the changed data this command operates on. 40 34 * Add to the lists, don't clear them. -
src/org/openstreetmap/josm/command/DeleteCommand.java
r30 r31 1 1 package org.openstreetmap.josm.command; 2 2 3 import java.awt.Component;4 3 import java.util.Collection; 5 6 import javax.swing.JLabel; 4 import java.util.HashSet; 7 5 8 6 import org.openstreetmap.josm.data.osm.DataSet; 9 import org.openstreetmap.josm.data.osm.Key;10 import org.openstreetmap.josm.data.osm.LineSegment;11 import org.openstreetmap.josm.data.osm.Node;12 7 import org.openstreetmap.josm.data.osm.OsmPrimitive; 13 import org.openstreetmap.josm.data.osm.Track; 8 import org.openstreetmap.josm.data.osm.visitor.AddVisitor; 9 import org.openstreetmap.josm.data.osm.visitor.CollectBackReferencesVisitor; 10 import org.openstreetmap.josm.data.osm.visitor.DeleteVisitor; 14 11 import org.openstreetmap.josm.data.osm.visitor.Visitor; 15 12 … … 23 20 * The dataset this command operates on. 24 21 */ 25 DataSet ds; 22 final DataSet ds; 23 /** 24 * The primitive that get deleted. 25 */ 26 final Collection<OsmPrimitive> data = new HashSet<OsmPrimitive>(); 26 27 27 /** 28 * Helper that adds the object. 29 * @author imi 30 */ 31 private final class AddVisitor implements Visitor { 32 public void visit(Node n) {ds.nodes.add(n);} 33 public void visit(LineSegment ls) {ds.lineSegments.add(ls);} 34 public void visit(Track t) {ds.tracks.add(t);} 35 public void visit(Key k) {throw new IllegalStateException("Keys are added by using ChangeKeyValueCommand");} 36 } 37 38 /** 39 * Helper that deletes the object. Does not respect back reference cache. 40 * @author imi 41 */ 42 private final class DeleteVisitor implements Visitor { 43 public void visit(Node n) {ds.nodes.remove(n);} 44 public void visit(LineSegment ls) {ds.lineSegments.remove(ls);} 45 public void visit(Track t) {ds.tracks.remove(t);} 46 public void visit(Key k) {throw new IllegalStateException("Keys are added by using ChangeKeyValueCommand");} 47 } 48 49 50 51 /** 52 * The primitives that are going to deleted. 53 */ 54 private final Collection<OsmPrimitive> data; 55 56 public DeleteCommand(DataSet ds, Collection<OsmPrimitive> data) { 28 public DeleteCommand(DataSet ds, OsmPrimitive osm) { 57 29 this.ds = ds; 58 this.data = data; 30 CollectBackReferencesVisitor v = new CollectBackReferencesVisitor(ds); 31 osm.visit(v); 32 data.addAll(v.data); 33 data.add(osm); 59 34 } 60 35 61 36 public void executeCommand() { 62 Visitor v = new DeleteVisitor(); 37 Visitor v = new DeleteVisitor(ds); 63 38 for (OsmPrimitive osm : data) 64 39 osm.visit(v); … … 66 41 67 42 public void undoCommand() { 68 Visitor v = new AddVisitor(); 43 Visitor v = new AddVisitor(ds); 69 44 for (OsmPrimitive osm : data) 70 45 osm.visit(v); 71 }72 73 public Component commandDescription() {74 return new JLabel("Delete "+data.size()+" primitives");75 46 } 76 47 -
src/org/openstreetmap/josm/command/MoveCommand.java
r30 r31 1 1 package org.openstreetmap.josm.command; 2 2 3 import java.awt.Component;4 3 import java.awt.geom.Point2D; 5 4 import java.util.Collection; … … 7 6 import java.util.LinkedList; 8 7 import java.util.List; 9 10 import javax.swing.JLabel;11 8 12 9 import org.openstreetmap.josm.data.osm.Node; … … 25 22 * The objects that should be moved. 26 23 */ 27 p rivate List<OsmPrimitive> objects;24 public List<Node> objects = new LinkedList<Node>(); 28 25 /** 29 26 * x difference movement. Coordinates are in northern/eastern … … 38 35 * x/y List of all old positions of the objects. 39 36 */ 40 private List<Point2D.Double> oldPositions; 41 37 private List<Point2D.Double> oldPositions = new LinkedList<Point2D.Double>(); 38 42 39 /** 43 40 * Create a MoveCommand and assign the initial object set and movement vector. 44 41 */ 45 42 public MoveCommand(Collection<OsmPrimitive> objects, double x, double y) { 46 this.objects = new LinkedList<OsmPrimitive>(objects);47 43 this.x = x; 48 44 this.y = y; 45 this.objects = getAffectedNodes(objects); 46 for (Node n : this.objects) 47 oldPositions.add(new Point2D.Double(n.coor.x, n.coor.y)); 49 48 } 50 49 51 public void executeCommand() { 50 /** 51 * @return a list of all nodes that will be moved if using the given set of 52 * objects. 53 */ 54 public static List<Node> getAffectedNodes(Collection<OsmPrimitive> objects) { 52 55 AllNodesVisitor visitor = new AllNodesVisitor(); 53 56 for (OsmPrimitive osm : objects) 54 57 osm.visit(visitor); 55 for (Node n : visitor.nodes) { 58 return new LinkedList<Node>(visitor.nodes); 59 } 60 61 /** 62 * Move the same set of objects again by the specified vector. The vectors 63 * are added together and so the resulting will be moved to the previous 64 * vector plus this one. 65 * 66 * The move is immediatly executed and any undo will undo both vectors to 67 * the original position the objects had before first moving. 68 */ 69 public void moveAgain(double x, double y) { 70 for (Node n : objects) { 71 n.coor.x += x; 72 n.coor.y += y; 73 } 74 this.x += x; 75 this.y += y; 76 } 77 78 public void executeCommand() { 79 for (Node n : objects) { 56 80 n.coor.x += x; 57 81 n.coor.y += y; … … 60 84 61 85 public void undoCommand() { 62 AllNodesVisitor visitor = new AllNodesVisitor();63 for (OsmPrimitive osm : objects)64 osm.visit(visitor);65 86 Iterator<Point2D.Double> it = oldPositions.iterator(); 66 for (Node n : visitor.nodes) {87 for (Node n : objects) { 67 88 Point2D.Double p = it.next(); 68 89 n.coor.x = p.x; … … 71 92 } 72 93 73 public Component commandDescription() {74 String xstr = Math.abs(x) + (x < 0 ? "W" : "E");75 String ystr = Math.abs(y) + (y < 0 ? "S" : "N");76 return new JLabel("Move "+objects.size()+" primitives "+xstr+" "+ystr);77 }78 79 94 public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted, Collection<OsmPrimitive> added) { 80 95 for (OsmPrimitive osm : objects) 81 if (!modified.contains(osm)) 82 modified.add(osm); 96 modified.add(osm); 83 97 } 84 98 }
Note:
See TracChangeset
for help on using the changeset viewer.
