Ignore:
Timestamp:
2013-08-22T00:33:32+02:00 (11 years ago)
Author:
Don-vip
Message:

fix #8987 - immutable coordinates (patch by shinigami)

File:
1 edited

Legend:

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

    r6069 r6173  
    99import java.util.LinkedList;
    1010import java.util.List;
     11
    1112import javax.swing.Icon;
    1213
     
    4849
    4950    /**
    50      * Small helper for holding the interesting part of the old data state of the
    51      * objects.
    52      */
    53     public static class OldState {
    54         LatLon latlon;
    55         EastNorth en; // cached EastNorth to be used for applying exact displacenment
    56         boolean modified;
    57     }
    58 
    59     /**
    6051     * List of all old states of the objects.
    6152     */
    62     private List<OldState> oldState = new LinkedList<OldState>();
     53    private List<OldNodeState> oldState = new LinkedList<OldNodeState>();
    6354
    6455    public MoveCommand(OsmPrimitive osm, double x, double y) {
     
    8576        this.nodes = AllNodesVisitor.getAllNodes(objects);
    8677        for (Node n : this.nodes) {
    87             OldState os = new OldState();
    88             os.latlon = new LatLon(n.getCoor());
    89             os.en = n.getEastNorth();
    90             os.modified = n.isModified();
    91             oldState.add(os);
    92         }
    93     }
    94 
    95      public MoveCommand(Collection<OsmPrimitive> objects, EastNorth start, EastNorth end) {
    96          this(objects, end.getX()-start.getX(), end.getY()-start.getY());
    97          startEN =  start;
    98      }
    99 
    100      public MoveCommand(OsmPrimitive p, EastNorth start, EastNorth end) {
    101          this(Collections.singleton(p), end.getX()-start.getX(), end.getY()-start.getY());
    102          startEN =  start;
    103      }
     78            oldState.add(new OldNodeState(n));
     79        }
     80    }
     81
     82    public MoveCommand(Collection<OsmPrimitive> objects, EastNorth start, EastNorth end) {
     83        this(objects, end.getX()-start.getX(), end.getY()-start.getY());
     84        startEN =  start;
     85    }
     86
     87    public MoveCommand(OsmPrimitive p, EastNorth start, EastNorth end) {
     88        this(Collections.singleton(p), end.getX()-start.getX(), end.getY()-start.getY());
     89        startEN =  start;
     90    }
    10491
    10592    /**
     
    135122    }
    136123
    137      /**
     124    /**
    138125     * Changes base point of movement
    139126     * @param newDraggedStartPoint - new starting point after movement (where user clicks to start new drag)
     
    141128    public void changeStartPoint(EastNorth newDraggedStartPoint) {
    142129        startEN = new EastNorth(newDraggedStartPoint.getX()-x, newDraggedStartPoint.getY()-y);
    143      }
     130    }
    144131
    145132    /**
     
    161148
    162149    private void updateCoordinates() {
    163         Iterator<OldState> it = oldState.iterator();
    164         for (Node n : nodes) {
    165             OldState os = it.next();
    166             n.setEastNorth(os.en.add(x, y));
     150        Iterator<OldNodeState> it = oldState.iterator();
     151        for (Node n : nodes) {
     152            OldNodeState os = it.next();
     153            n.setEastNorth(os.eastNorth.add(x, y));
    167154        }
    168155    }
     
    183170
    184171    @Override public void undoCommand() {
    185         Iterator<OldState> it = oldState.iterator();
    186         for (Node n : nodes) {
    187             OldState os = it.next();
     172        Iterator<OldNodeState> it = oldState.iterator();
     173        for (Node n : nodes) {
     174            OldNodeState os = it.next();
    188175            n.setCoor(os.latlon);
    189176            n.setModified(os.modified);
Note: See TracChangeset for help on using the changeset viewer.