Changeset 29399 in osm for applications/editors
- Timestamp:
- 2013-03-25T20:11:11+01:00 (12 years ago)
- Location:
- applications/editors/josm/plugins/imagery_offset_db/src/iodb
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/imagery_offset_db/src/iodb/GetImageryOffsetAction.java
r29394 r29399 26 26 * @license WTFPL 27 27 */ 28 public class GetImageryOffsetAction extends JosmAction {28 public class GetImageryOffsetAction extends JosmAction implements ImageryOffsetWatcher.OffsetStateListener { 29 29 private Icon iconOffsetOk; 30 30 private Icon iconOffsetBad; … … 39 39 KeyEvent.VK_I, Shortcut.ALT_CTRL), true); 40 40 iconOffsetOk = ImageProvider.get("getoffset"); 41 iconOffsetBad = ImageProvider.get("getoffsetnow"); // todo: create icon41 iconOffsetBad = ImageProvider.get("getoffsetnow"); 42 42 ImageryOffsetWatcher.getInstance().register(this); 43 43 } -
applications/editors/josm/plugins/imagery_offset_db/src/iodb/ImageryOffsetWatcher.java
r29394 r29399 12 12 * for the current layer. 13 13 * 14 * @author zverik 14 * @author Zverik 15 * @license WTFPL 15 16 */ 16 17 public class ImageryOffsetWatcher implements MapView.ZoomChangeListener, MapView.LayerChangeListener { 17 18 private static final double THRESHOLD = 1e-8; 18 private static final double MAX_DISTANCE = Main.pref.getDouble("iodb.offset.radius", 15) * 1000;19 private static ImageryOffsetWatcher instance; 19 20 private Map<Integer, ImageryLayerData> layers = new TreeMap<Integer, ImageryLayerData>(); 20 private List< GetImageryOffsetAction> listeners = new ArrayList<GetImageryOffsetAction>();21 private List<OffsetStateListener> listeners = new ArrayList<OffsetStateListener>(); 21 22 private Timer time; 22 private static ImageryOffsetWatcher instance;23 private boolean offsetGood ;23 private double maxDistance; 24 private boolean offsetGood = true; 24 25 26 /** 27 * Create an instance and register it as a listener to MapView. 28 * Also starts a timer task. 29 */ 25 30 private ImageryOffsetWatcher() { 26 if( MAX_DISTANCE <= 0 ) 27 return; 31 maxDistance = Main.pref.getDouble("iodb.offset.radius", 15); 28 32 MapView.addZoomChangeListener(this); 29 33 MapView.addLayerChangeListener(this); … … 42 46 } 43 47 48 /** 49 * This class is a singleton, this method returns the instance, 50 * creating it if neccessary. 51 */ 44 52 public static ImageryOffsetWatcher getInstance() { 45 53 if( instance == null ) { … … 49 57 } 50 58 51 public void register( GetImageryOffsetAction listener ) { 59 /** 60 * Register an offset state listener. 61 */ 62 public void register( OffsetStateListener listener ) { 52 63 listeners.add(listener); 53 64 listener.offsetStateChanged(offsetGood); 54 65 } 55 66 56 public void unregister( GetImageryOffsetAction listener ) { 67 /** 68 * Unregister an offset state listener. 69 */ 70 public void unregister( OffsetStateListener listener ) { 57 71 listeners.remove(listener); 58 72 } 59 73 74 /** 75 * Change stored offset state, notify listeners if needed. 76 */ 60 77 private void setOffsetGood( boolean good ) { 61 78 if( good != offsetGood ) { 62 for( GetImageryOffsetActionlistener : listeners )79 for( OffsetStateListener listener : listeners ) 63 80 listener.offsetStateChanged(good); 64 81 } … … 66 83 } 67 84 85 /** 86 * Check if the offset state has been changed. 87 */ 68 88 private void checkOffset() { 89 if( maxDistance <= 0 ) { 90 setOffsetGood(true); 91 return; 92 } 69 93 ImageryLayer layer = ImageryOffsetTools.getTopImageryLayer(); 70 94 if( layer == null ) { … … 96 120 setOffsetGood(true); 97 121 } else { 98 setOffsetGood(data.lastChecked != null && center.greatCircleDistance(data.lastChecked) <= MAX_DISTANCE);122 setOffsetGood(data.lastChecked != null && center.greatCircleDistance(data.lastChecked) <= maxDistance * 1000); 99 123 } 100 124 } 101 125 } 102 126 127 /** 128 * This class stores an offset and last location for a single imagery layer. 129 * All fields are public, because this is not enterprise. 130 */ 103 131 private static class ImageryLayerData { 104 132 public double lastDx = 0.0; … … 123 151 } 124 152 153 /** 154 * This task is run every 1-2 seconds. 155 */ 125 156 private class IntervalOffsetChecker extends TimerTask { 157 /** 158 * Reread max radius setting and update offset state. 159 */ 126 160 @Override 127 161 public void run() { 162 maxDistance = Main.pref.getDouble("iodb.offset.radius", 15); 128 163 checkOffset(); 129 164 } 130 165 } 166 167 /** 168 * The interface for offset listeners. 169 */ 170 public interface OffsetStateListener { 171 void offsetStateChanged( boolean isOffsetGood ); 172 } 131 173 }
Note:
See TracChangeset
for help on using the changeset viewer.