Changeset 27120 in osm for applications/editors
- Timestamp:
- 2011-11-22T16:18:12+01:00 (13 years ago)
- Location:
- applications/editors/josm/plugins/piclayer
- Files:
-
- 17 added
- 5 deleted
- 2 edited
- 15 moved
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/piclayer/build.xml
r27119 r27120 22 22 --> 23 23 <project name="PicLayer" default="dist" basedir="."> 24 <property name="commit.message" value=" applied #J5852 (patch by Petschge) - new shear option"/>24 <property name="commit.message" value="PicLayer rewritten - lots changed"/> 25 25 <property name="plugin.main.version" value="4549"/> 26 26 <!-- -
applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/PicLayerPlugin.java
r26489 r27120 25 25 26 26 import java.awt.event.KeyEvent; 27 27 28 import javax.swing.JMenu; 28 29 29 30 import org.openstreetmap.josm.Main; 30 import org.openstreetmap.josm.plugins.Plugin;31 import org.openstreetmap.josm.plugins.PluginInformation;32 31 import org.openstreetmap.josm.gui.IconToggleButton; 32 import org.openstreetmap.josm.gui.MapFrame; 33 33 import org.openstreetmap.josm.gui.MapView; 34 34 import org.openstreetmap.josm.gui.MapView.LayerChangeListener; 35 35 import org.openstreetmap.josm.gui.layer.Layer; 36 import org.openstreetmap.josm.gui.MapFrame; 36 import org.openstreetmap.josm.plugins.Plugin; 37 import org.openstreetmap.josm.plugins.PluginInformation; 38 import org.openstreetmap.josm.plugins.piclayer.actions.newlayer.NewLayerFromClipboardAction; 39 import org.openstreetmap.josm.plugins.piclayer.actions.newlayer.NewLayerFromFileAction; 40 import org.openstreetmap.josm.plugins.piclayer.actions.transform.MovePictureAction; 41 import org.openstreetmap.josm.plugins.piclayer.actions.transform.RotatePictureAction; 42 import org.openstreetmap.josm.plugins.piclayer.actions.transform.ScaleXPictureAction; 43 import org.openstreetmap.josm.plugins.piclayer.actions.transform.ScaleXYPictureAction; 44 import org.openstreetmap.josm.plugins.piclayer.actions.transform.ScaleYPictureAction; 45 import org.openstreetmap.josm.plugins.piclayer.actions.transform.ShearPictureAction; 46 import org.openstreetmap.josm.plugins.piclayer.actions.transform.affine.MovePointAction; 47 import org.openstreetmap.josm.plugins.piclayer.actions.transform.affine.TransformPointAction; 37 48 38 49 /** … … 41 52 public class PicLayerPlugin extends Plugin implements LayerChangeListener { 42 53 43 // Plugin menu44 private JMenu m_menu = null;45 54 46 55 // Toolbar buttons 47 private IconToggleButton m_movePictureButton = null; 48 private IconToggleButton m_rotatePictureButton = null; 49 private IconToggleButton m_scalexPictureButton = null; 50 private IconToggleButton m_scaleyPictureButton = null; 51 private IconToggleButton m_scalexyPictureButton = null; 52 private IconToggleButton m_shearPictureButton = null; 56 static IconToggleButton movePictureButton = null; 57 static IconToggleButton movePointButton = null; 58 static IconToggleButton transformPointButton = null; 59 static IconToggleButton rotatePictureButton = null; 60 static IconToggleButton scalexPictureButton = null; 61 static IconToggleButton scaleyPictureButton = null; 62 static IconToggleButton scalexyPictureButton = null; 63 static IconToggleButton shearPictureButton = null; 53 64 54 // Menu actions55 private NewLayerFromFileAction m_newFromFileAction= null;56 private NewLayerFromClipboardAction m_newFromClipAction = null;65 // Plugin menu 66 private JMenu menu = null; 67 private ActionVisibilityChangeMenu actionVisibility; 57 68 58 69 /** … … 64 75 // Create menu entry 65 76 if ( Main.main.menu != null ) { 66 m _menu = Main.main.menu.addMenu(marktr("PicLayer") , KeyEvent.VK_I, Main.main.menu.defaultMenuPos, ht("/Plugin/PicLayer"));77 menu = Main.main.menu.addMenu(marktr("PicLayer") , KeyEvent.VK_I, Main.main.menu.defaultMenuPos, ht("/Plugin/PicLayer")); 67 78 } 68 79 69 80 // Add menu items 70 if ( m_menu != null ) { 71 m_menu.add( m_newFromFileAction = new NewLayerFromFileAction() ); 72 m_menu.add( m_newFromClipAction = new NewLayerFromClipboardAction() ); 73 m_newFromFileAction.setEnabled( false ); 74 m_newFromClipAction.setEnabled( false ); 81 if ( menu != null ) { 82 menu.add(new NewLayerFromFileAction()); 83 menu.add(new NewLayerFromClipboardAction()); 84 menu.setEnabled(false); 75 85 } 76 86 … … 82 92 * Called when the map is created. Creates the toolbar buttons. 83 93 */ 94 @Override 84 95 public void mapFrameInitialized(MapFrame oldFrame, MapFrame newFrame) { 85 96 if(newFrame != null) { 86 97 // Create plugin map modes 87 98 MovePictureAction movePictureAction = new MovePictureAction(newFrame); 99 MovePointAction movePointAction = new MovePointAction(newFrame); 100 TransformPointAction transformPointAction = new TransformPointAction(newFrame); 101 88 102 RotatePictureAction rotatePictureAction = new RotatePictureAction(newFrame); 89 103 ScaleXYPictureAction scaleXYPictureAction = new ScaleXYPictureAction(newFrame); … … 92 106 ShearPictureAction shearPictureAction = new ShearPictureAction(newFrame); 93 107 // Create plugin buttons and add them to the toolbar 94 m_movePictureButton = new IconToggleButton(movePictureAction); 95 m_rotatePictureButton = new IconToggleButton(rotatePictureAction); 96 m_scalexyPictureButton = new IconToggleButton(scaleXYPictureAction); 97 m_scalexPictureButton = new IconToggleButton(scaleXPictureAction); 98 m_scaleyPictureButton = new IconToggleButton(scaleYPictureAction); 99 m_shearPictureButton = new IconToggleButton(shearPictureAction); 100 newFrame.addMapMode(m_movePictureButton); 101 newFrame.addMapMode(m_rotatePictureButton); 102 newFrame.addMapMode(m_scalexyPictureButton); 103 newFrame.addMapMode(m_scalexPictureButton); 104 newFrame.addMapMode(m_scaleyPictureButton); 105 newFrame.addMapMode(m_shearPictureButton); 108 movePictureButton = new IconToggleButton(movePictureAction); 109 movePointButton = new IconToggleButton(movePointAction); 110 transformPointButton = new IconToggleButton(transformPointAction); 111 rotatePictureButton = new IconToggleButton(rotatePictureAction); 112 scalexyPictureButton = new IconToggleButton(scaleXYPictureAction); 113 scalexPictureButton = new IconToggleButton(scaleXPictureAction); 114 scaleyPictureButton = new IconToggleButton(scaleYPictureAction); 115 shearPictureButton = new IconToggleButton(shearPictureAction); 116 newFrame.addMapMode(movePictureButton); 117 newFrame.addMapMode(movePointButton); 118 newFrame.addMapMode(transformPointButton); 119 newFrame.addMapMode(rotatePictureButton); 120 newFrame.addMapMode(scalexyPictureButton); 121 newFrame.addMapMode(scalexPictureButton); 122 newFrame.addMapMode(scaleyPictureButton); 123 newFrame.addMapMode(shearPictureButton); 106 124 // newFrame.toolGroup.add(m_movePictureButton); 107 125 // newFrame.toolGroup.add(m_rotatePictureButton); 108 126 // newFrame.toolGroup.add(m_scalePictureButton); 109 127 // Show them by default 110 m_movePictureButton.setVisible(true); 111 m_rotatePictureButton.setVisible(true); 112 m_scalexyPictureButton.setVisible(true); 113 m_scalexPictureButton.setVisible(true); 114 m_scaleyPictureButton.setVisible(true); 115 m_shearPictureButton.setVisible(true); 128 129 if (actionVisibility == null) 130 menu.add(actionVisibility = new ActionVisibilityChangeMenu()); 116 131 } 117 132 } 118 133 119 134 /** 120 135 * The toolbar buttons shall be active only when the PicLayer is active. 121 136 */ 137 @Override 122 138 public void activeLayerChange(Layer oldLayer, Layer newLayer) { 123 139 } … … 128 144 * one must exist first). User should not be able to load a picture too early. 129 145 */ 146 @Override 130 147 public void layerAdded(Layer arg0) { 131 m_newFromFileAction.setEnabled( true ); 132 m_newFromClipAction.setEnabled( true ); 148 menu.setEnabled(true); 133 149 } 134 150 … … 136 152 * When all layers are gone - the menu is gone too. 137 153 */ 154 @Override 138 155 public void layerRemoved(Layer arg0) { 139 156 boolean enable = Main.map.mapView.getAllLayers().size() != 0; 140 m_newFromFileAction.setEnabled( enable ); 141 m_newFromClipAction.setEnabled( enable ); 157 menu.setEnabled(enable); 142 158 } 143 159 }; -
applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/actions/LoadPictureCalibrationAction.java
r27054 r27120 19 19 ***************************************************************************/ 20 20 21 package org.openstreetmap.josm.plugins.piclayer ;21 package org.openstreetmap.josm.plugins.piclayer.actions; 22 22 23 23 import static org.openstreetmap.josm.tools.I18n.tr; … … 26 26 import java.io.File; 27 27 import java.io.FileInputStream; 28 import java.io.FileNotFoundException;29 import java.io.FileOutputStream;30 import java.io.IOException;31 import java.util.Properties;32 28 33 29 import javax.swing.JFileChooser; … … 36 32 import org.openstreetmap.josm.Main; 37 33 import org.openstreetmap.josm.actions.JosmAction; 34 import org.openstreetmap.josm.plugins.piclayer.layer.CalibrationFileFilter; 35 import org.openstreetmap.josm.plugins.piclayer.layer.PicLayerAbstract; 38 36 39 37 /** … … 41 39 * 42 40 */ 41 @SuppressWarnings("serial") 43 42 public class LoadPictureCalibrationAction extends JosmAction { 44 43 -
applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/actions/SavePictureCalibrationAction.java
r27054 r27120 19 19 ***************************************************************************/ 20 20 21 package org.openstreetmap.josm.plugins.piclayer ;21 package org.openstreetmap.josm.plugins.piclayer.actions; 22 22 23 23 import static org.openstreetmap.josm.tools.I18n.tr; … … 25 25 import java.awt.event.ActionEvent; 26 26 import java.io.File; 27 import java.io.FileNotFoundException;28 27 import java.io.FileOutputStream; 29 import java.io.IOException;30 28 import java.util.Properties; 31 29 … … 35 33 import org.openstreetmap.josm.Main; 36 34 import org.openstreetmap.josm.actions.JosmAction; 35 import org.openstreetmap.josm.plugins.piclayer.layer.CalibrationFileFilter; 36 import org.openstreetmap.josm.plugins.piclayer.layer.PicLayerAbstract; 37 37 38 38 /** … … 41 41 * TODO Four almost identical classes. Refactoring needed. 42 42 */ 43 @SuppressWarnings("serial") 43 44 public class SavePictureCalibrationAction extends JosmAction { 44 45 -
applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/actions/newlayer/NewLayerFromClipboardAction.java
r27054 r27120 19 19 ***************************************************************************/ 20 20 21 package org.openstreetmap.josm.plugins.piclayer ;21 package org.openstreetmap.josm.plugins.piclayer.actions.newlayer; 22 22 23 23 import static org.openstreetmap.josm.tools.I18n.tr; … … 29 29 import org.openstreetmap.josm.Main; 30 30 import org.openstreetmap.josm.actions.JosmAction; 31 import org.openstreetmap.josm.plugins.piclayer.layer.PicLayerFromClipboard; 31 32 32 33 /** … … 34 35 * the content of the clipboard. 35 36 */ 37 @SuppressWarnings("serial") 36 38 public class NewLayerFromClipboardAction extends JosmAction { 37 39 -
applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/actions/newlayer/NewLayerFromFileAction.java
r27054 r27120 19 19 ***************************************************************************/ 20 20 21 package org.openstreetmap.josm.plugins.piclayer ;21 package org.openstreetmap.josm.plugins.piclayer.actions.newlayer; 22 22 23 23 import static org.openstreetmap.josm.tools.I18n.tr; … … 36 36 import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor; 37 37 import org.openstreetmap.josm.gui.layer.Layer; 38 import org.openstreetmap.josm.plugins.piclayer.layer.PicLayerFromFile; 38 39 39 40 /** 40 41 * Action responsible for creation of new layers based on image files. 41 42 */ 43 @SuppressWarnings("serial") 42 44 public class NewLayerFromFileAction extends JosmAction { 43 45 -
applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/actions/transform/MovePictureAction.java
r27054 r27120 19 19 ***************************************************************************/ 20 20 21 package org.openstreetmap.josm.plugins.piclayer ;21 package org.openstreetmap.josm.plugins.piclayer.actions.transform; 22 22 23 23 import static org.openstreetmap.josm.tools.I18n.tr; 24 24 25 25 import java.awt.event.MouseEvent; 26 import java.awt.event.MouseListener;27 import java.awt.event.MouseMotionListener;28 26 29 27 import org.openstreetmap.josm.Main; 30 import org.openstreetmap.josm.actions.mapmode.MapMode;31 28 import org.openstreetmap.josm.gui.MapFrame; 29 import org.openstreetmap.josm.plugins.piclayer.actions.GenericPicTransformAction; 32 30 import org.openstreetmap.josm.tools.ImageProvider; 33 31 import org.openstreetmap.josm.data.coor.EastNorth; 34 35 //TODO: Move/Rotate/Scale/Shear action classes are similar. Do the redesign!36 32 37 33 /** 38 34 * This class handles the input during moving the picture. 39 35 */ 40 public class MovePictureAction extends MapMode implements MouseListener, MouseMotionListener 41 { 42 // Action ongoing? 43 private boolean mb_dragging = false; 44 45 // Last mouse position 46 private EastNorth m_prevEastNorth; 47 48 // The layer we're working on 49 private PicLayerAbstract m_currentLayer = null; 36 @SuppressWarnings("serial") 37 public class MovePictureAction extends GenericPicTransformAction { 50 38 51 39 /** … … 56 44 } 57 45 58 @Override 59 public void enterMode() { 60 super.enterMode(); 61 Main.map.mapView.addMouseListener(this); 62 Main.map.mapView.addMouseMotionListener(this); 63 } 64 65 @Override 66 public void exitMode() { 67 super.exitMode(); 68 Main.map.mapView.removeMouseListener(this); 69 Main.map.mapView.removeMouseMotionListener(this); 70 } 71 72 @Override 73 public void mousePressed(MouseEvent e) { 74 75 // If everything is OK, we start dragging/moving the picture 76 if ( Main.map.mapView.getActiveLayer() instanceof PicLayerAbstract ) { 77 m_currentLayer = (PicLayerAbstract)Main.map.mapView.getActiveLayer(); 78 79 if ( m_currentLayer != null && e.getButton() == MouseEvent.BUTTON1 ) { 80 mb_dragging = true; 81 m_prevEastNorth=Main.map.mapView.getEastNorth(e.getX(),e.getY()); 82 } 83 } 84 } 85 86 @Override 87 public void mouseDragged(MouseEvent e) { 88 // Picture moving is ongoing 89 if(mb_dragging) { 90 EastNorth eastNorth = Main.map.mapView.getEastNorth(e.getX(),e.getY()); 91 m_currentLayer.movePictureBy( 92 eastNorth.east()-m_prevEastNorth.east(), 93 eastNorth.north()-m_prevEastNorth.north() 94 ); 95 m_prevEastNorth = eastNorth; 96 Main.map.mapView.repaint(); 97 } 98 } 99 100 @Override 101 public void mouseReleased(MouseEvent e) { 102 // Stop moving 103 mb_dragging = false; 104 } 46 @Override 47 protected void doAction(MouseEvent e) { 48 EastNorth eastNorth = Main.map.mapView.getEastNorth(e.getX(),e.getY()); 49 currentLayer.movePictureBy( 50 eastNorth.east() - prevEastNorth.east(), 51 eastNorth.north() - prevEastNorth.north() 52 ); 53 } 105 54 106 55 } -
applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/actions/transform/RotatePictureAction.java
r27054 r27120 19 19 ***************************************************************************/ 20 20 21 package org.openstreetmap.josm.plugins.piclayer ;21 package org.openstreetmap.josm.plugins.piclayer.actions.transform; 22 22 23 23 import static org.openstreetmap.josm.tools.I18n.tr; 24 24 25 import java.awt.event.InputEvent; 25 26 import java.awt.event.MouseEvent; 26 import java.awt.event.MouseListener;27 import java.awt.event.MouseMotionListener;28 27 29 28 import org.openstreetmap.josm.Main; 30 import org.openstreetmap.josm.actions.mapmode.MapMode;31 29 import org.openstreetmap.josm.gui.MapFrame; 30 import org.openstreetmap.josm.plugins.piclayer.actions.GenericPicTransformAction; 32 31 import org.openstreetmap.josm.tools.ImageProvider; 33 34 //TODO: Move/Rotate/Scale/Shear action classes are similar. Do the redesign!35 32 36 33 /** 37 34 * This class handles the input during rotating the picture. 38 35 */ 39 public class RotatePictureAction extends MapMode implements MouseListener, MouseMotionListener 40 { 41 // Action ongoing? 42 private boolean mb_dragging = false; 43 44 // Last mouse position 45 private int m_prevY; 46 47 // Layer we're working on 48 private PicLayerAbstract m_currentLayer = null; 36 @SuppressWarnings("serial") 37 public class RotatePictureAction extends GenericPicTransformAction { 49 38 50 39 /** … … 53 42 public RotatePictureAction(MapFrame frame) { 54 43 super(tr("PicLayer rotate"), "rotate", tr("Drag to rotate the picture"), frame, ImageProvider.getCursor("crosshair", null)); 55 // TODO Auto-generated constructor stub56 44 } 57 45 58 @Override 59 public void enterMode() { 60 super.enterMode(); 61 Main.map.mapView.addMouseListener(this); 62 Main.map.mapView.addMouseMotionListener(this); 63 } 64 65 @Override 66 public void exitMode() { 67 super.exitMode(); 68 Main.map.mapView.removeMouseListener(this); 69 Main.map.mapView.removeMouseMotionListener(this); 70 } 71 72 @Override 73 public void mousePressed(MouseEvent e) { 74 // Start rotating 75 if ( Main.map.mapView.getActiveLayer() instanceof PicLayerAbstract ) { 76 m_currentLayer = (PicLayerAbstract)Main.map.mapView.getActiveLayer(); 77 78 if ( m_currentLayer != null && e.getButton() == MouseEvent.BUTTON1 ) { 79 mb_dragging = true; 80 m_prevY=e.getY(); 81 } 46 @Override 47 protected void doAction(MouseEvent e) { 48 double factor; 49 if ( ( e.getModifiersEx() & InputEvent.SHIFT_DOWN_MASK ) != 0 ) { 50 factor = Main.pref.getDouble("piclayer.rotatefactors.high_precision", 100.0); 82 51 } 83 } 84 85 @Override 86 public void mouseDragged(MouseEvent e) { 87 // Rotate the picture 88 if(mb_dragging) { 89 double factor; 90 if ( ( e.getModifiersEx() & e.SHIFT_DOWN_MASK ) != 0 ) { 91 factor = Main.pref.getDouble("piclayer.rotatefactors.high_precision", 100.0); 92 } 93 else { 94 factor = Main.pref.getDouble("piclayer.rotatefactors.low_precision", 10.0 ); 95 } 96 m_currentLayer.rotatePictureBy( ( e.getY() - m_prevY ) / factor ); 97 m_prevY = e.getY(); 98 Main.map.mapView.repaint(); 99 } 100 } 101 102 @Override public void mouseReleased(MouseEvent e) { 103 // End rotating 104 mb_dragging = false; 105 } 106 52 else { 53 factor = Main.pref.getDouble("piclayer.rotatefactors.low_precision", 10.0 ); 54 } 55 currentLayer.rotatePictureBy( ( e.getY() - prevMousePoint.getY() ) / factor ); 56 } 107 57 } -
applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/actions/transform/ScalePictureActionAbstract.java
r27054 r27120 19 19 ***************************************************************************/ 20 20 21 package org.openstreetmap.josm.plugins.piclayer ;21 package org.openstreetmap.josm.plugins.piclayer.actions.transform; 22 22 23 import java.awt.event.InputEvent; 23 24 import java.awt.event.MouseEvent; 24 import java.awt.event.MouseListener;25 import java.awt.event.MouseMotionListener;26 25 27 26 import org.openstreetmap.josm.Main; 28 import org.openstreetmap.josm.actions.mapmode.MapMode;29 27 import org.openstreetmap.josm.gui.MapFrame; 28 import org.openstreetmap.josm.plugins.piclayer.actions.GenericPicTransformAction; 30 29 import org.openstreetmap.josm.tools.ImageProvider; 31 32 // TODO: Move/Rotate/Scale action classes are similar. Do the redesign!33 30 34 31 /** 35 32 * This class handles the input during scaling the picture. 36 33 */ 37 public abstract class ScalePictureActionAbstract extends MapMode implements MouseListener, MouseMotionListener 38 { 39 // Scaling ongoing? 40 private boolean mb_dragging = false; 34 @SuppressWarnings("serial") 35 public abstract class ScalePictureActionAbstract extends GenericPicTransformAction { 41 36 42 // Last mouse position 43 private int m_prevY; 44 45 // Layer we're working on 46 protected PicLayerAbstract m_currentLayer = null; 47 48 /** 37 /** 49 38 * Constructor 50 39 */ 51 40 public ScalePictureActionAbstract (String name, String icon, String tooltip, MapFrame frame) { 52 41 super(name, icon, tooltip, frame, ImageProvider.getCursor("crosshair", null)); 53 // TODO Auto-generated constructor stub54 42 } 55 43 56 @Override 57 public void enterMode() { 58 super.enterMode(); 59 Main.map.mapView.addMouseListener(this); 60 Main.map.mapView.addMouseMotionListener(this); 61 } 62 63 @Override 64 public void exitMode() { 65 super.exitMode(); 66 Main.map.mapView.removeMouseListener(this); 67 Main.map.mapView.removeMouseMotionListener(this); 68 } 69 70 @Override 71 public void mousePressed(MouseEvent e) { 72 // Start scaling 73 if ( Main.map.mapView.getActiveLayer() instanceof PicLayerAbstract ) { 74 m_currentLayer = (PicLayerAbstract)Main.map.mapView.getActiveLayer(); 75 76 if ( m_currentLayer != null && e.getButton() == MouseEvent.BUTTON1 ) { 77 mb_dragging = true; 78 m_prevY = e.getY(); 79 } 44 protected void doAction(MouseEvent e) { 45 double factor; 46 if ( ( e.getModifiersEx() & InputEvent.SHIFT_DOWN_MASK ) != 0 ) { 47 factor = Main.pref.getDouble("piclayer.scalefactors.high_precision", 1.0005); 80 48 } 81 } 82 83 @Override 84 public void mouseDragged(MouseEvent e) { 85 // Scale the picture 86 if(mb_dragging) { 87 double factor; 88 if ( ( e.getModifiersEx() & e.SHIFT_DOWN_MASK ) != 0 ) { 89 factor = Main.pref.getDouble("piclayer.scalefactors.high_precision", 1.0005); 90 } 91 else { 92 factor = Main.pref.getDouble("piclayer.scalefactors.low_precision", 1.015); 93 } 94 doTheScale( Math.pow(factor, m_prevY - e.getY() ) ); 95 m_prevY = e.getY(); 96 Main.map.mapView.repaint(); 97 } 98 } 99 100 @Override 101 public void mouseReleased(MouseEvent e) { 102 // Stop scaling 103 mb_dragging = false; 49 else { 50 factor = Main.pref.getDouble("piclayer.scalefactors.low_precision", 1.015); 51 } 52 doTheScale( Math.pow(factor, prevMousePoint.getY() - e.getY() ) ); 104 53 } 105 54 106 55 /** 107 * Does the actual scaling in the inherited class.108 */109 protected abstract void doTheScale( double scale );56 * Does the actual scaling in the inherited class. 57 */ 58 protected abstract void doTheScale( double scale ); 110 59 111 60 } -
applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/actions/transform/ScaleXPictureAction.java
r27054 r27120 19 19 ***************************************************************************/ 20 20 21 package org.openstreetmap.josm.plugins.piclayer ;21 package org.openstreetmap.josm.plugins.piclayer.actions.transform; 22 22 23 23 import static org.openstreetmap.josm.tools.I18n.tr; 24 24 25 import org.openstreetmap.josm.Main;26 import org.openstreetmap.josm.actions.mapmode.MapMode;27 25 import org.openstreetmap.josm.gui.MapFrame; 28 import org.openstreetmap.josm.tools.ImageProvider;29 30 // TODO: Move/Rotate/Scale/Shear action classes are similar. Do the redesign!31 26 32 27 /** 33 28 * This class handles the input during scaling the picture. 34 29 */ 30 @SuppressWarnings("serial") 35 31 public class ScaleXPictureAction extends ScalePictureActionAbstract 36 32 { … … 40 36 public ScaleXPictureAction(MapFrame frame) { 41 37 super(tr("PicLayer scale X"), "scale_x", tr("Drag to scale the picture in the X Axis"), frame); 42 // TODO Auto-generated constructor stub43 38 } 44 39 45 40 public void doTheScale( double scale ) { 46 m_currentLayer.scalePictureBy( scale, 1.0 );41 currentLayer.scalePictureBy( scale, 1.0 ); 47 42 } 48 43 } -
applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/actions/transform/ScaleXYPictureAction.java
r27054 r27120 19 19 ***************************************************************************/ 20 20 21 package org.openstreetmap.josm.plugins.piclayer ;21 package org.openstreetmap.josm.plugins.piclayer.actions.transform; 22 22 23 23 import static org.openstreetmap.josm.tools.I18n.tr; 24 24 25 import org.openstreetmap.josm.Main;26 import org.openstreetmap.josm.actions.mapmode.MapMode;27 25 import org.openstreetmap.josm.gui.MapFrame; 28 import org.openstreetmap.josm.tools.ImageProvider;29 30 // TODO: Move/Rotate/Scale/Shear action classes are similar. Do the redesign!31 26 32 27 /** 33 28 * This class handles the input during scaling the picture. 34 29 */ 30 @SuppressWarnings("serial") 35 31 public class ScaleXYPictureAction extends ScalePictureActionAbstract 36 32 { … … 40 36 public ScaleXYPictureAction(MapFrame frame) { 41 37 super(tr("PicLayer scale"), "scale", tr("Drag to scale the picture in the X and Y Axis"), frame); 42 // TODO Auto-generated constructor stub43 38 } 44 39 45 40 public void doTheScale( double scale ) { 46 m_currentLayer.scalePictureBy( scale, scale );41 currentLayer.scalePictureBy( scale, scale ); 47 42 } 48 43 } -
applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/actions/transform/ScaleYPictureAction.java
r27054 r27120 19 19 ***************************************************************************/ 20 20 21 package org.openstreetmap.josm.plugins.piclayer ;21 package org.openstreetmap.josm.plugins.piclayer.actions.transform; 22 22 23 23 import static org.openstreetmap.josm.tools.I18n.tr; 24 24 25 import org.openstreetmap.josm.Main;26 import org.openstreetmap.josm.actions.mapmode.MapMode;27 25 import org.openstreetmap.josm.gui.MapFrame; 28 import org.openstreetmap.josm.tools.ImageProvider;29 30 // TODO: Move/Rotate/Scale/Shear action classes are similar. Do the redesign!31 26 32 27 /** 33 28 * This class handles the input during scaling the picture. 34 29 */ 30 @SuppressWarnings("serial") 35 31 public class ScaleYPictureAction extends ScalePictureActionAbstract 36 32 { … … 40 36 public ScaleYPictureAction(MapFrame frame) { 41 37 super(tr("PicLayer scale Y"), "scale_y", tr("Drag to scale the picture in the Y Axis"), frame); 42 // TODO Auto-generated constructor stub43 38 } 44 39 45 40 public void doTheScale( double scale ) { 46 m_currentLayer.scalePictureBy( 1.0, scale );47 41 currentLayer.scalePictureBy( 1.0, scale ); 42 } 48 43 } -
applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/actions/transform/ShearPictureAction.java
r27054 r27120 21 21 ***************************************************************************/ 22 22 23 package org.openstreetmap.josm.plugins.piclayer ;23 package org.openstreetmap.josm.plugins.piclayer.actions.transform; 24 24 25 25 import static org.openstreetmap.josm.tools.I18n.tr; 26 26 27 27 import java.awt.event.MouseEvent; 28 import java.awt.event.MouseListener;29 import java.awt.event.MouseMotionListener;30 28 31 29 import org.openstreetmap.josm.Main; 32 import org.openstreetmap.josm.actions.mapmode.MapMode;33 30 import org.openstreetmap.josm.gui.MapFrame; 31 import org.openstreetmap.josm.plugins.piclayer.actions.GenericPicTransformAction; 34 32 import org.openstreetmap.josm.tools.ImageProvider; 35 33 import org.openstreetmap.josm.data.coor.EastNorth; 36 37 //TODO: Move/Rotate/Scale/Shear action classes are similar. Do the redesign!38 34 39 35 /** 40 36 * This class handles the input during shearing of the picture. 41 37 */ 42 public class ShearPictureAction extends MapMode implements MouseListener, MouseMotionListener 43 { 44 // Action ongoing? 45 private boolean mb_dragging = false; 38 @SuppressWarnings("serial") 39 public class ShearPictureAction extends GenericPicTransformAction { 46 40 47 // Last mouse position 48 private EastNorth m_prevEastNorth; 49 50 // The layer we're working on 51 private PicLayerAbstract m_currentLayer = null; 52 53 /** 41 /** 54 42 * Constructor 55 43 */ … … 58 46 } 59 47 60 @Override 61 public void enterMode() { 62 super.enterMode(); 63 Main.map.mapView.addMouseListener(this); 64 Main.map.mapView.addMouseMotionListener(this); 65 } 66 67 @Override 68 public void exitMode() { 69 super.exitMode(); 70 Main.map.mapView.removeMouseListener(this); 71 Main.map.mapView.removeMouseMotionListener(this); 72 } 73 74 @Override 75 public void mousePressed(MouseEvent e) { 76 77 // If everything is OK, we start dragging/moving the picture 78 if ( Main.map.mapView.getActiveLayer() instanceof PicLayerAbstract ) { 79 m_currentLayer = (PicLayerAbstract)Main.map.mapView.getActiveLayer(); 80 81 if ( m_currentLayer != null && e.getButton() == MouseEvent.BUTTON1 ) { 82 mb_dragging = true; 83 m_prevEastNorth=Main.map.mapView.getEastNorth(e.getX(),e.getY()); 84 } 85 } 86 } 87 88 @Override 89 public void mouseDragged(MouseEvent e) { 90 // Picture moving is ongoing 91 if(mb_dragging) { 92 EastNorth eastNorth = Main.map.mapView.getEastNorth(e.getX(),e.getY()); 93 m_currentLayer.shearPictureBy( 94 1000* (eastNorth.east()-m_prevEastNorth.east()), 95 1000* (eastNorth.north()-m_prevEastNorth.north()) 96 ); 97 m_prevEastNorth = eastNorth; 98 Main.map.mapView.repaint(); 99 } 100 } 101 102 @Override 103 public void mouseReleased(MouseEvent e) { 104 // Stop moving 105 mb_dragging = false; 106 } 48 @Override 49 protected void doAction(MouseEvent e) { 50 EastNorth eastNorth = Main.map.mapView.getEastNorth(e.getX(),e.getY()); 51 currentLayer.shearPictureBy( 52 1000* (eastNorth.east() - prevEastNorth.east()), 53 1000* (eastNorth.north() - prevEastNorth.north()) 54 ); 55 } 107 56 108 57 } -
applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/layer/CalibrationFileFilter.java
r27054 r27120 18 18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 19 19 ***************************************************************************/ 20 package org.openstreetmap.josm.plugins.piclayer ;20 package org.openstreetmap.josm.plugins.piclayer.layer; 21 21 22 22 import static org.openstreetmap.josm.tools.I18n.tr; -
applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/layer/PicLayerAbstract.java
r27054 r27120 19 19 ***************************************************************************/ 20 20 21 package org.openstreetmap.josm.plugins.piclayer ;21 package org.openstreetmap.josm.plugins.piclayer.layer; 22 22 23 23 import static org.openstreetmap.josm.tools.I18n.tr; 24 24 25 25 import java.awt.Color; 26 import java.awt.Component;27 26 import java.awt.Graphics2D; 28 27 import java.awt.Image; 28 import java.awt.Point; 29 29 import java.awt.Toolkit; 30 import java.awt.event.ActionEvent; 30 import java.awt.geom.AffineTransform; 31 import java.awt.geom.NoninvertibleTransformException; 32 import java.awt.geom.Point2D; 31 33 import java.io.BufferedReader; 32 import java.io.File;33 import java.io.FileInputStream;34 import java.io.FileReader;35 34 import java.io.IOException; 36 35 import java.io.InputStream; 37 36 import java.io.InputStreamReader; 38 37 import java.io.Reader; 39 import java.util.List;40 38 import java.util.Properties; 41 39 42 import javax.swing.AbstractAction;43 40 import javax.swing.Action; 44 41 import javax.swing.Icon; 45 42 import javax.swing.ImageIcon; 46 import javax.swing.JMenu;47 43 48 44 import org.openstreetmap.josm.Main; … … 54 50 import org.openstreetmap.josm.gui.MapView; 55 51 import org.openstreetmap.josm.gui.layer.Layer; 52 import org.openstreetmap.josm.plugins.piclayer.actions.LoadPictureCalibrationAction; 53 import org.openstreetmap.josm.plugins.piclayer.actions.ResetCalibrationAction; 54 import org.openstreetmap.josm.plugins.piclayer.actions.SavePictureCalibrationAction; 55 import org.openstreetmap.josm.plugins.piclayer.transform.PictureTransform; 56 56 import org.openstreetmap.josm.tools.Utils; 57 57 … … 62 62 * anything...) 63 63 */ 64 public abstract class PicLayerAbstract extends Layer 65 { 64 public abstract class PicLayerAbstract extends Layer { 66 65 // Counter - just for naming of layers 67 private static int m_counter = 0;66 private static int imageCounter = 0; 68 67 // This is the main image to be displayed 69 private Image m_image = null; 68 private Image image = null; 69 private static Image pinImage; 70 70 // Initial position of the image in the real world 71 private EastNorth m_initial_position;71 private EastNorth initialImagePosition; 72 72 // Position of the image in the real world 73 private EastNorth m_position; 74 // Angle of rotation of the image 75 private double m_angle = 0.0; 76 // Scale of the image 77 private double m_scalex = 1.0; 78 private double m_scaley = 1.0; 79 // Shear of the image 80 private double m_shearx = 0.0; 81 private double m_sheary = 0.0; 73 private EastNorth imagePosition; 82 74 // The scale that was set on the map during image creation 83 private double m_initial_scale = 1.0;75 private double initialImageScale = 1.0; 84 76 // Layer icon 85 private Icon m_layericon = null; 77 private Icon layerIcon = null; 78 79 private PictureTransform transformer; 80 81 public PictureTransform getTransformer() { 82 return transformer; 83 } 86 84 87 85 // Keys for saving in Properties … … 97 95 private final String SHEARY = "SHEARY"; 98 96 97 private final String MATRIXm00 = "M00"; 98 private final String MATRIXm01 = "M01"; 99 private final String MATRIXm10 = "M10"; 100 private final String MATRIXm11 = "M11"; 101 private final String MATRIXm02 = "M02"; 102 private final String MATRIXm12 = "M12"; 103 99 104 /** 100 105 * Constructor 101 106 */ 102 107 public PicLayerAbstract() { 103 super("PicLayer #" + m_counter);108 super("PicLayer #" + imageCounter); 104 109 105 110 //Increase number 106 m_counter++;111 imageCounter++; 107 112 108 113 // Load layer icon 109 m_layericon = new ImageIcon(Toolkit.getDefaultToolkit().createImage(PicLayerAbstract.class.getResource("/images/layericon.png"))); 114 layerIcon = new ImageIcon(Toolkit.getDefaultToolkit().createImage(getClass().getResource("/images/layericon.png"))); 115 116 if (pinImage == null) { 117 // allow system to load the image and use it in future 118 pinImage = new ImageIcon(Toolkit.getDefaultToolkit().createImage(getClass().getResource("/images/arrow.png"))).getImage(); 119 } 110 120 } 111 121 … … 116 126 public void initialize() throws IOException { 117 127 // First, we initialize the calibration, so that createImage() can rely on it 118 128 119 129 // If the map does not exist - we're screwed. We should not get into this situation in the first place! 120 130 if ( Main.map != null && Main.map.mapView != null ) { 121 // Geographical position of the image 122 // getCenter() documentation claims it returns a clone, but this is not in line with the code, 123 // which actually returns the same object upon subsequent calls. This messes things up 124 // when we loading several pictures and associated cal's in one go. 125 // So as a workaround, copy the object manually : 126 // TODO: not sure about this code below, probably there is a better way to clone the objects 131 127 132 EastNorth center = Main.map.mapView.getCenter(); 128 m_initial_position = new EastNorth(center.east(), center.north()); 129 m_position = new EastNorth(center.east(), center.north()); 133 134 imagePosition = new EastNorth(center.east(), center.north()); 135 initialImagePosition = new EastNorth(imagePosition.east(), imagePosition.north()); 130 136 // Initial scale at which the image was loaded 131 m_initial_scale = Main.map.mapView.getDist100Pixel();137 initialImageScale = Main.map.mapView.getDist100Pixel(); 132 138 } else { 133 139 throw new IOException(tr("Could not find the map object.")); … … 135 141 136 142 // Create image 137 m_image = createImage();138 if ( m_image == null ) {143 image = createImage(); 144 if ( image == null ) { 139 145 throw new IOException(tr("PicLayer failed to load or import the image.")); 140 146 } 141 147 // Load image completely 142 (new ImageIcon(m_image)).getImage(); 143 148 (new ImageIcon(image)).getImage(); 149 150 transformer = new PictureTransform(); 151 144 152 lookForCalibration(); 145 153 } … … 157 165 * To be overridden by subclasses. Returns the user readable name of the layer. 158 166 */ 159 protected abstract String getPicLayerName(); 160 161 @Override 162 public Icon getIcon() { 163 return m_layericon; 164 } 165 166 @Override 167 public Object getInfoComponent() { 168 // TODO Auto-generated method stub 169 return null; 170 } 167 public abstract String getPicLayerName(); 168 169 @Override 170 public Icon getIcon() { return layerIcon; } 171 172 @Override 173 public Object getInfoComponent() { return null; } 171 174 172 175 @Override … … 174 177 // Main menu 175 178 return new Action[] { 176 new Reset SubmenuAction(),179 new ResetCalibrationAction(this, transformer), 177 180 SeparatorLayerAction.INSTANCE, 178 181 new SavePictureCalibrationAction(this), 179 182 new LoadPictureCalibrationAction(this), 180 183 SeparatorLayerAction.INSTANCE, 181 new RenameLayerAction(null,this) 184 new RenameLayerAction(null,this), 182 185 }; 183 186 } … … 190 193 @Override 191 194 public boolean isMergable(Layer arg0) { 192 // TODO Auto-generated method stub193 195 return false; 194 196 } 195 197 196 198 @Override 197 public void mergeFrom(Layer arg0) { 198 // TODO Auto-generated method stub 199 200 } 199 public void mergeFrom(Layer arg0) {} 201 200 202 201 @Override 203 202 public void paint(Graphics2D g2, MapView mv, Bounds bounds) { 204 203 205 if ( m_image != null) {204 if ( image != null) { 206 205 207 206 // Position image at the right graphical place … … 213 212 214 213 // This is now the offset in screen pixels 215 double pic_offset_x = (( m_position.east() - leftop.east() ) * pixel_per_en);216 double pic_offset_y = (( leftop.north() - m_position.north() ) * pixel_per_en);214 double pic_offset_x = (( imagePosition.east() - leftop.east() ) * pixel_per_en); 215 double pic_offset_y = (( leftop.north() - imagePosition.north() ) * pixel_per_en); 217 216 218 217 Graphics2D g = (Graphics2D)g2.create(); 219 218 // Move 220 219 g.translate( pic_offset_x, pic_offset_y ); 221 // Rotate 222 g.rotate( m_angle * Math.PI / 180.0 ); 220 223 221 // Scale 224 double scalex = m_scalex * m_initial_scale * pixel_per_en / getMetersPerEasting(m_position) / 100;225 double scaley = m_scaley * m_initial_scale * pixel_per_en / getMetersPerNorthing(m_position) / 100;222 double scalex = initialImageScale * pixel_per_en / getMetersPerEasting(imagePosition) / 100; 223 double scaley = initialImageScale * pixel_per_en / getMetersPerNorthing(imagePosition) / 100; 226 224 g.scale( scalex, scaley ); 227 // Shear 228 g. shear(m_shearx, m_sheary);225 226 g.transform(transformer.getTransform()); 229 227 230 228 // Draw picture 231 g.drawImage( m_image, -m_image.getWidth(null) / 2, -m_image.getHeight(null) / 2, null );229 g.drawImage( image, -image.getWidth(null) / 2, -image.getHeight(null) / 2, null ); 232 230 233 231 // Draw additional rectangle for the active pic layer … … 235 233 g.setColor( new Color( 0xFF0000 ) ); 236 234 g.drawRect( 237 - m_image.getWidth(null) / 2,238 - m_image.getHeight(null) / 2,239 m_image.getWidth(null),240 m_image.getHeight(null)235 -image.getWidth(null) / 2, 236 -image.getHeight(null) / 2, 237 image.getWidth(null), 238 image.getHeight(null) 241 239 ); 242 240 } 241 // draw points for selection 242 Graphics2D gPoints = (Graphics2D)g2.create(); 243 244 gPoints.translate(pic_offset_x, pic_offset_y); 245 246 gPoints.setColor(Color.RED); // red color for points output 247 248 AffineTransform tr = AffineTransform.getScaleInstance(scalex, scaley); 249 tr.concatenate(transformer.getTransform()); 250 251 for (Point2D p : transformer.getOriginPoints()) { 252 Point2D trP = tr.transform(p, null); 253 int x = (int)trP.getX(), y = (int)trP.getY(); 254 gPoints.drawOval(x-2, y-2, 5, 5); 255 gPoints.drawImage(pinImage, x, y, null); 256 } 257 243 258 } else { 244 259 // TODO: proper logging 245 System.out.println( "PicLayerAbstract::paint - general drawing error ( m_image is null or Graphics not 2D" );246 } 247 } 248 260 System.out.println( "PicLayerAbstract::paint - general drawing error (image is null or Graphics not 2D" ); 261 } 262 } 263 249 264 /** 250 265 * Returns the distance in meter, that corresponds to one unit in east north 251 * space. For normal projections, it is about 1 (but usually changing with 266 * space. For normal projections, it is about 1 (but usually changing with 252 267 * latitude). 253 * For EPSG:4326, it is the distance from one meridian of full degree to the 268 * For EPSG:4326, it is the distance from one meridian of full degree to the 254 269 * next (a couple of kilometers). 255 270 */ … … 259 274 * a shift of that size in east north space without 260 275 * going out of bounds. 261 * 276 * 262 277 * Also, this should get us somewhere in the range of meters, 263 278 * so we get the result at the point 'en' and not some average. … … 265 280 double naturalScale = Main.getProjection().getDefaultZoomInPPD(); 266 281 naturalScale *= 0.01; // make a little smaller 267 282 268 283 LatLon ll1 = Main.getProjection().eastNorth2latlon( 269 284 new EastNorth(en.east() - naturalScale, en.north())); 270 285 LatLon ll2 = Main.getProjection().eastNorth2latlon( 271 286 new EastNorth(en.east() + naturalScale, en.north())); 272 287 273 288 double dist = ll1.greatCircleDistance(ll2) / naturalScale / 2; 274 289 return dist; … … 279 294 double naturalScale = Main.getProjection().getDefaultZoomInPPD(); 280 295 naturalScale *= 0.01; 281 296 282 297 LatLon ll1 = Main.getProjection().eastNorth2latlon( 283 298 new EastNorth(en.east(), en.north()- naturalScale)); 284 299 LatLon ll2 = Main.getProjection().eastNorth2latlon( 285 300 new EastNorth(en.east(), en.north() + naturalScale)); 286 301 287 302 double dist = ll1.greatCircleDistance(ll2) / naturalScale / 2; 288 303 return dist; 289 304 } 290 291 /** 292 * Moves the picture. Scaled in EastNorth... 293 */ 294 public void movePictureBy( double east, double north ) { 295 m_position = m_position.add( east, north ); 296 } 297 298 /** 299 * Scales the picture. scalex and scaley will multiply the current factor 300 */ 301 public void scalePictureBy( double scalex, double scaley ) { 302 m_scalex *= scalex; 303 m_scaley *= scaley; 304 } 305 306 /** 307 * Rotates the picture. Scales in angles. 308 */ 309 public void rotatePictureBy( double angle ) { 310 m_angle += angle; 311 } 312 313 /** 314 * Shear the picture. shearx and sheary will separately add to the 315 * corresponding current value 316 */ 317 public void shearPictureBy( double shearx, double sheary ) { 318 m_shearx += shearx; 319 m_sheary += sheary; 320 } 321 322 /** 323 * Sets the image position to the initial position 324 */ 325 public void resetPosition() { 326 m_position = m_initial_position; 327 } 328 329 /** 330 * Sets the image scale to 1.0 331 */ 332 public void resetScale() { 333 m_scalex = 1.0; 334 m_scaley = 1.0; 335 } 336 337 /** 338 * Sets the image angle to 0.0 339 */ 340 public void resetAngle() { 341 m_angle = 0.0; 342 } 343 344 345 /** 346 * Sets the image to no shear 347 */ 348 public void resetShear() { 349 m_shearx = 0.0; 350 m_sheary = 0.0; 351 } 305 352 306 @Override 353 307 /** … … 357 311 */ 358 312 public void visitBoundingBox(BoundingXYVisitor arg0) { 359 if ( m_image == null )313 if ( image == null ) 360 314 return; 361 315 String projcode = Main.getProjection().toCode(); 362 316 363 317 // TODO: bounding box only supported when coordinates are in meters 364 // The reason for that is that this .cal think makes us a hard time. 365 // The position is stored as a raw data (can be either in degrees or 366 // in meters, depending on the projection used at creation), but the 318 // The reason for that is that this .cal think makes us a hard time. 319 // The position is stored as a raw data (can be either in degrees or 320 // in meters, depending on the projection used at creation), but the 367 321 // initial scale is in m/100pix 368 322 // So for now, we support the bounding box only when everything is in meters 369 323 if (projcode.equals("EPSG:4326") ) 370 324 return; 371 372 EastNorth center = m_position;373 double w = m_image.getWidth(null);374 double h = m_image.getHeight(null);325 326 EastNorth center = imagePosition; 327 double w = image.getWidth(null); 328 double h = image.getHeight(null); 375 329 double diag_pix = Math.sqrt(w*w+h*h); 376 377 // m_initial_scale is a the scale (unit: m/100pix) at creation time 378 double diag_m = (diag_pix/100) * m_initial_scale; 379 380 double factor = Math.max(m_scalex, m_scaley); 330 331 // initialImageScale is a the scale (unit: m/100pix) at creation time 332 double diag_m = (diag_pix/100) * initialImageScale; 333 334 AffineTransform trans = transformer.getTransform(); 335 double factor = Math.max(trans.getScaleX(), trans.getScaleY()); 336 381 337 double offset = factor * diag_m / 2.0; 382 338 … … 393 349 public void saveCalibration( Properties props ) { 394 350 // Save 395 props.put(INITIAL_POS_X, "" + m_initial_position.getX()); 396 props.put(INITIAL_POS_Y, "" + m_initial_position.getY()); 397 props.put(POSITION_X, "" + m_position.getX()); 398 props.put(POSITION_Y, "" + m_position.getY()); 399 props.put(INITIAL_SCALE, "" + m_initial_scale); 400 props.put(SCALEX, "" + m_scalex); 401 props.put(SCALEY, "" + m_scaley); 402 props.put(ANGLE, "" + m_angle); 403 props.put(SHEARX, "" + m_shearx); 404 props.put(SHEARY, "" + m_sheary); 351 double[] matrix = new double[6]; 352 transformer.getTransform().getMatrix(matrix); 353 354 props.put(MATRIXm00, Double.toString(matrix[0])); 355 props.put(MATRIXm01, Double.toString(matrix[1])); 356 props.put(MATRIXm10, Double.toString(matrix[2])); 357 props.put(MATRIXm11, Double.toString(matrix[3])); 358 props.put(MATRIXm02, Double.toString(matrix[4])); 359 props.put(MATRIXm12, Double.toString(matrix[5])); 360 props.put(POSITION_X, Double.toString(imagePosition.getX())); 361 props.put(POSITION_Y, Double.toString(imagePosition.getY())); 405 362 } 406 363 … … 423 380 public void loadCalibration( Properties props ) { 424 381 // Load 425 double pos_x = Double.valueOf( props.getProperty(POSITION_X)); 426 double pos_y = Double.valueOf( props.getProperty(POSITION_Y)); 382 383 AffineTransform transform; 384 385 if (props.containsKey(INITIAL_POS_X)) {// old format 427 386 double in_pos_x = Double.valueOf( props.getProperty(INITIAL_POS_X)); 428 387 double in_pos_y = Double.valueOf( props.getProperty(INITIAL_POS_Y)); … … 433 392 double shear_x = Double.valueOf( props.getProperty(SHEARX)); 434 393 double shear_y = Double.valueOf( props.getProperty(SHEARY)); 435 m_position.setLocation(pos_x, pos_y); 436 m_initial_position.setLocation(pos_x, pos_y); 437 m_angle = angle; 438 m_scalex = scale_x; 439 m_scaley = scale_y; 440 m_shearx = shear_x; 441 m_sheary = shear_y; 442 m_initial_scale = in_scale; 443 // Refresh 444 Main.map.mapView.repaint(); 445 } 446 394 395 initialImagePosition.setLocation(in_pos_x, in_pos_y); 396 397 // transform to matrix from these values - need testing 398 transform = AffineTransform.getRotateInstance(angle); 399 transform.scale(scale_x, scale_y); 400 transform.shear(shear_x, shear_y); 401 initialImageScale = in_scale; 402 } else { 403 double pos_x = Double.valueOf( props.getProperty(POSITION_X)); 404 double pos_y = Double.valueOf( props.getProperty(POSITION_Y)); 405 imagePosition = new EastNorth(pos_x, pos_y); 406 initialImageScale = 1; //in_scale 407 408 // initialize matrix 409 double[] matrix = new double[6]; 410 matrix[0] = Double.parseDouble(props.getProperty(MATRIXm00)); 411 matrix[1] = Double.parseDouble(props.getProperty(MATRIXm01)); 412 matrix[2] = Double.parseDouble(props.getProperty(MATRIXm10)); 413 matrix[3] = Double.parseDouble(props.getProperty(MATRIXm11)); 414 matrix[4] = Double.parseDouble(props.getProperty(MATRIXm02)); 415 matrix[5] = Double.parseDouble(props.getProperty(MATRIXm12)); 416 417 transform = new AffineTransform(matrix); 418 } 419 transformer.resetCalibration(); 420 transformer.getTransform().concatenate(transform); 421 422 // Refresh 423 Main.map.mapView.repaint(); 424 } 425 447 426 public void loadWorldfile(InputStream is) throws IOException { 448 427 BufferedReader br = null; … … 456 435 } 457 436 double sx=e[0], ry=e[1], rx=e[2], sy=e[3], dx=e[4], dy=e[5]; 458 int w = m_image.getWidth(null);459 int h = m_image.getHeight(null);460 m_position.setLocation(461 dx + w/2*sx + h/2*rx, 437 int w = image.getWidth(null); 438 int h = image.getHeight(null); 439 imagePosition.setLocation( 440 dx + w/2*sx + h/2*rx, 462 441 dy + w/2*ry + h/2*sy 463 442 ); 464 m_initial_position.setLocation(m_position); 465 m_angle = 0; 466 m_scalex = 100*sx*getMetersPerEasting(m_position); 467 m_scaley = -100*sy*getMetersPerNorthing(m_position); 468 m_shearx = rx / sx; 469 m_sheary = ry / sy; 470 m_initial_scale = 1; 443 initialImagePosition.setLocation(imagePosition); 444 // m_angle = 0; 445 double scalex = 100*sx*getMetersPerEasting(imagePosition); 446 double scaley = -100*sy*getMetersPerNorthing(imagePosition); 447 double shearx = rx / sx; 448 double sheary = ry / sy; 449 450 transformer.resetCalibration(); 451 AffineTransform tr = transformer.getTransform(); 452 tr.scale(scalex, scaley); 453 tr.shear(shearx, sheary); 454 455 initialImageScale = 1; 471 456 Main.map.mapView.repaint(); 472 457 } finally { … … 475 460 } 476 461 477 private class ResetSubmenuAction extends AbstractAction implements LayerAction { 478 479 public ResetSubmenuAction() { 480 super(tr("Reset")); 481 } 482 483 public void actionPerformed(ActionEvent e) { 484 } 485 486 public Component createMenuComponent() { 487 JMenu reset_submenu = new JMenu(this); 488 reset_submenu.add( new ResetPictureAllAction( PicLayerAbstract.this ) ); 489 reset_submenu.addSeparator(); 490 reset_submenu.add( new ResetPicturePositionAction( PicLayerAbstract.this ) ); 491 reset_submenu.add( new ResetPictureAngleAction( PicLayerAbstract.this ) ); 492 reset_submenu.add( new ResetPictureScaleAction( PicLayerAbstract.this ) ); 493 reset_submenu.add( new ResetPictureShearAction( PicLayerAbstract.this ) ); 494 return reset_submenu; 495 } 496 497 public boolean supportLayers(List<Layer> layers) { 498 return layers.size() == 1 && layers.get(0) instanceof PicLayerAbstract; 499 } 500 462 public Point2D transformPoint(Point p) throws NoninvertibleTransformException { 463 // Position image at the right graphical place 464 465 EastNorth center = Main.map.mapView.getCenter(); 466 EastNorth leftop = Main.map.mapView.getEastNorth( 0, 0 ); 467 // Number of pixels for one unit in east north space. 468 // This is the same in x- and y- direction. 469 double pixel_per_en = ( Main.map.mapView.getWidth() / 2.0 ) / ( center.east() - leftop.east() ); 470 471 // This is now the offset in screen pixels 472 double pic_offset_x = (( imagePosition.east() - leftop.east() ) * pixel_per_en); 473 double pic_offset_y = (( leftop.north() - imagePosition.north() ) * pixel_per_en); // something bad... 474 475 AffineTransform pointTrans = AffineTransform.getTranslateInstance(pic_offset_x, pic_offset_y); 476 477 double scalex = initialImageScale * pixel_per_en / getMetersPerEasting(imagePosition) / 100; 478 double scaley = initialImageScale * pixel_per_en / getMetersPerNorthing(imagePosition) / 100; 479 480 pointTrans.scale(scalex, scaley); // ok here 481 482 pointTrans.concatenate(transformer.getTransform()); 483 484 Point2D result = pointTrans.inverseTransform(p, null); 485 return result; 486 } 487 488 /** 489 * Moves the picture. Scaled in EastNorth... 490 */ 491 public void movePictureBy(double x, double y) { 492 imagePosition = imagePosition.add(x, y); 493 } 494 495 public void rotatePictureBy(double angle) { 496 transformer.concatenateTransform(AffineTransform.getRotateInstance(angle)); 497 } 498 499 public void scalePictureBy(double scalex, double scaley) { 500 transformer.concatenateTransform(AffineTransform.getScaleInstance(scalex, scaley)); 501 } 502 503 public void shearPictureBy(double shx, double shy) { 504 transformer.concatenateTransform(AffineTransform.getShearInstance(shx, shy)); 505 } 506 507 public void resetCalibration() { 508 transformer.resetCalibration(); 509 imagePosition.setLocation(initialImagePosition); 510 } 511 512 // get image coordinates by mouse coords 513 public Point2D findSelectedPoint(Point point) { 514 if (image == null) 515 return null; 516 517 try { 518 Point2D pressed = transformPoint(point); 519 for (Point2D p : transformer.getOriginPoints()) 520 if (p.distance(pressed) <= 4.0) // if user clicked to select some of origin point 521 return p; 522 } catch (NoninvertibleTransformException e) { 523 e.printStackTrace(); 524 } 525 return null; 501 526 } 502 527 } -
applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/layer/PicLayerFromClipboard.java
r27054 r27120 19 19 ***************************************************************************/ 20 20 21 package org.openstreetmap.josm.plugins.piclayer ;21 package org.openstreetmap.josm.plugins.piclayer.layer; 22 22 23 23 import static org.openstreetmap.josm.tools.I18n.tr; … … 62 62 63 63 @Override 64 p rotectedString getPicLayerName() {64 public String getPicLayerName() { 65 65 return "Clipboard"; 66 66 } -
applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/layer/PicLayerFromFile.java
r27054 r27120 19 19 ***************************************************************************/ 20 20 21 package org.openstreetmap.josm.plugins.piclayer ;21 package org.openstreetmap.josm.plugins.piclayer.layer; 22 22 23 23 import static org.openstreetmap.josm.tools.I18n.tr; … … 263 263 264 264 @Override 265 p rotectedString getPicLayerName() {265 public String getPicLayerName() { 266 266 return m_tooltiptext; 267 267 }
Note:
See TracChangeset
for help on using the changeset viewer.