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.extjs.gxt.ui.client.widget.tips.ToolTip.java

License:sencha.com license

protected void delayHide() {
    if (isAttached() && hideTimer == null && toolTipConfig.isAutoHide() && !toolTipConfig.isCloseable()) {
        if (toolTipConfig.getHideDelay() == 0) {
            hide();//from  w w w .  jav  a 2 s.com
            return;
        }
        hideTimer = new Timer() {
            public void run() {
                hide();
            }
        };
        hideTimer.schedule(toolTipConfig.getHideDelay());
    }
}

From source file:com.extjs.gxt.ui.client.widget.tips.ToolTip.java

License:sencha.com license

protected void delayShow() {
    if (!isAttached() && showTimer == null) {
        if ((new Date().getTime() - lastActive.getTime()) < quickShowInterval) {
            show();/* w w w .ja  v a 2  s  .c o m*/
        } else {
            if (toolTipConfig.getShowDelay() > 0) {
                showTimer = new Timer() {
                    public void run() {
                        show();
                    }
                };
                showTimer.schedule(toolTipConfig.getShowDelay());
            } else {
                show();
            }
        }
    } else if (isAttached()) {
        show();
    }
}

From source file:com.ezee.web.common.ui.main.EzeeWebMain.java

private void applyDateTimer() {
    Timer dateTimer = new Timer() {
        @Override/*w  w w  .  jav  a  2s  .  c  o m*/
        public void run() {
            setDate();
        }
    };
    dateTimer.scheduleRepeating(60 * 1000);
}

From source file:com.garmin.gwt.communicator.testing.client.Showcase.java

License:Apache License

@Override
public void onModuleLoad() {

    // small delay to allow the page to parse the plugin
    final Timer delay = new Timer() {
        @Override/*from w w w. ja  v a 2  s.  com*/
        public void run() {
            conditionallyLoadScreen();
        }
    };
    delay.schedule(300);
}

From source file:com.garmin.gwt.communicator.testing.client.Showcase.java

License:Apache License

private void testReadFromDeviceXml() {
    // unlock plugin
    if (!plugin.unlock(keys)) {
        displayToConsole("failed to unlock plugin!");
    }/*from  w w  w.  j a  va 2s.  co m*/

    // get list of devices
    plugin.startFindDevices();

    final Timer poller = new Timer() {
        @Override
        public void run() {
            if (plugin.finishFindDevices()) {
                this.cancel();
                String deviceXml = plugin.getDevicesXml();
                displayToConsole(deviceXml);
            }
        }
    };
    poller.scheduleRepeating(200);
}

From source file:com.geocento.webapps.eobroker.common.client.widgets.material.MaterialSearch.java

License:Apache License

public MaterialSearch() {

    super(new TextBox());

    setType(InputType.SEARCH);// ww  w.  j  ava  2s.  c  o m

    iconSearch.setLayoutPosition(Style.Position.ABSOLUTE);
    iconSearch.setLeft(10);
    insert(iconSearch, 0);

    iconLoading.setLayoutPosition(Style.Position.ABSOLUTE);
    iconLoading.setLeft(10);
    insert(iconLoading, 0);

    label.getElement().setAttribute("for", "search");
    add(label);

    add(iconClose);
    iconClose.addMouseDownHandler(mouseDownEvent -> CloseEvent.fire(MaterialSearch.this, getText()));

    // populate the lists of search result on search panel
    searchResult = new MaterialSearchResult();
    add(searchResult);
    addKeyUpHandler(new KeyUpHandler() {

        private Timer fetchTimer;
        private String currentText = "";

        @Override
        public void onKeyUp(KeyUpEvent event) {
            // Apply selected search
            switch (event.getNativeEvent().getKeyCode()) {
            case KeyCodes.KEY_ENTER: {
                if (getCurSel() == -1) {
                    hideListSearches();
                    presenter.textSelected(getText());
                } else {
                    MaterialLink selLink = getSelectedLink();
                    reset(selLink.getText());
                    selLink.fireEvent(new GwtEvent<ClickHandler>() {
                        @Override
                        public com.google.gwt.event.shared.GwtEvent.Type<ClickHandler> getAssociatedType() {
                            return ClickEvent.getType();
                        }

                        @Override
                        protected void dispatch(ClickHandler handler) {
                            handler.onClick(null);
                        }
                    });
                }
                event.stopPropagation();
            }
                break;
            case KeyCodes.KEY_DOWN: {
                int totalItems = searchResult.getWidgetCount();
                if (curSel >= totalItems) {
                    setCurSel(getCurSel());
                    applyHighlightedItem((MaterialLink) searchResult.getWidget(curSel - 1));
                } else {
                    setCurSel(getCurSel() + 1);
                    applyHighlightedItem((MaterialLink) searchResult.getWidget(curSel));
                }
                event.stopPropagation();
            }
                break;
            case KeyCodes.KEY_UP: {
                if (curSel <= -1) {
                    setCurSel(-1);
                    applyHighlightedItem((MaterialLink) searchResult.getWidget(curSel));
                } else {
                    setCurSel(getCurSel() - 1);
                    applyHighlightedItem((MaterialLink) searchResult.getWidget(curSel));
                }
                event.stopPropagation();
            }
                break;
            default:
                if (fetchTimer != null) {
                    fetchTimer.cancel();
                    fetchTimer = null;
                }
                // create a timer to make sure we don't query too soon
                fetchTimer = new Timer() {

                    @Override
                    public void run() {
                        // make sure we don't refresh options if the text hasn't changed
                        String text = getText();
                        if (text.contentEquals(currentText)) {
                            return;
                        }
                        currentText = text;
                        presenter.textChanged(currentText);
                        fetchTimer = null;
                    }
                };
                // start the timer to make sure we waited long enough
                fetchTimer.schedule(300);
                break;
            }
        }
    });
    addCloseHandler(new CloseHandler<String>() {
        @Override
        public void onClose(CloseEvent<String> event) {
            reset("");
            presenter.textSelected("");
            setFocus(true);
        }
    });
    addBlurHandler(new BlurHandler() {
        @Override
        public void onBlur(BlurEvent event) {
            new Timer() {

                @Override
                public void run() {
                    hideListSearches();
                }
            }.schedule(300);
        }
    });
    hideListSearches();
    setLoading(false);
}

