Ignore:
Timestamp:
2009-10-13T19:40:21+02:00 (15 years ago)
Author:
jttt
Message:

Added PrimitiveData classes. Uses PrimitiveData as storage for Command's undo function

File:
1 edited

Legend:

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

    r2025 r2284  
    1313import org.openstreetmap.josm.data.osm.Node;
    1414import org.openstreetmap.josm.data.osm.OsmPrimitive;
     15import org.openstreetmap.josm.data.osm.PrimitiveData;
    1516import org.openstreetmap.josm.data.osm.Relation;
    1617import org.openstreetmap.josm.data.osm.Way;
     
    2526 *
    2627 * The command remembers the {@see OsmDataLayer} it is operating on.
    27  * 
     28 *
    2829 * @author imi
    2930 */
     
    3132
    3233    private static final class CloneVisitor extends AbstractVisitor {
    33         public Map<OsmPrimitive, OsmPrimitive> orig = new HashMap<OsmPrimitive, OsmPrimitive>();
     34        public Map<OsmPrimitive, PrimitiveData> orig = new HashMap<OsmPrimitive, PrimitiveData>();
    3435
    3536        public void visit(Node n) {
    36             orig.put(n, new Node(n));
     37            orig.put(n, n.save());
    3738        }
    3839        public void visit(Way w) {
    39             orig.put(w, new Way(w));
     40            orig.put(w, w.save());
    4041        }
    4142        public void visit(Relation e) {
    42             orig.put(e, new Relation(e));
     43            orig.put(e, e.save());
    4344        }
    4445    }
    4546
    4647    /** the map of OsmPrimitives in the original state to OsmPrimitives in cloned state */
    47     private Map<OsmPrimitive, OsmPrimitive> cloneMap = new HashMap<OsmPrimitive, OsmPrimitive>();
     48    private Map<OsmPrimitive, PrimitiveData> cloneMap = new HashMap<OsmPrimitive, PrimitiveData>();
    4849
    4950    /** the layer which this command is applied to */
     
    5657    /**
    5758     * Creates a new command in the context of a specific data layer
    58      * 
     59     *
    5960     * @param layer the data layer
    6061     */
     
    8687     */
    8788    public void undoCommand() {
    88         for (Entry<OsmPrimitive, OsmPrimitive> e : cloneMap.entrySet()) {
    89             e.getKey().cloneFrom(e.getValue());
     89        for (Entry<OsmPrimitive, PrimitiveData> e : cloneMap.entrySet()) {
     90            e.getKey().load(e.getValue(), layer.data);
    9091        }
    9192    }
     
    9596     * any buffer if it is not longer applicable to the dataset (e.g. it was part of
    9697     * the removed layer)
    97      * 
     98     *
    9899     * @param oldLayer the old layer
    99100     * @return true if this command
     
    109110     * of the object. Usually for undoing.
    110111     */
    111     public OsmPrimitive getOrig(OsmPrimitive osm) {
    112         OsmPrimitive o = cloneMap.get(osm);
     112    public PrimitiveData getOrig(OsmPrimitive osm) {
     113        PrimitiveData o = cloneMap.get(osm);
    113114        if (o != null)
    114115            return o;
    115116        Main.debug("unable to find osm with id: " + osm.getId() + " hashCode: " + osm.hashCode());
    116117        for (OsmPrimitive t : cloneMap.keySet()) {
    117             OsmPrimitive to = cloneMap.get(t);
     118            PrimitiveData to = cloneMap.get(t);
    118119            Main.debug("now: " + t.getId() + " hashCode: " + t.hashCode());
    119120            Main.debug("orig: " + to.getId() + " hashCode: " + to.hashCode());
     
    124125    /**
    125126     * Replies the layer this command is (or was) applied to.
    126      * 
     127     *
    127128     * @return
    128129     */
Note: See TracChangeset for help on using the changeset viewer.