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

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

Introduction

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

Prototype

Timer

Source Link

Usage

From source file:com.googlecode.gwtgl.example.client.examples.lighting.wrapper.LightingWrapperExample.java

License:Apache License

/**
 * Updates the Matrix widgets every 500ms
 *///  w  ww.j a  v  a 2  s.  com
private void showMatrices() {
    Timer timer = new Timer() {
        @Override
        public void run() {
            perspectiveMatrixWidget.setData(perspectiveMatrix);
            translationMatrixWidget.setData(translationMatrix);
            rotationMatrixWidget.setData(rotationMatrix);
            resultingMatrixWidget.setData(resultingMatrix);
        }
    };
    timer.scheduleRepeating(500);
}

From source file:com.googlecode.gwtphonegap.client.PhoneGapStandardImpl.java

License:Apache License

@Override
public void initializePhoneGap(final int timeoutInMs) {

    final long end = System.currentTimeMillis() + timeoutInMs;
    if (isPhoneGapInitialized()) {

        firePhoneGapAvailable();//from w  ww  . j  ava  2s. c  o  m

    } else {
        Timer timer = new Timer() {

            @Override
            public void run() {
                if (isPhoneGapInitialized()) {
                    firePhoneGapAvailable();
                    return;
                }

                if (System.currentTimeMillis() - end > 0) {
                    handlerManager.fireEvent(new PhoneGapTimeoutEvent());
                } else {
                    schedule(INIT_TICK);
                }

            }
        };

        timer.schedule(INIT_TICK);
    }
}

From source file:com.googlecode.gwtquake.client.GwtQuake.java

License:Open Source License

public void onModuleLoad() {
    // Initialize drivers.
    Document doc = Document.get();
    doc.setTitle("GWT Quake II");
    BodyElement body = doc.getBody();/* w ww.  java2 s .c  om*/
    Style style = body.getStyle();
    style.setPadding(0, Unit.PX);
    style.setMargin(0, Unit.PX);
    style.setBorderWidth(0, Unit.PX);
    style.setProperty("height", "100%");
    style.setBackgroundColor("#000");
    style.setColor("#888");

    //   Window.alert("UA: " + userAgent+ " type: " + browserType);

    boolean wireframe = ("" + Window.Location.getHash()).indexOf("wireframe") != -1;

    canvas = (CanvasElement) doc.createElement("canvas");
    video = doc.createElement("video");

    w = Window.getClientWidth();
    h = Window.getClientHeight();
    canvas.setWidth(w);
    canvas.setHeight(h);
    style = canvas.getStyle();
    style.setProperty("height", "100%");
    style.setProperty("width", "100%");

    style = video.getStyle();
    style.setProperty("height", "100%");
    style.setProperty("width", "100%");
    style.setProperty("display", "none");

    body.appendChild(canvas);
    body.appendChild(video);

    try {
        Globals.autojoin.value = Window.Location.getHash().indexOf("autojoin") != -1 ? 1.0f : 0.0f;
        final Renderer renderer = wireframe ? new GwtWireframeGLRenderer(canvas)
                : new GwtWebGLRenderer(canvas, video);
        Globals.re = renderer;

        ResourceLoader.impl = new GwtResourceLoaderImpl();
        Compatibility.impl = new CompatibilityImpl();

        Sound.impl = new GwtSound();
        NET.socketFactory = new WebSocketFactoryImpl();
        //      Sys.impl = new Sys.SysImpl() {
        //        public void exit(int status) {
        //          Window.alert("Something's rotten in Denmark");
        //          Window.Location.assign("gameover.html");
        //        }
        //      };

        // Flags.
        QuakeCommon.Init(new String[] { "GQuake" });

        // Enable stdout.
        Globals.nostdout = ConsoleVariables.Get("nostdout", "0", 0);

        Window.addResizeHandler(new ResizeHandler() {

            public void onResize(ResizeEvent event) {
                if (Window.getClientWidth() == w && Window.getClientHeight() == h) {
                    return;
                }

                w = Window.getClientWidth();
                h = Window.getClientHeight();

                renderer.GLimp_SetMode(new Dimension(w, h), 0, false);
            }
        });

        //      QuakeServer.main(new String[0], new DummySNetImpl(), false);

        timer = new Timer() {
            double startTime = Duration.currentTimeMillis();

            @Override
            public void run() {
                try {
                    double curTime = Duration.currentTimeMillis();
                    boolean pumping = ResourceLoader.Pump();
                    if (pumping) {
                        Screen.UpdateScreen2();
                    } else {
                        int dt = (int) (curTime - startTime);
                        GwtKBD.Frame(dt);
                        QuakeCommon.Frame(dt);
                    }
                    startTime = curTime;
                    timer.schedule(ResourceLoader.Pump() ? LOADING_DELAY : INTER_FRAME_DELAY);
                } catch (Exception e) {
                    Compatibility.printStackTrace(e);
                }
            }
        };
        timer.schedule(INTER_FRAME_DELAY);
    } catch (Exception e) {
        Compatibility.printStackTrace(e);
        DivElement div = doc.createDivElement();
        div.setInnerHTML(NO_WEBGL_MESSAGE);
        body.appendChild(div);
    }
}

