/** Set whether or not resize checking is enabled. If disabled, elements will still be resized on window events, but the timer * will not check their dimensions periodically. * * @param enabled true to enable the resize checking timer */ public void setResizeCheckingEnabled (boolean enabled) { if (enabled && !resizeCheckingEnabled) { resizeCheckingEnabled = true; if (windowHandler == null) { windowHandler = Window.addResizeHandler(this); } resizeCheckTimer.schedule(resizeCheckDelay); } else if (!enabled && resizeCheckingEnabled) { resizeCheckingEnabled = false; if (windowHandler != null) { windowHandler.removeHandler(); windowHandler = null; } resizeCheckTimer.cancel(); } }
final void fire(int scheduleCancelCounter) { // Workaround for broken clearTimeout in IE. if (scheduleCancelCounter != cancelCounter) { return; } if (!isRepeating) { timerId = null; } // Run the timer's code. run(); }
/** * Schedules a timer to elapse in the future. If the timer is already running then it will be * first canceled before re-scheduling. * * @param delayMillis how long to wait before the timer elapses, in milliseconds */ public void schedule(int delayMillis) { if (delayMillis < 0) { throw new IllegalArgumentException("must be non-negative"); } if (isRunning()) { cancel(); } isRepeating = false; timerId = setTimeout(createCallback(this, cancelCounter), delayMillis); }
/** * Cancels this timer. If the timer is not running, this is a no-op. */ public void cancel() { if (!isRunning()) { return; } cancelCounter++; if (isRepeating) { clearInterval(timerId); } else { clearTimeout(timerId); } timerId = null; }
@Override public AnimationHandle requestAnimationFrame(final AnimationCallback callback, Element element) { // Save the animation frame request. AnimationHandleImpl requestId = new AnimationHandleImpl(callback); animationRequests.add(requestId); // Start the timer if it isn't started. if (animationRequests.size() == 1) { timer.schedule(DEFAULT_FRAME_DELAY); } // Return the request id. return requestId; }
private void cancelAnimationFrame(AnimationHandle requestId) { // Remove the request from the list. animationRequests.remove(requestId); // Stop the timer if there are no more requests. if (animationRequests.size() == 0) { timer.cancel(); } }
/** * Schedules a timer that elapses repeatedly. If the timer is already running then it will be * first canceled before re-scheduling. * * @param periodMillis how long to wait before the timer elapses, in milliseconds, between each * repetition */ public void scheduleRepeating(int periodMillis) { if (periodMillis <= 0) { throw new IllegalArgumentException("must be positive"); } if (isRunning()) { cancel(); } isRepeating = true; timerId = setInterval(createCallback(this, cancelCounter), periodMillis); }
public void setAutoPlay(boolean autoPlay) { this.autoPlay = autoPlay; this.handlerRegistrations.removeHandler(); if (autoPlay) { this.autoPlayTimer.scheduleRepeating(this.timerDelay); this.handlerRegistrations.add(this.addDomHandler(this, MouseOverEvent.getType())); this.handlerRegistrations.add(this.addDomHandler(this, MouseOutEvent.getType())); } else { this.autoPlayTimer.cancel(); } }
public void startScrollingVelocityTimer() { if (scrollingVelocityTimer == null) { scrollingVelocityTimer = new Timer() { @Override public void run() { scrollingVelocity++; } }; scrollingVelocityTimer.scheduleRepeating(100); } }
public void startMonitoring() { if (panel.isAttached()) { timer.run(); timer.scheduleRepeating(interval); } }
public void show() { if (null != this.timer && this.timer.isRunning()) { return; } startTimer(); view.show(); }
private boolean throttleMessages(final List<Message> txMessages) { final int window = throttleOutgoing(); if (window <= 0) { heldMessages.addAll(txMessages); throttleTimer.schedule(-window); return true; } else { return false; } }
private List<Message> getDeferredToSend() { throttleTimer.cancel(); try { return new ArrayList<Message>(heldMessages); } finally { heldMessages.clear(); } }