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

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

Introduction

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

Prototype

public synchronized void scheduleRepeating(final int periodMs) 

Source Link

Document

Schedules a timer that elapses repeatedly.

Usage

From source file:jetbrains.jetpad.mapper.gwt.DomUtil.java

License:Apache License

public static Property<Boolean> checkbox(final InputElement element) {
    return new Property<Boolean>() {
        private Registration myTimerRegistration;
        private Listeners<EventHandler<? super PropertyChangeEvent<Boolean>>> myListeners = new Listeners<>();

        @Override/*from  ww w . j  a  va 2s .  com*/
        public Boolean get() {
            return element.isChecked();
        }

        @Override
        public void set(Boolean value) {
            element.setChecked(value);
        }

        @Override
        public Registration addHandler(final EventHandler<? super PropertyChangeEvent<Boolean>> handler) {
            if (myListeners.isEmpty()) {
                final Value<Boolean> value = new Value<>(element.isChecked());
                final Timer timer = new Timer() {
                    @Override
                    public void run() {
                        final boolean currentValue = element.isChecked();
                        if (currentValue != value.get()) {
                            myListeners.fire(
                                    new ListenerCaller<EventHandler<? super PropertyChangeEvent<Boolean>>>() {
                                        @Override
                                        public void call(EventHandler<? super PropertyChangeEvent<Boolean>> l) {
                                            l.onEvent(new PropertyChangeEvent<>(value.get(), currentValue));
                                        }
                                    });
                            value.set(currentValue);
                        }
                    }
                };
                timer.scheduleRepeating(100);
                myTimerRegistration = new Registration() {
                    @Override
                    protected void doRemove() {
                        timer.cancel();
                    }
                };
            }
            final Registration reg = myListeners.add(handler);
            return new Registration() {
                @Override
                protected void doRemove() {
                    reg.remove();
                    if (myListeners.isEmpty()) {
                        myTimerRegistration.remove();
                        myTimerRegistration = null;
                    }
                }
            };
        }

        @Override
        public String getPropExpr() {
            return "checkbox(" + element + ")";
        }
    };
}

From source file:jschismes.client.Progress.java

License:Apache License

/**
 * Show the modal dialog containing the progress bar, and configures a timer to automatically update the progress.
 *//* www. j a va  2 s.c om*/
public void show(int seconds) {
    if (seconds < 1)
        return;
    int periodMillis = seconds * 1000 / pTimer.steps;
    Timer t = new pTimer(this);
    t.scheduleRepeating(periodMillis);
}

From source file:mobi.openddr.example.gwtcanvasdemo.client.DmapGwtCanvas.java

License:Open Source License

public void onModuleLoad() {
    UserAgent impl = GWT.create(UserAgent.class);
    Window win = GWT.create(Window.class);

    String compileTimeValue = impl.getCompileTimeValue();
    String runtimeValue = impl.getRuntimeValue();
    System.out.println(compileTimeValue + "->" + runtimeValue);
    height = win.getClientHeight() - 100;
    width = win.getClientWidth() - 80;//from  ww  w  .j a va 2 s .co  m

    canvas = Canvas.createIfSupported();
    backBuffer = Canvas.createIfSupported();
    if (canvas == null) {
        RootPanel.get(HOLDER_ID).add(new Label(UPGRADE_MESSAGE));
        return;
    }

    // init the canvases
    canvas.setWidth(width + "px");
    canvas.setHeight(height + "px");
    canvas.setCoordinateSpaceWidth(width);
    canvas.setCoordinateSpaceHeight(height);
    backBuffer.setCoordinateSpaceWidth(width);
    backBuffer.setCoordinateSpaceHeight(height);
    RootPanel.get(HOLDER_ID).add(canvas);
    context = canvas.getContext2d();
    backBufferContext = backBuffer.getContext2d();

    // init the objects
    logoGroup = new LogoGroup(width, height, 18, 165);
    ballGroup = new BallGroup(width, height);
    lens = new Lens(35, 15, width, height, new Vector(320, 150), new Vector(1, 1));

    // init handlers
    initHandlers();

    // setup timer
    final Timer timer = new Timer() {
        @Override
        public void run() {
            doUpdate();
        }
    };
    timer.scheduleRepeating(REFRESH_RATE);
}

From source file:n3phele.client.presenter.AbstractActivityProgressActivity.java

License:Open Source License

private void initProgressUpdate() {
    // setup timer to refresh list automatically
    Timer refreshTimer = new Timer() {
        public void run() {
            if (progressList != null) {
                for (int i = 0; i < progressList.size(); i++) {
                    Progress progress = progressList.get(i);
                    String status = progress.getStatus();
                    if (!"COMPLETE".equals(status) && !"FAILED".equals(status) && !"CANCELLED".equals(status)) {
                        int update = updateProgress(progress);
                        if (update != progress.getPercentx10Complete()) {
                            //progress.setPercentagex10Complete(update);
                            display.refresh(i, progress);
                        }//  w  w  w.ja  v  a  2s.co m
                    }
                }
            }
        }
    };
    refreshTimer.scheduleRepeating(30000);
}