From source file:com.ghusse.dolomite.core.SignedJsonpRequest.java

License:Apache License

/**
 * Finally sends the request./* w w  w . java 2 s. com*/
 * @param baseUri     Uri where to send the request
 * @param arguments   Arguments of the request
 */
void send(final String baseUri, final Map<String, String> arguments) {
    registerCallbacks(CALLBACKS);

    String prefix = CALLBACKS_NAME + "." + callbackId;
    arguments.put(this.callbackParam, prefix + ".onSuccess");

    if (failureCallbackParam != null) {
        arguments.put(this.failureCallbackParam, prefix + ".onFailure");
    }

    UrlBuilder.sign(arguments, this.signatureParam, this.secret);

    final String uri = UrlBuilder.getUri(baseUri, arguments);

    ScriptElement script = Document.get().createScriptElement();
    script.setType("text/javascript");
    script.setId(callbackId);
    script.setSrc(uri.toString());
    timer = new Timer() {
        @Override
        public void run() {
            onFailure(new TimeoutException("Timeout while calling " + baseUri));
        }
    };
    timer.schedule(timeout);
    getHeadElement().appendChild(script);
}

From source file:com.ghusse.dolomite.flickr.auth.Authentification.java

License:Open Source License

/**
 * Opens an authentification popup./*  w w  w.  ja v a 2  s  .  c om*/
 * @param frob    Previously returned frob from the API
 */
private void requestPermission(final String frob) {
    HashMap<String, String> arguments = new HashMap<String, String>();
    arguments.put("api_key", this.credentials.getKey());
    arguments.put("perms", this.perms.toString());
    arguments.put("frob", frob);

    UrlBuilder.sign(arguments, "api_sig", this.credentials.getSecret());

    Window.open(UrlBuilder.getUri(AUTH_URL, arguments), "_blank", "resizable=yes,scrollbars=yes,status=yes");

    timer = new Timer() {
        @Override
        public void run() {
            callback.onFailure(new TimeoutException("Timeout : waiting for a valid authentification token"));
            callback = null;
        }
    };

    this.getToken(frob);
}

From source file:com.github.gwtcannonjs.demo.client.impl.BodyTypesDemo.java

License:Open Source License

@Override
public void run() {
    /**/*  ww w. j  a  va  2s .co  m*/
     * Demos of the Body.type types.
     */
    final Demo demo = CANNON.newDemo();
    final int size = 2;

    demo.addScene("Moving box", new AddSceneCallback() {
        @Override
        public void execute() {
            World world = setupWorld(demo);

            Box boxShape = CANNON.newBox(CANNON.newVec3(size, size, size));
            Sphere sphereShape = CANNON.newSphere(size);

            double mass = 5, boxMass = 0;

            // Kinematic Box
            // Does only collide with dynamic bodies, but does not respond to any force.
            // Its movement can be controlled by setting its velocity.
            final Body b1 = CANNON.newBody(CANNON.newBodyOptions().withMass(boxMass).withType(Body.KINEMATIC)
                    .withPosition(CANNON.newVec3(0, 0, 0.5 * size)));
            b1.addShape(boxShape);
            world.addBody(b1);
            demo.addVisual(b1);

            // To control the box movement we must set its velocity
            b1.getVelocity().set(0, 0, 5);
            new Timer() {
                @Override
                public void run() {
                    if (b1.getVelocity().getZ() < 0)
                        b1.getVelocity().set(0, 0, 5);
                    else
                        b1.getVelocity().set(0, 0, -5);
                }
            }.scheduleRepeating(1000);

            // Dynamic Sphere
            // Dynamic bodies can collide with bodies of all other types.
            Body b2 = CANNON.newBody(CANNON.newBodyOptions().withMass(mass));
            b2.addShape(sphereShape);
            b2.getPosition().set(0, 0, 3 * size);
            world.addBody(b2);
            demo.addVisual(b2);
        }
    });

    demo.start();
}

