List of usage examples for com.google.gwt.user.client Timer Timer
Timer
From source file:com.bedatadriven.rebar.appcache.client.Html5AppCache.java
License:Apache License
@Override public void ensureCached(final AsyncCallback<Void> callback) { Cookies.removeCookie(DISABLE_COOKIE_NAME); if (callbackIfCached(callback)) return;//from www .j a va 2 s .c om // otherwise we need to wait until the download is complete. // unfortunately there doesn't seem to be a way to determine whether we're busy // downloading for the first time, or a new version new Timer() { @Override public void run() { if (callbackIfCached(callback)) { this.cancel(); } } }.scheduleRepeating(1000); }
From source file:com.bedatadriven.rebar.appcache.client.Html5AppCache.java
License:Apache License
@Override public void ensureUpToDate(final AsyncCallback<Void> callback) { LOGGER.fine("ensureUpToDate starting..."); Cookies.removeCookie(DISABLE_COOKIE_NAME); // an error retrieving the cache does not neccessarily // alter the status if it is just a network problem. // but we want to make sure that we have an answer so we // have to trap the errors ourselves sinkErrorEvent(this); final ErrorListener errors = new ErrorListener(); LOGGER.fine("Status: " + statusDebugString()); if (getAppCacheStatus() == IDLE || getAppCacheStatus() == UPDATE_READY) { try {/*w ww. j a va 2s . co m*/ LOGGER.fine("Calling update()"); update(); } catch (Exception e) { LOGGER.log(Level.SEVERE, "Html5AppCache: call to update() threw exception. Current state = " + getAppCacheStatus(), e); callback.onFailure(e); return; } } final long startTime = new Date().getTime(); new Timer() { @Override public void run() { LOGGER.fine("Status: " + statusDebugString()); switch (getAppCacheStatus()) { case IDLE: if (errors.haveOccurred()) { callback.onFailure(new AppCacheException(AppCacheErrorType.CONNECTION)); } else { callback.onSuccess(null); } this.cancel(); break; case UPDATE_READY: callback.onSuccess(null); this.cancel(); break; case UNCACHED: callback.onFailure(new AppCacheException(AppCacheErrorType.MISSING_MANIFEST)); this.cancel(); break; case OBSOLETE: callback.onFailure(new AppCacheException(AppCacheErrorType.OBSOLETE)); this.cancel(); break; default: case CHECKING: case DOWNLOADING: long runningTime = new Date().getTime() - startTime; if (runningTime > TIMEOUT_MILLISECONDS) { callback.onFailure(new AppCacheException(AppCacheErrorType.TIMEOUT)); this.cancel(); } } } }.scheduleRepeating(500); }
From source file:com.bedatadriven.rebar.appcache.client.Html5AppCache.java
License:Apache License
@Override public void removeCache(final AsyncCallback<Void> callback) { int status = 0; try {// w w w . j a v a 2 s.c o m status = getAppCacheStatus(); if (status == UNCACHED || status == OBSOLETE) { callback.onSuccess(null); } else { Cookies.setCookie(DISABLE_COOKIE_NAME, DISABLE_COOKIE_VALUE); update(); new Timer() { @Override public void run() { switch (getAppCacheStatus()) { case IDLE: case UPDATE_READY: // connection problems preventing the app cache as being marked as obsolete callback.onFailure(new AppCacheException(AppCacheErrorType.CONNECTION)); this.cancel(); Cookies.removeCookie(DISABLE_COOKIE_NAME); break; case UNCACHED: case OBSOLETE: callback.onSuccess(null); this.cancel(); Cookies.removeCookie(DISABLE_COOKIE_NAME); break; } } }.scheduleRepeating(500); } } catch (Exception e) { callback.onFailure(new AppCacheException(e)); } }
From source file:com.beyobe.client.MgwtAppEntryPoint.java
License:Apache License
@Override public void onModuleLoad() { GWT.setUncaughtExceptionHandler(new UncaughtExceptionHandler() { @Override/*from ww w . jav a 2 s .c om*/ public void onUncaughtException(Throwable e) { //TODO put in your own meaninful handler Window.alert("Sorry! Unexpected error: " + e.getMessage()); e.printStackTrace(); } }); new Timer() { @Override public void run() { start(); } }.schedule(1); }
From source file:com.blackducksoftware.tools.commonframework.core.gwt.async.AsyncUtils.java
License:Apache License
/** * Schedule a task for some future time. Useful for polling to check * progress after starting an asynchronous task. * //from w w w .j a v a 2s . c om * @param numSeconds * The task will be run this many seconds from now * @param taskToSchedule * The task to run (when it's time) */ public void scheduleTask(int numSeconds, final ScheduledTask taskToSchedule) { if (timer == null) { timer = new Timer() { public void run() { taskToSchedule.runAfterTimer(); } }; } timer.schedule(numSeconds * 1000); }
From source file:com.bramosystems.oss.player.core.client.impl.QTStateManagerIE.java
License:Apache License
@Override public void initOnLoad(final String playerId, final QTStateManager.OnLoadHandler onLoadHandler) { Timer tt = new Timer() { @Override/*from w ww . j a v a 2 s. c om*/ public void run() { QuickTimePlayerImpl impl = QuickTimePlayerImpl.getPlayer(playerId); try { String v = impl.getPluginVersion(); if (v != null) { cancel(); onLoadHandler.onDebug("Plugin Version : " + v); onLoadHandler.initImpl(impl); } } catch (Exception e) { } } }; tt.scheduleRepeating(200); // IE workarround ... }
From source file:com.bramosystems.oss.player.core.client.skin.CustomPlayerControl.java
License:Apache License
private Widget getPlayerWidget(final UIStyleResource imgPack) { imgPack.ensureInjected();// www . ja v a 2 s .c om seekbar = new CSSSeekBar(5); seekbar.setStylePrimaryName(STYLE_NAME); seekbar.addStyleDependentName("seekbar"); seekbar.setWidth("95%"); seekbar.addSeekChangeHandler(new SeekChangeHandler() { @Override public void onSeekChanged(SeekChangeEvent event) { player.setPlayPosition(event.getSeekPosition() * player.getMediaDuration()); } }); playTimer = new Timer() { @Override public void run() { updateSeekState(); } }; play = new CPCButton(imgPack.playDisabled(), new ClickHandler() { @Override public void onClick(ClickEvent event) { switch (playState) { case Stop: case Pause: try { // play media... play.setEnabled(false); // avoid multiple clicks player.playMedia(); } catch (PlayException ex) { DebugEvent.fire(player, DebugEvent.MessageType.Error, ex.getMessage()); } break; case Playing: player.pauseMedia(); } } }); play.setStyleName(imgPack.play()); play.setEnabled(false); stop = new CPCButton(imgPack.stopDisabled(), new ClickHandler() { @Override public void onClick(ClickEvent event) { player.stopMedia(); } }); stop.setStyleName(imgPack.stop()); stop.setEnabled(false); prev = new CPCButton(imgPack.prevDisabled(), new ClickHandler() { @Override public void onClick(ClickEvent event) { if (player instanceof PlaylistSupport) { try { ((PlaylistSupport) player).playPrevious(); } catch (PlayException ex) { next.setEnabled(false); DebugEvent.fire(player, DebugEvent.MessageType.Info, ex.getMessage()); } } } }); prev.setStyleName(imgPack.prev()); prev.setEnabled(false); next = new CPCButton(imgPack.nextDisabled(), new ClickHandler() { @Override public void onClick(ClickEvent event) { if (player instanceof PlaylistSupport) { try { ((PlaylistSupport) player).playNext(); } catch (PlayException ex) { next.setEnabled(false); DebugEvent.fire(player, DebugEvent.MessageType.Info, ex.getMessage()); } } } }); next.setStyleName(imgPack.next()); next.setEnabled(false); vc = new VolumeControl(5); vc.setStyleName(imgPack.volume()); vc.setPopupStyleName(STYLE_NAME + "-volumeControl"); vc.addVolumeChangeHandler(new VolumeChangeHandler() { @Override public void onVolumeChanged(VolumeChangeEvent event) { player.setVolume(event.getNewVolume()); } }); player.addLoadingProgressHandler(new LoadingProgressHandler() { @Override public void onLoadingProgress(LoadingProgressEvent event) { seekbar.setLoadingProgress(event.getProgress()); vc.setVolume(player.getVolume()); updateSeekState(); } }); player.addPlayStateHandler(new PlayStateHandler() { @Override public void onPlayStateChanged(PlayStateEvent event) { int index = event.getItemIndex(); switch (event.getPlayState()) { case Paused: toPlayState(PlayState.Pause, imgPack); next.setEnabled(index < (((PlaylistSupport) player).getPlaylistSize() - 1)); prev.setEnabled(index > 0); break; case Started: toPlayState(PlayState.Playing, imgPack); next.setEnabled(index < (((PlaylistSupport) player).getPlaylistSize() - 1)); prev.setEnabled(index > 0); break; case Stopped: case Finished: toPlayState(PlayState.Stop, imgPack); next.setEnabled(false); prev.setEnabled(false); break; } } }); player.addPlayerStateHandler(new PlayerStateHandler() { @Override public void onPlayerStateChanged(PlayerStateEvent event) { switch (event.getPlayerState()) { case Ready: play.setEnabled(true); vc.setVolume(player.getVolume()); } } }); // Time label.. timeLabel = new Label("--:-- / --:--"); timeLabel.setWordWrap(false); timeLabel.setHorizontalAlignment(Label.ALIGN_CENTER); // build the UI... DockPanel face = new DockPanel(); face.setStyleName(""); face.setVerticalAlignment(DockPanel.ALIGN_MIDDLE); face.setSpacing(3); face.add(vc, DockPanel.WEST); face.add(play, DockPanel.WEST); face.add(stop, DockPanel.WEST); face.add(prev, DockPanel.WEST); face.add(next, DockPanel.WEST); face.add(timeLabel, DockPanel.EAST); face.add(seekbar, DockPanel.CENTER); face.setCellWidth(seekbar, "100%"); face.setCellHorizontalAlignment(seekbar, DockPanel.ALIGN_CENTER); return face; }
From source file:com.bramosystems.oss.player.provider.sample.client.Capsule.java
License:Apache License
/** * Constructs <code>Capsule</code> player to automatically playback the * media located at {@code mediaURL}, if {@code autoplay} is {@code true} using * the specified {@code plugin}.//from w w w . j a va2 s. co m * * @param plugin plugin to use for playback. * @param mediaURL the URL of the media to playback * @param autoplay {@code true} to start playing automatically, {@code false} otherwise * @param uiResource the CSS resource to use for the UI * * @throws PluginVersionException if the required plugin version is not installed on the client. * @throws PluginNotFoundException if the plugin is not installed on the client. * * @see Plugin * @since 1.2 */ public Capsule(Plugin plugin, String mediaURL, boolean autoplay, CapsuleUIResource uiResource) throws PluginNotFoundException, PluginVersionException, LoadException { // TODO: remove LoadEx on API 2.0.3 release ... super(plugin, mediaURL, autoplay, "64px", "100%"); uiRes = uiResource; uiRes.ensureInjected(); playState = PlayState.Stop; mItems = new ArrayList<MediaInfo.MediaInfoKey>(); progress = new ProgressBar(); progress.setWidth("95%"); playTimer = new Timer() { @Override public void run() { progress.setTime(getPlayPosition(), getMediaDuration()); } }; infoTimer = new Timer() { @Override public void run() { if (mItems.size() > 0) { MediaInfo.MediaInfoKey item = mItems.get(infoIndex); progress.setInfo(item.toString() + ": " + mInfo.getItem(item)); infoIndex++; infoIndex %= mItems.size(); } else { cancel(); } } @Override public void cancel() { super.cancel(); progress.setInfo(""); } }; play = new CButton(uiRes.pauseDisabled(), new ClickHandler() { @Override public void onClick(ClickEvent event) { switch (playState) { case Stop: case Pause: try { // play media... play.setEnabled(false); playMedia(); } catch (PlayException ex) { fireError(ex.getMessage()); } break; case Playing: pauseMedia(); } } }); play.setStyleName(uiRes.play()); play.setEnabled(false); stop = new CButton(uiRes.stopDisabled(), new ClickHandler() { @Override public void onClick(ClickEvent event) { stopMedia(); } }); stop.setStyleName(uiRes.stop()); stop.setEnabled(false); vc = new VolumeControl(5); vc.setStyleName(uiRes.volume()); vc.addVolumeChangeHandler(new VolumeChangeHandler() { @Override public void onVolumeChanged(VolumeChangeEvent event) { setVolume(event.getNewVolume()); } }); vc.setPopupStyleName("player-Capsule-volumeControl"); addLoadingProgressHandler(new LoadingProgressHandler() { @Override public void onLoadingProgress(LoadingProgressEvent event) { double prog = event.getProgress(); progress.setLoadingProgress(prog); if (prog == 1.0) { progress.setTime(0, getMediaDuration()); vc.setVolume(getVolume()); } } }); addPlayStateHandler(new PlayStateHandler() { @Override public void onPlayStateChanged(PlayStateEvent event) { switch (event.getPlayState()) { case Stopped: case Finished: toPlayState(PlayState.Stop); break; case Paused: toPlayState(PlayState.Pause); break; case Started: toPlayState(PlayState.Playing); break; } } }); addPlayerStateHandler(new PlayerStateHandler() { @Override public void onPlayerStateChanged(PlayerStateEvent event) { switch (event.getPlayerState()) { case BufferingFinished: case BufferingStarted: break; case Ready: play.setEnabled(true); vc.setVolume(getVolume()); } } }); // build the UI... DockPanel main = new DockPanel(); main.setStyleName("player-Capsule"); main.setSpacing(0); main.setVerticalAlignment(DockPanel.ALIGN_MIDDLE); main.setSize("100%", "64px"); main.add(new CEdge(uiRes.leftEdge()), DockPanel.WEST); main.add(play, DockPanel.WEST); main.add(stop, DockPanel.WEST); main.add(new CEdge(uiRes.rightEdge()), DockPanel.EAST); main.add(vc, DockPanel.EAST); main.add(progress, DockPanel.CENTER); main.setCellWidth(progress, "100%"); main.setCellHorizontalAlignment(progress, DockPanel.ALIGN_CENTER); setPlayerControlWidget(main); setWidth("100%"); }
From source file:com.bramosystems.oss.player.youtube.client.YouTubeBasePlayer.java
License:Apache License
/** * Constructs <code>YouTubeBasePlayer</code> with the specified {@code height} and * {@code width} to playback video {@code videoID} * * <p> {@code height} and {@code width} are specified as CSS units. * * @param videoID the ID of the video/* w w w. j ava2 s. c o m*/ * @param width the width of the player * @param height the height of the player * * @throws PluginNotFoundException if the required player plugin is not found * @throws PluginVersionException if player plugin version not found * @throws NullPointerException if either {@code videoID}, {@code height} or * {@code width} is null */ protected YouTubeBasePlayer(String videoID, String width, String height, final boolean useIframe) { if (height == null) { throw new NullPointerException("height cannot be null"); } if (width == null) { throw new NullPointerException("width cannot be null"); } if (videoID == null) { throw new NullPointerException("videoURL cannot be null"); } _width = width; _height = height; _vid = videoID; /* ypm = new YouTubePlaylistManager(new YouTubePlaylistManager.CallbackHandler() { @Override public void onError(String message) { fireError(message); } @Override public YouTubePlayerImpl getPlayerImpl() { return impl; } @Override public void onInfo(String info) { fireDebug(info); } }); */ playerId = DOM.createUniqueId().replace("-", ""); // setup loading event management ... bufferingTimer = new Timer() { @Override public void run() { LoadingProgressEvent.fire(YouTubeBasePlayer.this, impl.getVideoLoaded()); } }; addPlayerStateHandler(new PlayerStateHandler() { @Override public void onPlayerStateChanged(PlayerStateEvent event) { switch (event.getPlayerState()) { case BufferingStarted: bufferingTimer.scheduleRepeating(1000); break; case BufferingFinished: bufferingTimer.cancel(); } } }); }
From source file:com.calclab.emite.base.util.Platform.java
License:Open Source License
/** * Schedule an action to run in the future. * //from w w w . jav a 2s.co m * @param msecs delay before running the action (in milliseconds) * @param action the action to run */ public static final void schedule(final int msecs, final ScheduledAction action) { new Timer() { @Override public void run() { action.run(); } }.schedule(msecs); }