From source file:n3phele.client.presenter.AbstractCloudProcessActivity.java

License:Open Source License

private void initProcessUpdate() {
    // setup timer to refresh list automatically
    Timer refreshTimer = new Timer() {
        public void run() {
            if (cloudProcessSummaryList != null) {
                for (int i = 0; i < cloudProcessSummaryList.size(); i++) {
                    CloudProcessSummary summary = cloudProcessSummaryList.get(i);
                    String state = summary.getState();
                    if (!"COMPLETE".equals(state) && !"FAILED".equals(state) && !"CANCELLED".equals(state)) {
                        //int update = updateProgress(summary);
                        // if(update != summary.getPercentx10Complete()) {
                        //progress.setPercentagex10Complete(update);
                        display.refresh(i, summary);
                        //}
                    }//from   ww w .j  a v a  2  s  .  c  o  m
                }
            }
        }
    };
    refreshTimer.scheduleRepeating(30000);

}

From source file:net.imgseek.server.admin.client.Iskdaemon_admin.java

License:GNU General Public License

public void onModuleLoad() {

    WEB_ENDPOINT = GWT.getModuleBaseURL();

    // Load all the sinks.
    loadSinks();//w w w .java2 s. co m

    // Status panel
    statusPanel.setVisible(false);
    statusPanel.setStyleName("msg-alert");
    statusPanel.add(statusMessageLabel);
    statusPanel.setSpacing(8);
    statusPanel.setWidth("100%");
    Button closeBtn = new Button("Dismiss", new ClickHandler() {
        public void onClick(ClickEvent event) {
            statusPanel.setVisible(false);
        }
    });

    statusPanel.add(closeBtn);

    // Put the sink list on the left, and add the outer dock panel to the
    // root.
    sinkContainer = new DockPanel();
    sinkContainer.setStyleName("ks-Sink");

    VerticalPanel vp = new VerticalPanel();
    vp.setWidth("100%");
    vp.add(statusPanel);
    vp.add(description);
    vp.add(sinkContainer);

    description.setStyleName("ks-Info");

    // Common Header
    HorizontalPanel hpHeader = new HorizontalPanel();
    hpHeader.setWidth("100%");
    hpHeader.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT);

    HTML iskTitle = new HTML("isk-daemon (" + VERSION + ")");// " at <i>" +
    // WEB_ENDPOINT
    // +
    // "</i>");
    // TODO show remote server name when cluster funcionality is implemented
    iskTitle.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT);

    hpHeader.add(iskTitle);

    // Compose dock panel
    panel.add(hpHeader, DockPanel.NORTH);
    panel.add(list, DockPanel.WEST);
    panel.add(vp, DockPanel.CENTER);

    panel.setCellVerticalAlignment(list, HasAlignment.ALIGN_TOP);
    panel.setCellWidth(vp, "100%");
    RootPanel.get().add(panel);

    // Common Footer
    HorizontalPanel hpFooter = new HorizontalPanel();
    hpFooter.setWidth("100%");
    hpFooter.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT);

    HTML copyRightFooter = new HTML(
            "<div align='right'>Copyright &copy; <a target='_blank' href='http://server.imgseek.net/'>imgSeek</a>. All rights reserved. Licensed under the <a href='http://www.gnu.org/licenses/gpl-2.0-standalone.html'>GPLv2</a></div>");
    copyRightFooter.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT);

    // hpFooter.add(footerShare);
    hpFooter.add(copyRightFooter);
    RootPanel.get().add(hpFooter);

    // Start timer
    Timer t = new Timer() {
        public void run() {
            for (@SuppressWarnings("unchecked")
            Iterator<SinkInfo> iter = list.getSinks().iterator(); iter.hasNext();) {
                SinkInfo element = iter.next();
                element.getInstance().autoRefreshAll();
            }
        }
    };
    // Schedule the timer to run once in 5 seconds.
    t.scheduleRepeating(5000);

    // If the application starts with no history token, redirect to a new
    String initToken = History.getToken();
    if (initToken.length() == 0) {
        History.newItem("Status");
    }
    // Add history listener
    History.addValueChangeHandler(this);
    // Now that we've setup our listener, fire the initial history state.
    History.fireCurrentHistoryState();

    // TODO: check if iskdaemon instance is passwd protect then prompt for
    // login: http://code.google.com/p/gwt-stuff/
}

From source file:net.officefloor.tutorial.gwtapp.client.GwtAppEntryPoint.java

License:Open Source License

@Override
public void onModuleLoad() {

    // Provide the time label
    RootPanel panel = RootPanel.get("timer");
    final Label label = new Label("0");
    panel.add(label);/*from  w ww  .  j  a va2  s.c  om*/

    // Increment time each second
    Timer timer = new Timer() {
        @Override
        public void run() {
            long time = Long.parseLong(label.getText());
            time++;
            label.setText(String.valueOf(time));
        }
    };
    timer.scheduleRepeating(1000);
}

From source file:net.sourceforge.htmlunit.proxy.webapp.client.MainPanel.java

License:Apache License

/**
 * Constructor.// www  .  ja v a  2 s  .  c  o  m
 */
