Example usage for com.google.gwt.user.client Timer schedule

List of usage examples for com.google.gwt.user.client Timer schedule

Introduction

In this page you can find the example usage for com.google.gwt.user.client Timer schedule.

Prototype

public synchronized void schedule(int delayMs) 

Source Link

Document

Schedules a timer to elapse in the future.

Usage

From source file:nl.mpi.tg.eg.experiment.client.view.TimedStimulusView.java

License:Open Source License

public StimulusButton addTimedImage(final TimedEventMonitor timedEventMonitor, SafeUri imagePath,
        final String styleName, final int postLoadMs, final CancelableStimulusListener onLoadStimulusListener,
        final CancelableStimulusListener postLoadMsListener,
        final CancelableStimulusListener failedStimulusListener,
        final CancelableStimulusListener clickedStimulusListener) {
    cancelableListnerList.add(onLoadStimulusListener);
    cancelableListnerList.add(postLoadMsListener);
    cancelableListnerList.add(failedStimulusListener);
    cancelableListnerList.add(clickedStimulusListener);
    if (timedEventMonitor != null) {
        timedEventMonitor.registerEvent("addTimedImage");
    }/* w  w  w  .j  a va  2s .  co  m*/
    final Image image = new Image(imagePath);
    if (styleName != null) {
        image.addStyleName(styleName);
    }
    image.setVisible(false);
    image.addErrorHandler(new ErrorHandler() {
        @Override
        public void onError(ErrorEvent event) {
            if (timedEventMonitor != null) {
                timedEventMonitor.registerEvent("imageOnError");
            }
            failedStimulusListener.postLoadTimerFired();
        }
    });
    image.addLoadHandler(new LoadHandler() {

        @Override
        public void onLoad(LoadEvent event) {
            if (timedEventMonitor != null) {
                timedEventMonitor.registerEvent("imageOnLoad");
            }
            image.setVisible(true);
            if (onLoadStimulusListener != null) {
                onLoadStimulusListener.postLoadTimerFired();
            }
            Timer timer = new Timer() {
                @Override
                public void run() {
                    postLoadMsListener.postLoadTimerFired();
                }
            };
            timerList.add(timer);
            timer.schedule(postLoadMs);
        }
    });
    final SingleShotEventListner singleShotEventListner;
    if (clickedStimulusListener != null) {
        singleShotEventListner = new SingleShotEventListner() {

            @Override
            protected void singleShotFired() {
                clickedStimulusListener.postLoadTimerFired();
                resetSingleShot();
            }
        };
        image.addClickHandler(singleShotEventListner);
        image.addTouchStartHandler(singleShotEventListner);
        image.addTouchMoveHandler(singleShotEventListner);
        image.addTouchEndHandler(singleShotEventListner);
    } else {
        singleShotEventListner = null;
    }
    getActivePanel().add(image);
    return new StimulusButton() {
        @Override
        public Widget getWidget() {
            return image;
        }

        @Override
        public void addStyleName(String styleName) {
            image.addStyleName(styleName);
        }

        @Override
        public void removeStyleName(String styleName) {
            image.removeStyleName(styleName);
        }

        @Override
        public void setEnabled(boolean enabled) {
            if (singleShotEventListner != null) {
                singleShotEventListner.setEnabled(enabled);
            }
        }

        @Override
        public boolean isEnabled() {
            if (singleShotEventListner != null) {
                return singleShotEventListner.isEnabled();
            } else {
                return false;
            }
        }

        @Override
        public void setVisible(boolean visible) {
            image.setVisible(visible);
        }

        @Override
        public void triggerSingleShotEventListner() {
            clickedStimulusListener.postLoadTimerFired();
        }
    };
}

From source file:nl.mpi.tg.eg.experiment.client.view.TimedStimulusView.java

License:Open Source License