From source file:com.googlecode.gwtquake.client.GwtResourceLoaderImpl.java

License:Open Source License

private void processReadyList() {
    new Timer() {
        @Override//from   www  .  jav a2s  .c  om
        public void run() {
            for (int i = readyList.size() - 1; i >= 0; i--) {
                ResponseHandler handler = readyList.get(i);
                if (handler.sequenceNumber == currentSequenceNumber) {
                    if (handler.response != null) {
                        double t0 = Duration.currentTimeMillis();
                        handler.callback.onSuccess(sbb.stringToByteBuffer(handler.response));
                        Com.Printf("Processed #" + currentSequenceNumber + " in "
                                + (Duration.currentTimeMillis() - t0) / 1000.0 + "s\r");
                    }
                    readyList.remove(i);
                    currentSequenceNumber++;
                    processReadyList();
                    return;
                }
            }
        }
    }.schedule(RECEIVED_WAIT_TIME);
}

From source file:com.googlecode.konamigwt.hadoken.client.Hadoken.java

License:BEER-WARE LICENSE

/**
 * This is the entry point method.//w w w.ja  v  a 2  s . c om
 */
public void onModuleLoad() {

    final Button sendButton = new Button("Send");
    final TextBox nameField = new TextBox();
    nameField.setText("GWT User");
    final Label errorLabel = new Label();

    // We can add style names to widgets
    sendButton.addStyleName("sendButton");

    // Add the nameField and sendButton to the RootPanel
    // Use RootPanel.get() to get the entire body element
    RootPanel.get("nameFieldContainer").add(nameField);
    RootPanel.get("sendButtonContainer").add(sendButton);
    RootPanel.get("errorLabelContainer").add(errorLabel);

    // Focus the cursor on the name field when the app loads
    nameField.setFocus(true);
    nameField.selectAll();

    // Create the popup dialog box
    final DialogBox dialogBox = new DialogBox();
    dialogBox.setText("Remote Procedure Call");
    dialogBox.setAnimationEnabled(true);
    final Button closeButton = new Button("Close");
    // We can set the id of a widget by accessing its Element
    closeButton.getElement().setId("closeButton");
    final Label textToServerLabel = new Label();
    final HTML serverResponseLabel = new HTML();
    VerticalPanel dialogVPanel = new VerticalPanel();
    dialogVPanel.addStyleName("dialogVPanel");
    dialogVPanel.add(new HTML("<b>Sending name to the server:</b>"));
    dialogVPanel.add(textToServerLabel);
    dialogVPanel.add(new HTML("<br><b>Server replies:</b>"));
    dialogVPanel.add(serverResponseLabel);
    dialogVPanel.setHorizontalAlignment(VerticalPanel.ALIGN_RIGHT);
    dialogVPanel.add(closeButton);
    dialogBox.setWidget(dialogVPanel);

    // Add a handler to close the DialogBox
    closeButton.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent event) {

            dialogBox.hide();
            sendButton.setEnabled(true);
            sendButton.setFocus(true);
        }
    });

    // Quick and Dirty implementation
    new Konami(new KonamiHandler() {
        @Override
        public void onKonamiCodePerformed() {
            final Image image = new Image("media/ryu.gif");
            DOM.appendChild(RootPanel.get().getElement(), image.getElement());

            final Audio audio = Audio.createIfSupported();
            if (audio != null) {
                audio.setSrc("media/hadoken.ogg");
                DOM.appendChild(RootPanel.get().getElement(), audio.getElement());
                audio.play();
            }
            Timer timer = new Timer() {

                @Override
                public void run() {
                    DOM.removeChild(RootPanel.get().getElement(), image.getElement());
                    if (audio != null) {
                        DOM.removeChild(RootPanel.get().getElement(), audio.getElement());
                    }
                }

            };
            timer.schedule(1100);

        }
    }).start();

    // Create a handler for the sendButton and nameField
    class MyHandler implements ClickHandler, KeyUpHandler {
        /**
         * Fired when the user clicks on the sendButton.
         */
        public void onClick(ClickEvent event) {
            sendNameToServer();
        }

        /**
         * Fired when the user types in the nameField.
         */
        public void onKeyUp(KeyUpEvent event) {
            if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER) {
                sendNameToServer();
            }
        }

        /**
         * Send the name from the nameField to the server and wait for a response.
         */
        private void sendNameToServer() {
            // First, we validate the input.
            errorLabel.setText("");
            String textToServer = nameField.getText();
            if (!FieldVerifier.isValidName(textToServer)) {
                errorLabel.setText("Please enter at least four characters");
                return;
            }

            // Then, we send the input to the server.
            sendButton.setEnabled(false);
            textToServerLabel.setText(textToServer);
            serverResponseLabel.setText("");
            serverResponseLabel.removeStyleName("serverResponseLabelError");
            serverResponseLabel.setHTML("Hello " + textToServer);
            dialogBox.center();
            closeButton.setFocus(true);
        }
    }

    // Add a handler to send the name to the server
    MyHandler handler = new MyHandler();
    sendButton.addClickHandler(handler);
    nameField.addKeyUpHandler(handler);
}

