Ticket #8987: core.diff

File core.diff, 10.5 KB (added by shinigami, 13 years ago)
  • src/org/openstreetmap/josm/command/Command.java

     
    1515import javax.swing.JPanel;
    1616
    1717import org.openstreetmap.josm.Main;
     18import org.openstreetmap.josm.data.coor.EastNorth;
     19import org.openstreetmap.josm.data.coor.LatLon;
    1820import org.openstreetmap.josm.data.osm.Node;
    1921import org.openstreetmap.josm.data.osm.OsmPrimitive;
    2022import org.openstreetmap.josm.data.osm.PrimitiveData;
     
    5355        }
    5456    }
    5557
     58    /**
     59     * Small helper for holding the interesting part of the old data state of the
     60     * objects.
     61     */
     62    public static class OldNodeState {
     63
     64        final LatLon latlon;
     65        final EastNorth eastNorth; // cached EastNorth to be used for applying exact displacement
     66        final boolean modified;
     67
     68        public OldNodeState(Node node){
     69            latlon = node.getCoor();
     70            eastNorth = node.getEastNorth();
     71            modified = node.isModified();
     72        }
     73    }
     74
    5675    /** the map of OsmPrimitives in the original state to OsmPrimitives in cloned state */
    5776    private Map<OsmPrimitive, PrimitiveData> cloneMap = new HashMap<OsmPrimitive, PrimitiveData>();
    5877
  • src/org/openstreetmap/josm/command/MoveCommand.java

     
    88import java.util.Iterator;
    99import java.util.LinkedList;
    1010import java.util.List;
     11
    1112import javax.swing.Icon;
    1213
    1314import org.openstreetmap.josm.data.coor.EastNorth;
     
    4748    private double backupY;
    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) {
    6556        this(Collections.singleton(osm), x, y);
     
    8475        this.y = 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);
     78            oldState.add(new OldNodeState(n));
    9279        }
    9380    }
    9481
    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      }
     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    }
    9986
    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      }
     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    /**
    10693     * Move the same set of objects again by the specified vector. The vectors
     
    134121        updateCoordinates();
    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)
    140127     */
    141128    public void changeStartPoint(EastNorth newDraggedStartPoint) {
    142129        startEN = new EastNorth(newDraggedStartPoint.getX()-x, newDraggedStartPoint.getY()-y);
    143      }
     130    }
    144131
    145132    /**
    146133     * Save curent displacement to restore in case of some problems
     
    160147    }
    161148
    162149    private void updateCoordinates() {
    163         Iterator<OldState> it = oldState.iterator();
     150        Iterator<OldNodeState> it = oldState.iterator();
    164151        for (Node n : nodes) {
    165             OldState os = it.next();
    166             n.setEastNorth(os.en.add(x, y));
     152            OldNodeState os = it.next();
     153            n.setEastNorth(os.eastNorth.add(x, y));
    167154        }
    168155    }
    169156
     
    182169    }
    183170
    184171    @Override public void undoCommand() {
    185         Iterator<OldState> it = oldState.iterator();
     172        Iterator<OldNodeState> it = oldState.iterator();
    186173        for (Node n : nodes) {
    187             OldState os = it.next();
     174            OldNodeState os = it.next();
    188175            n.setCoor(os.latlon);
    189176            n.setModified(os.modified);
    190177        }
  • src/org/openstreetmap/josm/command/TransformNodesCommand.java

     
    1111import javax.swing.Icon;
    1212
    1313import org.openstreetmap.josm.data.coor.EastNorth;
    14 import org.openstreetmap.josm.data.coor.LatLon;
    1514import org.openstreetmap.josm.data.osm.Node;
    1615import org.openstreetmap.josm.data.osm.OsmPrimitive;
    1716import org.openstreetmap.josm.data.osm.visitor.AllNodesVisitor;
     
    2928     */
    3029    protected Collection<Node> nodes = new LinkedList<Node>();
    3130
    32     /**
    33      * Small helper for holding the interesting part of the old data state of the
    34      * nodes.
    35      */
    36     public static class OldState {
    37         LatLon latlon;
    38         EastNorth eastNorth;
    39         boolean modified;
    40     }
    4131
    4232    /**
    4333     * List of all old states of the nodes.
    4434     */
    45     protected Map<Node, OldState> oldStates = new HashMap<Node, OldState>();
     35    protected Map<Node, OldNodeState> oldStates = new HashMap<Node, OldNodeState>();
    4636
    4737    /**
    4838     * Stores the state of the nodes before the command.
    4939     */
    5040    protected void storeOldState() {
    5141        for (Node n : this.nodes) {
    52             OldState os = new OldState();
    53             os.latlon = new LatLon(n.getCoor());
    54             os.eastNorth = n.getEastNorth();
    55             os.modified = n.isModified();
    56             oldStates.put(n, os);
     42            oldStates.put(n, new OldNodeState(n));
    5743        }
    5844    }
    5945
     
    10692    @Override
    10793    public void undoCommand() {
    10894        for (Node n : nodes) {
    109             OldState os = oldStates.get(n);
     95            OldNodeState os = oldStates.get(n);
    11096            n.setCoor(os.latlon);
    11197            n.setModified(os.modified);
    11298        }
  • src/org/openstreetmap/josm/data/coor/EastNorth.java

     
    88 *
    99 * @author Imi
    1010 */
    11 public class EastNorth extends Coordinate implements Cloneable {
     11public class EastNorth extends Coordinate {
    1212
    1313    public EastNorth(double east, double north) {
    1414        super(east,north);
     
    3636
    3737    public EastNorth interpolate(EastNorth en2, double proportion) {
    3838        return new EastNorth(this.x + proportion * (en2.x - this.x),
    39             this.y + proportion * (en2.y - this.y));
     39                this.y + proportion * (en2.y - this.y));
    4040    }
    4141
    4242    public EastNorth getCenter(EastNorth en2) {
     
    5353    public double distance(final EastNorth en) {
    5454        return super.distance(en);
    5555    }
    56    
     56
    5757    /**
    5858     * Returns the square of the euclidean distance from this {@code EastNorth} to a specified {@code EastNorth}.
    5959     *
     
    7373    public double length(){
    7474        return Math.sqrt(x*x + y*y);
    7575    }
    76    
     76
    7777    /**
    7878     * Returns the heading, in radians, that you have to use to get from
    7979     * this EastNorth to another. Heading is mapped into [0, 2pi)
     
    8383     */
    8484    public double heading(EastNorth other) {
    8585        double hd = Math.atan2(other.east() - east(), other.north() - north());
    86         if(hd < 0) hd = 2 * Math.PI + hd;
     86        if(hd < 0) {
     87            hd = 2 * Math.PI + hd;
     88        }
    8789        return hd;
    8890    }
    8991
     
    129131    public boolean equalsEpsilon(EastNorth other, double e) {
    130132        return (Math.abs(x - other.x) < e && Math.abs(y - other.y) < e);
    131133    }
    132 
    133     @Override
    134     public EastNorth clone() throws CloneNotSupportedException {
    135         return (EastNorth) super.clone();
    136     }
    137134}
  • src/org/openstreetmap/josm/data/coor/LatLon.java

     
    2525 *
    2626 * @author Imi
    2727 */
    28 public class LatLon extends Coordinate implements Cloneable {
     28public class LatLon extends Coordinate {
    2929
    3030    /**
    3131     * Minimum difference in location to not be represented as the same position.
     
    157157        super(lon, lat);
    158158    }
    159159
    160     public LatLon(LatLon coor) {
     160    protected LatLon(LatLon coor) {
    161161        super(coor.lon(), coor.lat());
    162162    }
    163163
     
    221221    }
    222222
    223223    /**
    224      * Check if this is contained in given area or area is null. 
     224     * Check if this is contained in given area or area is null.
    225225     *
    226226     * @param a Area
    227      * @return <code>true</code> if this is contained in given area or area is null. 
     227     * @return <code>true</code> if this is contained in given area or area is null.
    228228     */
    229229    public boolean isIn(Area a) {
    230230        return a == null || a.contains(x, y);
     
    305305    public double distance(final LatLon ll) {
    306306        return super.distance(ll);
    307307    }
    308    
     308
    309309    /**
    310310     * Returns the square of the euclidean distance from this {@code LatLon} to a specified {@code LatLon}.
    311311     *
     
    316316    public double distanceSq(final LatLon ll) {
    317317        return super.distanceSq(ll);
    318318    }
    319    
     319
    320320    @Override public String toString() {
    321321        return "LatLon[lat="+lat()+",lon="+lon()+"]";
    322322    }
     
    394394            return false;
    395395        return true;
    396396    }
    397 
    398     @Override
    399     public LatLon clone() throws CloneNotSupportedException {
    400         return (LatLon) super.clone();
    401     }
    402397}