Changeset 29412 in osm for applications/editors/josm/plugins
- Timestamp:
- 2013-03-27T20:56:51+01:00 (12 years ago)
- Location:
- applications/editors/josm/plugins/imagery_offset_db
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/imagery_offset_db/build.xml
r29390 r29412 32 32 <property name="commit.message" value="Imagery Offset Database"/> 33 33 <!-- enter the *lowest* JOSM version this plugin is currently compatible with --> 34 <property name="plugin.main.version" value="4 549"/>34 <property name="plugin.main.version" value="4666"/> 35 35 <!-- 36 36 ************************************************ -
applications/editors/josm/plugins/imagery_offset_db/src/iodb/ImageryOffsetPlugin.java
r29408 r29412 5 5 import javax.swing.JMenu; 6 6 import org.openstreetmap.josm.Main; 7 import org.openstreetmap.josm.data.Version; 7 8 import org.openstreetmap.josm.plugins.Plugin; 8 9 import org.openstreetmap.josm.plugins.PluginInformation; … … 31 32 storeAction = new StoreImageryOffsetAction(); 32 33 33 JMenu offsetMenu = Main.main.menu.addMenu(marktr("Offset"), KeyEvent.VK_O, 6, "help"); 34 // before 5803 imagery menu was constantly regenerated, erasing extra items 35 // before 5729 it was regenerated only when the imagery list was modified (also bad) 36 int version = Version.getInstance().getVersion(); 37 JMenu offsetMenu = version < 5803 38 ? Main.main.menu.addMenu(marktr("Offset"), KeyEvent.VK_O, 6, "help") 39 : Main.main.menu.imageryMenu; 34 40 offsetMenu.add(getAction); 35 41 offsetMenu.add(storeAction); 42 if( version >= 5803 ) // todo: check if this is needed 43 offsetMenu.addSeparator(); 36 44 37 45 // an ugly hack to add this plugin to the toolbar 38 Collection<String> toolbar = new LinkedList<String>(Main.toolbar.getToolString()); 39 if( !toolbar.contains("getoffset") && Main.pref.getBoolean("iodb.modify.toolbar", true) ) { 40 toolbar.add("getoffset"); 41 Main.pref.putCollection("toolbar", toolbar); 46 if( Main.pref.getBoolean("iodb.modify.toolbar", true) ) { 47 Collection<String> toolbar = new LinkedList<String>(Main.toolbar.getToolString()); 48 if( !toolbar.contains("getoffset") ) { 49 toolbar.add("getoffset"); 50 Main.pref.putCollection("toolbar", toolbar); 51 Main.toolbar.refreshToolbarControl(); 52 } 42 53 Main.pref.put("iodb.modify.toolbar", false); 43 Main.toolbar.refreshToolbarControl();44 54 } 45 55 } -
applications/editors/josm/plugins/imagery_offset_db/src/iodb/ImageryOffsetWatcher.java
r29402 r29412 7 7 import org.openstreetmap.josm.gui.layer.ImageryLayer; 8 8 import org.openstreetmap.josm.gui.layer.Layer; 9 import org.openstreetmap.josm.tools.Destroyable; 9 10 10 11 /** … … 15 16 * @license WTFPL 16 17 */ 17 public class ImageryOffsetWatcher implements MapView.ZoomChangeListener, MapView.LayerChangeListener {18 public class ImageryOffsetWatcher implements MapView.ZoomChangeListener, MapView.LayerChangeListener, Destroyable { 18 19 private static final double THRESHOLD = 1e-8; 19 20 private static ImageryOffsetWatcher instance; … … 118 119 data.lastDy = layer.getDy(); 119 120 data.lastChecked = center; 121 storeLayerOffset(layer); 120 122 setOffsetGood(true); 121 123 } else { … … 125 127 } 126 128 129 /** 130 * Mark the current offset as good. This method is called by {@link OffsetDialog} 131 * to notify the watcher that an offset button has been clicked, and regardless of 132 * whether it has changed an offset, the currect imagery alignment is ok. 133 */ 127 134 public void markGood() { 128 135 ImageryLayer layer = ImageryOffsetTools.getTopImageryLayer(); … … 143 150 data.lastChecked = center; 144 151 } 152 storeLayerOffset(layer); 145 153 } 146 154 setOffsetGood(true); … … 166 174 167 175 public void layerAdded( Layer newLayer ) { 176 if( newLayer instanceof ImageryLayer ) 177 loadLayerOffset((ImageryLayer)newLayer); 168 178 checkOffset(); 169 179 } … … 171 181 public void layerRemoved( Layer oldLayer ) { 172 182 checkOffset(); 183 } 184 185 /** 186 * Saves the current imagery layer offset to preferences. It is stored as a 187 * collection of ':'-separated strings: imagery_id:lat:lon:dx:dy. No need for 188 * projections: nobody uses them anyway. 189 */ 190 private void storeLayerOffset( ImageryLayer layer ) { 191 String id = ImageryOffsetTools.getImageryID(layer); 192 if( !Main.pref.getBoolean("iodb.remember.offsets", true) || id == null ) 193 return; 194 Collection<String> offsets = new LinkedList<String>(Main.pref.getCollection("iodb.stored.offsets")); 195 for( Iterator<String> iter = offsets.iterator(); iter.hasNext(); ) { 196 String[] offset = iter.next().split(":"); 197 if( offset.length == 5 && offset[0].equals(id) ) 198 iter.remove(); 199 } 200 LatLon center = ImageryOffsetTools.getMapCenter(); 201 offsets.add(id + ":" + center.lat() + ":" + center.lon() + ":" + layer.getDx() + ":" + layer.getDy()); 202 Main.pref.putCollection("iodb.stored.offsets", offsets); 203 } 204 205 /** 206 * Loads the current imagery layer offset from preferences. 207 */ 208 private void loadLayerOffset( ImageryLayer layer ) { 209 String id = ImageryOffsetTools.getImageryID(layer); 210 if( !Main.pref.getBoolean("iodb.remember.offsets", true) || id == null ) 211 return; 212 Collection<String> offsets = Main.pref.getCollection("iodb.stored.offsets"); 213 for( String offset : offsets ) { 214 String[] parts = offset.split(":"); 215 if( parts.length == 5 && parts[0].equals(id) ) { 216 double[] dparts = new double[4]; 217 try { 218 for( int i = 0; i < 4; i++ ) 219 dparts[i] = Double.parseDouble(parts[i+1]); 220 } catch( Exception e ) { 221 continue; 222 } 223 LatLon lastPos = new LatLon(dparts[0], dparts[1]); 224 if( lastPos.greatCircleDistance(ImageryOffsetTools.getMapCenter()) < Math.max(maxDistance, 3.0) * 1000 ) { 225 // apply offset 226 layer.setOffset(dparts[2], dparts[3]); 227 return; 228 } 229 } 230 } 173 231 } 174 232 -
applications/editors/josm/plugins/imagery_offset_db/src/iodb/OffsetDialog.java
r29402 r29412 31 31 protected static final String PREF_CALIBRATION = "iodb.show.calibration"; 32 32 protected static final String PREF_DEPRECATED = "iodb.show.deprecated"; 33 private static final int MAX_OFFSETS = Main.main.pref.getInteger("iodb.max.offsets", 5);33 private static final int MAX_OFFSETS = Main.main.pref.getInteger("iodb.max.offsets", 4); 34 34 35 35 /**
Note:
See TracChangeset
for help on using the changeset viewer.