From source file:com.googlecode.mgwt.mvp.client.display.AnimatableDisplayTransistionImpl.java

License:Apache License

/** {@inheritDoc} */
@Override// www .ja  v  a2 s . c  o m
public void animate(Animation animation, boolean currentIsFirst, AnimationEndCallback callback) {

    lastCallback = callback;
    blurBeforeAnimation();

    showFirst = currentIsFirst;

    if (animation == null) {
        if (showFirst) {
            first.getElement().getStyle().setDisplay(Display.BLOCK);

        } else {
            second.getElement().getStyle().setDisplay(Display.BLOCK);
        }
        onAnimationEnd();
        return;
    }

    String type = animation.getCssName();

    if (animationEnd != null) {
        animationEnd.removeHandler();
        animationEnd = null;
    }

    animationEnd = main.addDomHandler(listener, TransitionEndEvent.getType());

    first.addStyleName(css.start());
    second.addStyleName(css.start());

    first.addStyleName(type);
    second.addStyleName(type);

    lastDir = animation.isInverse();
    // backwards
    if (animation.isInverse()) {
        first.addStyleName(this.css.reverse());
        second.addStyleName(this.css.reverse());

    }
    if (currentIsFirst) {
        first.addStyleName(this.css.in());
        second.addStyleName(this.css.out());

    } else {
        first.addStyleName(this.css.out());
        second.addStyleName(this.css.in());

    }

    first.getElement().getStyle().setDisplay(Display.BLOCK);
    second.getElement().getStyle().setDisplay(Display.BLOCK);

    new Timer() {

        @Override
        public void run() {
            first.removeStyleName(css.start());
            second.removeStyleName(css.start());
            first.addStyleName(css.end());
            second.addStyleName(css.end());

        }
    }.schedule(10);

}