@Deprecated
public void addTimedImage(final TimedEventMonitor timedEventMonitor, SafeUri imagePath, int percentOfPage,
        int maxHeight, int maxWidth, final String animateStyle, final Integer fixedPositionY,
        final int postLoadMs, final CancelableStimulusListener shownStimulusListener,
        final CancelableStimulusListener loadedStimulusListener,
        final CancelableStimulusListener failedStimulusListener,
        final CancelableStimulusListener clickedStimulusListener) {
    cancelableListnerList.add(shownStimulusListener);
    cancelableListnerList.add(loadedStimulusListener);
    cancelableListnerList.add(failedStimulusListener);
    cancelableListnerList.add(clickedStimulusListener);
    if (timedEventMonitor != null) {
        timedEventMonitor.registerEvent("addTimedImage");
    }/*  w ww.  j a va  2 s.  co  m*/
    final Image image = new Image(imagePath);
    if (animateStyle != null && !animateStyle.isEmpty()) {
        image.addStyleName(animateStyle);
        if (fixedPositionY != null) {
            image.getElement().getStyle().setLeft(fixedPositionY, Style.Unit.PCT);
        }
    }
    addSizeAttributes(image.getElement(), percentOfPage, maxHeight, maxWidth);
    image.addErrorHandler(new ErrorHandler() {
        @Override
        public void onError(ErrorEvent event) {
            if (timedEventMonitor != null) {
                timedEventMonitor.registerEvent("onError");
            }
            if (failedStimulusListener != null) {
                failedStimulusListener.postLoadTimerFired();
            }
        }
    });
    image.addLoadHandler(new LoadHandler() {

        @Override
        public void onLoad(LoadEvent event) {
            if (timedEventMonitor != null) {
                timedEventMonitor.registerEvent("onLoad");
            }
            if (shownStimulusListener != null) {
                shownStimulusListener.postLoadTimerFired();
            }
            Timer timer = new Timer() {
                @Override
                public void run() {
                    loadedStimulusListener.postLoadTimerFired();
                }
            };
            timerList.add(timer);
            timer.schedule(postLoadMs);
        }
    });
    if (clickedStimulusListener != null) {
        final SingleShotEventListner singleShotEventListner = new SingleShotEventListner() {

            @Override
            protected void singleShotFired() {
                clickedStimulusListener.postLoadTimerFired();
                resetSingleShot();
            }
        };
        image.addClickHandler(singleShotEventListner);
        image.addTouchStartHandler(singleShotEventListner);
        image.addTouchMoveHandler(singleShotEventListner);
        image.addTouchEndHandler(singleShotEventListner);
    }
    final HTMLPanel htmlPanel = new HTMLPanel("");
    htmlPanel.setStylePrimaryName("gridCell");
    htmlPanel.add(image);
    getActivePanel().add(htmlPanel);
}

From source file:nl.mpi.tg.eg.experiment.client.view.TimedStimulusView.java

License:Open Source License

public void addTimedAudio(final TimedEventMonitor timedEventMonitor, final SafeUri oggPath,
        final SafeUri mp3Path, boolean showPlaybackIndicator,
        final CancelableStimulusListener loadedStimulusListener,
        final CancelableStimulusListener failedStimulusListener,
        final CancelableStimulusListener playbackStartedStimulusListener,
        final CancelableStimulusListener playedStimulusListener, final boolean autoPlay, final String mediaId) {
    cancelableListnerList.add(loadedStimulusListener);
    cancelableListnerList.add(failedStimulusListener);
    cancelableListnerList.add(playbackStartedStimulusListener);
    cancelableListnerList.add(playedStimulusListener);
    try {// www .j  a  va2s . com
        if (timedEventMonitor != null) {
            timedEventMonitor.registerEvent("addTimedAudio");
        }
        final AudioPlayer audioPlayer = new AudioPlayer(new AudioExceptionListner() {
            @Override
            public void audioExceptionFired(AudioException audioException) {
                if (timedEventMonitor != null) {
                    timedEventMonitor.registerEvent("audioExceptionFired");
                }
                failedStimulusListener.postLoadTimerFired();
            }
        }, oggPath, mp3Path, autoPlay);
        audioList.put(mediaId, audioPlayer);
        //        audioPlayer.stopAll(); // Note that this stop all change will be a change in default behaviour, however there shouldn't be any instances where this is depended on, but that should be checked
        final Label playbackIndicator = new Label();
        final Timer playbackIndicatorTimer = new Timer() {
            public void run() {
                playbackIndicator.setText("CurrentTime: " + audioPlayer.getCurrentTime());
                //                    playbackIndicator.setWidth();
                this.schedule(100);
            }
        };
        timerList.add(playbackIndicatorTimer);
        if (showPlaybackIndicator) {
            playbackIndicator.setStylePrimaryName("playbackIndicator");
            getActivePanel().add(playbackIndicator);
            playbackIndicatorTimer.schedule(500);
        }
        audioPlayer.setEventListner(new AudioEventListner() {
            @Override
            public void audioLoaded() {
                if (timedEventMonitor != null) {
                    timedEventMonitor.registerEvent("audioLoaded");
                }
                loadedStimulusListener.postLoadTimerFired();
            }

            @Override
            public void audioStarted() {
                if (timedEventMonitor != null) {
                    timedEventMonitor.registerEvent("audioStarted");
                }
                playbackStartedStimulusListener.postLoadTimerFired();
            }

            @Override
            public void audioFailed() {
                if (timedEventMonitor != null) {
                    timedEventMonitor.registerEvent("audioFailed");
                }
                failedStimulusListener.postLoadTimerFired();
            }

            @Override
            public void audioEnded() {
                if (timedEventMonitor != null) {
                    timedEventMonitor.registerEvent("audioEnded");
                    timedEventMonitor.registerMediaLength(mediaId,
                            (long) (audioPlayer.getCurrentTime() * 1000));
                }
                //                    playbackIndicatorTimer.cancel();
                //                    playbackIndicator.removeFromParent();
                //                    audioPlayer.setEventListner(null); // prevent multiple triggering
                playedStimulusListener.postLoadTimerFired();
            }
        });
    } catch (AudioException audioException) {
        failedStimulusListener.postLoadTimerFired();
    }
}

