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:bingo.client.Bingo.java

License:Open Source License

private void initUserGrid(final BingoGrid bingoGrid) {
    bingoGrid.addClickHandler(new ClickHandler() {
        @Override/*w w  w.j  a v a  2s. co m*/
        public void onClick(ClickEvent event) {
            Cell cell = bingoGrid.getCellForEvent(event);
            if (cell != null) {
                final int row = cell.getRowIndex();
                final int col = cell.getCellIndex();
                if (!bingoGrid.cellHasBeenVoted(row, col)) {
                    bingoGrid.voteForCell(row, col);

                    bingoService.voteCell(userId, row, col, new AsyncCallback<Long>() {
                        @Override
                        public void onFailure(Throwable caught) {
                            message.setText(strings.errorUserVote());
                            bingoGrid.voteAgainstCell(row, col);
                        }

                        @Override
                        public void onSuccess(Long result) {
                            // For now, no control of lines completed
                            //                        bingoGrid.colorLines(result);
                        }
                    });
                } else {
                    message.setText(strings.alreadyVoted());
                }
            }
        }
    });

    Timer timer = new Timer() {
        @Override
        public void run() {
            updateUserGrid(bingoGrid, this);
        }
    };

    timer.scheduleRepeating(USER_TIMER);

    RootPanel.get("buttons").clear();
}

From source file:br.com.pegasus.solutions.smartgwt.lib.client.upload.FileUploader.java

License:Apache License

/**
 * init timer progressbar//ww  w . ja va  2 s.c  o  m
 * 
 * @param delayMilles
 *            int
 * @return void
 */
public void initTimerProgressBar(int delayMilles) {
    if (this.progressBarTimer == null) {
        this.progressBarTimer = new Timer() {
            public void run() {
                getProgressbar().setPercentDone((int) (Math.random() * 95.0D));
            }
        };
    }
    this.progressBarTimer.scheduleRepeating(delayMilles);
}

From source file:burrito.client.crud.widgets.FormattedRichTextArea.java

License:Apache License

@Override
protected void onAttach() {
    super.onAttach();

    Timer cssTimer = new Timer() {
        @Override/*from  w  w w .java  2s. c o m*/
        public void run() {
            Document doc = IFrameElement.as(getElement()).getContentDocument();
            StyleElement style = doc.createStyleElement();
            style.setInnerText(CSS);
            HeadElement.as(Element.as(doc.getBody().getPreviousSibling())).appendChild(style);
        }
    };

    cssTimer.schedule(100);
}

From source file:ca.nanometrics.gflot.client.example.DecimationExample.java

License:Open Source License

public Widget createExample() {
    PlotWithOverviewModel model = new PlotWithOverviewModel(PlotModelStrategy.downSamplingStrategy(20));
    PlotOptions plotOptions = new PlotOptions();
    plotOptions.setDefaultLineSeriesOptions(new LineSeriesOptions().setLineWidth(1).setShow(true));
    plotOptions.setDefaultPointsOptions(new PointsSeriesOptions().setRadius(2).setShow(true));
    plotOptions.setDefaultShadowSize(0);

    final SeriesHandler series = model.addSeries("Random Series", "#003366");

    // create the plot
    final PlotWithOverview plot = new PlotWithOverview(model, plotOptions);

    // pull the "fake" RPC service for new data
    final Timer updater = new Timer() {
        @Override//from   w w  w .jav a 2s . com
        public void run() {
            update(series, plot);
        }
    };

    // put it on a panel
    FlowPanel panel = new FlowPanel();
    panel.add(plot);
    HorizontalPanel buttonsPanel = new HorizontalPanel();
    buttonsPanel.setSpacing(5);
    buttonsPanel.add(new Button("Start", new ClickListener() {
        public void onClick(Widget sender) {
            updater.scheduleRepeating(1000);
        }
    }));
    buttonsPanel.add(new Button("Stop", new ClickListener() {
        public void onClick(Widget sender) {
            updater.cancel();
        }
    }));
    panel.add(buttonsPanel);
    return panel;
}

From source file:ca.nanometrics.gflot.client.example.SlidingWindowExample.java

License:Open Source License