public MainPanel() {
    initWidget(binder_.createAndBindUi(this));

    final Timer timer = new Timer() {

        @Override
        public void run() {
            if (!isError_) {
                logService_.getLog(counter_, new AsyncCallback<LogEntry[]>() {

                    public void onSuccess(final LogEntry[] logs) {
                        if (logs.length != 0) {
                            final LogEntry[] newEntries = new LogEntry[entries_.length + logs.length];
                            System.arraycopy(entries_, 0, newEntries, 0, entries_.length);
                            System.arraycopy(logs, 0, newEntries, entries_.length, logs.length);
                            entries_ = newEntries;
                            counter_ += logs.length;
                            updateTextArea();
                        }
                    }

                    public void onFailure(final Throwable caught) {
                        isError_ = true;
                        Window.alert("Failure connecting to server " + caught);
                        isError_ = false;
                    }
                });
            }
        }
    };
    timer.scheduleRepeating(1000);
}

From source file:no.eirikb.piratewars.client.MapPanel.java

License:BEER-WARE LICENSE

public MapPanel(GamePanel gamePanel2, ImageHandler imageHandler2, Map map2, int width, int height,
        int frameWidth, int frameHeigth) {
    this.gamePanel = gamePanel2;
    this.imageHandler = imageHandler2;
    this.map = map2;
    canvas = new Canvas(this, width, height, frameWidth, frameHeigth);
    add(canvas);//from w ww.j  av  a  2s.  co m

    Timer waterTimer = new Timer() {

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

    waterTimer.scheduleRepeating(WATERDELAY);

    canvas.setListener(new MouseListener() {

        public void onMouseDown(Widget sender, int x, int y) {
            if (gamePanel.myTurn() && animateMove == null) {
                if (x / canvas.getFrameWidth() % 2 != 0) {
                    y -= (canvas.getFrameHeight() / 2);
                }
                Frame f = getFrame(x, y);
                if (moveController == null && f.getShip() != null && f.getShip().isMovable()
                        && gamePanel.isMe(f.getShip().getUser())) {
                    moveController = new MoveController(map.getFrames());
                    moveController.addFrameNodes(f, f.getShip().getSteps());
                    drawWater();
                } else if (moveController != null) {
                    final FrameNode node = moveController.getFrameNode(f);
                    if (node != null && node.getFrame().getShip() == null) {
                        final Ship ship = moveController.getStart().getShip();
                        moveController = null;
                        ship.setFrame(null);

                        final Frame end = node.getFrame();

                        animateMove = new AnimateMove(canvas, imageHandler, node, ship);
                        drawWater();

                        animateMove.setAnimateListener(new AnimateListener() {

                            public void done() {
                                ship.setFrame(end);
                                ship.setMovable(false);
                                gamePanel.move();
                                animateMove.stop();
                                animateMove = null;
                                drawWater();
                            }
                        });
                        animateMove.start();
                    } else {
                        moveController = null;
                        drawWater();
                    }
                }
            }
        }

        public void onMouseEnter(Widget sender) {
        }

        public void onMouseLeave(Widget sender) {
        }

        public void onMouseMove(Widget sender, int x, int y) {
            if (x / canvas.getFrameWidth() % 2 != 0) {
                y -= (canvas.getFrameHeight() / 2);
            }
            Frame f = getFrame(x, y);
            if (lastHover != null && !f.equals(lastHover)) {
                canvas.drawImage(imageHandler.getWater(), lastHover, false);
                if (lastHover.getShip() != null) {
                    hover(lastHover);
                }
                if (moveController != null) {
                    FrameNode node = moveController.getFrameNode(lastHover);
                    if (node != null) {
                        if (lastHover.getShip() == null) {
                            hover(lastHover, 1);
                        }
                    }
                }
                lastHover = null;
            }
            if (f.getType() == FrameType.WATER) {
                hover(f);
                lastHover = f;
            }
        }

        public void onMouseUp(Widget sender, int x, int y) {
        }
    });
}

From source file:org.bioversityinternational.cisf.client.tools.Elements.java

License:Apache License

/**
 * Causes an element to "fade in" via opacity.  Make sure that element to fade is not visible before calling this method.
 * When the callback is invoked with onFadeStart, the element can be set to visible as it is entirely transparent.
 * When onFadeComplete is called, the element will be entirely opaque.
 * @param target the UIObject to be faded in
 * @param milliseconds how long the fade effect should take to process
 * @param callback the callback to be invoked on fade progress
 *//* w  w w  . j  av  a  2s  . com*/
public static void fadeIn(final UIObject target, final int milliseconds, final FadeCallback callback) {
    final Element e = target.getElement();
    final int interval = milliseconds / 50;
    setOpacity(e, 0);
    DeferredCommand.addCommand(new Command() {

        public void execute() {
            callback.onFadeStart();

            final Timer t = new Timer() {
                int pct = 0;

                @Override
                public void run() {
                    pct += 2;
                    setOpacity(e, pct);
                    if (pct == 100) {
                        this.cancel();
                        callback.onFadeComplete();
                    }
                }
            };
            t.scheduleRepeating(interval);

        }
    });
}