Changeset 25797 in osm for applications/editors/josm/plugins/livegps/src
- Timestamp:
- 2011-04-05T23:26:25+02:00 (14 years ago)
- Location:
- applications/editors/josm/plugins/livegps/src/livegps
- Files:
-
- 2 deleted
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/livegps/src/livegps/LiveGpsLayer.java
r23191 r25797 25 25 public static final String LAYER_NAME = tr("LiveGPS layer"); 26 26 public static final String KEY_LIVEGPS_COLOR = "color.livegps.position"; 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; 32 27 33 LatLon lastPos; 28 34 WayPoint lastPoint; … … 32 38 // JLabel lbl; 33 39 boolean autocenter; 34 private SimpleDateFormat dateFormat = new SimpleDateFormat( 35 "yyyy-MM-dd'T'HH:mm:ss.SSS"); 36 37 /** 38 * The suppressor is queried, if the GUI shall be re-drawn. 39 */ 40 private ILiveGpsSuppressor suppressor; 40 private SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS"); 41 private long lastUpdate = 0; 41 42 42 43 public LiveGpsLayer(GpxData data) { … … 49 50 GpxTrack trackBeingWritten = new SingleSegmentGpxTrack(trackSegment, attr); 50 51 data.tracks.add(trackBeingWritten); 52 53 initSleepTime(); 51 54 } 52 55 … … 155 158 156 159 /** 157 * @param suppressor the suppressor to set158 */159 public void setSuppressor(ILiveGpsSuppressor suppressor) {160 this.suppressor = suppressor;161 }162 163 /**164 * @return the suppressor165 */166 public ILiveGpsSuppressor getSuppressor() {167 return suppressor;168 }169 170 /**171 160 * Check, if a redraw is currently allowed. 172 161 * … … 175 164 */ 176 165 private boolean allowRedraw() { 177 if (this.suppressor != null) { 178 return this.suppressor.isAllowUpdate(); 179 } else { 180 return true; 166 Date date = new Date(); 167 long current = date.getTime(); 168 169 if (current - lastUpdate >= sleepTime) { 170 lastUpdate = current; 171 return true; 172 } else 173 return false; 174 } 175 176 /** 177 * Retrieve the sleepTime from the configuration. Be compatible with old 178 * version that stored value in seconds. If no such configuration key exists, 179 * it will be initialized here. 180 */ 181 private void initSleepTime() { 182 if ((sleepTime = Main.pref.getInteger(ConfigKey, 0)) == 0) { 183 if ((sleepTime = Main.pref.getInteger(oldConfigKey, 0)) != 0) { 184 sleepTime *= 1000; 185 Main.pref.put(oldConfigKey, null); 186 } else 187 sleepTime = DEFAULT_SLEEP_TIME; 181 188 } 189 190 // creates the setting, if none present. 191 Main.pref.putInteger(ConfigKey, sleepTime); 182 192 } 183 193 } -
applications/editors/josm/plugins/livegps/src/livegps/LiveGpsPlugin.java
r25790 r25797 39 39 private LiveGpsLayer lgpslayer = null; 40 40 41 /**42 * The LiveGpsSuppressor is queried, if an event shall be suppressed.43 */44 private LiveGpsSuppressor suppressor = null;45 46 /**47 * separate thread, where the LiveGpsSuppressor executes.48 */49 private Thread suppressorThread;50 51 41 public class CaptureAction extends JosmAction { 52 42 public CaptureAction() { … … 165 155 166 156 if (enable && !enabled) { 167 assert (suppressor == null);168 assert (suppressorThread == null);169 157 assert (acquirer == null); 170 158 assert (acquirerThread == null); 171 172 suppressor = new LiveGpsSuppressor();173 suppressorThread = new Thread(suppressor);174 159 175 160 acquirer = new LiveGpsAcquirer(); … … 183 168 } 184 169 185 lgpslayer.setSuppressor(suppressor);186 170 acquirer.addPropertyChangeListener(lgpslayer); 187 171 acquirer.addPropertyChangeListener(lgpsdialog); 188 172 189 suppressorThread.start();190 173 acquirerThread.start(); 191 174 … … 194 177 } else if (!enable && enabled) { 195 178 assert (lgpslayer != null); 196 assert (suppressor != null);197 assert (suppressorThread != null);198 179 assert (acquirer != null); 199 180 assert (acquirerThread != null); … … 202 183 acquirer = null; 203 184 acquirerThread = null; 204 205 suppressor.shutdown();206 suppressor = null;207 suppressorThread = null;208 209 lgpslayer.setSuppressor(null);210 185 211 186 enabled = false;
Note:
See TracChangeset
for help on using the changeset viewer.