Changeset 15961 in osm for applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/WMSAdjustAction.java
- Timestamp:
- 2009-06-17T09:46:26+02:00 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/WMSAdjustAction.java
r15841 r15961 1 package cadastre_fr; 1 package cadastre_fr; 2 2 3 3 import static org.openstreetmap.josm.tools.I18n.tr; … … 20 20 21 21 public class WMSAdjustAction extends MapMode implements 22 22 MouseListener, MouseMotionListener{ 23 23 24 24 private static final long serialVersionUID = 1L; 25 25 GeorefImage selectedImage; 26 26 private ArrayList<WMSLayer> modifiedLayers = new ArrayList<WMSLayer>(); 27 28 29 27 WMSLayer selectedLayer; 28 private boolean rasterMoved; 29 private EastNorth prevEastNorth; 30 30 enum Mode { moveXY, moveZ, rotate} 31 31 private Mode mode = null; 32 32 33 34 super(tr("Adjust WMS"), "adjustxywms", 35 tr("Adjust the position of the WMS layer (raster images only)"), mapFrame, 36 37 33 public WMSAdjustAction(MapFrame mapFrame) { 34 super(tr("Adjust WMS"), "adjustxywms", 35 tr("Adjust the position of the WMS layer (raster images only)"), mapFrame, 36 ImageProvider.getCursor("normal", "move")); 37 } 38 38 39 40 41 42 43 44 39 @Override public void enterMode() { 40 super.enterMode(); 41 Main.map.mapView.addMouseListener(this); 42 Main.map.mapView.addMouseMotionListener(this); 43 rasterMoved = false; 44 /*/ FOR TEST 45 45 for (Layer layer : Main.map.mapView.getAllLayers()) { 46 46 if (layer.visible && layer instanceof WMSLayer) { … … 50 50 } 51 51 Main.map.mapView.repaint();*/ 52 52 } 53 53 54 55 56 57 58 59 int reply = JOptionPane.showConfirmDialog(null, 54 @Override public void exitMode() { 55 super.exitMode(); 56 Main.map.mapView.removeMouseListener(this); 57 Main.map.mapView.removeMouseMotionListener(this); 58 if (rasterMoved && CacheControl.cacheEnabled) { 59 int reply = JOptionPane.showConfirmDialog(null, 60 60 "Save the changes in cache ?", 61 61 "Update cache", 62 JOptionPane.YES_NO_OPTION); 62 JOptionPane.YES_NO_OPTION); 63 63 if (reply == JOptionPane.OK_OPTION) { 64 64 saveModifiedLayers(); 65 65 } 66 67 68 66 } 67 modifiedLayers.clear(); 68 } 69 69 70 70 @Override 71 71 public void mousePressed(MouseEvent e) { 72 72 if (e.getButton() != MouseEvent.BUTTON1) … … 93 93 } 94 94 95 96 95 @Override public void mouseDragged(MouseEvent e) { 96 if(selectedImage != null && (mode == Mode.moveXY || mode == Mode.moveZ || mode == Mode.rotate)) { 97 97 EastNorth newEastNorth = Main.map.mapView.getEastNorth(e.getX(),e.getY()); 98 99 100 101 102 103 104 98 if (mode == Mode.moveXY) { 99 displace(prevEastNorth, newEastNorth); 100 } else if (mode == Mode.moveZ) { 101 resize(newEastNorth); 102 } else if (mode == Mode.rotate) { 103 rotate(prevEastNorth, newEastNorth); 104 } 105 105 rasterMoved = true; 106 106 if (!modifiedLayers.contains(selectedLayer)) … … 108 108 Main.map.mapView.repaint(); 109 109 prevEastNorth = newEastNorth; 110 111 112 113 110 } 111 } 112 113 private void displace(EastNorth start, EastNorth end) { 114 114 selectedLayer.displace(end.east()-start.east(), end.north()-start.north()); 115 116 117 115 } 116 117 private void resize(EastNorth newEastNorth) { 118 118 double dPrev = prevEastNorth.distance(selectedLayer.getRasterCenter().east(), selectedLayer.getRasterCenter().north()); 119 119 double dNew = newEastNorth.distance(selectedLayer.getRasterCenter().east(), selectedLayer.getRasterCenter().north()); 120 120 selectedLayer.resize(1 - dNew/dPrev); 121 122 123 124 125 126 121 } 122 123 private void rotate(EastNorth start, EastNorth end) { 124 EastNorth pivot = selectedLayer.getRasterCenter(); 125 double startAngle = Math.atan2(start.east()-pivot.east(), start.north()-pivot.north()); 126 double endAngle = Math.atan2(end.east()-pivot.east(), end.north()-pivot.north()); 127 127 double rotationAngle = endAngle - startAngle; 128 selectedLayer.rotate(rotationAngle); 129 128 selectedLayer.rotate(rotationAngle); 129 } 130 130 131 132 133 134 selectedImage = null; 135 136 137 138 131 @Override public void mouseReleased(MouseEvent e) { 132 //Main.map.mapView.repaint(); 133 Main.map.mapView.setCursor(Cursor.getDefaultCursor()); 134 selectedImage = null; 135 prevEastNorth = null; 136 selectedLayer = null; 137 mode = null; 138 } 139 139 140 141 142 143 144 145 140 public void mouseEntered(MouseEvent e) { 141 } 142 public void mouseExited(MouseEvent e) { 143 } 144 public void mouseMoved(MouseEvent e) { 145 } 146 146 147 148 149 150 147 @Override public void mouseClicked(MouseEvent e) { 148 } 149 150 private void saveModifiedLayers() { 151 151 for (WMSLayer wmsLayer : modifiedLayers) { 152 152 wmsLayer.saveNewCache(); 153 153 } 154 154 } 155 155 }
Note:
See TracChangeset
for help on using the changeset viewer.