Index: /applications/editors/josm/plugins/piclayer/README
===================================================================
--- /applications/editors/josm/plugins/piclayer/README	(revision 17326)
+++ /applications/editors/josm/plugins/piclayer/README	(revision 17327)
@@ -2,25 +2,9 @@
 ========
 
-This plugin is meant for showing images as a background of the data being edited.It offers two ways of loading the data - from a file and from the clipboard.This is an early version and is not end-user-proof, so please follow the steps exactly in case you want to use it.Actually... it's barely working at the moment but I already find it very useful :).
+A plugin for JOSM editor. Use it wisely - do not copy from copyrighted maps. Use "help" option to get a short tutorial.
 
-NOTE: Make sure the image is suitable, copyright-wise, if in doubt, don't use.
-Step 1) Load some data from the server so that map is visible.
-Step 2) Go to PicLayer menu and either choose to add a layer from a file or from the clipboard.
-Step 2a) If you chose a file, a file selector will pop-up. Choose the image you want. Of course the format you are using might not be supported yet :)
-Step 2b) If you chose a clipboard, please wait. For some reason it takes time. To be fixed later.
-NOTE) If something failed, you should get a message box. If not - check the console for messages (Linux only?)
-Step 3) Once the image is visible you may start positioning it. For that - select the PicLayer in the layers list and activate it (!).
-Step 4) Start aligning the image.
-Step 4a) Move the image by choosing 'Move' from the toolbar and draggin the mouse around with left button pressed.
-Step 4b) Rotate the image by choosing 'Rotate' from the toolbar and draggin the mouse up/down with left button pressed.
-Step 4c) Scale the image by choosing 'Scale' from the toolbar and draggin the mouse up/down with left button pressed.
-NOTE) If it does not work - make sure the right layer is selected.
-Step 5) If you need to reset your changes - you can use the popup menu available under the PicLayer entry in the layer list.
-
-This plugin is meant to help with mapping from photos (for me it's mostly buildings) for people who simply don't like MetaCarta Rectifier (like me).
-
-Although I wrote it only to help myself and currently have no intention of extending it beyond what I need, you may still contact me with any suggestions that you think are important: tomasz.stelmach@poczta.onet.pl
-
-I used wmsplugin and routing plugin code very much during coding. Thank you and I hope you don't mind :)
+Author: Tomasz Stelmach
+Email: tomasz.stelmach@poczta.onet.pl
+WWW: http://www.stelmach-online.net/
 
 HISTORY:
@@ -29,3 +13,7 @@
 2009.08.28:
 - added support for scaling in one axis only
+- added support for saving / loading image calibration
 - added new icons
+
+2009.04.27:
+- initial version
Index: /applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/CalibrationFileFilter.java
===================================================================
--- /applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/CalibrationFileFilter.java	(revision 17327)
+++ /applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/CalibrationFileFilter.java	(revision 17327)
@@ -0,0 +1,49 @@
+/***************************************************************************
+ *   Copyright (C) 2009 by Tomasz Stelmach                                 *
+ *   http://www.stelmach-online.net/                                       *
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ *   This program is distributed in the hope that it will be useful,       *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
+ *   GNU General Public License for more details.                          *
+ *                                                                         *
+ *   You should have received a copy of the GNU General Public License     *
+ *   along with this program; if not, write to the                         *
+ *   Free Software Foundation, Inc.,                                       *
+ *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
+ ***************************************************************************/
+package org.openstreetmap.josm.plugins.piclayer;
+
+import java.io.File;
+
+import javax.swing.filechooser.FileFilter;
+
+/**
+ * Filter for the file dialog. Allows only calibration files.
+ */
+public class CalibrationFileFilter extends FileFilter {
+	
+	// Extension used by calibration files
+	public static final String EXTENSION = ".cal";
+
+	@Override
+	public boolean accept(File f) {
+	    String ext3 = ( f.getName().length() > 4 ) ?  f.getName().substring( f.getName().length() - 4 ).toLowerCase() : "";
+
+	    // TODO: check what is supported by Java :)
+	    return ( f.isDirectory() 
+	    	||	ext3.equals( EXTENSION )
+	    	);
+	}
+
+	@Override
+	public String getDescription() {
+		return "Calibration Files (*" + EXTENSION + ")";
+	}
+
+}
Index: /applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/HelpAction.java
===================================================================
--- /applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/HelpAction.java	(revision 17326)
+++ /applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/HelpAction.java	(revision 17327)
@@ -76,7 +76,9 @@
             + "Step 4d) You can also choose to scale in just one axis by selecting the proper button."
             + "\n"
-            + "NOTE) If it does not work - make sure the right layer is selected."
+            + "NOTE) If it does not work - make sure the right layer is selected AND ACTIVATED."
             + "\n"
             + "Step 5) If you need to reset your changes - you can use the popup menu available under the PicLayer entry in the layer list."
+            + "\n"
+            + "Step 6) If you want to save the calibraton of the picture you have made, you can also do this using the popup menu."
             + "\n\n"
             + "This plugin is meant to help with mapping from photos (for me it's mostly buildings) for people who simply don't like MetaCarta Rectifier (like me)."
Index: /applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/LoadPictureCalibrationAction.java
===================================================================
--- /applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/LoadPictureCalibrationAction.java	(revision 17327)
+++ /applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/LoadPictureCalibrationAction.java	(revision 17327)
@@ -0,0 +1,80 @@
+/***************************************************************************
+ *   Copyright (C) 2009 by Tomasz Stelmach                                 *
+ *   http://www.stelmach-online.net/                                       *
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ *   This program is distributed in the hope that it will be useful,       *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
+ *   GNU General Public License for more details.                          *
+ *                                                                         *
+ *   You should have received a copy of the GNU General Public License     *
+ *   along with this program; if not, write to the                         *
+ *   Free Software Foundation, Inc.,                                       *
+ *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
+ ***************************************************************************/
+
+package org.openstreetmap.josm.plugins.piclayer;
+import java.awt.event.ActionEvent;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.Properties;
+
+import javax.swing.JFileChooser;
+import javax.swing.JOptionPane;
+
+import org.openstreetmap.josm.Main;
+import org.openstreetmap.josm.actions.JosmAction;
+
+/**
+ * Action for resetting properties of an image.
+ * 
+ * TODO Four almost identical classes. Refactoring needed.
+ */
+public class LoadPictureCalibrationAction extends JosmAction {
+
+	// Owner layer of the action
+	PicLayerAbstract m_owner = null;
+	
+	/**
+	 * Constructor
+	 */
+	public LoadPictureCalibrationAction( PicLayerAbstract owner ) {
+		super("Load Picture Calibration...", null, "Loads calibration data to a file", null, false);
+		// Remember the owner...
+		m_owner = owner;
+	}
+	
+	/**
+	 * Action handler
+	 */
+	public void actionPerformed(ActionEvent arg0) {
+		// Save dialog
+		final JFileChooser fc = new JFileChooser();
+		fc.setAcceptAllFileFilterUsed( false );
+		fc.setFileFilter( new CalibrationFileFilter() );
+		fc.setSelectedFile( new File(m_owner.getPicLayerName() + CalibrationFileFilter.EXTENSION));
+		int result = fc.showOpenDialog(Main.parent );
+
+		if ( result == JFileChooser.APPROVE_OPTION ) {
+					
+			// Load	
+			try {
+				Properties props = new Properties();
+				props.load(new FileInputStream(fc.getSelectedFile()));
+				m_owner.loadCalibration(props);
+			} catch (Exception e) {
+				// Error
+				e.printStackTrace();
+				JOptionPane.showMessageDialog(Main.parent , "Loading file failed: " + e.getMessage());
+			}
+		}	
+	}
+}
Index: /applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/PicLayerAbstract.java
===================================================================
--- /applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/PicLayerAbstract.java	(revision 17326)
+++ /applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/PicLayerAbstract.java	(revision 17327)
@@ -29,4 +29,6 @@
 import java.awt.image.BufferedImage;
 import java.io.IOException;
+import java.util.Properties;
+
 import javax.swing.Icon;
 import javax.swing.ImageIcon;
@@ -68,4 +70,14 @@
     // Layer icon
     private Icon m_layericon = null;
+    
+    // Keys for saving in Properties
+    private final String INITIAL_POS_X = "INITIAL_POS_X";
+    private final String INITIAL_POS_Y = "INITIAL_POS_y";
+    private final String POSITION_X = "POSITION_X";
+    private final String POSITION_Y = "POSITION_Y";
+    private final String ANGLE = "ANGLE";
+    private final String INITIAL_SCALE = "INITIAL_SCALE";
+    private final String SCALEX = "SCALEX";
+    private final String SCALEY = "SCALEY";
 
     /**
@@ -89,4 +101,7 @@
         m_popupmenu = new Component[]{
                 reset_submenu,
+                new JSeparator(),
+                new JMenuItem( new SavePictureCalibrationAction(this)),
+                new JMenuItem( new LoadPictureCalibrationAction(this)),
                 new JSeparator(),
                 new JMenuItem( new HelpAction() )
@@ -263,3 +278,44 @@
 
     }
+
+    /**
+     * Saves the calibration data into properties structure
+     * @param props Properties to save to
+     */
+    public void saveCalibration( Properties props ) {
+    	// Save
+    	props.put(INITIAL_POS_X, "" + m_initial_position.getX());
+    	props.put(INITIAL_POS_Y, "" + m_initial_position.getY());
+    	props.put(POSITION_X, "" + m_position.getX());
+    	props.put(POSITION_Y, "" + m_position.getY());
+    	props.put(INITIAL_SCALE, "" + m_initial_scale);
+    	props.put(SCALEX, "" + m_scalex);
+    	props.put(SCALEY, "" + m_scaley);
+    	props.put(ANGLE, "" + m_angle);
+    }
+    
+    /**
+     * Loads calibration data from properties structure
+     * @param props Properties to load from
+     * @return
+     */
+    public void loadCalibration( Properties props ) {
+    	// Load
+    		double pos_x = Double.valueOf( props.getProperty(POSITION_X));
+    		double pos_y = Double.valueOf( props.getProperty(POSITION_Y));
+    		double in_pos_x = Double.valueOf( props.getProperty(INITIAL_POS_X));
+    		double in_pos_y = Double.valueOf( props.getProperty(INITIAL_POS_Y));
+    		double angle = Double.valueOf( props.getProperty(ANGLE));
+    		double in_scale = Double.valueOf( props.getProperty(INITIAL_SCALE));
+    		double scale_x = Double.valueOf( props.getProperty(SCALEX));
+    		double scale_y = Double.valueOf( props.getProperty(SCALEY));
+  			m_position.setLocation(pos_x, pos_y);
+    		m_initial_position.setLocation(pos_x, pos_y);
+    		m_angle = angle;
+    		m_scalex = scale_x;
+    		m_scaley = scale_y;
+    		m_initial_scale = in_scale;
+    		// Refresh
+            Main.map.mapView.repaint();
+    }
 }