From source file:nl.strohalm.cyclos.mobile.client.configuration.ConfigurationPage.java

License:Open Source License

/**
 * Process the given url and language and configures the application with it
 */// w  w w.java2 s .co m
private void process(String url, String language) {
    // Block the page until url is processed
    final LoadingPopup popup = new LoadingPopup();
    popup.display();

    configurationService.configureApplication(url, language, new BaseAsyncCallback<ConfigurationStatus>() {
        @Override
        public void onSuccess(final ConfigurationStatus result) {
            Timer timer = new Timer() {
                @Override
                public void run() {
                    popup.hide();
                    switch (result) {
                    case RELOAD_APP:
                        final boolean supportsReload = ScreenHelper.supportsReload();
                        Notification.get()
                                .alert(supportsReload ? messages.theLanguageHasChanged()
                                        : messages.theLanguageHasChangedNoReload(), messages.notice(),
                                        messages.ok(), new AlertCallback() {
                                            @Override
                                            public void onOkButtonClicked() {
                                                // Reload application if supported
                                                if (supportsReload) {
                                                    CyclosMobile.get().reloadApplication();
                                                } else {
                                                    // Otherwise hide popup and continue
                                                    Navigation.get().goNoHistory(PageAnchor.LOAD_GENERAL_DATA);
                                                }
                                            }
                                        });
                        break;
                    case INVALID_URL:
                        Notification.get().error(messages.invalidUrlConfiguration());
                        break;
                    case CONFIGURED:
                        Navigation.get().goNoHistory(PageAnchor.LOAD_GENERAL_DATA);
                        break;
                    }
                }
            };
            timer.schedule(1500);
        }

        @Override
        public void onFailure(Throwable caught) {
            popup.hide();
            super.onFailure(caught);
        }
    });
}

From source file:nl.strohalm.cyclos.mobile.client.CyclosMobile.java

License:Open Source License

/**
 * Initializes the mobile application//w ww  .  j av  a 2  s  .c om
 */
private void initApplication() {

    GWT.setUncaughtExceptionHandler(new GWT.UncaughtExceptionHandler() {
        @Override
        public void onUncaughtException(Throwable e) {
            ErrorHandler.handle(e);
        }
    });

    phoneGap = GWT.create(PhoneGap.class);
    phoneGap.addHandler(new PhoneGapAvailableHandler() {
        @Override
        public void onPhoneGapAvailable(PhoneGapAvailableEvent event) {

            String splash = Storage.get().getItem("splash");

            // If there is no splash screen available to display, start the application
            if (StringHelper.isEmpty(splash)) {
                startApplication();
            } else {
                // Wait for the splash screen
                Timer t = new Timer() {
                    @Override
                    public void run() {
                        startApplication();
                    }
                };
                t.schedule(2000);
            }
        }
    });

    phoneGap.addHandler(new PhoneGapTimeoutHandler() {
        @Override
        public void onPhoneGapTimeout(PhoneGapTimeoutEvent event) {
            throw new IllegalStateException(Messages.Accessor.get().loadingApplicationError());
        }
    });
    phoneGap.initializePhoneGap(30 * 1000); // 30 seconds
}

From source file:nl.strohalm.cyclos.mobile.client.ui.widgets.DataList.java

