/* */ package quicktime.app.time;
/* */
/* */ import quicktime.QTException;
/* */ import quicktime.std.StdQTException;
/* */ import quicktime.std.clocks.RateCallBack;
/* */ import quicktime.std.clocks.TimeBase;
/* */ import quicktime.std.clocks.TimeCallBack;
/* */ import quicktime.std.clocks.TimeJumpCallBack;
/* */ import quicktime.std.clocks.TimeRecord;
/* */ import quicktime.std.movies.Movie;
/* */
/* */ public class Timer
/* */ implements Timeable
/* */ {
/* */ private static final boolean debug = false;
/* 81 */ private static int count = 1;
/* */ private Movie m;
/* */ TimeBase theTimeBase;
/* */ private Ticklish target;
/* */ private int whichOne;
/* 142 */ private boolean doesTickle = true;
/* 143 */ private boolean cbActive = false;
/* 144 */ private boolean isTimerTicking = false;
/* */ private RC rc;
/* */ private TC tc;
/* */ private TJ tj;
/* */ private float lastKnownRate;
/* */
/* */ public Timer(int paramInt1, int paramInt2)
/* */ throws QTException
/* */ {
/* 90 */ this(paramInt1, paramInt2, null);
/* */ }
/* */
/* */ public Timer(int paramInt1, int paramInt2, Ticklish paramTicklish)
/* */ throws QTException
/* */ {
/* 101 */ this(paramInt1, paramInt2, paramTicklish, null);
/* */ }
/* */
/* */ public Timer(int paramInt1, int paramInt2, Ticklish paramTicklish, Movie paramMovie)
/* */ throws QTException
/* */ {
/* 113 */ if (paramInt1 == 0) throw new QTException("scale cannot be zero");
/* 114 */ this.m = paramMovie;
/* 115 */ if (this.m != null) {
/* 116 */ this.theTimeBase = this.m.getTimeBase();
/* 117 */ this.isTimerTicking = (this.theTimeBase.getEffectiveRate() != 0.0F);
/* */ } else {
/* 119 */ this.theTimeBase = new TimeBase();
/* 120 */ this.theTimeBase.setStartTime(new TimeRecord());
/* 121 */ TimeRecord localTimeRecord = new TimeRecord();
/* 122 */ localTimeRecord.setValue(86400L);
/* 123 */ localTimeRecord.setScale(1);
/* 124 */ this.theTimeBase.setStopTime(localTimeRecord);
/* 125 */ this.theTimeBase.setFlags(1);
/* */ }
/* 127 */ this.tc = new TC(this.theTimeBase, paramInt1, Math.abs(paramInt2), 0);
/* 128 */ this.tj = new TJ(this.theTimeBase);
/* 129 */ this.whichOne = (count++);
/* 130 */ this.target = paramTicklish;
/* 131 */ this.rc = new RC(this.theTimeBase);
/* */ }
/* */
/* */ public boolean isTicking()
/* */ {
/* 157 */ return this.isTimerTicking;
/* */ }
/* */
/* */ public boolean isTickling()
/* */ {
/* 166 */ return this.doesTickle;
/* */ }
/* */
/* */ public void setTickling(boolean paramBoolean)
/* */ throws StdQTException
/* */ {
/* 175 */ this.doesTickle = paramBoolean;
/* 176 */ if (isActive()) {
/* 177 */ this.tc.cancel();
/* 178 */ if (this.doesTickle) {
/* 179 */ this.tc.value = (this.theTimeBase.getTime(this.tc.scale) + this.tc.period);
/* 180 */ this.tc.flags = (this.lastKnownRate > 0.0F ? 1 : 2);
/* 181 */ this.tc.callMeWhen();
/* */ } else {
/* 183 */ this.tc.cancelAndCleanup();
/* */ }
/* */ }
/* */ }
/* */
/* */ public Ticklish getTicklish()
/* */ {
/* 193 */ return this.target;
/* */ }
/* */
/* */ public final TimeBase getTimeBase()
/* */ {
/* 201 */ return this.theTimeBase;
/* */ }
/* */
/* */ public synchronized void rescheduleTickle(int paramInt1, int paramInt2)
/* */ throws QTException
/* */ {
/* 213 */ if (paramInt1 == 0) throw new QTException("scale cannot be zero");
/* 214 */ this.tc.cancel();
/* 215 */ this.tc.scale = paramInt1;
/* 216 */ this.tc.period = paramInt2;
/* 217 */ this.tc.value = this.theTimeBase.getTime(paramInt1);
/* 218 */ this.tc.flags = (this.lastKnownRate > 0.0F ? 1 : 2);
/* 219 */ if (this.cbActive)
/* 220 */ this.tc.callMeWhen();
/* 221 */ this.doesTickle = true;
/* */ }
/* */
/* */ public int getScale()
/* */ {
/* 229 */ return this.tc.scale;
/* */ }
/* */
/* */ public int getPeriod()
/* */ {
/* 237 */ return Math.abs(this.tc.period);
/* */ }
/* */
/* */ public float getRate()
/* */ {
/* 246 */ return this.theTimeBase.getRate();
/* */ }
/* */
/* */ public void setRate(float paramFloat)
/* */ {
/* 258 */ this.theTimeBase.setRate(paramFloat);
/* 259 */ if (paramFloat == 0.0F)
/* 260 */ this.isTimerTicking = false;
/* */ else
/* 262 */ this.isTimerTicking = true;
/* */ }
/* */
/* */ public synchronized void setActive(boolean paramBoolean)
/* */ throws QTException
/* */ {
/* 270 */ if (paramBoolean == this.cbActive) return;
/* 271 */ this.cbActive = paramBoolean;
/* */
/* 273 */ this.tc.cancel();
/* 274 */ this.tj.cancel();
/* 275 */ this.rc.cancel();
/* */
/* 277 */ if (this.cbActive) {
/* 278 */ this.lastKnownRate = this.theTimeBase.getEffectiveRate();
/* */
/* 281 */ this.rc.callMeWhen();
/* 282 */ this.tj.callMeWhen();
/* 283 */ this.isTimerTicking = (this.lastKnownRate != 0.0F);
/* */
/* 285 */ if (this.lastKnownRate != 0.0F) {
/* 286 */ this.tc.period = Math.abs(this.tc.period);
/* 287 */ if (this.lastKnownRate < 0.0F)
/* 288 */ this.tc.period = (-this.tc.period);
/* 289 */ this.tc.value = this.theTimeBase.getTime(this.tc.scale);
/* 290 */ doTimeChanged(this.lastKnownRate, this.theTimeBase.getTime(1000));
/* */ }
/* */ }
/* */ else
/* */ {
/* 295 */ this.rc.cancelAndCleanup();
/* 296 */ this.tj.cancelAndCleanup();
/* 297 */ this.tc.cancelAndCleanup();
/* */ }
/* */ }
/* */
/* */ public boolean isActive()
/* */ {
/* 305 */ return this.cbActive;
/* */ }
/* */
/* */ public String toString() {
/* 309 */ return getClass().getName() + "[isActive=" + isActive() + ",whichOne=" + this.whichOne + ",rate=" + this.theTimeBase.getRate() + ",efRate=" + this.theTimeBase.getEffectiveRate() + ",scale=" + getScale() + "]";
/* */ }
/* */
/* */ protected void timeChanged(int paramInt)
/* */ throws QTException
/* */ {
/* 319 */ if (this.target != null)
/* 320 */ this.target.timeChanged(paramInt);
/* */ }
/* */
/* */ protected boolean tickle(float paramFloat, int paramInt)
/* */ throws QTException
/* */ {
/* 333 */ if (this.target != null)
/* 334 */ return this.target.tickle(paramFloat, paramInt);
/* 335 */ return false;
/* */ }
/* */
/* */ protected void finalize()
/* */ throws Throwable
/* */ {
/* 342 */ setActive(false);
/* 343 */ super.finalize();
/* */ }
/* */
/* */ private final synchronized void doTimeChanged(float paramFloat, int paramInt)
/* */ throws QTException
/* */ {
/* 352 */ if (this.cbActive) {
/* 353 */ timeChanged(paramInt);
/* 354 */ this.lastKnownRate = paramFloat;
/* 355 */ if ((this.lastKnownRate != 0.0F) && (this.doesTickle) && (this.cbActive))
/* 356 */ doReschedule(this.lastKnownRate, true);
/* */ else
/* 358 */ this.tc.cancel();
/* */ }
/* */ }
/* */
/* */ private final void doTickle(float paramFloat, int paramInt)
/* */ throws QTException
/* */ {
/* 369 */ if (paramFloat != 0.0F)
/* 370 */ synchronized (this) {
/* 371 */ if (this.cbActive)
/* 372 */ if ((tickle(paramFloat, paramInt)) && (this.cbActive))
/* 373 */ doReschedule(paramFloat, false);
/* */ else
/* 375 */ setTickling(false);
/* */ }
/* */ }
/* */
/* */ private void doReschedule(float paramFloat, boolean paramBoolean)
/* */ throws QTException
/* */ {
/* 382 */ this.tc.cancel();
/* */
/* 385 */ int i = this.theTimeBase.getTime(this.tc.scale);
/* 386 */ if (paramBoolean) {
/* 387 */ this.tc.value = i;
/* */ }
/* 389 */ else if (paramFloat > 0.0F) {
/* 390 */ this.tc.value += this.tc.period;
/* 391 */ if (this.tc.value <= i) {
/* 392 */ this.tc.value = i;
/* */ }
/* */ }
/* */ else
/* */ {
/* 397 */ this.tc.value += this.tc.period;
/* 398 */ if (this.tc.value > i) {
/* 399 */ this.tc.value = i;
/* */ }
/* */
/* */ }
/* */
/* 405 */ this.tc.callMeWhen();
/* */ }
/* */
/* */ private class RC extends RateCallBack
/* */ {
/* */ RC(TimeBase arg2)
/* */ throws QTException
/* */ {
/* 457 */ super(0.0F, 0);
/* */ }
/* */
/* */ public void execute()
/* */ {
/* */ try
/* */ {
/* 464 */ if (this.rateWhenCalled > 0.0F) {
/* 465 */ Timer.this.isTimerTicking = true;
/* 466 */ if (Timer.this.lastKnownRate <= 0.0F) {
/* 467 */ Timer.this.tc.cancel();
/* 468 */ Timer.this.tc.period = Math.abs(Timer.this.tc.period);
/* 469 */ Timer.this.doTimeChanged(this.rateWhenCalled, this.timeWhenCalledMsecs);
/* */ }
/* 471 */ } else if (this.rateWhenCalled < 0.0F) {
/* 472 */ Timer.this.isTimerTicking = true;
/* 473 */ if (Timer.this.lastKnownRate >= 0.0F) {
/* 474 */ Timer.this.tc.cancel();
/* 475 */ Timer.this.tc.period = Math.abs(Timer.this.tc.period);
/* 476 */ Timer.this.tc.period = (-Timer.this.tc.period);
/* 477 */ Timer.this.doTimeChanged(this.rateWhenCalled, this.timeWhenCalledMsecs);
/* */ }
/* */ } else {
/* 480 */ Timer.this.isTimerTicking = false;
/* 481 */ if (Timer.this.lastKnownRate != 0.0F) {
/* 482 */ Timer.this.tc.cancel();
/* 483 */ Timer.this.doTimeChanged(this.rateWhenCalled, this.timeWhenCalledMsecs);
/* */ }
/* */ }
/* */
/* 487 */ cancel();
/* 488 */ if (Timer.this.isActive())
/* 489 */ callMeWhen();
/* */ }
/* */ catch (QTException localQTException) {
/* 492 */ localQTException.printStackTrace();
/* */ }
/* */ }
/* */ }
/* */
/* */ private class TJ extends TimeJumpCallBack
/* */ {
/* */ TJ(TimeBase arg2)
/* */ throws QTException
/* */ {
/* 436 */ super();
/* */ }
/* */
/* */ public void execute()
/* */ {
/* 442 */ Timer.this.tc.cancel();
/* */ try
/* */ {
/* 445 */ Timer.this.doTimeChanged(this.rateWhenCalled, this.timeWhenCalledMsecs);
/* 446 */ cancel();
/* 447 */ if (Timer.this.isActive())
/* 448 */ callMeWhen();
/* */ } catch (QTException localQTException) {
/* 450 */ localQTException.printStackTrace();
/* */ }
/* */ }
/* */ }
/* */
/* */ private class TC extends TimeCallBack
/* */ {
/* */ int period;
/* */
/* */ TC(TimeBase paramInt1, int paramInt2, int paramInt3, int arg5)
/* */ throws QTException
/* */ {
/* 417 */ super(paramInt2, paramInt3, 3);
/* 418 */ this.period = paramInt3;
/* */ }
/* */
/* */ public void execute()
/* */ {
/* */ try
/* */ {
/* 427 */ Timer.this.doTickle(this.rateWhenCalled, this.timeWhenCalledMsecs);
/* */ } catch (QTException localQTException) {
/* 429 */ localQTException.printStackTrace();
/* */ }
/* */ }
/* */ }
/* */ }
/* Location: Z:\System\Library\Java\Extensions\QTJava.zip
* Qualified Name: quicktime.app.time.Timer
* JD-Core Version: 0.6.2
*/