Changeset 23 in josm for src/org/openstreetmap/josm/command


Ignore:
Timestamp:
2005-10-27T00:38:03+02:00 (20 years ago)
Author:
imi
Message:
  • added commands to support undo later
  • added Edit-Layer concept
  • painting of deleted objects
Location:
src/org/openstreetmap/josm/command
Files:
2 added
4 edited

Legend:

Unmodified
Added
Removed
  • src/org/openstreetmap/josm/command/AddCommand.java

    r22 r23  
    4343                SelectionComponentVisitor v = new SelectionComponentVisitor();
    4444                osm.visit(v);
    45                 return new JLabel(v.name, v.icon, JLabel.LEADING);
     45                return new JLabel("Add "+v.name, v.icon, JLabel.LEADING);
    4646        }
    4747       
    4848        public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted, Collection<OsmPrimitive> added) {
    49                 if (!added.contains(osm))
     49                if (added != null && !added.contains(osm))
    5050                        added.add(osm);
    5151        }
     
    6565        public void visit(LineSegment ls) {
    6666                Main.main.ds.pendingLineSegments.add(ls);
     67                Main.main.ds.addBackReference(ls.start, ls);
     68                Main.main.ds.addBackReference(ls.end, ls);
    6769        }
    6870
     
    7476                Main.main.ds.tracks.add(t);
    7577                for (Iterator<LineSegment> it =  Main.main.ds.pendingLineSegments.iterator(); it.hasNext();)
    76                         if (t.segments().contains(it.next()))
     78                        if (t.segments.contains(it.next()))
    7779                                it.remove();
     80                for (LineSegment ls : t.segments) {
     81                        Main.main.ds.addBackReference(ls, t);
     82                        Main.main.ds.addBackReference(ls.start, t);
     83                        Main.main.ds.addBackReference(ls.end, t);
     84                }
    7885        }
    7986
  • src/org/openstreetmap/josm/command/CombineCommand.java

    r22 r23  
    4646        public void executeCommand() {
    4747                if (del instanceof LineSegment) {
    48                         LineSegment ls = (LineSegment)mod;
    49                         Track t = (Track)del;
    50                         if (!Main.main.ds.pendingLineSegments().contains(ls))
     48                        LineSegment ls = (LineSegment)del;
     49                        Track t = (Track)mod;
     50                        if (!Main.main.ds.pendingLineSegments.contains(ls))
    5151                                throw new IllegalStateException("Should not be able to select non-pending line segments.");
    5252                       
    5353                        Main.main.ds.pendingLineSegments.remove(ls);
    54                         if (t.getStartingNode() != ls.getEnd())
     54                        if (t.getStartingNode() != ls.end)
    5555                                t.add(ls);
    5656                        else
    57                                 t.addStart(ls);
     57                                t.segments.add(0,ls);
    5858                } else {
    5959                        Track t1 = (Track)mod;
    6060                        Track t2 = (Track)del;
    61                         t1.addAll(t2.segments());
     61                        t1.segments.addAll(t2.segments);
    6262                        if (t1.keys == null)
    6363                                t1.keys = t2.keys;
    6464                        else   
    6565                                t1.keys.putAll(t2.keys);
    66                         t2.destroy();
    6766                        Main.main.ds.tracks.remove(t2);
    6867                }
     68                Main.main.ds.rebuildBackReferences();
    6969        }
    7070
     
    8282       
    8383        public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted, Collection<OsmPrimitive> added) {
    84                 if (!modified.contains(mod))
     84                if (modified != null && !modified.contains(mod))
    8585                        modified.add(mod);
    86                 if (deleted.contains(del))
     86                if (deleted != null && deleted.contains(del))
    8787                        throw new IllegalStateException("Deleted object twice: "+del);
    8888                deleted.add(del);
  • src/org/openstreetmap/josm/command/Command.java

    r22 r23  
    2727        /**
    2828         * Fill in the changed data this command operates on (for sending to the server).
    29          * Add to the lists, don't clear them.
    30          * @param modified  The modified primitives
    31          * @param deleted   The deleted primitives
    32          * @param added         The added primitives
     29         * Add to the lists, don't clear them. The lists can be <code>null</code>
     30         * in which case they are ignored.
     31         *
     32         * @param modified  The modified primitives or <code>null</code>
     33         * @param deleted   The deleted primitives or <code>null</code>
     34         * @param added         The added primitives or <code>null</code>
    3335         */
    3436        void fillModifiedData(Collection<OsmPrimitive> modified,
  • src/org/openstreetmap/josm/command/MoveCommand.java

    r22 r23  
    33import java.awt.Component;
    44import java.util.Collection;
    5 import java.util.HashSet;
    65
    76import javax.swing.JLabel;
     
    98import org.openstreetmap.josm.data.osm.Node;
    109import org.openstreetmap.josm.data.osm.OsmPrimitive;
     10import org.openstreetmap.josm.data.osm.visitor.AllNodesVisitor;
    1111
    1212/**
     
    4949
    5050        public void executeCommand() {
    51                 Collection<Node> movingNodes = new HashSet<Node>();
     51                AllNodesVisitor visitor = new AllNodesVisitor();
    5252                for (OsmPrimitive osm : objects)
    53                         movingNodes.addAll(osm.getAllNodes());
    54                 for (Node n : movingNodes) {
     53                        osm.visit(visitor);
     54                for (Node n : visitor.nodes) {
    5555                        n.coor.x += x;
    5656                        n.coor.y += y;
     
    6565
    6666        public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted, Collection<OsmPrimitive> added) {
    67                 for (OsmPrimitive osm : objects)
    68                         if (!modified.contains(osm))
    69                                 modified.add(osm);
     67                if (modified != null)
     68                        for (OsmPrimitive osm : objects)
     69                                if (!modified.contains(osm))
     70                                        modified.add(osm);
    7071        }
    7172}
Note: See TracChangeset for help on using the changeset viewer.