Ignore:
Timestamp:
2012-08-10T21:01:12+02:00 (7 years ago)
Author:
akks
Message:

fix #7082 (?) - CTRL-drag in selection mode problem, see #7888: SelectAction and MoveCommand rework

File:
1 edited

Legend:

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

    r4918 r5418  
    3333    private Collection<Node> nodes = new LinkedList<Node>();
    3434    /**
     35     * Starting position, base command point, current (mouse-drag) position = startEN + (x,y) =
     36     */
     37    private EastNorth startEN;
     38
     39    /**
    3540     * x difference movement. Coordinates are in northern/eastern
    3641     */
     
    4045     */
    4146    private double y;
     47
     48    private double backupX;
     49    private double backupY;
    4250
    4351    /**
     
    4755    public static class OldState {
    4856        LatLon latlon;
     57        EastNorth en; // cached EastNorth to be used for applying exact displacenment
    4958        boolean modified;
    5059    }
     
    6675        this(objects, offset.getX(), offset.getY());
    6776    }
    68 
     77   
    6978    /**
    7079     * Create a MoveCommand and assign the initial object set and movement vector.
     
    7281    public MoveCommand(Collection<OsmPrimitive> objects, double x, double y) {
    7382        super();
     83        startEN = null;
     84        saveCheckpoint(); // (0,0) displacement will be saved
    7485        this.x = x;
    7586        this.y = y;
     
    7889            OldState os = new OldState();
    7990            os.latlon = new LatLon(n.getCoor());
     91            os.en = n.getEastNorth();
    8092            os.modified = n.isModified();
    8193            oldState.add(os);
     
    8395    }
    8496
     97     public MoveCommand(Collection<OsmPrimitive> objects, EastNorth start, EastNorth end) {
     98         this(objects, end.getX()-start.getX(), end.getY()-start.getY());
     99         startEN =  start;
     100     }
     101
     102     public MoveCommand(OsmPrimitive p, EastNorth start, EastNorth end) {
     103         this(Collections.singleton(p), end.getX()-start.getX(), end.getY()-start.getY());
     104         startEN =  start;
     105     }
     106     
    85107    /**
    86108     * Move the same set of objects again by the specified vector. The vectors
     
    102124        moveAgain(x - this.x, y - this.y);
    103125    }
     126   
     127    /**
     128     * Change the displacement vector to have endpoint @param currentEN
     129     * starting point is  startEN
     130     */
     131    public void applyVectorTo(EastNorth currentEN) {
     132        if (startEN == null)
     133            return;
     134        x = currentEN.getX() - startEN.getX();
     135        y = currentEN.getY() - startEN.getY();
     136        updateCoordinates();
     137    }
     138
     139     /**
     140     * Changes base point of movement
     141     * @param newDraggedStartPoint - new starting point after movement (where user clicks to start new drag)
     142     */
     143    public void changeStartPoint(EastNorth newDraggedStartPoint) {
     144        startEN = new EastNorth(newDraggedStartPoint.getX()-x, newDraggedStartPoint.getY()-y);
     145     }
     146
     147    /**
     148     * Save curent displacement to restore in case of some problems
     149     */
     150    public void saveCheckpoint() {
     151        backupX = x;
     152        backupY = y;
     153    }
     154
     155    /**
     156     * Restore old displacement in case of some problems
     157     */
     158    public void resetToCheckpoint() {
     159        x = backupX;
     160        y = backupY;
     161        updateCoordinates();
     162    }
     163
     164    private void updateCoordinates() {
     165        Iterator<OldState> it = oldState.iterator();
     166        for (Node n : nodes) {
     167            OldState os = it.next();
     168            n.setEastNorth(os.en.add(x, y));
     169        }
     170    }
    104171
    105172    @Override public boolean executeCommand() {
Note: See TracChangeset for help on using the changeset viewer.