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


Ignore:
Timestamp:
2005-10-23T22:13:33+02:00 (20 years ago)
Author:
imi
Message:

starting restructure of dataset. Checkpoint is broken!

Location:
src/org/openstreetmap/josm/command
Files:
1 added
4 edited

Legend:

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

    r21 r22  
    22
    33import java.awt.Component;
     4import java.util.Collection;
    45import java.util.Iterator;
    56
    67import javax.swing.JLabel;
    78
     9import org.openstreetmap.josm.Main;
    810import org.openstreetmap.josm.data.osm.Key;
    911import org.openstreetmap.josm.data.osm.LineSegment;
     
    2628         */
    2729        private final OsmPrimitive osm;
    28         /**
    29          * The dataset to add the primitive to.
    30          */
    31         private final DataSet ds;
    3230
    3331        /**
    3432         * Create the command and specify the element to add.
    3533         */
    36         public AddCommand(OsmPrimitive osm, DataSet dataSet) {
     34        public AddCommand(OsmPrimitive osm) {
    3735                this.osm = osm;
    38                 this.ds = dataSet;
    3936        }
    4037
     
    4239                osm.visit(this);
    4340        }
    44 
     41       
    4542        public Component commandDescription() {
    4643                SelectionComponentVisitor v = new SelectionComponentVisitor();
    4744                osm.visit(v);
    4845                return new JLabel(v.name, v.icon, JLabel.LEADING);
     46        }
     47       
     48        public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted, Collection<OsmPrimitive> added) {
     49                if (!added.contains(osm))
     50                        added.add(osm);
    4951        }
    5052
     
    5456         */
    5557        public void visit(Node n) {
    56                 ds.nodes.add(n);
     58                Main.main.ds.nodes.add(n);
    5759        }
    5860
     
    6264         */
    6365        public void visit(LineSegment ls) {
    64                 ds.pendingLineSegments.add(ls);
     66                Main.main.ds.pendingLineSegments.add(ls);
    6567        }
    6668
     
    7072         */
    7173        public void visit(Track t) {
    72                 ds.addTrack(t);
    73                 for (Iterator<LineSegment> it =  ds.pendingLineSegments.iterator(); it.hasNext();)
     74                Main.main.ds.tracks.add(t);
     75                for (Iterator<LineSegment> it =  Main.main.ds.pendingLineSegments.iterator(); it.hasNext();)
    7476                        if (t.segments().contains(it.next()))
    7577                                it.remove();
  • src/org/openstreetmap/josm/command/Command.java

    r21 r22  
    22
    33import java.awt.Component;
     4import java.util.Collection;
     5
     6import org.openstreetmap.josm.data.osm.OsmPrimitive;
    47
    58
    69/**
    710 * Classes implementing Command modify a dataset in a specific way. A command is
    8  * one atomic action on a dataset, such as move or delete.
     11 * one atomic action on a specific dataset, such as move or delete.
    912 *
    1013 * @author imi
     
    1619         */
    1720        void executeCommand();
    18        
     21
    1922        /**
    2023         * Give a description of the command as component to draw
    2124         */
    2225        Component commandDescription();
     26       
     27        /**
     28         * 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
     33         */
     34        void fillModifiedData(Collection<OsmPrimitive> modified,
     35                        Collection<OsmPrimitive> deleted,
     36                        Collection<OsmPrimitive> added);
    2337}
  • src/org/openstreetmap/josm/command/DataSet.java

    r21 r22  
    205205         */
    206206        public void mergeFrom(DataSet ds, boolean mergeEqualNodes) {
    207                 System.out.println(nodes.size()+" "+pendingLineSegments.size()+" "+tracks.size());
    208                 if (mergeEqualNodes) {
     207                if (mergeEqualNodes && !nodes.isEmpty()) {
    209208                        Map<Node, Node> mergeMap = new HashMap<Node, Node>();
    210209                        Set<Node> nodesToAdd = new HashSet<Node>();
     
    247246                        pendingLineSegments.addAll(ds.pendingLineSegments);
    248247                }
    249                 System.out.println(nodes.size()+" "+pendingLineSegments.size()+" "+tracks.size());
    250248        }
    251249
     
    258256                        return;
    259257                for (OsmPrimitive osm : list) {
    260                         osm.setSelected(false, this);
     258                        osm.setSelected(false);
    261259                        if (osm.keys != null)
    262260                                clearSelection(osm.keys.keySet());
  • src/org/openstreetmap/josm/command/MoveCommand.java

    r21 r22  
    6363                return new JLabel("Move "+objects.size()+" primitives "+xstr+" "+ystr);
    6464        }
     65
     66        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);
     70        }
    6571}
Note: See TracChangeset for help on using the changeset viewer.