public Widget createExample() {
    PlotWithOverviewModel model = new PlotWithOverviewModel(PlotModelStrategy.slidingWindowStrategy(20));
    PlotOptions plotOptions = new PlotOptions();
    plotOptions.setDefaultLineSeriesOptions(new LineSeriesOptions().setLineWidth(1).setShow(true));
    plotOptions.setDefaultPointsOptions(new PointsSeriesOptions().setRadius(2).setShow(true));
    plotOptions.setDefaultShadowSize(0);
    plotOptions.setXAxisOptions(new TimeSeriesAxisOptions());

    PlotOptions overviewPlotOptions = new PlotOptions().setDefaultShadowSize(0)
            .setLegendOptions(new LegendOptions().setShow(false))
            .setDefaultLineSeriesOptions(new LineSeriesOptions().setLineWidth(1).setFill(true))
            .setSelectionOptions(// ww w  . ja v  a2s  .c  om
                    new SelectionOptions().setMode(SelectionOptions.X_SELECTION_MODE).setDragging(true))
            .setXAxisOptions(new TimeSeriesAxisOptions());

    final SeriesHandler series = model.addSeries("Random Series", "#FF9900");

    // create the plot
    final PlotWithOverview plot = new PlotWithOverview(model, plotOptions, overviewPlotOptions);

    // pull the "fake" RPC service for new data
    final Timer updater = new Timer() {
        @Override
        public void run() {
            update(series, plot);
        }
    };

    // put it on a panel
    FlowPanel panel = new FlowPanel();
    panel.add(plot);
    HorizontalPanel buttonsPanel = new HorizontalPanel();
    buttonsPanel.setSpacing(5);
    buttonsPanel.add(new Button("Start", new ClickListener() {
        public void onClick(Widget sender) {
            updater.scheduleRepeating(1000);
        }
    }));
    buttonsPanel.add(new Button("Stop", new ClickListener() {
        public void onClick(Widget sender) {
            updater.cancel();
        }
    }));
    panel.add(buttonsPanel);
    return panel;
}

From source file:ca.wimsc.client.common.widgets.google.TouchHandler.java

License:Apache License

/**
 * Touch move handler./*from w w  w  .ja  va 2 s  .co  m*/
 *
 * @param e The touchmove event.
 */
@SuppressWarnings("unused")
private void onMove(final TouchEvent e) {
    if (!tracking || dragDelegate == null) {
        return;
    }

    // Prevent native scrolling.
    e.preventDefault();

    com.google.gwt.dom.client.Touch touch = getTouchFromEvent(e);
    Point touchCoordinate = new Point(touch.getPageX(), touch.getPageY());

    double moveX = lastTouchPosition.x - touchCoordinate.x;
    double moveY = lastTouchPosition.y - touchCoordinate.y;
    totalMoveX += Math.abs(moveX);
    totalMoveY += Math.abs(moveY);
    lastTouchPosition.x = touchCoordinate.x;
    lastTouchPosition.y = touchCoordinate.y;

    // Handle case where they are getting close to leaving the window.
    // End events are unreliable when the touch is leaving the viewport area.
    // If they are close to the bottom or the right, and we don't get any other
    // touch events for another 100ms, assume they have left the screen. This
    // does not seem to be a problem for scrolling off the top or left of the
    // viewport area.
    if (scrollOffTimer != null) {
        scrollOffTimer.cancel();
    }
    if ((Window.getClientHeight() - touchCoordinate.y) < TOUCH_END_WORKAROUND_THRESHOLD
            || (Window.getClientWidth() - touchCoordinate.x) < TOUCH_END_WORKAROUND_THRESHOLD) {

        scrollOffTimer = new Timer() {
            @Override
            public void run() {
                e.setTimeStamp(Duration.currentTimeMillis());
                onEnd(e);
            }
        };
        scrollOffTimer.schedule(100);
    }

    boolean firstDrag = false;
    if (!dragging) {
        if (totalMoveY > MIN_TRACKING_FOR_DRAG || totalMoveX > MIN_TRACKING_FOR_DRAG) {
            dragging = true;
            firstDrag = true;
            dragDelegate.onDragStart(e);
        }
    }

    if (dragging) {
        dragDelegate.onDragMove(e);

        lastEvent = e;

        // This happens when they are dragging slowly. If they are dragging slowly
        // then we should reset the start time and position to where they are now.
        // This will be important during the drag end when we report to the
        // draggable delegate what kind of drag just happened.
        if (e.getTimeStamp() - recentTime > MAX_TRACKING_TIME) {
            recentTime = e.getTimeStamp();
            recentTouchPosition = touchCoordinate;
        }
    }
}

From source file:cc.alcina.framework.gwt.client.ide.widget.ActionProgress.java

License:Apache License

