Changeset 26823 in osm for applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/WMSAdjustAction.java
- Timestamp:
- 2011-10-09T23:41:21+02:00 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/WMSAdjustAction.java ¶
r24934 r26823 12 12 import java.awt.event.MouseListener; 13 13 import java.awt.event.MouseMotionListener; 14 import java.util.ArrayList;15 14 16 15 import javax.swing.JOptionPane; … … 22 21 import org.openstreetmap.josm.data.coor.EastNorth; 23 22 import org.openstreetmap.josm.tools.ImageProvider; 24 import org.openstreetmap.josm.gui.layer.Layer;25 23 26 24 public class WMSAdjustAction extends MapMode implements … … 28 26 29 27 private static final long serialVersionUID = 1L; 30 private ArrayList<WMSLayer> modifiedLayers = new ArrayList<WMSLayer>(); 31 WMSLayer selectedLayer; 28 private WMSLayer modifiedLayer = null; 32 29 private boolean rasterMoved; 33 30 private EastNorth prevEastNorth; … … 38 35 public WMSAdjustAction(MapFrame mapFrame) { 39 36 super(tr("Adjust WMS"), "adjustxywms", 40 tr("Adjust the position of the WMS layer (raster images only)"), mapFrame, 37 tr("Adjust the position of the WMS layer (saved for raster images only)"), mapFrame, 41 38 ImageProvider.getCursor("normal", "move")); 42 39 } … … 44 41 @Override public void enterMode() { 45 42 if (Main.map != null) { 46 selectedLayer = null; 47 WMSLayer possibleLayer = null; 48 int cRasterLayers = 0; 49 for (Layer l : Main.map.mapView.getAllLayers()) { 50 if (l instanceof WMSLayer && ((WMSLayer)l).isRaster()) { 51 possibleLayer = (WMSLayer)l; 52 cRasterLayers++; 53 } 54 } 55 Layer activeLayer = Main.map.mapView.getActiveLayer(); 56 if (activeLayer instanceof WMSLayer && ((WMSLayer)activeLayer).isRaster()) { 57 selectedLayer = (WMSLayer)activeLayer; 58 } else if (cRasterLayers == 1) { 59 selectedLayer = possibleLayer; 60 } 61 if (selectedLayer != null) { 43 if (Main.map.mapView.getActiveLayer() instanceof WMSLayer) { 44 modifiedLayer = (WMSLayer)Main.map.mapView.getActiveLayer(); 62 45 super.enterMode(); 63 46 Main.map.mapView.addMouseListener(this); 64 47 Main.map.mapView.addMouseMotionListener(this); 65 48 rasterMoved = false; 66 selectedLayer.adjustModeEnabled = true;49 modifiedLayer.adjustModeEnabled = true; 67 50 } else { 68 JOptionPane.showMessageDialog(Main.parent,tr("This mode works only if active layer is\n" 69 +"a cadastre \"plan image\" (raster image)"));51 // JOptionPane.showMessageDialog(Main.parent,tr("This mode works only if active layer is\n" 52 // +"a cadastre layer")); 70 53 exitMode(); 71 54 Main.map.selectMapMode((MapMode)Main.map.getDefaultButtonAction()); … … 78 61 Main.map.mapView.removeMouseListener(this); 79 62 Main.map.mapView.removeMouseMotionListener(this); 80 if (rasterMoved && CacheControl.cacheEnabled) { 63 if (rasterMoved && CacheControl.cacheEnabled && modifiedLayer.isRaster()) { 81 64 int reply = JOptionPane.showConfirmDialog(null, 82 65 "Save the changes in cache ?", … … 87 70 } 88 71 } 89 modifiedLayers.clear();90 if ( selectedLayer != null) {91 selectedLayer.adjustModeEnabled = false;92 selectedLayer = null;72 rasterMoved = false; 73 if (modifiedLayer != null) { 74 modifiedLayer.adjustModeEnabled = false; 75 modifiedLayer = null; 93 76 } 94 77 } … … 101 84 // boolean alt = (e.getModifiers() & ActionEvent.ALT_MASK) != 0; 102 85 boolean shift = (e.getModifiers() & ActionEvent.SHIFT_MASK) != 0; 103 if (shift && !ctrl) 86 if (shift && !ctrl && modifiedLayer.isRaster()) 104 87 mode = Mode.moveZ; 105 else if (shift && ctrl) 88 else if (shift && ctrl && modifiedLayer.isRaster()) 106 89 mode = Mode.rotate; 107 90 else … … 124 107 prevEastNorth = newEastNorth; 125 108 } 126 if (!modifiedLayers.contains(selectedLayer))127 modifiedLayers.add(selectedLayer);128 109 Main.map.mapView.repaint(); 129 110 } … … 141 122 142 123 private void displace(EastNorth start, EastNorth end) { 143 selectedLayer.displace(end.east()-start.east(), end.north()-start.north());124 modifiedLayer.displace(end.east()-start.east(), end.north()-start.north()); 144 125 } 145 126 146 127 private void resize(EastNorth newEastNorth) { 147 EastNorth center = selectedLayer.getRasterCenter();128 EastNorth center = modifiedLayer.getRasterCenter(); 148 129 double dPrev = prevEastNorth.distance(center.east(), center.north()); 149 130 double dNew = newEastNorth.distance(center.east(), center.north()); 150 selectedLayer.resize(center, dNew/dPrev);131 modifiedLayer.resize(center, dNew/dPrev); 151 132 } 152 133 153 134 private void rotate(EastNorth start, EastNorth end) { 154 EastNorth pivot = selectedLayer.getRasterCenter();135 EastNorth pivot = modifiedLayer.getRasterCenter(); 155 136 double startAngle = Math.atan2(start.east()-pivot.east(), start.north()-pivot.north()); 156 137 double endAngle = Math.atan2(end.east()-pivot.east(), end.north()-pivot.north()); 157 138 double rotationAngle = endAngle - startAngle; 158 selectedLayer.rotate(pivot, rotationAngle);139 modifiedLayer.rotate(pivot, rotationAngle); 159 140 } 160 141 161 142 private void rotateFrameOnly(EastNorth start, EastNorth end) { 162 143 if (start != null && end != null) { 163 EastNorth pivot = selectedLayer.getRasterCenter();144 EastNorth pivot = modifiedLayer.getRasterCenter(); 164 145 double startAngle = Math.atan2(start.east()-pivot.east(), start.north()-pivot.north()); 165 146 double endAngle = Math.atan2(end.east()-pivot.east(), end.north()-pivot.north()); 166 147 double rotationAngle = endAngle - startAngle; 167 if ( selectedLayer.getImage(0).orgCroppedRaster != null) {148 if (modifiedLayer.getImage(0).orgCroppedRaster != null) { 168 149 for (int i=0; i<4; i++) { 169 croppedRaster[i] = selectedLayer.getImage(0).orgCroppedRaster[i].rotate(pivot, rotationAngle);150 croppedRaster[i] = modifiedLayer.getImage(0).orgCroppedRaster[i].rotate(pivot, rotationAngle); 170 151 } 171 152 croppedRaster[4] = croppedRaster[0]; … … 197 178 198 179 private void saveModifiedLayers() { 199 for (WMSLayer wmsLayer : modifiedLayers) { 200 wmsLayer.grabThread.saveNewCache(); 201 } 180 modifiedLayer.grabThread.saveNewCache(); 202 181 } 203 182 }
Note:
See TracChangeset
for help on using the changeset viewer.