Changeset 25808 in osm
- Timestamp:
- 2011-04-06T21:23:49+02:00 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/livegps/src/livegps/LiveGpsLayer.java
r25805 r25808 26 26 public static final String KEY_LIVEGPS_COLOR = "color.livegps.position"; 27 27 28 private static final int DEFAULT_SLEEP_TIME = 500; /* Default sleep time is 0.5 seconds. */ 29 private static final String oldConfigKey = "livegps.refreshinterval"; /* in seconds */ 30 private static final String ConfigKey = "livegps.refresh_interval_msec"; /* in msec */ 31 private int sleepTime; 28 private static final int DEFAULT_REFRESH_INTERVAL = 250; 29 private static final int DEFAULT_CENTER_INTERVAL = 5000; 30 private static final String oldC_REFRESH_INTERVAL = "livegps.refreshinterval"; /* in seconds */ 31 private static final String C_REFRESH_INTERVAL = "livegps.refresh_interval_msec"; /* in msec */ 32 private static final String C_CENTER_INTERVAL = "livegps.center_interval_msec"; /* in msec */ 33 private int refreshInterval; 34 private int centerInterval; 35 private long lastRedraw = 0; 36 private long lastCenter = 0; 32 37 33 38 LatLon lastPos; … … 39 44 boolean autocenter; 40 45 private SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS"); 41 private long lastUpdate = 0;42 46 43 47 public LiveGpsLayer(GpxData data) { … … 51 55 data.tracks.add(trackBeingWritten); 52 56 53 init SleepTime();57 initIntervals(); 54 58 } 55 59 56 60 void setCurrentPosition(double lat, double lon) { 57 // System.out.println("adding pos " + lat + "," + lon);58 61 LatLon thisPos = new LatLon(lat, lon); 59 if ((lastPos != null) && (thisPos.equalsEpsilon(lastPos))) {62 if ((lastPos != null) && (thisPos.equalsEpsilon(lastPos))) 60 63 // no change in position 61 64 // maybe show a "paused" cursor or some such 62 65 return; 63 }64 66 65 67 lastPos = thisPos; … … 67 69 lastPoint.attr.put("time", dateFormat.format(new Date())); 68 70 trackSegment.addWaypoint(lastPoint); 69 if (autocenter && allow Redraw()) {71 if (autocenter && allowCenter()) 70 72 center(); 71 }72 73 } 73 74 … … 145 146 setCourse(data.getCourse()); 146 147 } 147 if ( !autocenter &&allowRedraw()){148 if (allowRedraw()) 148 149 Main.map.repaint(); 149 }150 150 } 151 151 } … … 162 162 long current = date.getTime(); 163 163 164 if (current - last Update >= sleepTime) {165 last Update= current;164 if (current - lastRedraw >= refreshInterval) { 165 lastRedraw = current; 166 166 return true; 167 167 } else … … 170 170 171 171 /** 172 * Retrieve the sleepTime from the configuration. Be compatible with old 173 * version that stored value in seconds. If no such configuration key exists, 174 * it will be initialized here. 175 */ 176 private void initSleepTime() { 177 if ((sleepTime = Main.pref.getInteger(ConfigKey, 0)) == 0) { 178 if ((sleepTime = Main.pref.getInteger(oldConfigKey, 0)) != 0) { 179 sleepTime *= 1000; 180 Main.pref.put(oldConfigKey, null); 172 * Check, if a autocentering is currently allowed. 173 * 174 * @return true, if a autocentering is permitted, false, if a autocentering 175 * should be suppressed. 176 */ 177 private boolean allowCenter() { 178 Date date = new Date(); 179 long current = date.getTime(); 180 181 if (current - lastCenter >= centerInterval) { 182 lastCenter = current; 183 return true; 184 } else 185 return false; 186 } 187 188 /** 189 * Retrieve the refreshInterval and centerInterval from the configuration. Be compatible 190 * with old version that stored refreshInterval in seconds. If no such configuration key 191 * exists, it will be initialized here. 192 */ 193 private void initIntervals() { 194 if ((refreshInterval = Main.pref.getInteger(C_REFRESH_INTERVAL, 0)) == 0) { 195 if ((refreshInterval = Main.pref.getInteger(oldC_REFRESH_INTERVAL, 0)) != 0) { 196 refreshInterval *= 1000; 197 Main.pref.put(oldC_REFRESH_INTERVAL, null); 181 198 } else 182 sleepTime = DEFAULT_SLEEP_TIME; 183 } 184 185 // creates the setting, if none present. 186 Main.pref.putInteger(ConfigKey, sleepTime); 199 refreshInterval = DEFAULT_REFRESH_INTERVAL; 200 } 201 202 if ((centerInterval = Main.pref.getInteger(C_CENTER_INTERVAL, 0)) == 0) 203 centerInterval = DEFAULT_CENTER_INTERVAL; 204 205 Main.pref.putInteger(C_REFRESH_INTERVAL, refreshInterval); 206 Main.pref.putInteger(C_CENTER_INTERVAL, centerInterval); 187 207 } 188 208 }
Note:
See TracChangeset
for help on using the changeset viewer.