< prev index next >

modules/javafx.graphics/src/main/java/com/sun/glass/ui/Timer.java

Print this page
rev 10048 : 8166564: @native for mac builds
Reviewed-by: kcr


   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 package com.sun.glass.ui;
  26 


  27 /**
  28  * A high-resolution timer.
  29  *
  30  * An application may either override its run() method, or pass a Runnable
  31  * object to the constructor of the Timer class.
  32  * <p>
  33  * The run() method may be invoked on a thread other than the UI thread. If
  34  * a developer wants to process timer events on the UI thread, they can use
  35  * the Application.invokeLater/invokeAndWait() API.
  36  */
  37 public abstract class Timer {
  38 
  39     private final static double UNSET_PERIOD = -1.0; // 0 is valid value, so can't use it here
  40     private final static double SET_PERIOD   = -2.0; // token value for vsync timer
  41 
  42     private final Runnable runnable;
  43     private long ptr;
  44     private double period = UNSET_PERIOD;
  45 
  46     protected abstract long _start(Runnable runnable);
  47     protected abstract long _start(Runnable runnable, int period);
  48     protected abstract void _stop(long timer);
  49 
  50     /**
  51      * Constructs a new timer.
  52      *
  53      * If the application overrides the Timer.run(), it should call super.run()
  54      * in order to run the runnable passed to the constructor.
  55      */
  56     protected Timer(Runnable runnable) {
  57         if (runnable == null) {
  58             throw new IllegalArgumentException("runnable shouldn't be null");
  59         }
  60         this.runnable = runnable;




   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 package com.sun.glass.ui;
  26 
  27 import java.lang.annotation.Native;
  28 
  29 /**
  30  * A high-resolution timer.
  31  *
  32  * An application may either override its run() method, or pass a Runnable
  33  * object to the constructor of the Timer class.
  34  * <p>
  35  * The run() method may be invoked on a thread other than the UI thread. If
  36  * a developer wants to process timer events on the UI thread, they can use
  37  * the Application.invokeLater/invokeAndWait() API.
  38  */
  39 public abstract class Timer {
  40 
  41     @Native private final static double UNSET_PERIOD = -1.0; // 0 is valid value, so can't use it here
  42     @Native private final static double SET_PERIOD   = -2.0; // token value for vsync timer
  43 
  44     private final Runnable runnable;
  45     private long ptr;
  46     private double period = UNSET_PERIOD;
  47 
  48     protected abstract long _start(Runnable runnable);
  49     protected abstract long _start(Runnable runnable, int period);
  50     protected abstract void _stop(long timer);
  51 
  52     /**
  53      * Constructs a new timer.
  54      *
  55      * If the application overrides the Timer.run(), it should call super.run()
  56      * in order to run the runnable passed to the constructor.
  57      */
  58     protected Timer(Runnable runnable) {
  59         if (runnable == null) {
  60             throw new IllegalArgumentException("runnable shouldn't be null");
  61         }
  62         this.runnable = runnable;


< prev index next >