Changeset 25797 in osm for applications/editors


Ignore:
Timestamp:
2011-04-05T23:26:25+02:00 (14 years ago)
Author:
glebius
Message:

Simplify suppressing. We do not really need a separate thread,
an interface and a special class for such a trivial task.

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  
    2525    public static final String LAYER_NAME = tr("LiveGPS layer");
    2626    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
    2733    LatLon lastPos;
    2834    WayPoint lastPoint;
     
    3238    // JLabel lbl;
    3339    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;
    4142
    4243    public LiveGpsLayer(GpxData data) {
     
    4950        GpxTrack trackBeingWritten = new SingleSegmentGpxTrack(trackSegment, attr);
    5051        data.tracks.add(trackBeingWritten);
     52
     53        initSleepTime();
    5154    }
    5255
     
    155158
    156159    /**
    157      * @param suppressor the suppressor to set
    158      */
    159     public void setSuppressor(ILiveGpsSuppressor suppressor) {
    160         this.suppressor = suppressor;
    161     }
    162 
    163     /**
    164      * @return the suppressor
    165      */
    166     public ILiveGpsSuppressor getSuppressor() {
    167         return suppressor;
    168     }
    169 
    170     /**
    171160     * Check, if a redraw is currently allowed.
    172161     *
     
    175164     */
    176165    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;
    181188        }
     189
     190        // creates the setting, if none present.
     191        Main.pref.putInteger(ConfigKey, sleepTime);
    182192    }
    183193}
  • applications/editors/josm/plugins/livegps/src/livegps/LiveGpsPlugin.java

    r25790 r25797  
    3939    private LiveGpsLayer lgpslayer = null;
    4040
    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 
    5141    public class CaptureAction extends JosmAction {
    5242        public CaptureAction() {
     
    165155       
    166156        if (enable && !enabled) {
    167             assert (suppressor == null);
    168             assert (suppressorThread == null);
    169157            assert (acquirer == null);
    170158            assert (acquirerThread == null);
    171 
    172             suppressor = new LiveGpsSuppressor();
    173             suppressorThread = new Thread(suppressor);
    174159
    175160            acquirer = new LiveGpsAcquirer();
     
    183168            }
    184169
    185             lgpslayer.setSuppressor(suppressor);
    186170            acquirer.addPropertyChangeListener(lgpslayer);
    187171            acquirer.addPropertyChangeListener(lgpsdialog);
    188172
    189             suppressorThread.start();
    190173            acquirerThread.start();
    191174
     
    194177        } else if (!enable && enabled) {
    195178            assert (lgpslayer != null);
    196             assert (suppressor != null);
    197             assert (suppressorThread != null);
    198179            assert (acquirer != null);
    199180            assert (acquirerThread != null);
     
    202183            acquirer = null;
    203184            acquirerThread = null;
    204 
    205             suppressor.shutdown();
    206             suppressor = null;
    207             suppressorThread = null;
    208 
    209             lgpslayer.setSuppressor(null);
    210185
    211186            enabled = false;
Note: See TracChangeset for help on using the changeset viewer.