Changeset 32462 in osm for applications/editors/josm/plugins/imagery_offset_db/src
- Timestamp:
- 2016-06-30T03:08:25+02:00 (9 years ago)
- Location:
- applications/editors/josm/plugins/imagery_offset_db/src/iodb
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/imagery_offset_db/src/iodb/ImageryOffsetWatcher.java
r30737 r32462 1 1 package iodb; 2 2 3 import java.util.*; 3 import java.util.ArrayList; 4 import java.util.Collection; 5 import java.util.Iterator; 6 import java.util.LinkedList; 7 import java.util.List; 8 import java.util.Map; 9 import java.util.Timer; 10 import java.util.TimerTask; 11 import java.util.TreeMap; 12 4 13 import org.openstreetmap.josm.Main; 5 14 import org.openstreetmap.josm.data.coor.LatLon; 6 15 import org.openstreetmap.josm.gui.MapView; 16 import org.openstreetmap.josm.gui.NavigatableComponent.ZoomChangeListener; 7 17 import org.openstreetmap.josm.gui.layer.ImageryLayer; 8 18 import org.openstreetmap.josm.gui.layer.Layer; 19 import org.openstreetmap.josm.gui.layer.LayerManager.LayerAddEvent; 20 import org.openstreetmap.josm.gui.layer.LayerManager.LayerChangeListener; 21 import org.openstreetmap.josm.gui.layer.LayerManager.LayerOrderChangeEvent; 22 import org.openstreetmap.josm.gui.layer.LayerManager.LayerRemoveEvent; 23 import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeEvent; 24 import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeListener; 9 25 import org.openstreetmap.josm.tools.Destroyable; 10 26 … … 16 32 * @license WTFPL 17 33 */ 18 public class ImageryOffsetWatcher implements MapView.ZoomChangeListener,MapView.LayerChangeListener, Destroyable {34 public class ImageryOffsetWatcher implements ZoomChangeListener, LayerChangeListener, ActiveLayerChangeListener, Destroyable { 19 35 private static final double THRESHOLD = 1e-8; 20 36 private static ImageryOffsetWatcher instance; … … 32 48 maxDistance = Main.pref.getDouble("iodb.offset.radius", 15); 33 49 MapView.addZoomChangeListener(this); 34 MapView.addLayerChangeListener(this); 50 Main.getLayerManager().addLayerChangeListener(this); 51 Main.getLayerManager().addActiveLayerChangeListener(this); 35 52 checkOffset(); // we assume there's at the most one imagery layer at this moment 36 53 time = new Timer(); … … 41 58 * Unregister all events. This actually gets never called, but it's not a problem. 42 59 */ 60 @Override 43 61 public void destroy() { 44 62 MapView.removeZoomChangeListener(this); 45 MapView.removeLayerChangeListener(this); 63 Main.getLayerManager().removeLayerChangeListener(this); 64 Main.getLayerManager().removeActiveLayerChangeListener(this); 46 65 time.cancel(); 47 66 } … … 165 184 } 166 185 186 @Override 167 187 public void zoomChanged() { 168 188 checkOffset(); 169 189 } 170 190 171 public void activeLayerChange( Layer oldLayer, Layer newLayer ) { 172 checkOffset(); 173 } 174 175 public void layerAdded( Layer newLayer ) { 176 if( newLayer instanceof ImageryLayer ) 177 loadLayerOffset((ImageryLayer)newLayer); 178 checkOffset(); 179 } 180 181 public void layerRemoved( Layer oldLayer ) { 182 checkOffset(); 191 @Override 192 public void activeOrEditLayerChanged(ActiveLayerChangeEvent e) { 193 checkOffset(); 194 } 195 196 @Override 197 public void layerAdded(LayerAddEvent e) { 198 Layer newLayer = e.getAddedLayer(); 199 if (newLayer instanceof ImageryLayer) 200 loadLayerOffset((ImageryLayer) newLayer); 201 checkOffset(); 202 } 203 204 @Override 205 public void layerRemoving(LayerRemoveEvent e) { 206 checkOffset(); 207 } 208 209 @Override 210 public void layerOrderChanged(LayerOrderChangeEvent e) { 183 211 } 184 212 … … 204 232 205 233 /** 206 * Loads the current imagery layer offset from preferences. 234 * Loads the current imagery layer offset from preferences. 207 235 */ 208 236 private void loadLayerOffset( ImageryLayer layer ) { -
applications/editors/josm/plugins/imagery_offset_db/src/iodb/OffsetDialog.java
r32046 r32462 38 38 import org.openstreetmap.josm.gui.JosmUserIdentityManager; 39 39 import org.openstreetmap.josm.gui.MapView; 40 import org.openstreetmap.josm.gui.NavigatableComponent.ZoomChangeListener; 40 41 import org.openstreetmap.josm.gui.layer.ImageryLayer; 41 42 import org.openstreetmap.josm.gui.layer.MapViewPaintable; … … 51 52 * @license WTFPL 52 53 */ 53 public class OffsetDialog extends JDialog implements ActionListener, MapView.ZoomChangeListener, MapViewPaintable {54 public class OffsetDialog extends JDialog implements ActionListener, ZoomChangeListener, MapViewPaintable { 54 55 protected static final String PREF_CALIBRATION = "iodb.show.calibration"; 55 56 protected static final String PREF_DEPRECATED = "iodb.show.deprecated"; … … 276 277 JOptionPane.showMessageDialog(Main.parent, 277 278 tr("The topmost imagery layer has been shifted to presumably match\n" 278 + "OSM data in the area. Please check that the offset is still valid\n" 279 + "by downloading GPS tracks and comparing them and OSM data to the imagery."), 279 + "OSM data in the area. Please check that the offset is still valid\n" 280 + "by downloading GPS tracks and comparing them and OSM data to the imagery."), 280 281 ImageryOffsetTools.DIALOG_TITLE, JOptionPane.INFORMATION_MESSAGE); 281 282 Main.pref.put("iodb.offset.message", true); … … 283 284 } else if( selectedOffset instanceof CalibrationObject ) { 284 285 CalibrationLayer clayer = new CalibrationLayer((CalibrationObject)selectedOffset); 285 Main. map.mapView.addLayer(clayer);286 Main.getLayerManager().addLayer(clayer); 286 287 clayer.panToCenter(); 287 288 if( !Main.pref.getBoolean("iodb.calibration.message", false) ) { 288 289 JOptionPane.showMessageDialog(Main.parent, 289 290 tr("A layer has been added with a calibration geometry. Hide data layers,\n" 290 + "find the corresponding feature on the imagery layer and move it accordingly."), 291 + "find the corresponding feature on the imagery layer and move it accordingly."), 291 292 ImageryOffsetTools.DIALOG_TITLE, JOptionPane.INFORMATION_MESSAGE); 292 293 Main.pref.put("iodb.calibration.message", true); -
applications/editors/josm/plugins/imagery_offset_db/src/iodb/StoreImageryOffsetAction.java
r30738 r32462 1 1 package iodb; 2 3 import static org.openstreetmap.josm.tools.I18n.tr; 2 4 3 5 import java.awt.event.ActionEvent; 4 6 import java.io.UnsupportedEncodingException; 5 import java.net.*; 6 import java.util.*; 7 import java.net.URLEncoder; 8 import java.util.Collection; 9 import java.util.HashMap; 10 import java.util.Map; 11 7 12 import javax.swing.JOptionPane; 13 8 14 import org.openstreetmap.josm.Main; 9 15 import org.openstreetmap.josm.actions.JosmAction; 10 16 import org.openstreetmap.josm.data.coor.LatLon; 11 import org.openstreetmap.josm.data.osm.*; 17 import org.openstreetmap.josm.data.osm.Node; 18 import org.openstreetmap.josm.data.osm.OsmPrimitive; 19 import org.openstreetmap.josm.data.osm.Way; 12 20 import org.openstreetmap.josm.gui.JosmUserIdentityManager; 13 21 import org.openstreetmap.josm.gui.layer.ImageryLayer; 14 import static org.openstreetmap.josm.tools.I18n.tr;15 22 16 23 /** 17 24 * Upload the current imagery offset or an calibration geometry information. 18 * 25 * 19 26 * @author Zverik 20 27 * @license WTFPL … … 39 46 * and we don't have one when a user name is needed. 40 47 */ 48 @Override 41 49 public void actionPerformed(ActionEvent e) { 42 50 if( Main.map == null || Main.map.mapView == null ) … … 56 64 if( userName.indexOf('@') > 0 ) 57 65 userName = userName.replace('@', ','); 58 66 59 67 // check if an object suitable for calibration is selected 60 68 OsmPrimitive calibration = null; 61 if ( getCurrentDataSet() != null62 Collection<OsmPrimitive> selectedObjects = get CurrentDataSet().getSelected();69 if (getLayerManager().getEditDataSet() != null) { 70 Collection<OsmPrimitive> selectedObjects = getLayerManager().getEditDataSet().getSelected(); 63 71 if( selectedObjects.size() == 1 ) { 64 72 OsmPrimitive selection = selectedObjects.iterator().next();
Note:
See TracChangeset
for help on using the changeset viewer.