Ignore:
Timestamp:
2012-01-04T14:30:39+01:00 (13 years ago)
Author:
larry0ua
Message:

'PicLayer - now all actions are shown in history and user can undo/redo changes'

Location:
applications/editors/josm/plugins/piclayer
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/piclayer/build.xml

    r27352 r27403  
    2222-->
    2323<project name="PicLayer" default="dist" basedir=".">
    24     <property name="commit.message" value="PicLayer - fix of #7171"/>
     24    <property name="commit.message" value="PicLayer - now all actions are shown in history and user can undo/redo changes"/>
    2525    <property name="plugin.main.version" value="4669"/>
    2626    <!--
  • applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/actions/GenericPicTransformAction.java

    r27168 r27403  
    1313import org.openstreetmap.josm.gui.MapFrame;
    1414import org.openstreetmap.josm.gui.layer.Layer;
     15import org.openstreetmap.josm.plugins.piclayer.command.TransformCommand;
    1516import org.openstreetmap.josm.plugins.piclayer.layer.PicLayerAbstract;
    1617import org.openstreetmap.josm.tools.Shortcut;
     
    2425        protected EastNorth prevEastNorth = null;
    2526        protected Point2D prevMousePoint = null;
     27        protected TransformCommand currentCommand = null;
     28        private String actionName;
    2629
    27         public GenericPicTransformAction(String name, String iconName,
     30        public GenericPicTransformAction(String name, String actionName, String iconName,
    2831                        String tooltip, Shortcut shortcut, MapFrame mapFrame, Cursor cursor) {
    2932                super(name, iconName, tooltip, shortcut, mapFrame, cursor);
     33                this.actionName = actionName;
    3034        }
    3135
    32         public GenericPicTransformAction(String name, String iconName,
     36        public GenericPicTransformAction(String name, String actionName, String iconName,
    3337                        String tooltip, MapFrame mapFrame, Cursor cursor) {
    3438                super(name, iconName, tooltip, mapFrame, cursor);
     39        this.actionName = actionName;
    3540        }
    3641
     
    6166                    // try to find and fill selected point if possible
    6267                    selectedPoint = currentLayer.findSelectedPoint(e.getPoint());
     68                    currentCommand = new TransformCommand(currentLayer, actionName);
    6369                }
    6470            }
     
    8288            // End action
    8389            isDragging = false;
     90            currentCommand.addIfChanged();
    8491        }
    8592
  • applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/actions/ResetCalibrationAction.java

    r27120 r27403  
    55import java.awt.event.ActionEvent;
    66
    7 import org.openstreetmap.josm.Main;
    87import org.openstreetmap.josm.actions.JosmAction;
     8import org.openstreetmap.josm.plugins.piclayer.command.TransformCommand;
    99import org.openstreetmap.josm.plugins.piclayer.layer.PicLayerAbstract;
    1010import org.openstreetmap.josm.plugins.piclayer.transform.PictureTransform;
     
    1818                this.layer = layer;
    1919        }
    20        
     20
    2121        @Override
    2222        public void actionPerformed(ActionEvent arg0) {
     23            TransformCommand currentCommand = new TransformCommand(layer, tr("Calibration reset"));
    2324                layer.resetCalibration();
    24                 Main.map.mapView.repaint();
     25                currentCommand.addIfChanged();
    2526        }
    2627}
  • applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/actions/transform/MovePictureAction.java

    r27120 r27403  
    2626
    2727import org.openstreetmap.josm.Main;
     28import org.openstreetmap.josm.data.coor.EastNorth;
    2829import org.openstreetmap.josm.gui.MapFrame;
    2930import org.openstreetmap.josm.plugins.piclayer.actions.GenericPicTransformAction;
    3031import org.openstreetmap.josm.tools.ImageProvider;
    31 import org.openstreetmap.josm.data.coor.EastNorth;
    3232
    3333/**
     
    4141     */
    4242    public MovePictureAction(MapFrame frame) {
    43         super(tr("PicLayer move"), "move", tr("Drag to move the picture"), frame, ImageProvider.getCursor("crosshair", null));
     43        super(tr("PicLayer move"), tr("Moved"), "move", tr("Drag to move the picture"), frame, ImageProvider.getCursor("crosshair", null));
    4444    }
    4545
  • applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/actions/transform/RotatePictureAction.java

    r27120 r27403  
    4141     */
    4242    public RotatePictureAction(MapFrame frame) {
    43         super(tr("PicLayer rotate"), "rotate", tr("Drag to rotate the picture"), frame, ImageProvider.getCursor("crosshair", null));
     43        super(tr("PicLayer rotate"), tr("Rotated"), "rotate", tr("Drag to rotate the picture"), frame, ImageProvider.getCursor("crosshair", null));
    4444    }
    4545
     
    5252        else {
    5353            factor = Main.pref.getDouble("piclayer.rotatefactors.low_precision", 10.0 );
    54         }           
     54        }
    5555        currentLayer.rotatePictureBy( ( e.getY() - prevMousePoint.getY() ) / factor );
    5656        }
  • applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/actions/transform/ScalePictureActionAbstract.java

    r27120 r27403  
    3838     * Constructor
    3939     */
    40     public ScalePictureActionAbstract (String name, String icon, String tooltip, MapFrame frame) {
    41         super(name, icon, tooltip, frame, ImageProvider.getCursor("crosshair", null));
     40    public ScalePictureActionAbstract (String name, String actionName, String icon, String tooltip, MapFrame frame) {
     41        super(name, actionName, icon, tooltip, frame, ImageProvider.getCursor("crosshair", null));
    4242    }
    4343
     44    @Override
    4445    protected void doAction(MouseEvent e) {
    4546        double factor;
     
    4950        else {
    5051            factor = Main.pref.getDouble("piclayer.scalefactors.low_precision", 1.015);
    51         }           
     52        }
    5253        doTheScale( Math.pow(factor, prevMousePoint.getY() - e.getY() ) );
    5354    }
  • applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/actions/transform/ScaleXPictureAction.java

    r27120 r27403  
    3535     */
    3636    public ScaleXPictureAction(MapFrame frame) {
    37         super(tr("PicLayer scale X"), "scale_x", tr("Drag to scale the picture in the X Axis"), frame);
     37        super(tr("PicLayer scale X"), tr("Scaled by X"), "scale_x", tr("Drag to scale the picture in the X Axis"), frame);
    3838    }
    3939
     40    @Override
    4041    public void doTheScale( double scale ) {
    4142            currentLayer.scalePictureBy( scale, 1.0 );
  • applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/actions/transform/ScaleXYPictureAction.java

    r27120 r27403  
    3535     */
    3636    public ScaleXYPictureAction(MapFrame frame) {
    37         super(tr("PicLayer scale"), "scale", tr("Drag to scale the picture in the X and Y Axis"), frame);
     37        super(tr("PicLayer scale"), tr("Scaled"), "scale", tr("Drag to scale the picture in the X and Y Axis"), frame);
    3838    }
    3939
     40    @Override
    4041    public void doTheScale( double scale ) {
    4142            currentLayer.scalePictureBy( scale, scale );
  • applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/actions/transform/ScaleYPictureAction.java

    r27120 r27403  
    3535     */
    3636    public ScaleYPictureAction(MapFrame frame) {
    37         super(tr("PicLayer scale Y"), "scale_y", tr("Drag to scale the picture in the Y Axis"), frame);
     37        super(tr("PicLayer scale Y"), tr("Scaled by Y"), "scale_y", tr("Drag to scale the picture in the Y Axis"), frame);
    3838    }
    3939
     40    @Override
    4041    public void doTheScale( double scale ) {
    4142        currentLayer.scalePictureBy( 1.0, scale );
  • applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/actions/transform/ShearPictureAction.java

    r27120 r27403  
    2828
    2929import org.openstreetmap.josm.Main;
     30import org.openstreetmap.josm.data.coor.EastNorth;
    3031import org.openstreetmap.josm.gui.MapFrame;
    3132import org.openstreetmap.josm.plugins.piclayer.actions.GenericPicTransformAction;
    3233import org.openstreetmap.josm.tools.ImageProvider;
    33 import org.openstreetmap.josm.data.coor.EastNorth;
    3434
    3535/**
     
    4343     */
    4444    public ShearPictureAction(MapFrame frame) {
    45         super(tr("PicLayer shear"), "shear", tr("Drag to shear the picture"), frame, ImageProvider.getCursor("crosshair", null));
     45        super(tr("PicLayer shear"), tr("Sheared"), "shear", tr("Drag to shear the picture"), frame, ImageProvider.getCursor("crosshair", null));
    4646    }
    4747
  • applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/actions/transform/affine/MovePointAction.java

    r27168 r27403  
    77import java.awt.geom.Point2D;
    88
    9 import org.openstreetmap.josm.Main;
    109import org.openstreetmap.josm.gui.MapFrame;
    1110import org.openstreetmap.josm.plugins.piclayer.actions.GenericPicTransformAction;
     
    1716
    1817        public MovePointAction(MapFrame frame) {
    19         super(tr("PicLayer Move point"), "movepoint", tr("Drag or create point on the picture"), frame, ImageProvider.getCursor("crosshair", null));
     18        super(tr("PicLayer Move point"), tr("Point added/moved"), "movepoint", tr("Drag or create point on the picture"), frame, ImageProvider.getCursor("crosshair", null));
    2019        }
    2120
     
    4241                        if (selectedPoint == null)
    4342                                currentLayer.getTransformer().addOriginPoint(pressed);
     43
     44                        currentCommand.addIfChanged();
    4445                } catch (NoninvertibleTransformException e1) {
    4546                        e1.printStackTrace();
    4647                }
    47                 Main.map.mapView.repaint();
    4848        }
    4949
  • applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/actions/transform/affine/TransformPointAction.java

    r27168 r27403  
    1717
    1818        public TransformPointAction(MapFrame frame) {
    19                 super(tr("PicLayer Transform point"), "transformpoint", tr("Transform point on the picture"), frame, ImageProvider.getCursor("crosshair", null));
     19                super(tr("PicLayer Transform point"), tr("Point transformed"), "transformpoint", tr("Transform point on the picture"), frame, ImageProvider.getCursor("crosshair", null));
    2020        }
    2121
     
    3030                                currentLayer.getTransformer().updatePair(selectedPoint, pressed);
    3131                        }
     32
     33                        currentCommand.addIfChanged();
    3234                } catch (NoninvertibleTransformException e1) {
    3335                        e1.printStackTrace();
  • applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/layer/PicLayerAbstract.java

    r27231 r27403  
    575575        return selected;
    576576    }
     577
     578    public void saveTransformCommand() {
     579
     580    }
    577581}
  • applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/transform/PictureTransform.java

    r27191 r27403  
    1212
    1313        private List<Point2D> originPoints;
    14         private List<Point2D> desiredPoints;
    1514
    1615        public PictureTransform() {
    1716                cachedTransform = new AffineTransform();
    1817                originPoints = new ArrayList<Point2D>(3);
    19                 desiredPoints = new ArrayList<Point2D>(3);
    2018        }
    2119
     
    2422        }
    2523
    26         public List<? extends Point2D> getOriginPoints() {
    27                 return originPoints;
    28         }
    29 
    30         public List<? extends Point2D> getDesiredPoints() {
    31                 return desiredPoints;
    32         }
    33 
    34         public void addDesiredPoint(Point2D picturePoint) {
    35                 if (desiredPoints.size() < 3)
    36                         desiredPoints.add(picturePoint);
    37                 trySolve();
    38         }
    39 
    40         private AffineTransform solveEquation() throws NoSolutionException {
     24        private AffineTransform solveEquation(List<Point2D> desiredPoints) throws NoSolutionException {
    4125                Matrix3D X = new Matrix3D(originPoints);
    4226                Matrix3D Y = new Matrix3D(desiredPoints);
     
    4933                if (originPoints.size() < 3)
    5034                        originPoints.add(originPoint);
    51                 trySolve();
    5235        }
    5336
    5437        public void resetCalibration() {
    5538                originPoints.clear();
    56                 desiredPoints.clear();
    5739                modified = false;
    5840                cachedTransform = new AffineTransform();
    59         }
    60 
    61         private void trySolve() {
    62                 if (desiredPoints.size() == 3 && originPoints.size() == 3) {
    63                         try {
    64                                 cachedTransform.concatenate(solveEquation());
    65                                 modified = true;
    66                                 desiredPoints.clear();
    67                         } catch (NoSolutionException e) {
    68                                 System.err.println(e.getMessage());
    69                         }
    70                 }
    7141        }
    7242
     
    8656                        return;
    8757
    88                 desiredPoints.clear();
     58                List<Point2D> desiredPoints = new ArrayList<Point2D>(3);
    8959
    9060                for (Point2D origin : originPoints) {
     
    9464                                desiredPoints.add(origin);
    9565                }
    96                 trySolve();
     66                trySolve(desiredPoints);
    9767        }
     68
     69    private void trySolve(List<Point2D> desiredPoints) {
     70        if (desiredPoints.size() == 3 && originPoints.size() == 3) {
     71            try {
     72                cachedTransform.concatenate(solveEquation(desiredPoints));
     73                modified = true;
     74                desiredPoints.clear();
     75            } catch (NoSolutionException e) {
     76                System.err.println(e.getMessage());
     77            }
     78        }
     79    }
    9880
    9981        public void replaceOriginPoint(Point2D originPoint, Point2D newOriginPoint) {
     
    135117        modified = false;
    136118    }
     119
     120    public void setTransform(AffineTransform newTransform) {
     121        cachedTransform = new AffineTransform(newTransform);
     122    }
     123
     124    public List<Point2D> getOriginPoints() {
     125        return originPoints;
     126    }
     127
     128    public void setOriginPoints(List<Point2D> list) {
     129        this.originPoints = new ArrayList<Point2D>(list);
     130    }
    137131}
Note: See TracChangeset for help on using the changeset viewer.