Index: /applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/PicLayerPlugin.java
===================================================================
--- /applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/PicLayerPlugin.java	(revision 30355)
+++ /applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/PicLayerPlugin.java	(revision 30356)
@@ -118,7 +118,7 @@
 
     private IconToggleButton picLayerActionButtonFactory(MapMode action) {
-    	IconToggleButton button = new IconToggleButton(action);
-    	button.setAutoHideDisabledButton(true);
-    	return button;
+        IconToggleButton button = new IconToggleButton(action);
+        button.setAutoHideDisabledButton(true);
+        return button;
     }
 
@@ -136,5 +136,5 @@
 
         if (newPic) {
-        	((PicLayerAbstract)newLayer).setDrawPoints(true);
+            ((PicLayerAbstract)newLayer).setDrawPoints(true);
         }
     }
Index: /applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/actions/GenericPicTransformAction.java
===================================================================
--- /applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/actions/GenericPicTransformAction.java	(revision 30355)
+++ /applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/actions/GenericPicTransformAction.java	(revision 30356)
@@ -20,61 +20,61 @@
 public abstract class GenericPicTransformAction extends MapMode implements MouseListener, MouseMotionListener {
 
-	protected boolean isDragging = false;
-	protected PicLayerAbstract currentLayer = null;
-	protected Point2D selectedPoint = null;
-	protected EastNorth prevEastNorth = null;
-	protected Point2D prevMousePoint = null;
-	protected TransformCommand currentCommand = null;
-	private String actionName;
+    protected boolean isDragging = false;
+    protected PicLayerAbstract currentLayer = null;
+    protected Point2D selectedPoint = null;
+    protected EastNorth prevEastNorth = null;
+    protected Point2D prevMousePoint = null;
+    protected TransformCommand currentCommand = null;
+    private String actionName;
 
-	public GenericPicTransformAction(String name, String actionName, String iconName,
-			String tooltip, Shortcut shortcut, MapFrame mapFrame, Cursor cursor) {
-		super(name, iconName, tooltip, shortcut, mapFrame, cursor);
-		this.actionName = actionName;
-	}
+    public GenericPicTransformAction(String name, String actionName, String iconName,
+            String tooltip, Shortcut shortcut, MapFrame mapFrame, Cursor cursor) {
+        super(name, iconName, tooltip, shortcut, mapFrame, cursor);
+        this.actionName = actionName;
+    }
 
-	public GenericPicTransformAction(String name, String actionName, String iconName,
-			String tooltip, MapFrame mapFrame, Cursor cursor) {
-		super(name, iconName, tooltip, mapFrame, cursor);
+    public GenericPicTransformAction(String name, String actionName, String iconName,
+            String tooltip, MapFrame mapFrame, Cursor cursor) {
+        super(name, iconName, tooltip, mapFrame, cursor);
         this.actionName = actionName;
-	}
+    }
 
-	@Override
-	public void enterMode() {
-	    super.enterMode();
-	    Main.map.mapView.addMouseListener(this);
-	    Main.map.mapView.addMouseMotionListener(this);
-	}
+    @Override
+    public void enterMode() {
+        super.enterMode();
+        Main.map.mapView.addMouseListener(this);
+        Main.map.mapView.addMouseMotionListener(this);
+    }
 
-	@Override
-	public void exitMode() {
-	    super.exitMode();
-	    Main.map.mapView.removeMouseListener(this);
-	    Main.map.mapView.removeMouseMotionListener(this);
-	}
+    @Override
+    public void exitMode() {
+        super.exitMode();
+        Main.map.mapView.removeMouseListener(this);
+        Main.map.mapView.removeMouseMotionListener(this);
+    }
 
-	@Override
-	public void mousePressed(MouseEvent e) {
-	    // Start action
-	    if ( Main.map.mapView.getActiveLayer() instanceof PicLayerAbstract ) {
-	        currentLayer = (PicLayerAbstract)Main.map.mapView.getActiveLayer();
+    @Override
+    public void mousePressed(MouseEvent e) {
+        // Start action
+        if ( Main.map.mapView.getActiveLayer() instanceof PicLayerAbstract ) {
+            currentLayer = (PicLayerAbstract)Main.map.mapView.getActiveLayer();
 
-	        if ( currentLayer != null && e.getButton() == MouseEvent.BUTTON1 ) {
-	            requestFocusInMapView();
-	            isDragging = true;
-	            prevMousePoint = new Point(e.getPoint());
-	            prevEastNorth = Main.map.mapView.getEastNorth(e.getX(),e.getY());
-	            // try to find and fill selected point if possible
-	            selectedPoint = currentLayer.findSelectedPoint(e.getPoint());
-	            currentCommand = new TransformCommand(currentLayer, actionName);
-	        }
-	    }
-	}
+            if ( currentLayer != null && e.getButton() == MouseEvent.BUTTON1 ) {
+                requestFocusInMapView();
+                isDragging = true;
+                prevMousePoint = new Point(e.getPoint());
+                prevEastNorth = Main.map.mapView.getEastNorth(e.getX(),e.getY());
+                // try to find and fill selected point if possible
+                selectedPoint = currentLayer.findSelectedPoint(e.getPoint());
+                currentCommand = new TransformCommand(currentLayer, actionName);
+            }
+        }
+    }
 
-	@Override
+    @Override
     public void mouseDragged(MouseEvent e) {
         // Call action performing
         if(isDragging && currentLayer != null) {
-        	doAction(e);
+            doAction(e);
             prevMousePoint = new Point(e.getPoint());
             prevEastNorth = Main.map.mapView.getEastNorth(e.getX(),e.getY());
@@ -83,26 +83,26 @@
     }
 
-	protected abstract void doAction(MouseEvent e);
+    protected abstract void doAction(MouseEvent e);
 
-	@Override
-	public void mouseReleased(MouseEvent e) {
-	    // End action
-	    isDragging = false;
-	    if (currentCommand != null)
-	        currentCommand.addIfChanged();
-	}
+    @Override
+    public void mouseReleased(MouseEvent e) {
+        // End action
+        isDragging = false;
+        if (currentCommand != null)
+            currentCommand.addIfChanged();
+    }
 
-	@Override
-	public boolean layerIsSupported(Layer l) {
-		return l instanceof PicLayerAbstract;
-	}
+    @Override
+    public boolean layerIsSupported(Layer l) {
+        return l instanceof PicLayerAbstract;
+    }
 
-	protected void updateDrawPoints(boolean value) {
-	    Layer active = Main.map.mapView.getActiveLayer();
+    protected void updateDrawPoints(boolean value) {
+        Layer active = Main.map.mapView.getActiveLayer();
         if (active instanceof PicLayerAbstract) {
             ((PicLayerAbstract)active).setDrawPoints(value);
         }
         Main.map.mapView.repaint();
-	}
+    }
 
 }
Index: /applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/actions/ResetCalibrationAction.java
===================================================================
--- /applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/actions/ResetCalibrationAction.java	(revision 30355)
+++ /applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/actions/ResetCalibrationAction.java	(revision 30356)
@@ -13,15 +13,15 @@
 public class ResetCalibrationAction extends JosmAction {
 
-	private PicLayerAbstract layer;
-	public ResetCalibrationAction(PicLayerAbstract layer, PictureTransform transformer) {
-		super(tr("Reset Calibration"), null, tr("Reset calibration"), null, false);
-		this.layer = layer;
-	}
+    private PicLayerAbstract layer;
+    public ResetCalibrationAction(PicLayerAbstract layer, PictureTransform transformer) {
+        super(tr("Reset Calibration"), null, tr("Reset calibration"), null, false);
+        this.layer = layer;
+    }
 
-	@Override
-	public void actionPerformed(ActionEvent arg0) {
-	    TransformCommand currentCommand = new TransformCommand(layer, tr("Calibration reset"));
-		layer.resetCalibration();
-		currentCommand.addIfChanged();
-	}
+    @Override
+    public void actionPerformed(ActionEvent arg0) {
+        TransformCommand currentCommand = new TransformCommand(layer, tr("Calibration reset"));
+        layer.resetCalibration();
+        currentCommand.addIfChanged();
+    }
 }
Index: /applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/actions/newlayer/NewLayerFromFileAction.java
===================================================================
--- /applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/actions/newlayer/NewLayerFromFileAction.java	(revision 30355)
+++ /applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/actions/newlayer/NewLayerFromFileAction.java	(revision 30356)
@@ -134,17 +134,17 @@
                     KMLReader kml = new KMLReader(file);
                     kml.process();
-                    JOptionPane.showMessageDialog(null, tr("KML calibration is in beta stage and may produce incorrectly calibrated layers!\nPlease use http://josm.openstreetmap.de/ticket/5451 to upload your KMLs that were calibrated incorrectly."));
+                    JOptionPane.showMessageDialog(null, tr("KML calibration is in beta stage and may produce incorrectly calibrated layers!\n"+
+                    "Please use {0} to upload your KMLs that were calibrated incorrectly.",
+                    "https://josm.openstreetmap.de/ticket/5451"));
                     for (KMLGroundOverlay overlay : kml.getGroundOverlays()) {
                         //TODO: zoom to whole picture, not only the last
                         addNewLayerFromKML(file, overlay, newLayerPos);
                     }
-
                 } else {
-                addNewLayerFromFile(file, newLayerPos, fc.getSelectedFiles().length == 1);
-
+                    addNewLayerFromFile(file, newLayerPos, fc.getSelectedFiles().length == 1);
+                }
             }
         }
     }