Index: /applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/PicLayerFromClipboard.java
===================================================================
--- /applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/PicLayerFromClipboard.java	(revision 17326)
+++ /applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/PicLayerFromClipboard.java	(revision 17327)
@@ -61,5 +61,5 @@
 	@Override
 	protected String getPicLayerName() {
-		return super.name + " <Clipboard>";
+		return "Clipboard";
 	}
 
Index: /applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/PicLayerFromFile.java
===================================================================
--- /applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/PicLayerFromFile.java	(revision 17326)
+++ /applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/PicLayerFromFile.java	(revision 17327)
@@ -40,5 +40,5 @@
     	m_file = file;
     	// Generate tooltip text
-    	m_tooltiptext = super.name + " <" + m_file.getAbsolutePath() + ">";
+    	m_tooltiptext = m_file.getAbsolutePath();
     }	
     
Index: /applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/ResetPictureAllAction.java
===================================================================
--- /applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/ResetPictureAllAction.java	(revision 17326)
+++ /applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/ResetPictureAllAction.java	(revision 17327)
@@ -39,5 +39,5 @@
 	 */
 	public ResetPictureAllAction( PicLayerAbstract owner ) {
-		super("All", null, null, null, false);
+		super("All", null, "Resets picture calibration", null, false);
 		// Remember the owner...
 		m_owner = owner;
Index: /applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/ResetPictureAngleAction.java
===================================================================
--- /applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/ResetPictureAngleAction.java	(revision 17326)
+++ /applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/ResetPictureAngleAction.java	(revision 17327)
@@ -39,5 +39,5 @@
 	 */
 	public ResetPictureAngleAction( PicLayerAbstract owner ) {
-		super("Angle", null, null, null, false);
+		super("Angle", null, "Resets picture rotation", null, false);
 		// Remember the owner...
 		m_owner = owner;
Index: /applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/ResetPicturePositionAction.java
===================================================================
--- /applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/ResetPicturePositionAction.java	(revision 17326)
+++ /applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/ResetPicturePositionAction.java	(revision 17327)
@@ -39,5 +39,5 @@
 	 */
 	public ResetPicturePositionAction( PicLayerAbstract owner ) {
-		super("Position", null, null, null, false);
+		super("Position", null, "Resets picture position", null, false);
 		// Remember the owner...
 		m_owner = owner;
Index: /applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/ResetPictureScaleAction.java
===================================================================
--- /applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/ResetPictureScaleAction.java	(revision 17326)
+++ /applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/ResetPictureScaleAction.java	(revision 17327)
@@ -39,5 +39,5 @@
 	 */
 	public ResetPictureScaleAction( PicLayerAbstract owner ) {
-		super("Scale", null, null, null, false);
+		super("Scale", null, "Resets picture scale", null, false);
 		// Remember the owner...
 		m_owner = owner;
Index: /applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/SavePictureCalibrationAction.java
===================================================================
--- /applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/SavePictureCalibrationAction.java	(revision 17327)
+++ /applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/SavePictureCalibrationAction.java	(revision 17327)
@@ -0,0 +1,86 @@
+/***************************************************************************
+ *   Copyright (C) 2009 by Tomasz Stelmach                                 *
+ *   http://www.stelmach-online.net/                                       *
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ *   This program is distributed in the hope that it will be useful,       *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
+ *   GNU General Public License for more details.                          *
+ *                                                                         *
+ *   You should have received a copy of the GNU General Public License     *
+ *   along with this program; if not, write to the                         *
+ *   Free Software Foundation, Inc.,                                       *
+ *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
+ ***************************************************************************/
+
+package org.openstreetmap.josm.plugins.piclayer;
+import java.awt.event.ActionEvent;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.Properties;
+
+import javax.swing.JFileChooser;
+import javax.swing.JOptionPane;
+
+import org.openstreetmap.josm.Main;
+import org.openstreetmap.josm.actions.JosmAction;
+
+/**
+ * Action for resetting properties of an image.
+ * 
+ * TODO Four almost identical classes. Refactoring needed.
+ */
+public class SavePictureCalibrationAction extends JosmAction {
+
+	// Owner layer of the action
+	PicLayerAbstract m_owner = null;
+	
+	/**
+	 * Constructor
+	 */
+	public SavePictureCalibrationAction( PicLayerAbstract owner ) {
+		super("Save Picture Calibration...", null, "Saves calibration data to a file", null, false);
+		// Remember the owner...
+		m_owner = owner;
+	}
+	
+	/**
+	 * Action handler
+	 */
+	public void actionPerformed(ActionEvent arg0) {
+		// Save dialog
+		final JFileChooser fc = new JFileChooser();
+		fc.setAcceptAllFileFilterUsed( false );
+		fc.setFileFilter( new CalibrationFileFilter() );
+		fc.setSelectedFile( new File(m_owner.getPicLayerName() + CalibrationFileFilter.EXTENSION));
+		int result = fc.showSaveDialog( Main.parent );
+
+		if ( result == JFileChooser.APPROVE_OPTION ) {
+			// Check file extension and force it to be valid
+			File file = fc.getSelectedFile();
+			String path = file.getAbsolutePath();
+			if ( path.length() < CalibrationFileFilter.EXTENSION.length()
+				|| !path.substring( path.length() - 4 ).equals(CalibrationFileFilter.EXTENSION)) {
+				file = new File( path + CalibrationFileFilter.EXTENSION );
+			}
+						
+			// Save
+			Properties props = new Properties();
+			m_owner.saveCalibration(props);
+			try {
+				props.store(new FileOutputStream(file), "JOSM PicLayer plugin calibration data");
+			} catch (Exception e) {
+				// Error
+				e.printStackTrace();
+				JOptionPane.showMessageDialog(Main.parent , "Saving file failed: " + e.getMessage());
+			}
+		}	
+	}
+}