From source file:com.github.gwtcannonjs.demo.client.impl.PileDemo.java

License:Open Source License

@Override
public void run() {
    final Demo demo = CANNON.newDemo();
    final double size = 1;

    // Spheres//from w  w  w .  ja v a2  s  .  c  o m
    demo.addScene("Pile", new AddSceneCallback() {
        @Override
        public void execute() {
            if (interval != null)
                interval.cancel();

            final World world = demo.getWorld();

            world.getGravity().set(0, 0, -50);
            world.setBroadphase(CANNON.newNaiveBroadphase());
            ((GSSolver) world.getSolver().cast()).setIterations(5);

            world.getDefaultContactMaterial().setContactEquationStiffness(5e6);
            world.getDefaultContactMaterial().setContactEquationRelaxation(10);

            // Since we have many bodies and they don't move very much, we can use the less accurate quaternion normalization
            world.setQuatNormalizeFast(true);
            world.setQuatNormalizeSkip(4); // ...and we do not have to normalize every step.

            // ground plane
            Shape groundShape = CANNON.newPlane();
            Body groundBody = CANNON.newBody(CANNON.newBodyOptions().withMass(0));
            groundBody.addShape(groundShape);
            groundBody.getPosition().set(0, 0, 0);
            world.addBody(groundBody);
            demo.addVisual(groundBody);

            // plane -x
            Shape planeShapeXmin = CANNON.newPlane();
            Body planeXmin = CANNON.newBody(CANNON.newBodyOptions().withMass(0));
            planeXmin.addShape(planeShapeXmin);
            planeXmin.getQuaternion().setFromAxisAngle(CANNON.newVec3(0, 1, 0), Math.PI / 2);
            planeXmin.getPosition().set(-5, 0, 0);
            world.addBody(planeXmin);

            // Plane +x
            Shape planeShapeXmax = CANNON.newPlane();
            Body planeXmax = CANNON.newBody(CANNON.newBodyOptions().withMass(0));
            planeXmax.addShape(planeShapeXmax);
            planeXmax.getQuaternion().setFromAxisAngle(CANNON.newVec3(0, 1, 0), -Math.PI / 2);
            planeXmax.getPosition().set(5, 0, 0);
            world.addBody(planeXmax);

            // Plane -y
            Shape planeShapeYmin = CANNON.newPlane();
            Body planeYmin = CANNON.newBody(CANNON.newBodyOptions().withMass(0));
            planeYmin.addShape(planeShapeYmin);
            planeYmin.getQuaternion().setFromAxisAngle(CANNON.newVec3(1, 0, 0), -Math.PI / 2);
            planeYmin.getPosition().set(0, -5, 0);
            world.addBody(planeYmin);

            // Plane +y
            Shape planeShapeYmax = CANNON.newPlane();
            Body planeYmax = CANNON.newBody(CANNON.newBodyOptions().withMass(0));
            planeYmax.addShape(planeShapeYmax);
            planeYmax.getQuaternion().setFromAxisAngle(CANNON.newVec3(1, 0, 0), Math.PI / 2);
            planeYmax.getPosition().set(0, 5, 0);
            world.addBody(planeYmax);

            final JsArray<Body> bodies = JsArray.createArray().cast();
            i = 0;
            interval = new Timer() {
                @Override
                public void run() {
                    // Sphere
                    i++;
                    Shape sphereShape = CANNON.newSphere(size);
                    Body b1 = CANNON.newBody(CANNON.newBodyOptions().withMass(5));
                    b1.addShape(sphereShape);
                    b1.getPosition().set(2 * size * Math.sin(i), 2 * size * Math.cos(i), 7 * 2 * size);
                    world.addBody(b1);
                    demo.addVisual(b1);
                    bodies.push(b1);

                    if (bodies.length() > 80) {
                        Body b = bodies.shift();
                        demo.removeVisual(b);
                        world.remove(b);
                    }
                }
            };
            interval.scheduleRepeating(100);
        }
    });

    demo.start();
}