From source file:com.googlecode.mgwt.ui.client.MGWT.java

License:Apache License

/**
 *
 * Considered internal don`t call!/*www . ja v  a2s. c o  m*/
 * <p>
 * fixIOSScrollIssueBlur
 * </p>
 */
public static void fixIOSScrollIssueBlur() {
    if (!scrollingDisabled) {
        return;
    }
    if (timer != null) {
        timer.cancel();

    }

    timer = new Timer() {

        @Override
        public void run() {
            Window.scrollTo(0, 0);

        }

    };

    timer.schedule(100);
}

From source file:com.googlecode.mgwt.ui.client.util.impl.AddressBarUtilIphoneImpl.java

License:Apache License

private static void doScroll() {
    new Timer() {

        @Override// www.  j  av a  2s.  c  o  m
        public void run() {
            Window.scrollTo(0, 1);

        }
    }.schedule(1);
}

From source file:com.googlecode.mgwt.ui.client.widget.base.PullArrowStandardHandler.java

License:Apache License

@Override
public void onPullAction(PullWidget pullWidget) {
    if (pullActionHandler == null)
        return;/*from   w w  w  .ja v a 2  s  .c om*/

    if (callRunning)
        return;
    callRunning = true;
    pullWidget.setHTML(loadingText != null ? loadingText : "");

    pullArrow.showLoadingIndicator();

    pullActionHandler.onPullAction(new AsyncCallback<Void>() {

        @Override
        public void onFailure(Throwable caught) {
            pullArrow.showError();
            pullArrow.setHTML(errorText != null ? errorText : "");

            new Timer() {

                @Override
                public void run() {
                    callRunning = false;
                    pullPanel.refresh();

                    pullArrow.setHTML(normalText != null ? normalText : "");
                    pullArrow.showArrow();

                }
            }.schedule(errorTime);

        }

        @Override
        public void onSuccess(Void result) {
            callRunning = false;
            pullArrow.setHTML(normalText != null ? normalText : "");
            pullArrow.showArrow();

        }
    });

}

From source file:com.googlecode.mgwt.ui.client.widget.carousel.Carousel.java

License:Apache License

/**
 * refresh the carousel widget, this is necessary after changing child elements
 *//*w w  w  .jav  a  2s .  c o  m*/
public void refresh() {
    hasScollData = false;
    final int delay = MGWT.getOsDetection().isAndroid() ? 200 : 1;
    IMPL.adjust(main, container);
    // allow layout to happen..
    new Timer() {

        @Override
        public void run() {
            IMPL.adjust(main, container);

            scrollPanel.setScrollingEnabledX(true);
            scrollPanel.setScrollingEnabledY(false);

            scrollPanel.setShowVerticalScrollBar(false);
            scrollPanel.setShowHorizontalScrollBar(false);

            if (carouselIndicatorContainer != null) {
                carouselIndicatorContainer.removeFromParent();

            }

            int widgetCount = container.getWidgetCount();

            carouselIndicatorContainer = new CarouselIndicatorContainer(appearance.cssCarousel(), widgetCount);

            if (isVisibleCarouselIndicator) {
                main.add(carouselIndicatorContainer);
            }

            if (currentPage >= widgetCount) {
                currentPage = widgetCount - 1;
            }

            carouselIndicatorContainer.setSelectedIndex(currentPage);

            refreshHandler = scrollPanel.addScrollRefreshHandler(new ScrollRefreshEvent.Handler() {

                @Override
                public void onScrollRefresh(ScrollRefreshEvent event) {
                    refreshHandler.removeHandler();
                    refreshHandler = null;
                    LightArrayInt pagesX = scrollPanel.getPagesX();
                    if (currentPage < 0) {
                        currentPage = 0;
                    } else if (currentPage >= pagesX.length()) {
                        currentPage = pagesX.length() - 1;
                    }
                    scrollPanel.scrollToPage(currentPage, 0, 0);
                    hasScollData = true;
                }
            });
            scrollPanel.refresh();
        }

    }.schedule(delay);

}