License:Open Source License

/**
 * Hides the loading panel if available//from   w w w.j a va2 s  . c  o m
 */
private void hideLoading() {
    if (loadingEnabled) {
        // If exists data hide the panel using delay
        // to let the user see the message
        if (values != null && values.size() > 0) {
            Timer t = new Timer() {
                @Override
                public void run() {
                    // Hide loading panel
                    loadingPanel.setVisible(false);
                }
            };
            t.schedule(2000);
        } else {
            // Otherwise hide the panel
            loadingPanel.setVisible(false);
        }
    }
}

From source file:nl.strohalm.cyclos.mobile.client.ui.widgets.Spinner.java

License:Open Source License

/**
 * Stops image rotation with a bit of delay 
 * to avoid an ugly effect/*from   w  ww. ja v a  2s  . c om*/
 */
public void stopSpinner() {
    Timer t = new Timer() {
        @Override
        public void run() {
            stopSpinner(image.getElement());
        }
    };
    t.schedule(750);
}

From source file:nu.validator.htmlparser.gwt.HtmlParser.java

License:Open Source License

private void pump(boolean useSetTimeouts) throws SAXException {

    if (ending) {
        tokenizer.end();/*  w  w  w  .jav  a2 s  .  c o m*/
        domTreeBuilder.getDocument(); // drops the internal reference
        parseEndListener.parseComplete();
        // Don't schedule timeout
        return;
    }

    int docWriteLen = documentWriteBuffer.length();
    if (docWriteLen > 0) {
        char[] newBuf = new char[docWriteLen];
        documentWriteBuffer.getChars(0, docWriteLen, newBuf, 0);
        push(new UTF16Buffer(newBuf, 0, docWriteLen));
        documentWriteBuffer.setLength(0);
    }

    for (;;) {
        UTF16Buffer buffer = peek();
        if (!buffer.hasMore()) {
            if (buffer == stream) {
                if (buffer.getEnd() == streamLength) {
                    // Stop parsing
                    tokenizer.eof();
                    ending = true;
                    break;
                } else {
                    int newEnd = buffer.getStart() + CHUNK_SIZE;
                    buffer.setEnd(newEnd < streamLength ? newEnd : streamLength);
                    continue;
                }
            } else {
                pop();
                continue;
            }
        }
        // now we have a non-empty buffer
        buffer.adjust(lastWasCR);
        lastWasCR = false;
        if (buffer.hasMore()) {
            lastWasCR = tokenizer.tokenizeBuffer(buffer);
            domTreeBuilder.maybeRunScript();
            break;
        } else {
            continue;
        }
    }

    if (useSetTimeouts) {
        // schedule
        Timer timer = new Timer() {

            @Override
            public void run() {
                try {
                    pump(true);
                } catch (SAXException e) {
                    ending = true;
                    if (errorHandler != null) {
                        try {
                            errorHandler
                                    .fatalError(new SAXParseException(e.getMessage(), null, null, -1, -1, e));
                        } catch (SAXException e1) {
                        }
                    }
                }
            }

        };
        timer.schedule(1);
    } else {
        try {
            pump(false);
        } catch (SAXException e) {
            ending = true;
            if (errorHandler != null) {
                try {
                    errorHandler.fatalError(new SAXParseException(e.getMessage(), null, null, -1, -1, e));
                } catch (SAXException e1) {
                }
            }
        }
    }
}

From source file:org.activityinfo.ui.client.local.sync.SynchronizerDispatcher.java

License:Open Source License

private final <T extends CommandResult> void handleConnectionFailure(final Command<T> command, Throwable caught,
        final AsyncCallback<T> callback, final int attempt) {
    if (attempt > MAX_RETRY_COUNT) {
        callback.onFailure(new SyncException(SyncErrorType.CONNECTION_PROBLEM, caught));
    } else {//from  ww w  .j  a v  a  2 s  .  c o  m
        int delay = retryDelay(attempt);
        Timer timer = new Timer() {

            @Override
            public void run() {
                tryExecute(command, callback, attempt + 1);
            }
        };
        timer.schedule(delay);
    }
}

From source file:org.atmosphere.samples.client.Info.java

License:Apache License

public static void display(String title, String message) {

    final Info info = new Info(title, message);

    info.show();/*from  w  w  w.j av  a  2  s  . c o m*/

    Timer t = new Timer() {
        @Override
        public void run() {
            info.hide();
        }
    };
    t.schedule(4000);
}