Changeset 19000 in osm


Ignore:
Timestamp:
2009-12-08T23:43:51+01:00 (15 years ago)
Author:
casualwalker
Message:

LiveGps plugin: refresh interval will be set in seconds (more user-friendly than milliseconds).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/livegps/src/livegps/LiveGpsSuppressor.java

    r18942 r19000  
    1818public class LiveGpsSuppressor implements Runnable {
    1919
    20     /**
    21     * Default sleep time is 5 seconds.
    22     */
    23     private static final int DEFAULT_SLEEP_TIME = 5000;
     20        /**
     21        * Default sleep time is 5 seconds.
     22        */
     23        private static final int DEFAULT_SLEEP_TIME = 5000;
    2424
    25     /**
    26     * The currently used sleepTime.
    27     */
    28     private int sleepTime = DEFAULT_SLEEP_TIME;
     25        /**
     26        * The currently used sleepTime.
     27        */
     28        private int sleepTime = DEFAULT_SLEEP_TIME;
    2929
    30     /**
    31     * The flag allowUpdate is enabled once during the sleepTime.
    32     */
    33     private boolean allowUpdate = false;
     30        /**
     31        * The flag allowUpdate is enabled once during the sleepTime.
     32        */
     33        private boolean allowUpdate = false;
    3434
    35     /**
    36     * Controls if this thread is still in used.
    37     */
    38     boolean shutdownFlag = false;
     35        /**
     36        * Controls if this thread is still in used.
     37        */
     38        boolean shutdownFlag = false;
    3939
    40     /**
    41     * Run thread enables the allowUpdate flag once during its cycle.
    42     * @see java.lang.Runnable#run()
    43     */
    44     public void run() {
    45         initSleepTime();
     40        /**
     41        * Run thread enables the allowUpdate flag once during its cycle.
     42        * @see java.lang.Runnable#run()
     43        */
     44        public void run() {
     45                initSleepTime();
    4646
    47         shutdownFlag = false;
    48         while (!shutdownFlag) {
    49             setAllowUpdate(true);
     47                shutdownFlag = false;
     48                while (!shutdownFlag) {
     49                        setAllowUpdate(true);
    5050
    51             try {
    52                 Thread.sleep(getSleepTime());
    53             } catch (InterruptedException e) {
    54                 // TODO I never knew, how to handle this??? Probably just carry on
    55             }
    56         }
     51                        try {
     52                                Thread.sleep(getSleepTime());
     53                        } catch (InterruptedException e) {
     54                                // TODO I never knew, how to handle this??? Probably just carry
     55                                // on
     56                        }
     57                }
    5758
    58     }
     59        }
    5960
    60     /**
    61     * Retrieve the sleepTime from the configuration.
    62     * If no such configuration key exists, it will be initialized here.
    63     */
    64     private void initSleepTime() {
    65         // fetch it from the user setting, or use the default value.
    66         sleepTime = Main.pref.getInteger("livegps.refreshinterval",
    67                 DEFAULT_SLEEP_TIME);
    68         // creates the setting, if none present.
    69         Main.pref.putInteger("livegps.refreshinterval", sleepTime);
    70     }
     61        /**
     62        * Retrieve the sleepTime from the configuration.
     63        * If no such configuration key exists, it will be initialized here.
     64        */
     65        private void initSleepTime() {
     66                // fetch it from the user setting, or use the default value.
     67                int sleepSeconds = 0;
     68                sleepSeconds = Main.pref.getInteger("livegps.refreshinterval",
     69                                DEFAULT_SLEEP_TIME);
     70                // creates the setting, if none present.
     71                Main.pref.putInteger("livegps.refreshinterval", sleepSeconds);
    7172
    72     /**
    73      * Set the allowUpdate flag. May only privately accessible!
    74      * @param allowUpdate the allowUpdate to set
    75      */
    76     private synchronized void setAllowUpdate(boolean allowUpdate) {
    77         this.allowUpdate = allowUpdate;
    78     }
     73                // convert seconds into milliseconds internally.
     74                this.sleepTime = sleepSeconds * 1000;
     75        }
    7976
    80     /**
    81      * Query, if an update is currently allowed.
    82      * When it is allowed, it will disable the allowUpdate flag as a side effect.
    83      * (this means, one thread got to issue an update event)
    84      *
    85      * @return true, if an update is currently allowed; false, if the update shall be suppressed.
    86      */
    87     public synchronized boolean isAllowUpdate() {
     77        /**
     78         * Set the allowUpdate flag. May only privately accessible!
     79         * @param allowUpdate the allowUpdate to set
     80         */
     81        private synchronized void setAllowUpdate(boolean allowUpdate) {
     82                this.allowUpdate = allowUpdate;
     83        }
    8884
    89         if (allowUpdate) {
    90             allowUpdate = false;
    91             return true;
    92         } else {
    93             return false;
    94         }
    95     }
     85        /**
     86         * Query, if an update is currently allowed.
     87         * When it is allowed, it will disable the allowUpdate flag as a side effect.
     88         * (this means, one thread got to issue an update event)
     89         *
     90         * @return true, if an update is currently allowed; false, if the update shall be suppressed.
     91         */
     92        public synchronized boolean isAllowUpdate() {
    9693
    97     /**
    98      * Shut this thread down.
    99      */
    100     public void shutdown() {
    101         shutdownFlag = true;
    102     }
     94                if (allowUpdate) {
     95                        allowUpdate = false;
     96                        return true;
     97                } else {
     98                        return false;
     99                }
     100        }
    103101
    104     /**
    105      * @return the defaultSleepTime
    106      */
    107     private int getSleepTime() {
    108         return this.sleepTime;
    109     }
     102        /**
     103         * Shut this thread down.
     104         */
     105        public void shutdown() {
     106                shutdownFlag = true;
     107        }
     108
     109        /**
     110         * @return the defaultSleepTime
     111         */
     112        private int getSleepTime() {
     113                return this.sleepTime;
     114        }
    110115
    111116}
Note: See TracChangeset for help on using the changeset viewer.