Changeset 24812 in osm for applications/editors/josm/plugins/imageryadjust/src
- Timestamp:
- 2010-12-20T13:04:26+01:00 (14 years ago)
- Location:
- applications/editors/josm/plugins/imageryadjust
- Files:
-
- 2 added
- 2 copied
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/imageryadjust
-
Property svn:ignore
set to
bin
build
-
Property svn:ignore
set to
-
applications/editors/josm/plugins/imageryadjust/src/imageryadjust/ImageryAdjustMapMode.java
r24713 r24812 1 package wmsplugin;1 package imageryadjust; 2 2 3 3 import static org.openstreetmap.josm.tools.I18n.tr; … … 25 25 import org.openstreetmap.josm.gui.ExtendedDialog; 26 26 import org.openstreetmap.josm.gui.MapFrame; 27 import org.openstreetmap.josm.gui.layer.ImageryLayer; 27 28 import org.openstreetmap.josm.gui.layer.Layer; 28 29 import org.openstreetmap.josm.tools.GBC; 29 30 import org.openstreetmap.josm.tools.ImageProvider; 30 31 31 32 public class WMSAdjustAction extends MapMode implements MouseListener, MouseMotionListener{ 33 //static private final Logger logger = Logger.getLogger(WMSAdjustAction.class.getName()); 34 35 GeorefImage selectedImage; 32 public class ImageryAdjustMapMode extends MapMode implements MouseListener, MouseMotionListener{ 36 33 boolean mouseDown; 37 34 EastNorth prevEastNorth; 38 private WMSLayer adjustingLayer;35 private ImageryLayer adjustingLayer; 39 36 40 public WMSAdjustAction(MapFrame mapFrame) {41 super(tr("Adjust WMS"), "adjustwms",42 tr("Adjust the position of the selected WMSlayer"), mapFrame,37 public ImageryAdjustMapMode(MapFrame mapFrame) { 38 super(tr("Adjust imagery"), "adjustimg", 39 tr("Adjust the position of the selected imagery layer"), mapFrame, 43 40 ImageProvider.getCursor("normal", "move")); 44 41 } 45 42 46 47 48 43 @Override public void enterMode() { 49 44 super.enterMode(); 50 if (!has WMSLayersToAdjust()) {51 warnNo WMSLayers();45 if (!hasImageryLayersToAdjust()) { 46 warnNoImageryLayers(); 52 47 return; 53 48 } 54 List< WMSLayer> wmsLayers = Main.map.mapView.getLayersOfType(WMSLayer.class);55 if ( wmsLayers.size() == 1) {56 adjustingLayer = wmsLayers.get(0);49 List<ImageryLayer> layers = Main.map.mapView.getLayersOfType(ImageryLayer.class); 50 if (layers.size() == 1) { 51 adjustingLayer = layers.get(0); 57 52 } else { 58 adjustingLayer = ( WMSLayer)askAdjustLayer(Main.map.mapView.getLayersOfType(WMSLayer.class));53 adjustingLayer = (ImageryLayer)askAdjustLayer(Main.map.mapView.getLayersOfType(ImageryLayer.class)); 59 54 } 60 55 if (adjustingLayer == null) … … 80 75 if (adjustingLayer.isVisible()) { 81 76 prevEastNorth=Main.map.mapView.getEastNorth(e.getX(),e.getY()); 82 selectedImage = adjustingLayer.findImage(prevEastNorth); 83 if(selectedImage!=null) { 84 Main.map.mapView.setCursor 85 (Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR)); 86 } 77 Main.map.mapView.setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR)); 87 78 } 88 79 } 89 80 90 81 @Override public void mouseDragged(MouseEvent e) { 91 if(selectedImage!=null) { 92 EastNorth eastNorth= 93 Main.map.mapView.getEastNorth(e.getX(),e.getY()); 94 adjustingLayer.displace( 95 eastNorth.east()-prevEastNorth.east(), 96 eastNorth.north()-prevEastNorth.north() 97 ); 98 prevEastNorth = eastNorth; 99 Main.map.mapView.repaint(); 100 } 82 if (adjustingLayer == null || prevEastNorth == null) return; 83 EastNorth eastNorth= 84 Main.map.mapView.getEastNorth(e.getX(),e.getY()); 85 adjustingLayer.displace( 86 eastNorth.east()-prevEastNorth.east(), 87 eastNorth.north()-prevEastNorth.north() 88 ); 89 prevEastNorth = eastNorth; 90 Main.map.mapView.repaint(); 101 91 } 102 92 … … 104 94 Main.map.mapView.repaint(); 105 95 Main.map.mapView.setCursor(Cursor.getDefaultCursor()); 106 selectedImage = null;107 96 prevEastNorth = null; 108 97 } 109 98 110 @Override111 public void mouseEntered(MouseEvent e) {112 }113 114 @Override115 public void mouseExited(MouseEvent e) {116 }117 118 @Override119 public void mouseMoved(MouseEvent e) {120 }121 122 @Override public void mouseClicked(MouseEvent e) {123 }124 125 99 @Override public boolean layerIsSupported(Layer l) { 126 return has WMSLayersToAdjust();100 return hasImageryLayersToAdjust(); 127 101 } 128 102 … … 168 142 JPanel pnl = new JPanel(); 169 143 pnl.setLayout(new GridBagLayout()); 170 pnl.add(new JLabel(tr("Please select the WMSlayer to adjust.")), GBC.eol());144 pnl.add(new JLabel(tr("Please select the imagery layer to adjust.")), GBC.eol()); 171 145 pnl.add(layerList, GBC.eol()); 172 146 173 147 ExtendedDialog diag = new ExtendedDialog( 174 148 Main.parent, 175 tr("Select WMSlayer"),149 tr("Select imagery layer"), 176 150 new String[] { tr("Start adjusting"),tr("Cancel") } 177 151 ); 178 152 diag.setContent(pnl); 179 diag.setButtonIcons(new String[] { "mapmode/adjust wms", "cancel" });153 diag.setButtonIcons(new String[] { "mapmode/adjustimg", "cancel" }); 180 154 diag.showDialog(); 181 155 int decision = diag.getValue(); … … 187 161 188 162 /** 189 * Displays a warning message if there are no WMSlayers to adjust163 * Displays a warning message if there are no imagery layers to adjust 190 164 * 191 165 */ 192 protected void warnNo WMSLayers() {166 protected void warnNoImageryLayers() { 193 167 JOptionPane.showMessageDialog( 194 168 Main.parent, 195 tr("There are currently no WMSlayer to adjust."),169 tr("There are currently no imagery layer to adjust."), 196 170 tr("No layers to adjust"), 197 171 JOptionPane.WARNING_MESSAGE … … 200 174 201 175 /** 202 * Replies true if there is at least one WMSlayer176 * Replies true if there is at least one imagery layer 203 177 * 204 * @return true if there is at least one WMSlayer178 * @return true if there is at least one imagery layer 205 179 */ 206 protected boolean has WMSLayersToAdjust() {180 protected boolean hasImageryLayersToAdjust() { 207 181 if (Main.map == null) return false; 208 182 if (Main.map.mapView == null) return false; 209 return ! Main.map.mapView.getLayersOfType( WMSLayer.class).isEmpty();183 return ! Main.map.mapView.getLayersOfType(ImageryLayer.class).isEmpty(); 210 184 } 211 185 212 186 @Override 213 187 protected void updateEnabledState() { 214 setEnabled(has WMSLayersToAdjust());188 setEnabled(hasImageryLayersToAdjust()); 215 189 } 216 190 }
Note:
See TracChangeset
for help on using the changeset viewer.