Changeset 32675 in osm for applications/editors
- Timestamp:
- 2016-07-18T23:45:04+02:00 (8 years ago)
- Location:
- applications/editors/josm/plugins/piclayer
- Files:
-
- 2 added
- 27 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/piclayer/.project
r32286 r32675 16 16 </arguments> 17 17 </buildCommand> 18 <buildCommand> 19 <name>net.sf.eclipsecs.core.CheckstyleBuilder</name> 20 <arguments> 21 </arguments> 22 </buildCommand> 18 23 </buildSpec> 19 24 <natures> 20 25 <nature>org.eclipse.jdt.core.javanature</nature> 26 <nature>net.sf.eclipsecs.core.CheckstyleNature</nature> 21 27 </natures> 22 28 </projectDescription> -
applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/PicLayerPlugin.java
r32495 r32675 74 74 75 75 // Create menu entry 76 76 77 77 // Add menu items 78 78 MainMenu.add(Main.main.menu.imagerySubMenu, newLayerFromFileAction); … … 89 89 @Override 90 90 public void mapFrameInitialized(MapFrame oldFrame, MapFrame newFrame) { 91 if (newFrame != null) {91 if (newFrame != null) { 92 92 // Create plugin map modes 93 93 MovePictureAction movePictureAction = new MovePictureAction(newFrame); … … 114 114 buttonList.add(picLayerActionButtonFactory(shearPictureAction)); 115 115 116 for (IconToggleButton btn : buttonList) {116 for (IconToggleButton btn : buttonList) { 117 117 newFrame.addMapMode(btn); 118 118 } -
applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/actions/GenericPicTransformAction.java
r32329 r32675 57 57 public void mousePressed(MouseEvent e) { 58 58 // Start action 59 if ( Main.getLayerManager().getActiveLayer() instanceof PicLayerAbstract) {60 currentLayer = (PicLayerAbstract) Main.getLayerManager().getActiveLayer();59 if (Main.getLayerManager().getActiveLayer() instanceof PicLayerAbstract) { 60 currentLayer = (PicLayerAbstract) Main.getLayerManager().getActiveLayer(); 61 61 62 if ( currentLayer != null && e.getButton() == MouseEvent.BUTTON1) {62 if (currentLayer != null && e.getButton() == MouseEvent.BUTTON1) { 63 63 requestFocusInMapView(); 64 64 isDragging = true; 65 65 prevMousePoint = new Point(e.getPoint()); 66 prevEastNorth = Main.map.mapView.getEastNorth(e.getX(), e.getY());66 prevEastNorth = Main.map.mapView.getEastNorth(e.getX(), e.getY()); 67 67 // try to find and fill selected point if possible 68 68 selectedPoint = currentLayer.findSelectedPoint(e.getPoint()); … … 75 75 public void mouseDragged(MouseEvent e) { 76 76 // Call action performing 77 if (isDragging && currentLayer != null) {77 if (isDragging && currentLayer != null) { 78 78 doAction(e); 79 79 prevMousePoint = new Point(e.getPoint()); 80 prevEastNorth = Main.map.mapView.getEastNorth(e.getX(), e.getY());80 prevEastNorth = Main.map.mapView.getEastNorth(e.getX(), e.getY()); 81 81 Main.map.mapView.repaint(); 82 82 } … … 101 101 Layer active = Main.getLayerManager().getActiveLayer(); 102 102 if (active instanceof PicLayerAbstract) { 103 ((PicLayerAbstract) active).setDrawPoints(value);103 ((PicLayerAbstract) active).setDrawPoints(value); 104 104 } 105 105 Main.map.mapView.repaint(); 106 106 } 107 108 107 } -
applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/actions/LoadPictureCalibrationAction.java
r31729 r32675 51 51 * Constructor 52 52 */ 53 public LoadPictureCalibrationAction( PicLayerAbstract owner) {53 public LoadPictureCalibrationAction(PicLayerAbstract owner) { 54 54 super(tr("Load Picture Calibration..."), null, tr("Loads calibration data from a file"), null, false); 55 55 // Remember the owner... … … 64 64 // Save dialog 65 65 JFileChooser fc = new JFileChooser(); 66 fc.setAcceptAllFileFilterUsed( true);67 fc.setFileFilter( new CalibrationFileFilter());68 fc.setSelectedFile( 69 int result = fc.showOpenDialog(Main.parent 66 fc.setAcceptAllFileFilterUsed(true); 67 fc.setFileFilter(new CalibrationFileFilter()); 68 fc.setSelectedFile(new File(m_owner.getPicLayerName() + CalibrationFileFilter.EXTENSION)); 69 int result = fc.showOpenDialog(Main.parent); 70 70 71 if ( result == JFileChooser.APPROVE_OPTION) {71 if (result == JFileChooser.APPROVE_OPTION) { 72 72 73 73 // Load … … 77 77 // Error 78 78 e.printStackTrace(); 79 JOptionPane.showMessageDialog(Main.parent , tr("Loading file failed: {0}", e.getMessage()), tr("Problem occurred"), JOptionPane.WARNING_MESSAGE); 79 JOptionPane.showMessageDialog(Main.parent, 80 tr("Loading file failed: {0}", e.getMessage()), tr("Problem occurred"), JOptionPane.WARNING_MESSAGE); 80 81 } 81 82 } -
applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/actions/LoadPictureCalibrationFromWorldAction.java
r31729 r32675 28 28 29 29 JFileChooser fc = new JFileChooser(); 30 fc.setAcceptAllFileFilterUsed( true);31 int result = fc.showOpenDialog(Main.parent 30 fc.setAcceptAllFileFilterUsed(true); 31 int result = fc.showOpenDialog(Main.parent); 32 32 33 if ( result == JFileChooser.APPROVE_OPTION) {33 if (result == JFileChooser.APPROVE_OPTION) { 34 34 35 35 // Load … … 39 39 // Error 40 40 ex.printStackTrace(); 41 JOptionPane.showMessageDialog(Main.parent , tr("Loading file failed: {0}", ex.getMessage()), tr("Problem occurred"), JOptionPane.WARNING_MESSAGE); 41 JOptionPane.showMessageDialog(Main.parent, 42 tr("Loading file failed: {0}", ex.getMessage()), tr("Problem occurred"), JOptionPane.WARNING_MESSAGE); 42 43 } 43 44 } -
applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/actions/SavePictureCalibrationAction.java
r31729 r32675 50 50 * Constructor 51 51 */ 52 public SavePictureCalibrationAction( PicLayerAbstract owner) {52 public SavePictureCalibrationAction(PicLayerAbstract owner) { 53 53 super(tr("Save Picture Calibration..."), null, tr("Saves calibration data to a file"), null, false); 54 54 // Remember the owner... … … 63 63 // Save dialog 64 64 final JFileChooser fc = new JFileChooser(); 65 fc.setAcceptAllFileFilterUsed( true);66 fc.setFileFilter( new CalibrationFileFilter());67 fc.setSelectedFile( 68 int result = fc.showSaveDialog( Main.parent);65 fc.setAcceptAllFileFilterUsed(true); 66 fc.setFileFilter(new CalibrationFileFilter()); 67 fc.setSelectedFile(new File(m_owner.getPicLayerName() + CalibrationFileFilter.EXTENSION)); 68 int result = fc.showSaveDialog(Main.parent); 69 69 70 if ( result == JFileChooser.APPROVE_OPTION) {70 if (result == JFileChooser.APPROVE_OPTION) { 71 71 // Check file extension and force it to be valid 72 72 File file = fc.getSelectedFile(); 73 73 String path = file.getAbsolutePath(); 74 if ( 75 || !path.substring( path.length() - 4).equals(CalibrationFileFilter.EXTENSION)) {76 file = new File( path + CalibrationFileFilter.EXTENSION);74 if (path.length() < CalibrationFileFilter.EXTENSION.length() 75 || !path.substring(path.length() - 4).equals(CalibrationFileFilter.EXTENSION)) { 76 file = new File(path + CalibrationFileFilter.EXTENSION); 77 77 } 78 78 … … 85 85 // Error 86 86 e.printStackTrace(); 87 JOptionPane.showMessageDialog(Main.parent , tr("Saving file failed: {0}", e.getMessage()), tr("Problem occurred"), JOptionPane.WARNING_MESSAGE); 87 JOptionPane.showMessageDialog(Main.parent, 88 tr("Saving file failed: {0}", e.getMessage()), tr("Problem occurred"), JOptionPane.WARNING_MESSAGE); 88 89 } 89 90 } -
applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/actions/newlayer/NewLayerFromClipboardAction.java
r32495 r32675 56 56 try { 57 57 layer.initialize(); 58 } 59 catch (IOException e) { 58 } catch (IOException e) { 60 59 // Failed 61 System.out.println( "NewLayerFromClipboardAction::actionPerformed - " + e.getMessage());60 System.out.println("NewLayerFromClipboardAction::actionPerformed - " + e.getMessage()); 62 61 JOptionPane.showMessageDialog(null, e.getMessage(), tr("Problem occurred"), JOptionPane.WARNING_MESSAGE); 63 62 return; 64 63 } 65 64 // Add layer 66 Main.getLayerManager().addLayer( layer);65 Main.getLayerManager().addLayer(layer); 67 66 } 68 67 } -
applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/actions/newlayer/NewLayerFromFileAction.java
r32495 r32675 59 59 private String[] supportedExtensions; 60 60 61 publicImageFileFilter() {61 ImageFileFilter() { 62 62 List<String> extensions = new ArrayList<>(); 63 63 extensions.add("zip"); 64 64 extensions.add("kml"); 65 for (String ext : ImageIO.getReaderFormatNames()) 65 for (String ext : ImageIO.getReaderFormatNames()) { 66 66 extensions.add(ext); 67 } 67 68 supportedExtensions = extensions.toArray(new String[0]); 68 69 } … … 70 71 @Override 71 72 public boolean accept(File f) { 72 if ( f.isDirectory())73 if (f.isDirectory()) 73 74 return true; 74 75 … … 77 78 // Unfortunately, getReaderFormatNames does not always return ALL extensions in 78 79 // both lower and upper case, so we can not do a search in the array 79 for (String e: supportedExtensions) 80 if ( e.equalsIgnoreCase(fileExtension)) {80 for (String e: supportedExtensions) { 81 if (e.equalsIgnoreCase(fileExtension)) { 81 82 return true; 82 83 } 84 } 83 85 84 86 return false; 85 87 } 86 87 88 88 89 @Override … … 90 91 return tr("Supported image files, *.zip, *.kml"); 91 92 } 92 93 93 } 94 94 … … 108 108 // Choose a file 109 109 JFileChooser fc = new JFileChooser(Main.pref.get(m_lastdirprefname)); 110 fc.setAcceptAllFileFilterUsed( true);111 fc.setFileFilter( new ImageFileFilter());110 fc.setAcceptAllFileFilterUsed(true); 111 fc.setFileFilter(new ImageFileFilter()); 112 112 113 113 fc.setMultiSelectionEnabled(true); 114 int result = fc.showOpenDialog( Main.parent);114 int result = fc.showOpenDialog(Main.parent); 115 115 116 116 // Create a layer? 117 if ( result == JFileChooser.APPROVE_OPTION) {117 if (result == JFileChooser.APPROVE_OPTION) { 118 118 // The first loaded layer will be placed at the top of any other layer of the same class, 119 119 // or at the bottom of the stack if there is no such layer yet 120 120 // The next layers we load will be placed one after the other after this first layer 121 121 int newLayerPos = Main.getLayerManager().getLayers().size(); 122 for (Layer l : Main.getLayerManager().getLayersOfType(PicLayerAbstract.class)) {122 for (Layer l : Main.getLayerManager().getLayersOfType(PicLayerAbstract.class)) { 123 123 int pos = Main.getLayerManager().getLayers().indexOf(l); 124 124 if (pos < newLayerPos) newLayerPos = pos; 125 125 } 126 126 127 for (File file : fc.getSelectedFiles()) {127 for (File file : fc.getSelectedFiles()) { 128 128 // TODO: we need a progress bar here, it can take quite some time 129 129 … … 150 150 private void addNewLayerFromFile(File file, int newLayerPos, boolean isZoomToLayer) { 151 151 try { 152 PicLayerFromFile layer = new PicLayerFromFile( file);152 PicLayerFromFile layer = new PicLayerFromFile(file); 153 153 layer.initialize(); 154 154 155 155 placeLayer(layer, newLayerPos, isZoomToLayer); 156 } 157 catch (IOException e) { 156 } catch (IOException e) { 158 157 // Failed 159 System.out.println( "NewLayerFromFileAction::actionPerformed - " + e.getMessage());158 System.out.println("NewLayerFromFileAction::actionPerformed - " + e.getMessage()); 160 159 JOptionPane.showMessageDialog(null, e.getMessage(), tr("Problem occurred"), JOptionPane.WARNING_MESSAGE); 161 160 } … … 168 167 Main.map.mapView.moveLayer(layer, newLayerPos++); 169 168 170 if ( isZoomToLayer && Main.pref.getInteger("piclayer.zoom-on-load", 1) != 0) {169 if (isZoomToLayer && Main.pref.getInteger("piclayer.zoom-on-load", 1) != 0) { 171 170 // if we are loading a single picture file, zoom on it, so that the user can see something 172 171 BoundingXYVisitor v = new BoundingXYVisitor(); … … 175 174 } 176 175 } 176 177 177 private void addNewLayerFromKML(File root, KMLGroundOverlay overlay, int newLayerPos) { 178 178 try { … … 183 183 } catch (IOException e) { 184 184 // Failed 185 System.out.println( "NewLayerFromFileAction::actionPerformed - " + e.getMessage());185 System.out.println("NewLayerFromFileAction::actionPerformed - " + e.getMessage()); 186 186 JOptionPane.showMessageDialog(null, e.getMessage(), tr("Problem occurred"), JOptionPane.WARNING_MESSAGE); 187 187 } -
applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/actions/transform/MovePictureAction.java
r30356 r32675 46 46 @Override 47 47 protected void doAction(MouseEvent e) { 48 EastNorth eastNorth = Main.map.mapView.getEastNorth(e.getX(), e.getY());48 EastNorth eastNorth = Main.map.mapView.getEastNorth(e.getX(), e.getY()); 49 49 currentLayer.movePictureBy( 50 50 eastNorth.east() - prevEastNorth.east(), -
applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/actions/transform/RotatePictureAction.java
r30356 r32675 41 41 */ 42 42 public RotatePictureAction(MapFrame frame) { 43 super(tr("PicLayer rotate"), tr("Rotated"), "rotate", tr("Drag to rotate the picture"), frame, ImageProvider.getCursor("crosshair", null)); 43 super(tr("PicLayer rotate"), tr("Rotated"), "rotate", tr("Drag to rotate the picture"), 44 frame, ImageProvider.getCursor("crosshair", null)); 44 45 } 45 46 … … 47 48 protected void doAction(MouseEvent e) { 48 49 double factor; 49 if ( ( e.getModifiersEx() & InputEvent.SHIFT_DOWN_MASK ) != 0) {50 if ((e.getModifiersEx() & InputEvent.SHIFT_DOWN_MASK) != 0) { 50 51 factor = Main.pref.getDouble("piclayer.rotatefactors.high_precision", 100.0); 52 } else { 53 factor = Main.pref.getDouble("piclayer.rotatefactors.low_precision", 10.0); 51 54 } 52 else { 53 factor = Main.pref.getDouble("piclayer.rotatefactors.low_precision", 10.0 ); 54 } 55 currentLayer.rotatePictureBy( ( e.getY() - prevMousePoint.getY() ) / factor ); 55 currentLayer.rotatePictureBy((e.getY() - prevMousePoint.getY()) / factor); 56 56 } 57 57 } -
applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/actions/transform/ScalePictureActionAbstract.java
r30356 r32675 38 38 * Constructor 39 39 */ 40 public ScalePictureActionAbstract 40 public ScalePictureActionAbstract(String name, String actionName, String icon, String tooltip, MapFrame frame) { 41 41 super(name, actionName, icon, tooltip, frame, ImageProvider.getCursor("crosshair", null)); 42 42 } … … 45 45 protected void doAction(MouseEvent e) { 46 46 double factor; 47 if ( ( e.getModifiersEx() & InputEvent.SHIFT_DOWN_MASK ) != 0) {47 if ((e.getModifiersEx() & InputEvent.SHIFT_DOWN_MASK) != 0) { 48 48 factor = Main.pref.getDouble("piclayer.scalefactors.high_precision", 1.0005); 49 } 50 else { 49 } else { 51 50 factor = Main.pref.getDouble("piclayer.scalefactors.low_precision", 1.015); 52 51 } 53 doTheScale( Math.pow(factor, prevMousePoint.getY() - e.getY() ));52 doTheScale(Math.pow(factor, prevMousePoint.getY() - e.getY())); 54 53 } 55 54 … … 57 56 * Does the actual scaling in the inherited class. 58 57 */ 59 protected abstract void doTheScale( double scale);58 protected abstract void doTheScale(double scale); 60 59 61 60 } -
applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/actions/transform/ScaleXPictureAction.java
r27403 r32675 29 29 */ 30 30 @SuppressWarnings("serial") 31 public class ScaleXPictureAction extends ScalePictureActionAbstract 32 { 33 /* 31 public class ScaleXPictureAction extends ScalePictureActionAbstract { 32 33 /** 34 34 * Constructor 35 35 */ … … 39 39 40 40 @Override 41 public void doTheScale( double scale) {42 currentLayer.scalePictureBy( scale, 1.0);43 41 public void doTheScale(double scale) { 42 currentLayer.scalePictureBy(scale, 1.0); 43 } 44 44 } -
applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/actions/transform/ScaleXYPictureAction.java
r27403 r32675 29 29 */ 30 30 @SuppressWarnings("serial") 31 public class ScaleXYPictureAction extends ScalePictureActionAbstract 32 { 33 /* 31 public class ScaleXYPictureAction extends ScalePictureActionAbstract { 32 33 /** 34 34 * Constructor 35 35 */ … … 39 39 40 40 @Override 41 public void doTheScale( double scale) {42 currentLayer.scalePictureBy( scale, scale);43 41 public void doTheScale(double scale) { 42 currentLayer.scalePictureBy(scale, scale); 43 } 44 44 } -
applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/actions/transform/ScaleYPictureAction.java
r27403 r32675 29 29 */ 30 30 @SuppressWarnings("serial") 31 public class ScaleYPictureAction extends ScalePictureActionAbstract 32 { 33 /* 31 public class ScaleYPictureAction extends ScalePictureActionAbstract { 32 33 /** 34 34 * Constructor 35 35 */ … … 39 39 40 40 @Override 41 public void doTheScale( double scale) {42 currentLayer.scalePictureBy( 1.0, scale);41 public void doTheScale(double scale) { 42 currentLayer.scalePictureBy(1.0, scale); 43 43 } 44 44 } -
applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/actions/transform/ShearPictureAction.java
r30356 r32675 48 48 @Override 49 49 protected void doAction(MouseEvent e) { 50 EastNorth eastNorth = Main.map.mapView.getEastNorth(e.getX(), e.getY());50 EastNorth eastNorth = Main.map.mapView.getEastNorth(e.getX(), e.getY()); 51 51 currentLayer.shearPictureBy( 52 52 1000* (eastNorth.east() - prevEastNorth.east()), … … 54 54 ); 55 55 } 56 57 56 } -
applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/actions/transform/affine/RemovePointAction.java
r27662 r32675 44 44 updateDrawPoints(false); 45 45 } 46 47 48 46 } -
applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/actions/transform/affine/TransformPointAction.java
r30356 r32675 26 26 JOptionPane.showMessageDialog(null, tr("You should have 3 checkpoints to transform the image!"), tr("PicLayer"), JOptionPane.ERROR_MESSAGE, null); 27 27 else*/ 28 {28 //{ 29 29 currentLayer.getTransformer().updatePair(selectedPoint, pressed); 30 }30 //} 31 31 } 32 32 … … 36 36 } 37 37 } 38 38 39 @Override 39 40 public void enterMode() { -
applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/command/TransformCommand.java
r27883 r32675 27 27 beforeTransform = extractTransform(); 28 28 } 29 30 29 31 30 @Override -
applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/layer/CalibrationFileFilter.java
r27120 r32675 36 36 @Override 37 37 public boolean accept(File f) { 38 String ext3 = ( f.getName().length() > 4 ) ? f.getName().substring( f.getName().length() - 4).toLowerCase() : "";38 String ext3 = (f.getName().length() > 4) ? f.getName().substring(f.getName().length() - 4).toLowerCase() : ""; 39 39 40 40 // TODO: check what is supported by Java :) 41 return ( f.isDirectory() 42 || ext3.equals( EXTENSION ) 43 ); 41 return (f.isDirectory() || ext3.equals(EXTENSION)); 44 42 } 45 43 -
applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/layer/PicLayerAbstract.java
r32495 r32675 27 27 import java.awt.Image; 28 28 import java.awt.Point; 29 import java.awt.RenderingHints; 29 30 import java.awt.Toolkit; 30 import java.awt.RenderingHints;31 31 import java.awt.geom.AffineTransform; 32 32 import java.awt.geom.NoninvertibleTransformException; … … 155 155 156 156 // If the map does not exist - we're screwed. We should not get into this situation in the first place! 157 if ( Main.map != null && Main.map.mapView != null) {157 if (Main.map != null && Main.map.mapView != null) { 158 158 159 159 EastNorth center = Main.map.mapView.getCenter(); … … 170 170 // Create image 171 171 image = createImage(); 172 if ( image == null) {172 if (image == null) { 173 173 throw new IOException(tr("PicLayer failed to load or import the image.")); 174 174 } … … 188 188 189 189 protected abstract void lookForCalibration() throws IOException; 190 190 191 /** 191 192 * To be overridden by subclasses. Returns the user readable name of the layer. … … 194 195 195 196 @Override 196 public Icon getIcon() { return layerIcon; } 197 198 @Override 199 public Object getInfoComponent() { return null; } 197 public Icon getIcon() { 198 return layerIcon; 199 } 200 201 @Override 202 public Object getInfoComponent() { 203 return null; 204 } 200 205 201 206 @Override … … 209 214 new LoadPictureCalibrationFromWorldAction(this), 210 215 SeparatorLayerAction.INSTANCE, 211 new RenameLayerAction(null, this),216 new RenameLayerAction(null, this), 212 217 }; 213 218 } … … 229 234 public void paint(Graphics2D g2, MapView mv, Bounds bounds) { 230 235 231 if ( 236 if (image != null) { 232 237 233 238 // Position image at the right graphical place 234 239 EastNorth center = mv.getCenter(); 235 EastNorth leftop = mv.getEastNorth( 0, 0);240 EastNorth leftop = mv.getEastNorth(0, 0); 236 241 // Number of pixels for one unit in east north space. 237 242 // This is the same in x- and y- direction. 238 double pixel_per_en = ( mv.getWidth() / 2.0 ) / ( center.east() - leftop.east());243 double pixel_per_en = (mv.getWidth() / 2.0) / (center.east() - leftop.east()); 239 244 240 245 // This is now the offset in screen pixels 241 246 EastNorth imagePosition = transformer.getImagePosition(); 242 double pic_offset_x = (( imagePosition.east() - leftop.east()) * pixel_per_en);243 double pic_offset_y = (( leftop.north() - imagePosition.north()) * pixel_per_en);244 245 Graphics2D g = (Graphics2D) g2.create();247 double pic_offset_x = ((imagePosition.east() - leftop.east()) * pixel_per_en); 248 double pic_offset_y = ((leftop.north() - imagePosition.north()) * pixel_per_en); 249 250 Graphics2D g = (Graphics2D) g2.create(); 246 251 // Move 247 g.translate( pic_offset_x, pic_offset_y);252 g.translate(pic_offset_x, pic_offset_y); 248 253 249 254 // Scale 250 255 double scalex = initialImageScale * pixel_per_en / getMetersPerEasting(imagePosition) / 100; 251 256 double scaley = initialImageScale * pixel_per_en / getMetersPerNorthing(imagePosition) / 100; 252 g.scale( scalex, scaley);257 g.scale(scalex, scaley); 253 258 254 259 g.transform(transformer.getTransform()); … … 257 262 258 263 // Draw picture 259 g.drawImage( image, -image.getWidth(null) / 2, -image.getHeight(null) / 2, null);264 g.drawImage(image, -image.getWidth(null) / 2, -image.getHeight(null) / 2, null); 260 265 261 266 // Draw additional rectangle for the active pic layer 262 267 if (mv.getLayerManager().getActiveLayer() == this) { 263 g.setColor( new Color( 0xFF0000 ));268 g.setColor(new Color(0xFF0000)); 264 269 g.drawRect( 265 270 -image.getWidth(null) / 2, … … 269 274 ); 270 275 } 271 if (drawMarkers 276 if (drawMarkers) { 272 277 // draw markers for selection 273 Graphics2D gPoints = (Graphics2D) g2.create();278 Graphics2D gPoints = (Graphics2D) g2.create(); 274 279 275 280 gPoints.translate(pic_offset_x, pic_offset_y); … … 282 287 for (int i = 0; i < transformer.getOriginPoints().size(); i++) { 283 288 Point2D trP = tr.transform(transformer.getOriginPoints().get(i), null); 284 int x = (int) trP.getX(), y = (int)trP.getY();289 int x = (int) trP.getX(), y = (int) trP.getY(); 285 290 286 291 int dstx = x-pinAnchorX; 287 292 int dsty = y-pinAnchorY; 288 gPoints.drawImage(pinTiledImage, dstx, dsty, dstx+pinWidth, dsty+pinHeight, pinTileOffsetX[i], pinTileOffsetY[i], pinTileOffsetX[i]+pinWidth, pinTileOffsetY[i]+pinHeight, null); 293 gPoints.drawImage(pinTiledImage, dstx, dsty, dstx+pinWidth, dsty+pinHeight, 294 pinTileOffsetX[i], pinTileOffsetY[i], pinTileOffsetX[i]+pinWidth, pinTileOffsetY[i]+pinHeight, null); 289 295 } 290 296 } 291 297 } else { 292 298 // TODO: proper logging 293 System.out.println( "PicLayerAbstract::paint - general drawing error (image is null or Graphics not 2D");299 System.out.println("PicLayerAbstract::paint - general drawing error (image is null or Graphics not 2D"); 294 300 } 295 301 } … … 344 350 */ 345 351 public void visitBoundingBox(BoundingXYVisitor arg0) { 346 if ( image == null)352 if (image == null) 347 353 return; 348 354 String projcode = projection.toCode(); … … 354 360 // initial scale is in m/100pix 355 361 // So for now, we support the bounding box only when everything is in meters 356 if (projcode.equals("EPSG:4326") 362 if (projcode.equals("EPSG:4326")) 357 363 return; 358 364 … … 380 386 * @param props Properties to save to 381 387 */ 382 public void saveCalibration( Properties props) {388 public void saveCalibration(Properties props) { 383 389 // Save 384 390 double[] matrix = new double[6]; … … 401 407 * Loads calibration data from file 402 408 * @param file The file to read from 403 * @return404 409 */ 405 410 public void loadCalibration(InputStream is) throws IOException { … … 412 417 * Loads calibration data from properties structure 413 418 * @param props Properties to load from 414 * @return 415 */ 416 public void loadCalibration( Properties props ) { 419 */ 420 public void loadCalibration(Properties props) { 417 421 // Load 418 422 … … 426 430 427 431 initialImageScale = Double.valueOf(props.getProperty(INITIAL_SCALE, "1")); //in_scale 428 if (props.containsKey(SCALEX)) { // old format432 if (props.containsKey(SCALEX)) { // old format 429 433 //double in_pos_x = Double.valueOf(props.getProperty(INITIAL_POS_X, "0")); 430 434 //double in_pos_y = Double.valueOf(props.getProperty(INITIAL_POS_Y, "0")); … … 459 463 460 464 public void loadWorldfile(InputStream is) throws IOException { 461 465 462 466 try ( 463 467 Reader reader = new InputStreamReader(is); 464 468 BufferedReader br = new BufferedReader(reader) 465 469 ) { 466 double e[]= new double[6];467 for (int i =0; i<6; ++i) {470 double[] e = new double[6]; 471 for (int i = 0; i < 6; ++i) { 468 472 String line = br.readLine(); 469 473 e[i] = Double.parseDouble(line); 470 474 } 471 double sx =e[0], ry=e[1], rx=e[2], sy=e[3], dx=e[4], dy=e[5];475 double sx = e[0], ry = e[1], rx = e[2], sy = e[3], dx = e[4], dy = e[5]; 472 476 int w = image.getWidth(null); 473 477 int h = image.getHeight(null); … … 498 502 499 503 EastNorth center = Main.map.mapView.getCenter(); 500 EastNorth leftop = Main.map.mapView.getEastNorth( 0, 0);504 EastNorth leftop = Main.map.mapView.getEastNorth(0, 0); 501 505 // Number of pixels for one unit in east north space. 502 506 // This is the same in x- and y- direction. 503 double pixel_per_en = ( Main.map.mapView.getWidth() / 2.0 ) / ( center.east() - leftop.east());507 double pixel_per_en = (Main.map.mapView.getWidth() / 2.0) / (center.east() - leftop.east()); 504 508 505 509 EastNorth imageCenter = transformer.getImagePosition(); 506 510 // This is now the offset in screen pixels 507 double pic_offset_x = (( imageCenter.east() - leftop.east()) * pixel_per_en);508 double pic_offset_y = (( leftop.north() - imageCenter.north()) * pixel_per_en); // something bad...511 double pic_offset_x = ((imageCenter.east() - leftop.east()) * pixel_per_en); 512 double pic_offset_y = ((leftop.north() - imageCenter.north()) * pixel_per_en); // something bad... 509 513 510 514 AffineTransform pointTrans = AffineTransform.getTranslateInstance(pic_offset_x, pic_offset_y); … … 527 531 transformer.setImagePosition(transformer.getImagePosition().add(x, y)); 528 532 } 529 530 533 531 534 public void rotatePictureBy(double angle) { … … 572 575 Point2D pressed = transformPoint(point); 573 576 double mindist = 10; 574 for (Point2D p : transformer.getOriginPoints()) 577 for (Point2D p : transformer.getOriginPoints()) { 575 578 if (p.distance(pressed) < mindist) { // if user clicked to select some of origin point 576 579 selected = p; 577 580 mindist = p.distance(pressed); 578 581 } 582 } 579 583 return selected; 580 584 } catch (NoninvertibleTransformException e) { -
applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/layer/PicLayerFromClipboard.java
r27120 r32675 42 42 Transferable t = Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null); 43 43 // Check result 44 if ( t == null) {44 if (t == null) { 45 45 throw new IOException(tr("Nothing in clipboard")); 46 46 } … … 50 50 try { 51 51 if (t.isDataFlavorSupported(DataFlavor.imageFlavor)) { 52 image = (Image) t.getTransferData(DataFlavor.imageFlavor);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 throw new IOException( e.getMessage());57 throw new IOException(e.getMessage()); 58 58 } 59 59 -
applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/layer/PicLayerFromFile.java
r31729 r32675 53 53 private String m_tooltiptext; 54 54 55 public PicLayerFromFile( File file) {55 public PicLayerFromFile(File file) { 56 56 // Remember the file 57 57 m_file = file; … … 102 102 } 103 103 } else { 104 image = ImageIO.read( m_file);104 image = ImageIO.read(m_file); 105 105 return image; 106 106 } … … 126 126 127 127 String[][] imgExtensions = new String[][] { 128 { ".jpg", ".jpeg"},129 { ".png"},130 { ".tif", ".tiff"},131 { ".bmp"},128 {".jpg", ".jpeg"}, 129 {".png"}, 130 {".tif", ".tiff"}, 131 {".bmp"}, 132 132 }; 133 133 String[][] wldExtensions = new String[][] { 134 { ".wld", ".jgw", ".jpgw"},135 { ".wld", ".pgw", ".pngw"},136 { ".wld", ".tfw", ".tifw"},137 { 134 {".wld", ".jgw", ".jpgw"}, 135 {".wld", ".pgw", ".pngw"}, 136 {".wld", ".tfw", ".tifw"}, 137 {".wld", ".bmpw", ".bpw"}, 138 138 }; 139 139 … … 153 153 String extension = imgNameInZip.substring(dotIdx); 154 154 String namepart = imgNameInZip.substring(0, dotIdx); 155 for (int i =0; i<imgExtensions.length; ++i) {155 for (int i = 0; i < imgExtensions.length; ++i) { 156 156 if (Arrays.asList(imgExtensions[i]).contains(extension.toLowerCase())) { 157 157 for (String wldExtension : wldExtensions[i]) { … … 184 184 String extension = m_file.getName().substring(dotIdx); 185 185 String namepart = m_file.getName().substring(0, dotIdx); 186 for (int i =0; i<imgExtensions.length; ++i) {186 for (int i = 0; i < imgExtensions.length; ++i) { 187 187 if (Arrays.asList(imgExtensions[i]).contains(extension.toLowerCase())) { 188 188 for (String wldExtension : wldExtensions[i]) { … … 206 206 207 207 String msg = tr("A calibration file associated to the picture file was found: {0}\n", fileName); 208 if ( policy.equals("yes")) {208 if (policy.equals("yes")) { 209 209 loadcal = true; 210 } 211 else if ( policy.equals("no") ) { 210 } else if (policy.equals("no")) { 212 211 loadcal = false; 213 } 214 else if ( policy.equals("ask") ) { 212 } else if (policy.equals("ask")) { 215 213 msg += "\n" + tr("Set \"{0}\" to yes/no/ask in the preferences\n"+ 216 214 "to control the autoloading of calibration files.", prefkey); … … 220 218 loadcal = true; 221 219 } 222 } 223 else { 220 } else { 224 221 msg += "\n" + tr("It will be applied automatically."); 225 222 msg += "\n" + tr("Also, from now on, calibration files will always be loaded automatically."); -
applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/layer/PicLayerFromKML.java
r28559 r32675 28 28 setName(picture.getName()); 29 29 } 30 30 31 @Override 31 32 protected Image createImage() throws IOException { -
applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/layer/kml/KMLGroundOverlay.java
r27231 r32675 1 1 package org.openstreetmap.josm.plugins.piclayer.layer.kml; 2 3 2 4 3 public class KMLGroundOverlay { … … 15 14 return filename; 16 15 } 16 17 17 public void setFileName(String file) { 18 18 this.filename = file; 19 19 } 20 20 21 public double getNorth() { 21 22 return north; 22 23 } 24 23 25 public void setNorth(double north) { 24 26 this.north = north; 25 27 } 28 26 29 public double getSouth() { 27 30 return south; 28 31 } 32 29 33 public void setSouth(double south) { 30 34 this.south = south; 31 35 } 36 32 37 public double getEast() { 33 38 return east; 34 39 } 40 35 41 public void setEast(double east) { 36 42 this.east = east; 37 43 } 44 38 45 public double getWest() { 39 46 return west; 40 47 } 48 41 49 public void setWest(double west) { 42 50 this.west = west; 43 51 } 52 44 53 public double getRotate() { 45 54 return rotate; 46 55 } 56 47 57 public void setRotate(double rotate) { 48 58 this.rotate = rotate; 49 59 } 60 50 61 public String getName() { 51 62 return name; 52 63 } 64 53 65 public void setName(String name) { 54 66 this.name = name; -
applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/layer/kml/KMLReader.java
r30737 r32675 51 51 private KMLGroundOverlay overlay; 52 52 53 publicKMLHandler() {53 KMLHandler() { 54 54 result = new ArrayList<>(); 55 55 } -
applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/transform/Matrix3D.java
r30356 r32675 5 5 import java.util.List; 6 6 7 8 7 class Matrix3D { 9 8 double[][] a; 10 11 publicMatrix3D() {9 10 Matrix3D() { 12 11 a = new double[3][]; a[0] = new double[3]; a[1] = new double[3]; a[2] = new double[3]; 13 12 } 14 15 publicMatrix3D(PictureTransform pictureTransform, double b11, double b12, double b13, double b21, double b22, double b23, double b31, double b32, double b33) {13 14 Matrix3D(PictureTransform pictureTransform, double b11, double b12, double b13, double b21, double b22, double b23, double b31, double b32, double b33) { 16 15 this(); 17 16 18 17 a[0][0] = b11; a[0][1] = b12; a[0][2] = b13; 19 18 a[1][0] = b21; a[1][1] = b22; a[1][2] = b23; 20 19 a[2][0] = b31; a[2][1] = b32; a[2][2] = b33; 21 20 } 22 23 publicMatrix3D(List<? extends Point2D> list) {21 22 Matrix3D(List<? extends Point2D> list) { 24 23 this(); 25 26 for (int i=0; i<3; i++) {24 25 for (int i = 0; i < 3; i++) { 27 26 Point2D p = list.get(i); 28 27 a[0][i] = p.getX(); … … 34 33 public Matrix3D multiply(Matrix3D m) { 35 34 Matrix3D result = new Matrix3D(); 36 for (int i=0; i<3; i++)37 for (int j =0; j<3; j++) {35 for (int i = 0; i < 3; i++) { 36 for (int j = 0; j < 3; j++) { 38 37 double sum = 0; 39 for (int k =0; k<3; k++)38 for (int k = 0; k < 3; k++) { 40 39 sum += a[i][k]*m.a[k][j]; 40 } 41 41 result.a[i][j] = sum; 42 } 42 } 43 } 43 44 return result; 44 45 } 45 46 46 47 private double determinant() { 47 48 return a[0][0]*(a[1][1]*a[2][2]-a[1][2]*a[2][1])-a[0][1]*(a[1][0]*a[2][2]-a[1][2]*a[2][0]) 48 49 +a[0][2]*(a[1][0]*a[2][1]-a[1][1]*a[2][0]); 49 50 } 50 51 51 52 public Matrix3D inverse() throws NoSolutionException { 52 53 Matrix3D invert = new Matrix3D(); … … 54 55 if (Math.abs(det) <= Double.MIN_VALUE) 55 56 throw new NoSolutionException("Determinant = 0"); 56 57 57 58 double s = 1/det; 58 59 59 60 invert.a[0][0] = (s) * (a[1][1] * a[2][2] - a[1][2] * a[2][1]); 60 61 invert.a[1][0] = (s) * (a[1][2] * a[2][0] - a[1][0] * a[2][2]); … … 66 67 invert.a[1][2] = (s) * (a[0][2] * a[1][0] - a[0][0] * a[1][2]); 67 68 invert.a[2][2] = (s) * (a[0][0] * a[1][1] - a[0][1] * a[1][0]); 68 69 69 70 return invert; 70 71 } 71 72 72 73 public AffineTransform toAffineTransform() throws NoSolutionException { 73 74 if (!(Math.abs(a[2][0]) <= 1e-2 && Math.abs(a[2][1]) <= 1e-2 && Math.abs(a[2][2]-1) <= 1e-2)) -
applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/transform/NoSolutionException.java
r30356 r32675 2 2 3 3 class NoSolutionException extends Exception { 4 5 publicNoSolutionException(String message) {4 5 NoSolutionException(String message) { 6 6 super(message); 7 7 }
Note:
See TracChangeset
for help on using the changeset viewer.