-}
 
     private void addNewLayerFromFile(File file, int newLayerPos, boolean isZoomToLayer) {
Index: /applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/actions/transform/MovePictureAction.java
===================================================================
--- /applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/actions/transform/MovePictureAction.java	(revision 30355)
+++ /applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/actions/transform/MovePictureAction.java	(revision 30356)
@@ -44,12 +44,12 @@
     }
 
-	@Override
-	protected void doAction(MouseEvent e) {
-		EastNorth eastNorth = Main.map.mapView.getEastNorth(e.getX(),e.getY());
+    @Override
+    protected void doAction(MouseEvent e) {
+        EastNorth eastNorth = Main.map.mapView.getEastNorth(e.getX(),e.getY());
         currentLayer.movePictureBy(
             eastNorth.east() - prevEastNorth.east(),
             eastNorth.north() - prevEastNorth.north()
         );
-	}
+    }
 
 }
Index: /applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/actions/transform/RotatePictureAction.java
===================================================================
--- /applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/actions/transform/RotatePictureAction.java	(revision 30355)
+++ /applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/actions/transform/RotatePictureAction.java	(revision 30356)
@@ -44,7 +44,7 @@
     }
 
-	@Override
-	protected void doAction(MouseEvent e) {
-		double factor;
+    @Override
+    protected void doAction(MouseEvent e) {
+        double factor;
         if ( ( e.getModifiersEx() & InputEvent.SHIFT_DOWN_MASK ) != 0 ) {
             factor = Main.pref.getDouble("piclayer.rotatefactors.high_precision", 100.0);
@@ -54,4 +54,4 @@
         }
         currentLayer.rotatePictureBy( ( e.getY() - prevMousePoint.getY() ) / factor );
-	}
+    }
 }