public ActionProgress(final String id, AsyncCallback<JobTracker> completionCallback) {
    this.id = id;
    this.completionCallback = completionCallback;
    this.fp = new FlowPanel();
    fp.setStyleName("alcina-ActionProgress");
    grid = new Grid(4, 2);
    jobName = new InlineLabel();
    FlowPanel jobNCancel = new FlowPanel();
    jobNCancel.add(jobName);//from   w ww. ja  v  a 2s  .  c  o  m
    jobName.setStyleName("pad-right-5");
    this.cancelLink = new Link("(Cancel)", new ClickHandler() {
        public void onClick(ClickEvent event) {
            Widget sender = (Widget) event.getSource();
            cancelJob();
        }
    });
    jobNCancel.add(cancelLink);
    cancellingStatusMessage = new InlineLabel();
    cancellingStatusMessage.setVisible(false);
    jobNCancel.add(cancellingStatusMessage);
    addToGrid("Job", jobNCancel);
    times = new HTML();
    addToGrid("Time", times);
    message = new Label();
    message.setStyleName("message");
    addToGrid("Status", message);
    progress = new FlowPanel();
    progress.setStyleName("progress");
    bar = new FlowPanel();
    bar.setStyleName("bar");
    bar.add(progress);
    addToGrid("Progress", bar);
    grid.setCellSpacing(2);
    fp.add(grid);
    initWidget(fp);
    updateProgress();
    timer = new Timer() {
        boolean checking = false;

        @Override
        public void run() {
            AsyncCallback<JobTracker> callback = new AsyncCallback<JobTracker>() {
                public void onFailure(Throwable caught) {
                    checking = false;
                    if (maxConnectionFailure-- <= 0) {
                        stopTimer();
                        if (ActionProgress.this.completionCallback != null) {
                            ActionProgress.this.completionCallback.onFailure(caught);
                        }
                        throw new WrappedRuntimeException(caught);
                    }
                }

                public void onSuccess(JobTracker info) {
                    checking = false;
                    if (info == null) {
                        info = new JobTrackerImpl();
                        info.setJobName("Unknown job");
                        info.setComplete(true);
                        info.setProgressMessage("---");
                    }
                    if (info.isComplete()) {
                        stopTimer();
                        if (ActionProgress.this.completionCallback != null) {
                            ActionProgress.this.completionCallback.onSuccess(info);
                        }
                    }
                    setJobInfo(info);
                    fireNullPropertyChange("Updated");
                }
            };
            if (!checking) {
                ClientBase.getCommonRemoteServiceAsyncInstance().pollJobStatus(id, false, callback);
                checking = true;
            }
        }
    };
}

From source file:cc.alcina.framework.gwt.client.util.ClientUtils.java

License:Apache License

public static void runWithDelay(Runnable runnable, int delayMillis) {
    new Timer() {
        @Override//from   w  ww .  j  a  v  a 2  s.c  o  m
        public void run() {
            runnable.run();
        }
    }.schedule(delayMillis);
}

From source file:cc.alcina.framework.gwt.client.widget.dialog.OkCancelDialogBox.java

License:Apache License

@Override
protected void onAttach() {
    super.onAttach();
    checkReCenterTimer = new Timer() {
        private int lastCenterHeight;

        @Override//from   w  w w.  j  a v  a2 s .c  o m
        public void run() {
            if (lastCenterHeight != 0 && lastCenterHeight != getOffsetHeight()) {
                center();
            }
            lastCenterHeight = getOffsetHeight();
        }
    };
    checkReCenterTimer.scheduleRepeating(200);
    nativePreviewHandlerRegistration = Event.addNativePreviewHandler(e -> {
        int evtCode = e.getTypeInt();
        if (evtCode == Event.ONKEYDOWN && e.getNativeEvent().getKeyCode() == KeyCodes.KEY_ESCAPE) {
            cancel();
        }
        if (evtCode == Event.ONKEYDOWN && e.getNativeEvent().getKeyCode() == KeyCodes.KEY_ENTER
                && e.getNativeEvent().getCtrlKey()) {
            e.cancel();
            okButton.setFocus(true);
            onOkButtonClicked();
        }
    });
}

From source file:cc.alcina.framework.gwt.client.widget.FilterWidget.java

License:Apache License

protected void queueCommit() {
    String filterText = getTextBox().getText();
    if (CommonUtils.isNullOrEmpty(lastQueuedText) && CommonUtils.isNullOrEmpty(filterText)) {
        return;//from w  w  w .  j a  v  a  2  s . c o m
    }
    lastQueueAddMillis = System.currentTimeMillis();
    lastQueuedText = filterText;
    if (queueingFinishedTimer == null) {
        queueingFinishedTimer = new Timer() {
            long timerAddedMillis = lastQueueAddMillis;

            @Override
            public void run() {
                if (lastQueueAddMillis - timerAddedMillis == 0) {
                    commit();
                }
                timerAddedMillis = lastQueueAddMillis;
            }
        };
        queueingFinishedTimer.scheduleRepeating(filterDelayMs);
    }
}