Changeset 1169 in josm for trunk/src/org/openstreetmap/josm/command/AddCommand.java
- Timestamp:
- 2008-12-23T15:07:05+01:00 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/command/AddCommand.java
r655 r1169 22 22 * A command that adds an osm primitive to a dataset. Keys cannot be added this 23 23 * way. 24 * 24 * 25 25 * See {@link ChangeCommand ChangeCommand} for comments on relation back references. 26 * 26 * 27 27 * @author imi 28 28 */ 29 29 public class AddCommand extends Command { 30 30 31 /** 32 * The primitive to add to the dataset. 33 */ 34 private final OsmPrimitive osm; 35 36 private DataSet ds; 31 /** 32 * The primitive to add to the dataset. 33 */ 34 private final OsmPrimitive osm; 37 35 38 /** 39 * Create the command and specify the element to add. 40 */ 41 public AddCommand(OsmPrimitive osm) { 42 this.osm = osm; 43 this.ds = Main.main.editLayer().data; 44 } 36 private DataSet ds; 45 37 46 @Override public boolean executeCommand() { 47 osm.visit(new AddVisitor(ds)); 48 return true; 49 } 50 51 @Override public void undoCommand() { 52 osm.visit(new DeleteVisitor(ds)); 53 } 54 55 @Override public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted, Collection<OsmPrimitive> added) { 56 added.add(osm); 57 } 58 59 // faster implementation 60 @Override public boolean invalidBecauselayerRemoved(Layer oldLayer) { 61 return oldLayer instanceof OsmDataLayer && ((OsmDataLayer)oldLayer).data == ds; 38 /** 39 * Create the command and specify the element to add. 40 */ 41 public AddCommand(OsmPrimitive osm) { 42 this.osm = osm; 43 this.ds = Main.main.editLayer().data; 62 44 } 63 45 64 @Override public MutableTreeNode description() { 65 NameVisitor v = new NameVisitor(); 66 osm.visit(v); 67 return new DefaultMutableTreeNode(new JLabel(tr("Add")+" "+tr(v.className)+" "+v.name, v.icon, JLabel.HORIZONTAL)); 46 @Override public boolean executeCommand() { 47 osm.visit(new AddVisitor(ds)); 48 return true; 49 } 50 51 @Override public void undoCommand() { 52 osm.visit(new DeleteVisitor(ds)); 53 } 54 55 @Override public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted, Collection<OsmPrimitive> added) { 56 added.add(osm); 57 } 58 59 // faster implementation 60 @Override public boolean invalidBecauselayerRemoved(Layer oldLayer) { 61 return oldLayer instanceof OsmDataLayer && ((OsmDataLayer)oldLayer).data == ds; 62 } 63 64 @Override public MutableTreeNode description() { 65 NameVisitor v = new NameVisitor(); 66 osm.visit(v); 67 return new DefaultMutableTreeNode(new JLabel(tr("Add")+" "+tr(v.className)+" "+v.name, v.icon, JLabel.HORIZONTAL)); 68 68 } 69 69 }
Note:
See TracChangeset
for help on using the changeset viewer.