Index: /applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/actions/transform/ScalePictureActionAbstract.java
===================================================================
--- /applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/actions/transform/ScalePictureActionAbstract.java	(revision 30355)
+++ /applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/actions/transform/ScalePictureActionAbstract.java	(revision 30356)
@@ -35,5 +35,5 @@
 public abstract class ScalePictureActionAbstract extends GenericPicTransformAction {
 
-	/**
+    /**
      * Constructor
      */
Index: /applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/actions/transform/ShearPictureAction.java
===================================================================
--- /applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/actions/transform/ShearPictureAction.java	(revision 30355)
+++ /applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/actions/transform/ShearPictureAction.java	(revision 30356)
@@ -39,5 +39,5 @@
 public class ShearPictureAction extends GenericPicTransformAction {
 
-	/**
+    /**
      * Constructor
      */
@@ -46,6 +46,6 @@
     }
 
-	@Override
-	protected void doAction(MouseEvent e) {
+    @Override
+    protected void doAction(MouseEvent e) {
         EastNorth eastNorth = Main.map.mapView.getEastNorth(e.getX(),e.getY());
         currentLayer.shearPictureBy(
@@ -53,5 +53,5 @@
             1000* (eastNorth.north() - prevEastNorth.north())
         );
-	}
+    }
 
 }
