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.google.gerrit.client.diff.UnifiedCommentGroup.java

License:Apache License

@Override
void handleRedraw() {
    getLineWidget().onRedraw(() -> {/*from   w  w w .ja  v a 2  s.  co m*/
        if (canComputeHeight()) {
            if (getResizeTimer() != null) {
                getResizeTimer().cancel();
                setResizeTimer(null);
            }
            reportHeightChange();
        } else if (getResizeTimer() == null) {
            setResizeTimer(new Timer() {
                @Override
                public void run() {
                    if (canComputeHeight()) {
                        cancel();
                        setResizeTimer(null);
                        reportHeightChange();
                    }
                }
            });
            getResizeTimer().scheduleRepeating(5);
        }
    });
}

From source file:com.google.gerrit.client.patches.CommentEditorPanel.java

License:Apache License

public CommentEditorPanel(final PatchLineComment plc, final CommentLinkProcessor commentLinkProcessor) {
    super(commentLinkProcessor);
    comment = plc;//from  w ww  .  j ava 2s  . c  o m

    addStyleName(Gerrit.RESOURCES.css().commentEditorPanel());
    setAuthorNameText(Gerrit.getUserAccountInfo(), PatchUtil.C.draft());
    setMessageText(plc.getMessage());
    addDoubleClickHandler(this);

    expandTimer = new Timer() {
        @Override
        public void run() {
            expandText();
        }
    };
    text = new NpTextArea();
    text.setText(comment.getMessage());
    text.setCharacterWidth(INITIAL_COLS);
    text.setVisibleLines(INITIAL_LINES);
    text.setSpellCheck(true);
    text.addKeyDownHandler(new KeyDownHandler() {
        @Override
        public void onKeyDown(final KeyDownEvent event) {
            if ((event.isControlKeyDown() || event.isMetaKeyDown()) && !event.isAltKeyDown()
                    && !event.isShiftKeyDown()) {
                switch (event.getNativeKeyCode()) {
                case 's':
                case 'S':
                    event.preventDefault();
                    onSave(NULL_CALLBACK);
                    return;
                }
            }

            expandTimer.schedule(250);
        }
    });
    addContent(text);

    edit = new Button();
    edit.setText(PatchUtil.C.buttonEdit());
    edit.addClickHandler(this);
    addButton(edit);

    save = new Button();
    save.setText(PatchUtil.C.buttonSave());
    save.addClickHandler(this);
    addButton(save);

    cancel = new Button();
    cancel.setText(PatchUtil.C.buttonCancel());
    cancel.addClickHandler(this);
    addButton(cancel);

    discard = new Button();
    discard.setText(PatchUtil.C.buttonDiscard());
    discard.addClickHandler(this);
    addButton(discard);

    setOpen(true);
    if (isNew()) {
        edit();
    } else {
        render();
    }
}

From source file:com.google.gerrit.client.ui.RemoteSuggestOracle.java

License:Apache License

@Override
public void requestSuggestions(Request req, Callback cb) {
    if (!serveSuggestions) {
        return;/*ww w.  j a v  a  2  s. c o  m*/
    }

    // Use a timer for key stroke retention, such that we don't query the
    // backend for each and every keystroke we receive.
    if (requestRetentionTimer != null) {
        requestRetentionTimer.cancel();
    }
    requestRetentionTimer = new Timer() {
        @Override
        public void run() {
            Query q = new Query(req, cb);
            if (query == null) {
                query = q;
                q.start();
            } else {
                query = q;
            }
        }
    };
    requestRetentionTimer.schedule(200);
}

From source file:com.google.gwt.demos.gwtcanvas.client.LogoDemo.java

License:Apache License

public void drawDemo() {
    // The following is the same as doing
    // canvas.resize(width,height);
    canvas.setCoordSize(width, height);/* w w  w  .  ja v a2 s.  c  om*/
    canvas.setPixelHeight(height);
    canvas.setPixelWidth(width);

    String[] imageUrls = new String[] { "logo-185x175.png" };

    timer = new Timer() {

        @Override
        public void run() {
            renderingLoop();
        }

    };

    if (img == null) {
        // The first time this demo gets run we need to load our images.
        // Maintain a reference to the image we load so we can use it
        // the next time the demo is selected
        ImageLoader.loadImages(imageUrls, new ImageLoader.CallBack() {
            public void onImagesLoaded(ImageElement[] imageHandles) {
                // Drawing code involving images goes here
                img = imageHandles[0];
                timer.schedule(10);
            }
        });

    } else {
        // Go ahead and animate
        if (isImageLoaded(img)) {
            timer.schedule(10);
        } else {
            Window.alert("Refresh the page to reload the image.");
        }
    }
}

From source file:com.google.gwt.demos.gwtcanvas.client.ParticleDemo.java

License:Apache License

public void drawDemo() {
    canvas.resize(width, height);/*from   w w  w  .  ja  v  a 2  s  .co  m*/

    particles = new Particle[numParticles];

    for (int i = 0; i < particles.length; i++) {
        particles[i] = new Particle();
    }
    canvas.saveContext();
    canvas.setLineWidth(2);
    canvas.setStrokeStyle(new Color(255, 0, 0));

    t = new Timer() {
        public void run() {
            renderingLoop();
        }
    };
    t.schedule(10);
}

From source file:com.google.gwt.example.stockwatcher.client.StockWatcher.java

/**
 * Entry point method.//w  w  w .  j a  va2 s.co  m
 */
