Changeset 23190 in osm for applications/editors/josm/plugins/piclayer
- Timestamp:
- 2010-09-15T18:54:18+02:00 (14 years ago)
- Location:
- applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer
- Files:
-
- 19 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/CalibrationFileFilter.java
r20217 r23190 30 30 */ 31 31 public class CalibrationFileFilter extends FileFilter { 32 33 // Extension used by calibration files34 public static final String EXTENSION = ".cal";35 32 36 @Override 37 public boolean accept(File f) { 38 String ext3 = ( f.getName().length() > 4 ) ? f.getName().substring( f.getName().length() - 4 ).toLowerCase() : ""; 33 // Extension used by calibration files 34 public static final String EXTENSION = ".cal"; 39 35 40 // TODO: check what is supported by Java :) 41 return ( f.isDirectory() 42 || ext3.equals( EXTENSION ) 43 ); 44 } 36 @Override 37 public boolean accept(File f) { 38 String ext3 = ( f.getName().length() > 4 ) ? f.getName().substring( f.getName().length() - 4 ).toLowerCase() : ""; 45 39 46 @Override 47 public String getDescription() { 48 return tr("Calibration Files")+ " (*" + EXTENSION + ")"; 49 } 40 // TODO: check what is supported by Java :) 41 return ( f.isDirectory() 42 || ext3.equals( EXTENSION ) 43 ); 44 } 45 46 @Override 47 public String getDescription() { 48 return tr("Calibration Files")+ " (*" + EXTENSION + ")"; 49 } 50 50 } -
applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/LoadPictureCalibrationAction.java
r20217 r23190 44 44 public class LoadPictureCalibrationAction extends JosmAction { 45 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 46 // Owner layer of the action 47 PicLayerAbstract m_owner = null; 48 49 /** 50 * Constructor 51 */ 52 public LoadPictureCalibrationAction( PicLayerAbstract owner ) { 53 super(tr("Load Picture Calibration..."), null, tr("Loads calibration data to a file"), null, false); 54 // Remember the owner... 55 m_owner = owner; 56 } 57 58 /** 59 * Action handler 60 */ 61 public void actionPerformed(ActionEvent arg0) { 62 // Save dialog 63 final JFileChooser fc = new JFileChooser(); 64 fc.setAcceptAllFileFilterUsed( false ); 65 fc.setFileFilter( new CalibrationFileFilter() ); 66 fc.setSelectedFile( new File(m_owner.getPicLayerName() + CalibrationFileFilter.EXTENSION)); 67 int result = fc.showOpenDialog(Main.parent ); 68 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 69 if ( result == JFileChooser.APPROVE_OPTION ) { 70 71 // Load 72 try { 73 Properties props = new Properties(); 74 props.load(new FileInputStream(fc.getSelectedFile())); 75 m_owner.loadCalibration(props); 76 } catch (Exception e) { 77 // Error 78 e.printStackTrace(); 79 JOptionPane.showMessageDialog(Main.parent , tr("Loading file failed: {0}", e.getMessage())); 80 } 81 } 82 } 83 83 } -
applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/MovePictureAction.java
r20217 r23190 38 38 * This class handles the input during moving the picture. 39 39 */ 40 public class MovePictureAction extends MapMode implements MouseListener, MouseMotionListener 40 public class MovePictureAction extends MapMode implements MouseListener, MouseMotionListener 41 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; 50 51 /** 52 * Constructor 53 */ 54 public MovePictureAction(MapFrame frame) { 55 super(tr("PicLayer move"), "move", tr("Drag to move the picture"), frame, ImageProvider.getCursor("crosshair", null)); 56 } 42 // Action ongoing? 43 private boolean mb_dragging = false; 57 44 58 @Override 45 // Last mouse position 46 private EastNorth m_prevEastNorth; 47 48 // The layer we're working on 49 private PicLayerAbstract m_currentLayer = null; 50 51 /** 52 * Constructor 53 */ 54 public MovePictureAction(MapFrame frame) { 55 super(tr("PicLayer move"), "move", tr("Drag to move the picture"), frame, ImageProvider.getCursor("crosshair", null)); 56 } 57 58 @Override 59 59 public void enterMode() { 60 60 super.enterMode(); … … 63 63 } 64 64 65 @Override 65 @Override 66 66 public void exitMode() { 67 67 super.exitMode(); 68 68 Main.map.mapView.removeMouseListener(this); 69 69 Main.map.mapView.removeMouseMotionListener(this); 70 } 71 72 @Override 70 } 71 72 @Override 73 73 public void mousePressed(MouseEvent e) { 74 75 76 77 78 79 80 81 82 83 84 } 85 86 @Override 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 87 public void mouseDragged(MouseEvent e) { 88 88 // Picture moving is ongoing 89 89 if(mb_dragging) { 90 90 EastNorth eastNorth = Main.map.mapView.getEastNorth(e.getX(),e.getY()); 91 91 m_currentLayer.movePictureBy( 92 92 eastNorth.east()-m_prevEastNorth.east(), 93 93 eastNorth.north()-m_prevEastNorth.north() 94 94 ); … … 96 96 Main.map.mapView.repaint(); 97 97 } 98 } 99 100 @Override 98 } 99 100 @Override 101 101 public void mouseReleased(MouseEvent e) { 102 103 104 } 102 // Stop moving 103 mb_dragging = false; 104 } 105 105 106 106 } -
applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/NewLayerFromClipboardAction.java
r22549 r23190 35 35 */ 36 36 public class NewLayerFromClipboardAction extends JosmAction { 37 38 /**39 * Constructor...40 */41 public NewLayerFromClipboardAction() {42 super(tr("New picture layer from clipboard"), null, null, null, false);43 }44 37 45 /** 46 * Action handler 47 */ 48 public void actionPerformed(ActionEvent arg0) { 49 // Create layer from clipboard 50 PicLayerFromClipboard layer = new PicLayerFromClipboard(); 51 // Add layer only if successfully initialized 52 try { 53 layer.initialize(); 54 } 55 catch (IOException e) { 56 // Failed 57 System.out.println( "NewLayerFromClipboardAction::actionPerformed - " + e.getMessage() ); 58 JOptionPane.showMessageDialog(null, e.getMessage() ); 59 return; 60 } 61 // Add layer 62 Main.main.addLayer( layer ); 63 } 38 /** 39 * Constructor... 40 */ 41 public NewLayerFromClipboardAction() { 42 super(tr("New picture layer from clipboard"), null, null, null, false); 43 } 44 45 /** 46 * Action handler 47 */ 48 public void actionPerformed(ActionEvent arg0) { 49 // Create layer from clipboard 50 PicLayerFromClipboard layer = new PicLayerFromClipboard(); 51 // Add layer only if successfully initialized 52 try { 53 layer.initialize(); 54 } 55 catch (IOException e) { 56 // Failed 57 System.out.println( "NewLayerFromClipboardAction::actionPerformed - " + e.getMessage() ); 58 JOptionPane.showMessageDialog(null, e.getMessage() ); 59 return; 60 } 61 // Add layer 62 Main.main.addLayer( layer ); 63 } 64 64 } -
applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/NewLayerFromFileAction.java
r22549 r23190 39 39 */ 40 40 public class NewLayerFromFileAction extends JosmAction { 41 42 /**43 * Provides filtering of only image files.44 */45 private class ImageFileFilter extends FileFilter {46 41 47 @Override 48 public boolean accept(File f) { 49 50 String ext3 = ( f.getName().length() > 4 ) ? f.getName().substring( f.getName().length() - 4 ).toLowerCase() : ""; 51 String ext4 = ( f.getName().length() > 5 ) ? f.getName().substring( f.getName().length() - 5 ).toLowerCase() : ""; 42 /** 43 * Provides filtering of only image files. 44 */ 45 private class ImageFileFilter extends FileFilter { 52 46 53 // TODO: check what is supported by Java :) 54 return ( f.isDirectory() 55 || ext3.equals( ".jpg" ) 56 || ext4.equals( ".jpeg" ) 57 || ext3.equals( ".png" ) 58 ); 59 } 47 @Override 48 public boolean accept(File f) { 49 50 String ext3 = ( f.getName().length() > 4 ) ? f.getName().substring( f.getName().length() - 4 ).toLowerCase() : ""; 51 String ext4 = ( f.getName().length() > 5 ) ? f.getName().substring( f.getName().length() - 5 ).toLowerCase() : ""; 52 53 // TODO: check what is supported by Java :) 54 return ( f.isDirectory() 55 || ext3.equals( ".jpg" ) 56 || ext4.equals( ".jpeg" ) 57 || ext3.equals( ".png" ) 58 ); 59 } 60 60 61 61 62 @Override 63 public String getDescription() { 64 return tr("Image files"); 65 } 66 67 } 68 69 /** 70 * Constructor... 71 */ 72 public NewLayerFromFileAction() { 73 super(tr("New picture layer from file..."), null, null, null, false); 74 } 62 @Override 63 public String getDescription() { 64 return tr("Image files"); 65 } 75 66 76 /** 77 * Action handler 78 */ 79 public void actionPerformed(ActionEvent arg0) { 80 81 // Choose a file 82 JFileChooser fc = new JFileChooser(); 83 fc.setAcceptAllFileFilterUsed( false ); 84 fc.setFileFilter( new ImageFileFilter() ); 85 int result = fc.showOpenDialog( Main.parent ); 86 87 // Create a layer? 88 if ( result == JFileChooser.APPROVE_OPTION ) { 89 // Create layer from file 90 PicLayerFromFile layer = new PicLayerFromFile( fc.getSelectedFile() ); 91 // Add layer only if successfully initialized 92 try { 93 layer.initialize(); 94 } 95 catch (IOException e) { 96 // Failed 97 System.out.println( "NewLayerFromFileAction::actionPerformed - " + e.getMessage() ); 98 JOptionPane.showMessageDialog(null, e.getMessage() ); 99 return; 100 } 101 // Add layer 102 Main.main.addLayer( layer ); 103 } 104 105 } 67 } 68 69 /** 70 * Constructor... 71 */ 72 public NewLayerFromFileAction() { 73 super(tr("New picture layer from file..."), null, null, null, false); 74 } 75 76 /** 77 * Action handler 78 */ 79 public void actionPerformed(ActionEvent arg0) { 80 81 // Choose a file 82 JFileChooser fc = new JFileChooser(); 83 fc.setAcceptAllFileFilterUsed( false ); 84 fc.setFileFilter( new ImageFileFilter() ); 85 int result = fc.showOpenDialog( Main.parent ); 86 87 // Create a layer? 88 if ( result == JFileChooser.APPROVE_OPTION ) { 89 // Create layer from file 90 PicLayerFromFile layer = new PicLayerFromFile( fc.getSelectedFile() ); 91 // Add layer only if successfully initialized 92 try { 93 layer.initialize(); 94 } 95 catch (IOException e) { 96 // Failed 97 System.out.println( "NewLayerFromFileAction::actionPerformed - " + e.getMessage() ); 98 JOptionPane.showMessageDialog(null, e.getMessage() ); 99 return; 100 } 101 // Add layer 102 Main.main.addLayer( layer ); 103 } 104 105 } 106 106 } -
applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/PicLayerAbstract.java
r22549 r23190 275 275 */ 276 276 public void saveCalibration( Properties props ) { 277 278 279 280 281 282 283 284 285 277 // Save 278 props.put(INITIAL_POS_X, "" + m_initial_position.getX()); 279 props.put(INITIAL_POS_Y, "" + m_initial_position.getY()); 280 props.put(POSITION_X, "" + m_position.getX()); 281 props.put(POSITION_Y, "" + m_position.getY()); 282 props.put(INITIAL_SCALE, "" + m_initial_scale); 283 props.put(SCALEX, "" + m_scalex); 284 props.put(SCALEY, "" + m_scaley); 285 props.put(ANGLE, "" + m_angle); 286 286 } 287 287 … … 292 292 */ 293 293 public void loadCalibration( Properties props ) { 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 294 // Load 295 double pos_x = Double.valueOf( props.getProperty(POSITION_X)); 296 double pos_y = Double.valueOf( props.getProperty(POSITION_Y)); 297 double in_pos_x = Double.valueOf( props.getProperty(INITIAL_POS_X)); 298 double in_pos_y = Double.valueOf( props.getProperty(INITIAL_POS_Y)); 299 double angle = Double.valueOf( props.getProperty(ANGLE)); 300 double in_scale = Double.valueOf( props.getProperty(INITIAL_SCALE)); 301 double scale_x = Double.valueOf( props.getProperty(SCALEX)); 302 double scale_y = Double.valueOf( props.getProperty(SCALEY)); 303 m_position.setLocation(pos_x, pos_y); 304 m_initial_position.setLocation(pos_x, pos_y); 305 m_angle = angle; 306 m_scalex = scale_x; 307 m_scaley = scale_y; 308 m_initial_scale = in_scale; 309 // Refresh 310 310 Main.map.mapView.repaint(); 311 311 } … … 313 313 private class ResetSubmenuAction extends AbstractAction implements LayerAction { 314 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 315 public ResetSubmenuAction() { 316 super(tr("Reset")); 317 } 318 319 public void actionPerformed(ActionEvent e) { 320 } 321 322 public Component createMenuComponent() { 323 JMenu reset_submenu = new JMenu(this); 324 reset_submenu.add( new ResetPictureAllAction( PicLayerAbstract.this ) ); 325 reset_submenu.addSeparator(); 326 reset_submenu.add( new ResetPicturePositionAction( PicLayerAbstract.this ) ); 327 reset_submenu.add( new ResetPictureAngleAction( PicLayerAbstract.this ) ); 328 reset_submenu.add( new ResetPictureScaleAction( PicLayerAbstract.this ) ); 329 return reset_submenu; 330 } 331 332 public boolean supportLayers(List<Layer> layers) { 333 return layers.size() == 1 && layers.get(0) instanceof PicLayerAbstract; 334 } 335 335 336 336 } -
applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/PicLayerFromClipboard.java
r20217 r23190 35 35 public class PicLayerFromClipboard extends PicLayerAbstract { 36 36 37 38 39 40 41 37 @Override 38 protected Image createImage() throws IOException { 39 // Return item 40 Image image = null; 41 // Access the clipboard 42 42 Transferable t = Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null); 43 43 // Check result 44 44 if ( t == null ) { 45 45 throw new IOException(tr("Nothing in clipboard")); 46 46 } 47 47 48 48 // TODO: Why is it so slow? 49 49 // Try to make it an image data … … 52 52 image = (Image)t.getTransferData(DataFlavor.imageFlavor); 53 53 } else { 54 54 throw new IOException(tr("The clipboard data is not an image")); 55 55 } 56 56 } catch (UnsupportedFlavorException e) { 57 58 } 59 57 throw new IOException( e.getMessage() ); 58 } 59 60 60 return image; 61 61 } 62 62 63 64 65 66 63 @Override 64 protected String getPicLayerName() { 65 return "Clipboard"; 66 } 67 67 68 68 } -
applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/PicLayerFromFile.java
r17327 r23190 30 30 */ 31 31 public class PicLayerFromFile extends PicLayerAbstract { 32 33 34 35 36 32 33 // File to load from. 34 private File m_file; 35 // Tooltip text 36 private String m_tooltiptext; 37 37 38 38 public PicLayerFromFile( File file ) { 39 40 41 42 43 } 44 45 46 39 // Remember the file 40 m_file = file; 41 // Generate tooltip text 42 m_tooltiptext = m_file.getAbsolutePath(); 43 } 44 45 @Override 46 protected Image createImage() throws IOException { 47 47 // Try to load file 48 49 50 51 48 Image image = null; 49 image = ImageIO.read( m_file ); 50 return image; 51 } 52 52 53 54 55 56 } 53 @Override 54 protected String getPicLayerName() { 55 return m_tooltiptext; 56 } 57 57 } -
applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/PicLayerPlugin.java
r20217 r23190 59 59 */ 60 60 public PicLayerPlugin(PluginInformation info) { 61 62 61 super(info); 62 63 63 // Create menu entry 64 64 if ( Main.main.menu != null ) { -
applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/ResetPictureAllAction.java
r20217 r23190 35 35 public class ResetPictureAllAction extends JosmAction { 36 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 37 // Owner layer of the action 38 PicLayerAbstract m_owner = null; 39 40 /** 41 * Constructor 42 */ 43 public ResetPictureAllAction( PicLayerAbstract owner ) { 44 super(tr("All"), null, tr("Resets picture calibration"), null, false); 45 // Remember the owner... 46 m_owner = owner; 47 } 48 49 /** 50 * Action handler 51 */ 52 public void actionPerformed(ActionEvent arg0) { 53 // Reset 54 m_owner.resetAngle(); 55 m_owner.resetPosition(); 56 m_owner.resetScale(); 57 // Redraw 58 58 Main.map.mapView.repaint(); 59 59 } 60 60 } -
applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/ResetPictureAngleAction.java
r20217 r23190 35 35 public class ResetPictureAngleAction extends JosmAction { 36 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 37 // Owner layer of the action 38 PicLayerAbstract m_owner = null; 39 40 /** 41 * Constructor 42 */ 43 public ResetPictureAngleAction( PicLayerAbstract owner ) { 44 super(tr("Angle"), null, tr("Resets picture rotation"), null, false); 45 // Remember the owner... 46 m_owner = owner; 47 } 48 49 /** 50 * Action handler 51 */ 52 public void actionPerformed(ActionEvent arg0) { 53 // Reset 54 m_owner.resetAngle(); 55 // Redraw 56 56 Main.map.mapView.repaint(); 57 57 } 58 58 } -
applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/ResetPicturePositionAction.java
r20217 r23190 35 35 public class ResetPicturePositionAction extends JosmAction { 36 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 37 // Owner layer of the action 38 PicLayerAbstract m_owner = null; 39 40 /** 41 * Constructor 42 */ 43 public ResetPicturePositionAction( PicLayerAbstract owner ) { 44 super(tr("Reset position"), null, tr("Resets picture position"), null, false); 45 // Remember the owner... 46 m_owner = owner; 47 } 48 49 /** 50 * Action handler 51 */ 52 public void actionPerformed(ActionEvent arg0) { 53 // Reset 54 m_owner.resetPosition(); 55 // Redraw 56 56 Main.map.mapView.repaint(); 57 57 } 58 58 } -
applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/ResetPictureScaleAction.java
r20217 r23190 35 35 public class ResetPictureScaleAction extends JosmAction { 36 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 37 // Owner layer of the action 38 PicLayerAbstract m_owner = null; 39 40 /** 41 * Constructor 42 */ 43 public ResetPictureScaleAction( PicLayerAbstract owner ) { 44 super(tr("Scale"), null, tr("Resets picture scale"), null, false); 45 // Remember the owner... 46 m_owner = owner; 47 } 48 49 /** 50 * Action handler 51 */ 52 public void actionPerformed(ActionEvent arg0) { 53 // Reset 54 m_owner.resetScale(); 55 // Redraw 56 56 Main.map.mapView.repaint(); 57 57 } 58 58 } -
applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/RotatePictureAction.java
r20217 r23190 37 37 * This class handles the input during rotating the picture. 38 38 */ 39 public class RotatePictureAction extends MapMode implements MouseListener, MouseMotionListener 39 public class RotatePictureAction extends MapMode implements MouseListener, MouseMotionListener 40 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; 49 50 /** 51 * Constructor 52 */ 53 public RotatePictureAction(MapFrame frame) { 54 super(tr("PicLayer rotate"), "rotate", tr("Drag to rotate the picture"), frame, ImageProvider.getCursor("crosshair", null)); 55 // TODO Auto-generated constructor stub 56 } 41 // Action ongoing? 42 private boolean mb_dragging = false; 57 43 58 @Override 44 // Last mouse position 45 private int m_prevY; 46 47 // Layer we're working on 48 private PicLayerAbstract m_currentLayer = null; 49 50 /** 51 * Constructor 52 */ 53 public RotatePictureAction(MapFrame frame) { 54 super(tr("PicLayer rotate"), "rotate", tr("Drag to rotate the picture"), frame, ImageProvider.getCursor("crosshair", null)); 55 // TODO Auto-generated constructor stub 56 } 57 58 @Override 59 59 public void enterMode() { 60 60 super.enterMode(); … … 63 63 } 64 64 65 @Override 65 @Override 66 66 public void exitMode() { 67 67 super.exitMode(); 68 68 Main.map.mapView.removeMouseListener(this); 69 69 Main.map.mapView.removeMouseMotionListener(this); 70 } 71 72 @Override 70 } 71 72 @Override 73 73 public void mousePressed(MouseEvent e) { 74 75 76 77 78 79 80 81 82 83 } 84 85 @Override 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 } 82 } 83 } 84 85 @Override 86 86 public void mouseDragged(MouseEvent e) { 87 87 // Rotate the picture 88 88 if(mb_dragging) { 89 89 // TODO: Magic number … … 92 92 Main.map.mapView.repaint(); 93 93 } 94 } 95 94 } 95 96 96 @Override public void mouseReleased(MouseEvent e) { 97 98 99 } 97 // End rotating 98 mb_dragging = false; 99 } 100 100 101 101 } -
applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/SavePictureCalibrationAction.java
r20217 r23190 43 43 public class SavePictureCalibrationAction extends JosmAction { 44 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 45 // Owner layer of the action 46 PicLayerAbstract m_owner = null; 47 48 /** 49 * Constructor 50 */ 51 public SavePictureCalibrationAction( PicLayerAbstract owner ) { 52 super(tr("Save Picture Calibration..."), null, tr("Saves calibration data to a file"), null, false); 53 // Remember the owner... 54 m_owner = owner; 55 } 56 57 /** 58 * Action handler 59 */ 60 public void actionPerformed(ActionEvent arg0) { 61 // Save dialog 62 final JFileChooser fc = new JFileChooser(); 63 fc.setAcceptAllFileFilterUsed( false ); 64 fc.setFileFilter( new CalibrationFileFilter() ); 65 fc.setSelectedFile( new File(m_owner.getPicLayerName() + CalibrationFileFilter.EXTENSION)); 66 int result = fc.showSaveDialog( Main.parent ); 67 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 } 88 68 if ( result == JFileChooser.APPROVE_OPTION ) { 69 // Check file extension and force it to be valid 70 File file = fc.getSelectedFile(); 71 String path = file.getAbsolutePath(); 72 if ( path.length() < CalibrationFileFilter.EXTENSION.length() 73 || !path.substring( path.length() - 4 ).equals(CalibrationFileFilter.EXTENSION)) { 74 file = new File( path + CalibrationFileFilter.EXTENSION ); 75 } 76 77 // Save 78 Properties props = new Properties(); 79 m_owner.saveCalibration(props); 80 try { 81 props.store(new FileOutputStream(file), tr("JOSM PicLayer plugin calibration data")); 82 } catch (Exception e) { 83 // Error 84 e.printStackTrace(); 85 JOptionPane.showMessageDialog(Main.parent , tr("Saving file failed: {0}", e.getMessage())); 86 } 87 } 88 } 89 89 } -
applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/ScalePictureActionAbstract.java
r17321 r23190 35 35 * This class handles the input during scaling the picture. 36 36 */ 37 public abstract class ScalePictureActionAbstract extends MapMode implements MouseListener, MouseMotionListener 37 public abstract class ScalePictureActionAbstract extends MapMode implements MouseListener, MouseMotionListener 38 38 { 39 // Scaling ongoing? 40 private boolean mb_dragging = false; 41 42 // Last mouse position 43 private int m_prevY; 44 45 // Layer we're working on 46 protected PicLayerAbstract m_currentLayer = null; 47 48 /** 49 * Constructor 50 */ 51 public ScalePictureActionAbstract (String name, String icon, String tooltip, MapFrame frame) { 52 super(name, icon, tooltip, frame, ImageProvider.getCursor("crosshair", null)); 53 // TODO Auto-generated constructor stub 54 } 39 // Scaling ongoing? 40 private boolean mb_dragging = false; 55 41 56 @Override 42 // Last mouse position 43 private int m_prevY; 44 45 // Layer we're working on 46 protected PicLayerAbstract m_currentLayer = null; 47 48 /** 49 * Constructor 50 */ 51 public ScalePictureActionAbstract (String name, String icon, String tooltip, MapFrame frame) { 52 super(name, icon, tooltip, frame, ImageProvider.getCursor("crosshair", null)); 53 // TODO Auto-generated constructor stub 54 } 55 56 @Override 57 57 public void enterMode() { 58 58 super.enterMode(); … … 61 61 } 62 62 63 @Override 63 @Override 64 64 public void exitMode() { 65 65 super.exitMode(); 66 66 Main.map.mapView.removeMouseListener(this); 67 67 Main.map.mapView.removeMouseMotionListener(this); 68 } 69 70 @Override 68 } 69 70 @Override 71 71 public void mousePressed(MouseEvent e) { 72 73 74 75 76 77 78 79 80 81 } 82 83 @Override 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 } 80 } 81 } 82 83 @Override 84 84 public void mouseDragged(MouseEvent e) { 85 85 // Scale the picture 86 86 if(mb_dragging) { 87 87 doTheScale( ( e.getY() - m_prevY ) / 500.0 ); … … 90 90 } 91 91 } 92 93 @Override 92 93 @Override 94 94 public void mouseReleased(MouseEvent e) { 95 96 95 // Stop scaling 96 mb_dragging = false; 97 97 } 98 98 99 99 /** 100 100 * Does the actual scaling in the inherited class. -
applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/ScaleXPictureAction.java
r20217 r23190 33 33 * This class handles the input during scaling the picture. 34 34 */ 35 public class ScaleXPictureAction extends ScalePictureActionAbstract 35 public class ScaleXPictureAction extends ScalePictureActionAbstract 36 36 { 37 38 39 40 41 42 43 37 /* 38 * Constructor 39 */ 40 public ScaleXPictureAction(MapFrame frame) { 41 super(tr("PicLayer scale X"), "scale_x", tr("Drag to scale the picture in the X Axis"), frame); 42 // TODO Auto-generated constructor stub 43 } 44 44 45 45 public void doTheScale( double scale ) { 46 46 m_currentLayer.scalePictureBy( scale, 0.0 ); 47 47 } -
applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/ScaleXYPictureAction.java
r20217 r23190 33 33 * This class handles the input during scaling the picture. 34 34 */ 35 public class ScaleXYPictureAction extends ScalePictureActionAbstract 35 public class ScaleXYPictureAction extends ScalePictureActionAbstract 36 36 { 37 38 39 40 41 42 43 37 /* 38 * Constructor 39 */ 40 public ScaleXYPictureAction(MapFrame frame) { 41 super(tr("PicLayer scale"), "scale", tr("Drag to scale the picture in the X and Y Axis"), frame); 42 // TODO Auto-generated constructor stub 43 } 44 44 45 45 public void doTheScale( double scale ) { 46 46 m_currentLayer.scalePictureBy( scale, scale ); 47 47 } -
applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/ScaleYPictureAction.java
r20217 r23190 33 33 * This class handles the input during scaling the picture. 34 34 */ 35 public class ScaleYPictureAction extends ScalePictureActionAbstract 35 public class ScaleYPictureAction extends ScalePictureActionAbstract 36 36 { 37 38 39 40 41 42 43 37 /* 38 * Constructor 39 */ 40 public ScaleYPictureAction(MapFrame frame) { 41 super(tr("PicLayer scale Y"), "scale_y", tr("Drag to scale the picture in the Y Axis"), frame); 42 // TODO Auto-generated constructor stub 43 } 44 44 45 45 public void doTheScale( double scale ) { 46 46 m_currentLayer.scalePictureBy( 0.0, scale ); 47 47 }
Note:
See TracChangeset
for help on using the changeset viewer.