Index: /applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/actions/transform/affine/MovePointAction.java
===================================================================
--- /applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/actions/transform/affine/MovePointAction.java	(revision 30355)
+++ /applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/actions/transform/affine/MovePointAction.java	(revision 30356)
@@ -15,47 +15,47 @@
 public class MovePointAction extends GenericPicTransformAction {
 
-	public MovePointAction(MapFrame frame) {
+    public MovePointAction(MapFrame frame) {
         super(tr("PicLayer Move point"), tr("Point added/moved"), "movepoint", tr("Drag or create point on the picture"), frame, ImageProvider.getCursor("crosshair", null));
-	}
+    }
 
-	@Override
-	protected void doAction(MouseEvent e) {
-		try {
-			Point2D pressed = currentLayer.transformPoint(e.getPoint());
-			if (selectedPoint != null) {
-				currentLayer.getTransformer().replaceOriginPoint(selectedPoint, pressed);
-				selectedPoint = pressed;
-			}
-		} catch (NoninvertibleTransformException e1) {
-			e1.printStackTrace();
-		}
-	}
+    @Override
+    protected void doAction(MouseEvent e) {
+        try {
+            Point2D pressed = currentLayer.transformPoint(e.getPoint());
+            if (selectedPoint != null) {
+                currentLayer.getTransformer().replaceOriginPoint(selectedPoint, pressed);
+                selectedPoint = pressed;
+            }
+        } catch (NoninvertibleTransformException e1) {
+            e1.printStackTrace();
+        }
+    }
 
-	@Override
-	public void mouseClicked(MouseEvent e) {
-		if (currentLayer == null)
-			return;
+    @Override
+    public void mouseClicked(MouseEvent e) {
+        if (currentLayer == null)
+            return;
 
-		try {
-			Point2D pressed = currentLayer.transformPoint(e.getPoint());
-			if (selectedPoint == null)
-				currentLayer.getTransformer().addOriginPoint(pressed);
+        try {
+            Point2D pressed = currentLayer.transformPoint(e.getPoint());
+            if (selectedPoint == null)
+                currentLayer.getTransformer().addOriginPoint(pressed);
 
-			currentCommand.addIfChanged();
-		} catch (NoninvertibleTransformException e1) {
-			e1.printStackTrace();
-		}
-	}
+            currentCommand.addIfChanged();
+        } catch (NoninvertibleTransformException e1) {
+            e1.printStackTrace();
+        }
+    }
 
-	@Override
-	public void enterMode() {
-	    super.enterMode();
-	    updateDrawPoints(true);
-	}
+    @Override
+    public void enterMode() {
+        super.enterMode();
+        updateDrawPoints(true);
+    }
 
-	@Override
-	public void exitMode() {
-	    super.exitMode();
-	    updateDrawPoints(false);
-	}
+    @Override
+    public void exitMode() {
+        super.exitMode();
+        updateDrawPoints(false);
+    }
 }
