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


Ignore:
Timestamp:
2007-08-10T21:12:53+02:00 (18 years ago)
Author:
imi
Message:
  • fixed a bug that nodes were not created when no data layer was loaded
  • deprecated Main.map.mapView.addLayerChangeListener.
Location:
src/org/openstreetmap/josm/command
Files:
2 edited

Legend:

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

    r301 r304  
    1616import org.openstreetmap.josm.data.osm.visitor.DeleteVisitor;
    1717import org.openstreetmap.josm.data.osm.visitor.NameVisitor;
     18import org.openstreetmap.josm.gui.layer.Layer;
     19import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    1820
    1921/**
     
    3739        public AddCommand(OsmPrimitive osm) {
    3840                this.osm = osm;
    39                 this.ds = Main.ds;
     41                this.ds = Main.main.editLayer().data;
    4042        }
    4143
     
    5254        }
    5355
     56        // faster implementation
     57        @Override public boolean invalidBecauselayerRemoved(Layer oldLayer) {
     58            return oldLayer instanceof OsmDataLayer && ((OsmDataLayer)oldLayer).data == ds;
     59    }
     60
    5461        @Override public MutableTreeNode description() {
    5562                NameVisitor v = new NameVisitor();
  • src/org/openstreetmap/josm/command/Command.java

    r298 r304  
    1 // License: GPL. Copyright 2007 by Immanuel Scholz and others
     1//License: GPL. Copyright 2007 by Immanuel Scholz and others
    22package org.openstreetmap.josm.command;
    33
     
    1515import org.openstreetmap.josm.data.osm.Way;
    1616import org.openstreetmap.josm.data.osm.visitor.Visitor;
     17import org.openstreetmap.josm.gui.layer.Layer;
     18import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    1719
    1820
     
    3133        private static final class CloneVisitor implements Visitor {
    3234                public Map<OsmPrimitive, OsmPrimitive> orig = new HashMap<OsmPrimitive, OsmPrimitive>();
    33                
     35
    3436                public void visit(Node n) {
    3537                        orig.put(n, new Node(n));
    36             }
     38                }
    3739                public void visit(Segment s) {
    3840                        orig.put(s, new Segment(s));
    39             }
     41                }
    4042                public void visit(Way w) {
    4143                        orig.put(w, new Way(w));
    42             }
     44                }
    4345        }
    44        
     46
    4547        private CloneVisitor orig;
    46        
     48
    4749        /**
    4850         * Executes the command on the dataset. This implementation will remember all
     
    6971        }
    7072
     73
     74        /**
     75         * Called, when a layer has been removed to have the command remove itself from
     76         * any buffer if it is not longer applicable to the dataset (e.g. it was part of
     77         * the removed layer)
     78         */
     79        public boolean invalidBecauselayerRemoved(Layer oldLayer) {
     80                if (!(oldLayer instanceof OsmDataLayer))
     81                        return false;
     82                HashSet<OsmPrimitive> modified = new HashSet<OsmPrimitive>();
     83                fillModifiedData(modified, modified, modified);
     84                if (modified.isEmpty())
     85                        return false;
     86
     87                HashSet<OsmPrimitive> all = new HashSet<OsmPrimitive>(((OsmDataLayer)oldLayer).data.allPrimitives());
     88                for (OsmPrimitive osm : all)
     89                        if (all.contains(osm))
     90                                return true;
     91
     92                return false;
     93        }
     94
    7195        /**
    7296         * Fill in the changed data this command operates on.
Note: See TracChangeset for help on using the changeset viewer.