Changeset 25809 in osm for applications
- Timestamp:
- 2011-04-07T00:03:40+02:00 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/livegps/src/livegps/LiveGpsLayer.java
r25808 r25809 6 6 import java.awt.Graphics2D; 7 7 import java.awt.Point; 8 import java.awt.geom.Point2D; 9 import java.awt.Rectangle; 8 10 import java.beans.PropertyChangeEvent; 9 11 import java.beans.PropertyChangeListener; … … 28 30 private static final int DEFAULT_REFRESH_INTERVAL = 250; 29 31 private static final int DEFAULT_CENTER_INTERVAL = 5000; 32 private static final int DEFAULT_CENTER_FACTOR = 80; 30 33 private static final String oldC_REFRESH_INTERVAL = "livegps.refreshinterval"; /* in seconds */ 31 34 private static final String C_REFRESH_INTERVAL = "livegps.refresh_interval_msec"; /* in msec */ 32 35 private static final String C_CENTER_INTERVAL = "livegps.center_interval_msec"; /* in msec */ 36 private static final String C_CENTER_FACTOR = "livegps.center_factor" /* in percent */; 33 37 private int refreshInterval; 34 38 private int centerInterval; 39 private double centerFactor; 35 40 private long lastRedraw = 0; 36 41 private long lastCenter = 0; … … 69 74 lastPoint.attr.put("time", dateFormat.format(new Date())); 70 75 trackSegment.addWaypoint(lastPoint); 71 if (autocenter && allowCenter()) 72 center();76 77 conditionalCenter(thisPos); 73 78 } 74 79 … … 76 81 if (lastPoint != null) 77 82 Main.map.mapView.zoomTo(lastPoint.getCoor()); 83 } 84 85 public void conditionalCenter(LatLon Pos) { 86 Point2D P = Main.map.mapView.getPoint2D(Pos); 87 Rectangle rv = Main.map.mapView.getBounds(null); 88 Date date = new Date(); 89 long current = date.getTime(); 90 91 rv.grow(-(int)(rv.getHeight() * centerFactor), -(int)(rv.getWidth() * centerFactor)); 92 93 if (!rv.contains(P) || (centerInterval > 0 && current - lastCenter >= centerInterval)) { 94 Main.map.mapView.zoomTo(Pos); 95 lastCenter = current; 96 } 78 97 } 79 98 … … 170 189 171 190 /** 172 * Check, if a autocentering is currently allowed.173 *174 * @return true, if a autocentering is permitted, false, if a autocentering175 * 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 } else185 return false;186 }187 188 /**189 191 * Retrieve the refreshInterval and centerInterval from the configuration. Be compatible 190 192 * with old version that stored refreshInterval in seconds. If no such configuration key … … 192 194 */ 193 195 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); 198 } else 199 refreshInterval = DEFAULT_REFRESH_INTERVAL; 200 } 201 202 if ( (centerInterval = Main.pref.getInteger(C_CENTER_INTERVAL, 0)) == 0)203 center Interval = DEFAULT_CENTER_INTERVAL;196 if ((refreshInterval = Main.pref.getInteger(oldC_REFRESH_INTERVAL, 0)) != 0) { 197 refreshInterval *= 1000; 198 Main.pref.put(oldC_REFRESH_INTERVAL, null); 199 } else 200 refreshInterval = Main.pref.getInteger(C_REFRESH_INTERVAL, DEFAULT_REFRESH_INTERVAL); 201 202 centerInterval = Main.pref.getInteger(C_CENTER_INTERVAL, DEFAULT_CENTER_INTERVAL); 203 centerFactor = Main.pref.getInteger(C_CENTER_FACTOR, DEFAULT_CENTER_FACTOR); 204 if (centerFactor <= 1 || centerFactor >= 99) 205 centerFactor = DEFAULT_CENTER_FACTOR; 204 206 205 207 Main.pref.putInteger(C_REFRESH_INTERVAL, refreshInterval); 206 208 Main.pref.putInteger(C_CENTER_INTERVAL, centerInterval); 209 Main.pref.putInteger(C_CENTER_FACTOR, (int )centerFactor); 210 211 /* 212 * Do one time conversion of factor: user value means "how big is inner rectangle 213 * comparing to screen in percent", machine value means "what is the shrink ratio 214 * for each dimension on _both_ sides". 215 */ 216 217 centerFactor = (100 - centerFactor) / 2 / 100; 207 218 } 208 219 }
Note:
See TracChangeset
for help on using the changeset viewer.