Index: /applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/actions/transform/affine/TransformPointAction.java
===================================================================
--- /applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/actions/transform/affine/TransformPointAction.java	(revision 30355)
+++ /applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/actions/transform/affine/TransformPointAction.java	(revision 30356)
@@ -14,26 +14,26 @@
 public class TransformPointAction extends GenericPicTransformAction {
 
-	public TransformPointAction(MapFrame frame) {
-		super(tr("PicLayer Transform point"), tr("Point transformed"), "transformpoint", tr("Transform point on the picture"), frame, ImageProvider.getCursor("crosshair", null));
-	}
+    public TransformPointAction(MapFrame frame) {
+        super(tr("PicLayer Transform point"), tr("Point transformed"), "transformpoint", tr("Transform point on the picture"), frame, ImageProvider.getCursor("crosshair", null));
+    }
 
-	@Override
-	protected void doAction(MouseEvent e) {
-		try {
-			Point2D pressed = currentLayer.transformPoint(e.getPoint());
-			if (selectedPoint != null) {
-			    /*if (currentLayer.getTransformer().getOriginPoints().size() < 3)
-			        JOptionPane.showMessageDialog(null, tr("You should have 3 checkpoints to transform the image!"), tr("PicLayer"), JOptionPane.ERROR_MESSAGE, null);
-			    else*/
-			    {
-			        currentLayer.getTransformer().updatePair(selectedPoint, pressed);
-			    }
-			}
+    @Override
+    protected void doAction(MouseEvent e) {
+        try {
+            Point2D pressed = currentLayer.transformPoint(e.getPoint());
+            if (selectedPoint != null) {
+                /*if (currentLayer.getTransformer().getOriginPoints().size() < 3)
+                    JOptionPane.showMessageDialog(null, tr("You should have 3 checkpoints to transform the image!"), tr("PicLayer"), JOptionPane.ERROR_MESSAGE, null);
+                else*/
+                {
+                    currentLayer.getTransformer().updatePair(selectedPoint, pressed);
+                }
+            }
 
-			currentCommand.addIfChanged();
-		} catch (NoninvertibleTransformException e1) {
-			e1.printStackTrace();
-		}
-	}
+            currentCommand.addIfChanged();
+        } catch (NoninvertibleTransformException e1) {
+            e1.printStackTrace();
+        }
+    }
     @Override
     public void enterMode() {
Index: /applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/transform/Matrix3D.java
===================================================================
--- /applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/transform/Matrix3D.java	(revision 30355)
+++ /applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/transform/Matrix3D.java	(revision 30356)
@@ -7,71 +7,71 @@
 
 class Matrix3D {
-	double[][] a;
-	
-	public Matrix3D() {
-		a = new double[3][]; a[0] = new double[3]; a[1] = new double[3]; a[2] = new double[3];
-	}
-	
-	public Matrix3D(PictureTransform pictureTransform, double b11, double b12, double b13, double b21, double b22, double b23, double b31, double b32, double b33) {
-		this();
-		
-		a[0][0] = b11; a[0][1] = b12; a[0][2] = b13;
-		a[1][0] = b21; a[1][1] = b22; a[1][2] = b23;
-		a[2][0] = b31; a[2][1] = b32; a[2][2] = b33;
-	}
-	
-	public Matrix3D(List<? extends Point2D> list) {
-		this();
-		
-		for(int i=0; i<3; i++) {
-			Point2D p = list.get(i);
-			a[0][i] = p.getX();
-			a[1][i] = p.getY();
-			a[2][i] = 1;
-		}
-	}
+    double[][] a;
+    
+    public Matrix3D() {
+        a = new double[3][]; a[0] = new double[3]; a[1] = new double[3]; a[2] = new double[3];
+    }
+    
+    public Matrix3D(PictureTransform pictureTransform, double b11, double b12, double b13, double b21, double b22, double b23, double b31, double b32, double b33) {
+        this();
+        
+        a[0][0] = b11; a[0][1] = b12; a[0][2] = b13;
+        a[1][0] = b21; a[1][1] = b22; a[1][2] = b23;
+        a[2][0] = b31; a[2][1] = b32; a[2][2] = b33;
+    }
+    
+    public Matrix3D(List<? extends Point2D> list) {
+        this();
+        
+        for(int i=0; i<3; i++) {
+            Point2D p = list.get(i);
+            a[0][i] = p.getX();
+            a[1][i] = p.getY();
+            a[2][i] = 1;
+        }
+    }
 
-	public Matrix3D multiply(Matrix3D m) {
-		Matrix3D result = new Matrix3D();
-		for(int i=0; i<3; i++) 
-			for (int j=0; j<3; j++) {
-				double sum = 0;
-				for (int k=0; k<3; k++)
-					sum += a[i][k]*m.a[k][j];
-				result.a[i][j] = sum;
-			}				
-		return result;
-	}
-	
-	private double determinant() {
-		return a[0][0]*(a[1][1]*a[2][2]-a[1][2]*a[2][1])-a[0][1]*(a[1][0]*a[2][2]-a[1][2]*a[2][0])
-		   	+a[0][2]*(a[1][0]*a[2][1]-a[1][1]*a[2][0]);
-	}
-	
-	public Matrix3D inverse() throws NoSolutionException {
-		Matrix3D invert = new Matrix3D();
-		double det = determinant();
-		if (Math.abs(det) <= Double.MIN_VALUE)
-			throw new NoSolutionException("Determinant = 0");
-		
-		double s = 1/det;
-		
-	    invert.a[0][0] = (s) * (a[1][1] * a[2][2] - a[1][2] * a[2][1]);
-	    invert.a[1][0] = (s) * (a[1][2] * a[2][0] - a[1][0] * a[2][2]);
-	    invert.a[2][0] = (s) * (a[1][0] * a[2][1] - a[1][1] * a[2][0]);
-	    invert.a[0][1] = (s) * (a[0][2] * a[2][1] - a[0][1] * a[2][2]);
-	    invert.a[1][1] = (s) * (a[0][0] * a[2][2] - a[0][2] * a[2][0]);
-	    invert.a[2][1] = (s) * (a[0][1] * a[2][0] - a[0][0] * a[2][1]);
-	    invert.a[0][2] = (s) * (a[0][1] * a[1][2] - a[0][2] * a[1][1]);
-	    invert.a[1][2] = (s) * (a[0][2] * a[1][0] - a[0][0] * a[1][2]);
-	    invert.a[2][2] = (s) * (a[0][0] * a[1][1] - a[0][1] * a[1][0]);
-	    
-	    return invert;
-	}
-	
-	public AffineTransform toAffineTransform() throws NoSolutionException {
-		if (!(Math.abs(a[2][0]) <= 1e-2 && Math.abs(a[2][1]) <= 1e-2 && Math.abs(a[2][2]-1) <= 1e-2))
-			throw new NoSolutionException("Resulted matrix is not AF");
-		return new AffineTransform(a[0][0], a[1][0], a[0][1], a[1][1], a[0][2], a[1][2]);
-	}
+    public Matrix3D multiply(Matrix3D m) {
+        Matrix3D result = new Matrix3D();
+        for(int i=0; i<3; i++) 
+            for (int j=0; j<3; j++) {
+                double sum = 0;
+                for (int k=0; k<3; k++)
+                    sum += a[i][k]*m.a[k][j];
+                result.a[i][j] = sum;
+            }                
+        return result;
+    }
+    
+    private double determinant() {
+        return a[0][0]*(a[1][1]*a[2][2]-a[1][2]*a[2][1])-a[0][1]*(a[1][0]*a[2][2]-a[1][2]*a[2][0])
+               +a[0][2]*(a[1][0]*a[2][1]-a[1][1]*a[2][0]);
+    }
+    
+    public Matrix3D inverse() throws NoSolutionException {
+        Matrix3D invert = new Matrix3D();
+        double det = determinant();
+        if (Math.abs(det) <= Double.MIN_VALUE)
+            throw new NoSolutionException("Determinant = 0");
+        
+        double s = 1/det;
+        
+        invert.a[0][0] = (s) * (a[1][1] * a[2][2] - a[1][2] * a[2][1]);
+        invert.a[1][0] = (s) * (a[1][2] * a[2][0] - a[1][0] * a[2][2]);
+        invert.a[2][0] = (s) * (a[1][0] * a[2][1] - a[1][1] * a[2][0]);
+        invert.a[0][1] = (s) * (a[0][2] * a[2][1] - a[0][1] * a[2][2]);
+        invert.a[1][1] = (s) * (a[0][0] * a[2][2] - a[0][2] * a[2][0]);
+        invert.a[2][1] = (s) * (a[0][1] * a[2][0] - a[0][0] * a[2][1]);
+        invert.a[0][2] = (s) * (a[0][1] * a[1][2] - a[0][2] * a[1][1]);
+        invert.a[1][2] = (s) * (a[0][2] * a[1][0] - a[0][0] * a[1][2]);
+        invert.a[2][2] = (s) * (a[0][0] * a[1][1] - a[0][1] * a[1][0]);
+        
+        return invert;
+    }
+    
+    public AffineTransform toAffineTransform() throws NoSolutionException {
+        if (!(Math.abs(a[2][0]) <= 1e-2 && Math.abs(a[2][1]) <= 1e-2 && Math.abs(a[2][2]-1) <= 1e-2))
+            throw new NoSolutionException("Resulted matrix is not AF");
+        return new AffineTransform(a[0][0], a[1][0], a[0][1], a[1][1], a[0][2], a[1][2]);
+    }
 }
Index: /applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/transform/NoSolutionException.java
===================================================================
--- /applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/transform/NoSolutionException.java	(revision 30355)
+++ /applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/transform/NoSolutionException.java	(revision 30356)
@@ -2,9 +2,9 @@
 
 class NoSolutionException extends Exception {
-	
-	public NoSolutionException(String message) {
-		super(message);
-	}
+    
+    public NoSolutionException(String message) {
+        super(message);
+    }
 
-	private static final long serialVersionUID = 3170170664858078930L;
+    private static final long serialVersionUID = 3170170664858078930L;
 }
Index: /applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/transform/PictureTransform.java
===================================================================
--- /applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/transform/PictureTransform.java	(revision 30355)
+++ /applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/transform/PictureTransform.java	(revision 30356)
@@ -10,8 +10,8 @@
 public class PictureTransform {
 
-	private AffineTransform cachedTransform;
-	private EastNorth imagePosition;
+    private AffineTransform cachedTransform;
+    private EastNorth imagePosition;
 
-	public EastNorth getImagePosition() {
+    public EastNorth getImagePosition() {
         return imagePosition;
     }
@@ -23,90 +23,90 @@
     private boolean modified = false;
 
-	private List<Point2D> originPoints;
+    private List<Point2D> originPoints;
 
-	public PictureTransform() {
-		cachedTransform = new AffineTransform();
-		originPoints = new ArrayList<Point2D>(3);
-	}
+    public PictureTransform() {
+        cachedTransform = new AffineTransform();
+        originPoints = new ArrayList<Point2D>(3);
+    }
 
-	public AffineTransform getTransform() {
-		return cachedTransform;
-	}
+    public AffineTransform getTransform() {
+        return cachedTransform;
+    }
 
-	private AffineTransform solveEquation(List<Point2D> desiredPoints) throws NoSolutionException {
-		Matrix3D X = new Matrix3D(originPoints);
-		Matrix3D Y = new Matrix3D(desiredPoints);
-		Matrix3D result = Y.multiply(X.inverse());
+    private AffineTransform solveEquation(List<Point2D> desiredPoints) throws NoSolutionException {
+        Matrix3D X = new Matrix3D(originPoints);
+        Matrix3D Y = new Matrix3D(desiredPoints);
+        Matrix3D result = Y.multiply(X.inverse());
 
-		return result.toAffineTransform();
-	}
+        return result.toAffineTransform();
+    }
 
-	public void addOriginPoint(Point2D originPoint) {
-		if (originPoints.size() < 3)
-			originPoints.add(originPoint);
-	}
+    public void addOriginPoint(Point2D originPoint) {
+        if (originPoints.size() < 3)
+            originPoints.add(originPoint);
+    }
 
-	public void resetCalibration() {
-		originPoints.clear();
-		modified = false;
-		cachedTransform = new AffineTransform();
-	}
+    public void resetCalibration() {
+        originPoints.clear();
+        modified = false;
+        cachedTransform = new AffineTransform();
+    }
 
-	/**
-	 * updates pair of points (suppose that other pairs are (origin=>origin) points are the same),
-	 * solves equation,
-	 * applies transform matrix to the existing cachedTransform
-	 *
-	 * @param originPoint - should be one of origin points, otherwise - no transform applied
-	 * @param desiredPoint - new place for the point
-	 */
-	public void updatePair(Point2D originPoint, Point2D desiredPoint) {
-		if (originPoint == null)
-			return;
+    /**
+     * updates pair of points (suppose that other pairs are (origin=>origin) points are the same),
+     * solves equation,
+     * applies transform matrix to the existing cachedTransform
+     *
+     * @param originPoint - should be one of origin points, otherwise - no transform applied
+     * @param desiredPoint - new place for the point
+     */
+    public void updatePair(Point2D originPoint, Point2D desiredPoint) {
+        if (originPoint == null)
+            return;
 
-		switch (originPoints.size()) {
-		case 1: {
-		    cachedTransform.concatenate(AffineTransform.getTranslateInstance(desiredPoint.getX()-originPoint.getX(),
-		            desiredPoint.getY()-originPoint.getY()));
-		    break;
-		}
-		case 2: {
-		    // find triangle and move it
-		    List<Point2D> desiredPoints = new ArrayList<Point2D>(3);
-		    Point2D o1 = originPoints.get(0);
-		    Point2D o2 = originPoints.get(1);
-		    Point2D d1, d2;
-		    if (o2 == originPoint) {
-		        d2 = desiredPoint;
-		        d1 = (Point2D) o1.clone();
-		    } else {
-		        d1 = desiredPoint;
-		        d2 = (Point2D) o2.clone();
-		    }
-		    Point2D o3 = calculateTrianglePoint(o1, o2);
-		    Point2D d3 = calculateTrianglePoint(d1, d2);
-		    originPoints.add(o3);
-		    desiredPoints.add(d1); desiredPoints.add(d2); desiredPoints.add(d3);
-		    trySolve(desiredPoints);
-		    originPoints.remove(2);
-		    break;
-		}
-		case 3: {
-		    List<Point2D> desiredPoints = new ArrayList<Point2D>(3);
+        switch (originPoints.size()) {
+        case 1: {
+            cachedTransform.concatenate(AffineTransform.getTranslateInstance(desiredPoint.getX()-originPoint.getX(),
+                    desiredPoint.getY()-originPoint.getY()));
+            break;
+        }
+        case 2: {
+            // find triangle and move it
+            List<Point2D> desiredPoints = new ArrayList<Point2D>(3);
+            Point2D o1 = originPoints.get(0);
+            Point2D o2 = originPoints.get(1);
+            Point2D d1, d2;
+            if (o2 == originPoint) {
+                d2 = desiredPoint;
+                d1 = (Point2D) o1.clone();
+            } else {
+                d1 = desiredPoint;
+                d2 = (Point2D) o2.clone();
+            }
+            Point2D o3 = calculateTrianglePoint(o1, o2);
+            Point2D d3 = calculateTrianglePoint(d1, d2);
+            originPoints.add(o3);
+            desiredPoints.add(d1); desiredPoints.add(d2); desiredPoints.add(d3);
+            trySolve(desiredPoints);
+            originPoints.remove(2);
+            break;
+        }
+        case 3: {
+            List<Point2D> desiredPoints = new ArrayList<Point2D>(3);
 
-	        for (Point2D origin : originPoints) {
-	            if (origin.equals(originPoint))
-	                desiredPoints.add(desiredPoint);
-	            else
-	                desiredPoints.add(origin);
-	        }
-	        trySolve(desiredPoints);
-	        break;
-		}
-		default:
+            for (Point2D origin : originPoints) {
+                if (origin.equals(originPoint))
+                    desiredPoints.add(desiredPoint);
+                else
+                    desiredPoints.add(origin);
+            }
+            trySolve(desiredPoints);
+            break;
+        }
+        default:
 
-		}
+        }
 
-	}
+    }
 
     private Point2D calculateTrianglePoint(Point2D d1, Point2D d2) {
@@ -133,37 +133,37 @@
     }
 
-	public void replaceOriginPoint(Point2D originPoint, Point2D newOriginPoint) {
-		if (originPoint == null || newOriginPoint == null)
-			return;
+    public void replaceOriginPoint(Point2D originPoint, Point2D newOriginPoint) {
+        if (originPoint == null || newOriginPoint == null)
+            return;
 
-		int index = originPoints.indexOf(originPoint);
-		if (index < 0)
-			return;
+        int index = originPoints.indexOf(originPoint);
+        if (index < 0)
+            return;
 
-		originPoints.set(index, newOriginPoint);
-	}
+        originPoints.set(index, newOriginPoint);
+    }
 
-	public void concatenateTransformPoint(AffineTransform transform, Point2D trans) {
+    public void concatenateTransformPoint(AffineTransform transform, Point2D trans) {
 
-	    if (trans != null) {
+        if (trans != null) {
             AffineTransform centered = AffineTransform.getTranslateInstance(trans.getX(), trans.getY());
             centered.concatenate(transform);
             centered.translate(-trans.getX(), -trans.getY());
             cachedTransform.concatenate(centered);
-	    } else {
-	        cachedTransform.concatenate(transform);
-	    }
+        } else {
+            cachedTransform.concatenate(transform);
+        }
 
 
-		for (int i = 0; i < originPoints.size(); i++) {
-			Point2D point = originPoints.get(i);
-			transform.transform(point, point);
-		}
-		modified = true;
-	}
+        for (int i = 0; i < originPoints.size(); i++) {
+            Point2D point = originPoints.get(i);
+            transform.transform(point, point);
+        }
+        modified = true;
+    }
 
-	public boolean isModified() {
-	    return modified;
-	}
+    public boolean isModified() {
+        return modified;
+    }
 
     public void setModified() {