public void onModuleLoad() {

    // Create table for stock data.
    stocksFlexTable.setText(0, 0, "Symbol");
    stocksFlexTable.setText(0, 1, "Price");
    stocksFlexTable.setText(0, 2, "Change");
    stocksFlexTable.setText(0, 3, "Remove");

    // Add styles to elements in the stock list table
    stocksFlexTable.getRowFormatter().addStyleName(0, "watchListHeader");
    stocksFlexTable.addStyleName("watchList");
    stocksFlexTable.getCellFormatter().addStyleName(0, 1, "watchListNumericColumn");
    stocksFlexTable.getCellFormatter().addStyleName(0, 2, "watchListNumericColumn");
    stocksFlexTable.getCellFormatter().addStyleName(0, 3, "watchListRemoveColumn");

    // Assemble Add Stock panel.
    addPanel.add(newSymbolTextBox);
    addPanel.add(addStockButton);
    addPanel.addStyleName("addPanel");

    // Assemble Main panel.
    mainPanel.add(stocksFlexTable);
    mainPanel.add(addPanel);
    mainPanel.add(lastUpdatedLabel);

    // Associate the Main panel with the HTML host page.

    RootPanel.get("stockList").add(mainPanel);

    // Move cursor focus to the input box.
    newSymbolTextBox.setFocus(true);

    // Setup timer to refresh list automatically
    Timer refreshTimer = new Timer() {
        @Override
        public void run() {
            refreshWatchList();
        }
    };

    refreshTimer.scheduleRepeating(REFRESH_INTERVAL);

    // Listen for mouse events on the Add button.
    addStockButton.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent clickEvent) {
            addStock();
        }
    });

    // Listen for keyboard events in the input box
    newSymbolTextBox.addKeyDownHandler(new KeyDownHandler() {
        @Override
        public void onKeyDown(KeyDownEvent keyDownEvent) {
            if (keyDownEvent.getNativeKeyCode() == KeyCodes.KEY_ENTER) {
                addStock();
            }
        }
    });
}

From source file:com.google.gwt.examples.TimerExample.java

License:Apache License

public void onClick(ClickEvent event) {
    // Create a new timer that calls Window.alert().
    Timer t = new Timer() {
        @Override//from  w  w w  . j a v a  2  s  .  co m
        public void run() {
            Window.alert("Nifty, eh?");
        }
    };

    // Schedule the timer to run once in 5 seconds.
    t.schedule(5000);
}

From source file:com.google.gwt.gears.sample.gwtnote.client.AppController.java

License:Apache License

/**
 * Kicks off the main processing loop. That loop is a timer that fires every
 * 10 milliseconds, forever. It calls {@link #update()} which implements the
 * sync logic, and may or may not actually do anything for a give timer tick.
 * (For instance, it may be stalled waiting on an asynchronous RPC call to
 * return.)// w  w  w  .j  av  a  2 s. com
 */
public void startMainLoop() {
    init();

    Timer t = new Timer() {
        @Override
        public void run() {
            if (!ready) {
                return;
            }
            update();
        }
    };
    t.scheduleRepeating(10);
}

From source file:com.google.gwt.gears.sample.gwtnote.client.local.GearsHelper.java

License:Apache License

/**
 * Creates a new GearsHelper.//from  www . j  a v  a  2  s  .  c  o m
 */
public GearsHelper() {
    try {
        db = Factory.getInstance().createDatabase();
        try {
            db.execute(DB_FETCH_NAMES);
        } catch (GearsException ex) {
            db.execute(DB_CREATE);
        }

        // initialize the localstore and have it update the manifest
        localServer = Factory.getInstance().createLocalServer();
        store = localServer.createManagedStore("GWTGearsNote");
        store.setManifestUrl(GWT.getModuleBaseURL() + "manifest");
        store.checkForUpdate();
        Timer t = new Timer() {
            @Override
            public void run() {
                int status = store.getUpdateStatus();
                if (status == ManagedResourceStore.UPDATE_OK) {
                    this.cancel();
                } else if (status == ManagedResourceStore.UPDATE_FAILED) {
                    this.cancel();
                }
            }
        };
        t.scheduleRepeating(100);
    } catch (Throwable t) { // not just GearsException b/c we can also have NPEs
        localServer = null;
        store = null;
        db = null;
    }
}

From source file:com.google.gwt.gears.sample.managedresourcestore.client.ManagedResourceStoreDemo.java

License:Apache License

private void createManagedResourceStore() {
    try {//from  ww w . jav  a 2 s  . c o  m
        final ManagedResourceStore managedResourceStore = Offline.getManagedResourceStore();

        new Timer() {
            final String oldVersion = managedResourceStore.getCurrentVersion();

            @Override
            public void run() {
                switch (managedResourceStore.getUpdateStatus()) {
                case ManagedResourceStore.UPDATE_OK:
                    if (managedResourceStore.getCurrentVersion().equals(oldVersion)) {
                        statusLabel.setText("No update was available.");
                    } else {
                        statusLabel.setText("Update to " + managedResourceStore.getCurrentVersion()
                                + " was completed.  Please refresh the page to see the changes.");
                        createManagedResourceStoreButton.setEnabled(false);
                    }
                    break;
                case ManagedResourceStore.UPDATE_CHECKING:
                case ManagedResourceStore.UPDATE_DOWNLOADING:
                    statusLabel.setText("Transferring data");
                    schedule(500);
                    break;
                case ManagedResourceStore.UPDATE_FAILED:
                    statusLabel.setText(managedResourceStore.getLastErrorMessage());
                    break;
                }
            }
        }.schedule(500);

    } catch (GearsException e) {
        statusLabel.setText("");
        Window.alert(e.getMessage());
    }
}