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

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

Introduction

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

Prototype

public synchronized void cancel() 

Source Link

Document

Cancels this timer.

Usage

From source file:bingo.client.Bingo.java

License:Open Source License

private void initAdminGrid(final String userId, final BingoGrid bingoGrid, final boolean hasFinished) {
    final Timer timer = new Timer() {
        int totalParticipants = 0;

        @Override//from   w  ww.j  a  v  a 2 s.c o  m
        public void run() {
            bingoService.getTotalParticipants(userId, new AsyncCallback<Integer>() {
                @Override
                public void onFailure(Throwable caught) {
                }

                @Override
                public void onSuccess(Integer result) {
                    totalParticipants = result.intValue();
                }
            });

            bingoService.getVotes(userId, new AsyncCallback<int[][]>() {
                @Override
                public void onFailure(Throwable caught) {
                    message.setText(caught.getMessage());
                }

                @Override
                public void onSuccess(int[][] result) {
                    if (result == null) {
                        result = new int[BingoGrid.ROW][BingoGrid.COL];
                        for (int i = 0; i < BingoGrid.ROW; i++)
                            for (int j = 0; j < BingoGrid.COL; j++)
                                result[i][j] = 0;
                    }

                    for (int row = 0; row < BingoGrid.ROW; ++row)
                        for (int col = 0; col < BingoGrid.COL; ++col) {
                            bingoGrid.setVoteString(row, col, String.valueOf(result[row][col]),
                                    String.valueOf(totalParticipants));
                        }
                }
            });
        }
    };

    // If the game is not finished, repeat; if so, run once
    if (!hasFinished)
        timer.scheduleRepeating(ADMIN_TIMER);
    else
        timer.run();

    HorizontalPanel panel = new HorizontalPanel();
    panel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
    final Button finishButton = new Button();

    // If the game is not finished, allow finishing it; if so, allow download data
    if (!hasFinished)
        finishButton.setText(strings.finishBingo());
    else
        finishButton.setText(strings.download());

    finishButton.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            if (!hasFinished)
                bingoService.finishBingo(userId, new AsyncCallback<Void>() {
                    @Override
                    public void onFailure(Throwable caught) {
                        message.setText(caught.getMessage());
                    }

                    @Override
                    public void onSuccess(Void result) {
                        message.setText(strings.finishedBingo());
                        finishButton.setText(strings.download());
                        timer.cancel();
                    }
                });

            bingoService.getVotes(userId, new AsyncCallback<int[][]>() {
                @Override
                public void onFailure(Throwable caught) {
                    message.setText(caught.getMessage());
                }

                @Override
                public void onSuccess(int[][] result) {
                    // Create a popup dialog box
                    final DialogBox box = new DialogBox();
                    box.setText(strings.info());
                    box.setAnimationEnabled(true);

                    final Button boxAcceptButton = new Button(strings.accept());
                    boxAcceptButton.addClickHandler(new ClickHandler() {
                        @Override
                        public void onClick(ClickEvent event) {
                            box.hide();
                        }
                    });

                    Label boxLabel = new Label();
                    boxLabel.setText(strings.finishMessage());
                    HTML voteData = new HTML();
                    if (result == null) {
                        result = new int[BingoGrid.ROW][BingoGrid.COL];
                        for (int i = 0; i < BingoGrid.ROW; i++)
                            for (int j = 0; j < BingoGrid.COL; j++)
                                result[i][j] = 0;
                    }

                    String cellKey = "";
                    String cellString = "";
                    String voteDataString = "";
                    for (int row = 0; row < BingoGrid.ROW; ++row)
                        for (int col = 0; col < BingoGrid.COL; ++col) {
                            cellKey = "cell" + row + col;
                            cellString = strings.map().get(cellKey);
                            voteDataString += "&nbsp;&nbsp;&nbsp;" + cellString + " = " + result[row][col]
                                    + "<br>";
                        }
                    voteData.setHTML(voteDataString);
                    voteData.addStyleName("boxData");

                    VerticalPanel boxPanel = new VerticalPanel();
                    boxPanel.addStyleName("boxPanel");
                    boxPanel.add(boxLabel);
                    boxPanel.add(voteData);

                    HorizontalPanel buttonsPanel = new HorizontalPanel();
                    buttonsPanel.add(boxAcceptButton);
                    boxPanel.add(buttonsPanel);
                    boxPanel.setCellHorizontalAlignment(buttonsPanel, HasHorizontalAlignment.ALIGN_CENTER);

                    box.setWidget(boxPanel);
                    box.center();
                }
            });
        }
    });
    panel.add(finishButton);

    final Button terminateButton = new Button(strings.terminateButton());
    terminateButton.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            // Create a popup dialog box
            final DialogBox box = new DialogBox();
            box.setText(strings.warning());
            box.setAnimationEnabled(true);

            final Button boxCancelButton = new Button(strings.cancel());
            boxCancelButton.addClickHandler(new ClickHandler() {
                @Override
                public void onClick(ClickEvent event) {
                    box.hide();
                }
            });
            final Button boxAcceptButton = new Button(strings.accept());
            boxAcceptButton.addClickHandler(new ClickHandler() {
                @Override
                public void onClick(ClickEvent event) {
                    bingoService.terminateBingo(userId, new AsyncCallback<Void>() {
                        @Override
                        public void onFailure(Throwable caught) {
                            message.setText(caught.getMessage());
                        }

                        @Override
                        public void onSuccess(Void result) {
                            message.setText(strings.terminatedBingo());
                            timer.cancel();
                        }

                    });
                    box.hide();
                }
            });

            final Label boxLabel = new Label();
            boxLabel.setText(strings.terminateMessage());

            VerticalPanel boxPanel = new VerticalPanel();

            boxPanel.addStyleName("boxPanel");
            boxPanel.add(boxLabel);

            HorizontalPanel buttonsPanel = new HorizontalPanel();
            buttonsPanel.add(boxCancelButton);
            buttonsPanel.add(boxAcceptButton);
            boxPanel.add(buttonsPanel);

            box.setWidget(boxPanel);
            box.center();
        }
    });
    panel.add(terminateButton);

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

From source file:bingo.client.Bingo.java

License:Open Source License

private void updateUserGrid(final BingoGrid bingoGrid, final Timer timer) {
    bingoService.statusBingoVotes(userId, new AsyncCallback<boolean[][]>() {
        @Override//from  w  w w.  j av  a 2s.  co  m
        public void onFailure(Throwable caught) {
            message.setText(strings.errorUserSynchronization());
            if (timer != null)
                timer.cancel();
        }

        @Override
        public void onSuccess(boolean[][] result) {
            bingoGrid.colorVotes(result);
        }
    });

    // For now, no control of lines completed
    //      bingoService.statusBingoLines(userId, new AsyncCallback<Long>() {
    //         @Override
    //         public void onFailure(Throwable caught) {
    //            message.setText(strings.errorUserSynchronization());
    //            if(timer != null) timer.cancel();
    //         }
    //         @Override
    //         public void onSuccess(Long result) {
    //            bingoGrid.colorLines(result);
    //         }
    //      });
}

From source file:bufferings.ktr.wjr.client.runner.AbstractRunner.java

License:Apache License

/**
 * {@inheritDoc}/* w  w w.  j  a v a 2 s.c om*/
 */
public void cancelRunning() {
    cancelRequested = true;
    for (Timer retryTimer : retryTimerMap.values()) {
        retryTimer.cancel();
    }
    retryTimerMap.clear();
}

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 a2s. c  om*/
        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(//from   ww w  .  ja  v a  2 s. c o  m
                    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:com.akjava.gwt.threetest.client.NormalmapDemo.java

License:Apache License

@Override
public void start(final WebGLRenderer renderer, final int width, final int height, FocusPanel panel) {
    if (timer != null) {
        timer.cancel();
        timer = null;//from  ww w.j ava2s.c om
    }
    renderer.setClearColorHex(0x333333, 1);

    final Scene scene = THREE.Scene();

    final Camera camera = THREE.PerspectiveCamera(35, (double) width / height, .1, 10000);
    camera.getPosition().set(0, 300, 0);
    final Vector3 target = THREE.Vector3(0, 150, 0);
    scene.add(camera);

    JSONLoader loader = THREE.JSONLoader();

    loader.load("models/animation.js", new LoadHandler() {
        //loader.load("models/men2b_boned_gun.js", new LoadHandler() {

        @Override
        public void loaded(Geometry geometry) {
            log(geometry);

            Shader shader = ShaderUtils.lib("normal");
            Uniforms uniforms = UniformUtils.clone(shader.uniforms());
            uniforms.set("tNormal", ImageUtils.loadTexture("img/normalmap.png"));
            //uniforms.set("tNormal", ImageUtils.loadTexture("img/men2buv_n.png#10"));

            uniforms.set("enableDiffuse", true);
            uniforms.setHex("uDiffuseColor", 0xff0000);
            //uniforms.set("tDiffuse", ImageUtils.loadTexture("img/men2buv.png#1"));
            uniforms.set("tDiffuse", ImageUtils.loadTexture("img/uv.png#2"));
            uniforms.set("uNormalScale", 1);

            Material material = THREE.ShaderMaterial().fragmentShader(shader.fragmentShader())
                    .vertexShader(shader.vertexShader()).uniforms(uniforms).lights(true).morphTargets(false)
                    .build();

            model = new AnimationModel(geometry, material);
            model.getObject3D().getScale().set(15, 15, 15);
            model.getObject3D().getPosition().set(0, -100, 0);
            scene.add(model.getObject3D());

            GWT.log("loaded:");
        }
    });

    final Light light = THREE.DirectionalLight(0xeeeeee, 2);
    light.setPosition(1, 1, 1);
    light.getPosition().normalize();
    //scene.add(light);

    final Light light2 = THREE.DirectionalLight(0xeeeeee, 2);
    light2.setPosition(-1, -1, -1);
    light2.getPosition().normalize();
    scene.add(light2);

    final Light light3 = THREE.PointLight(0xffffff);
    light3.setPosition(0, 0, 600);
    scene.add(light3);
    //scene.add(light2);

    scene.add(THREE.AmbientLight(0xcccccc));

    //   MainWidget.cameraMove.setZ(-20);
    MainWidget.cameraMove.setZ(25);
    //   MainWidget.cameraRotation.setX(-90);
    final int radius = 600;

    last = System.currentTimeMillis();
    Timer timer = new Timer() {
        double theta;

        public void run() {
            try {
                theta += 0.2;

                camera.getPosition().setX(radius * Math.sin(theta * Math.PI / 360));
                camera.getPosition().setZ(radius * Math.cos(theta * Math.PI / 360));
                camera.lookAt(target);

                if (model != null) {
                    //TODO clock
                    long tmp = System.currentTimeMillis();
                    long delta = tmp - last;
                    //animMesh.updateAnimation(delta);
                    //animMesh.update((int) delta);
                    //tmpwork
                    int index = (int) (tmp / 100 % model.getFramelength());
                    model.select(index);
                    last = tmp;
                }

                renderer.render(scene, camera);

                MainWidget.stats.update();
            } catch (Exception e) {
                GWT.log(e.getMessage());
            }
        }
    };

    startTimer(timer);
}

From source file:com.akjava.gwt.threetest.client.PickDemo.java

License:Apache License

@Override
public void start(final WebGLRenderer renderer, final int width, final int height, FocusPanel panel) {
    if (timer != null) {
        timer.cancel();
        timer = null;/*from   w w w .  j ava  2s  . c o  m*/
    }
    //renderer.setClearColorHex(0xff0000, 0.5);

    final Map<Integer, Mesh> meshs = new HashMap<Integer, Mesh>();

    final Camera camera = THREE.PerspectiveCamera(35, (double) width / height, .1, 10000);
    camera.getPosition().set(0, 0, 50);

    final Scene scene = THREE.Scene();

    final Material material = THREE.MeshLambertMaterial(0xff00ff, false);

    final Mesh mesh = THREE.Mesh(THREE.CylinderGeometry(5, 5, 5, 6), material);
    scene.add(mesh);

    final Mesh mesh2 = THREE.Mesh(THREE.CylinderGeometry(5, 5, 5, 15),
            THREE.MeshLambertMaterial(0x00ff00, false));
    mesh2.setPosition(0, 10, 0);
    scene.add(mesh2);

    final Mesh mesh3 = THREE.Mesh(THREE.CylinderGeometry(5, 1, 5, 15),
            THREE.MeshLambertMaterial(0x0000ff, false));
    mesh3.setPosition(0, -10, 0);
    scene.add(mesh3);

    final Mesh mesh4 = THREE.Mesh(THREE.CylinderGeometry(5, 4.5, 5, 5),
            THREE.MeshLambertMaterial(0xffff00, false));
    mesh4.setPosition(-10, 0, 0);
    scene.add(mesh4);

    final Light light = THREE.PointLight(0xffffff);
    light.setPosition(10, 0, 10);
    scene.add(light);

    //scene.add(THREE.AmbientLight(0x330000));

    meshs.put(mesh.getId(), mesh);
    meshs.put(mesh2.getId(), mesh2);
    meshs.put(mesh3.getId(), mesh3);
    meshs.put(mesh4.getId(), mesh4);

    timer = new Timer() {
        public void run() {
            mesh.getRotation().incrementX(0.02);
            mesh.getRotation().incrementY(0.02);
            //mesh.setMaterials(material);
            //material.setColor(THREE.Color((int) (Math.random()*0xffffff)));
            //mesh.setMaterials(THREE.MeshLambertMaterial().color((int) (Math.random()*0xffffff)).build());
            renderer.render(scene, camera);

        }
    };
    timer.scheduleRepeating(1000 / 60);

    final Projector projector = THREE.Projector();
    panel.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            //GWT.log(event.getX()+"x"+event.getY()+" - "+width+"x"+height);
            JsArray<Intersect> intersects = projector.pickIntersects(event.getX(), event.getY(), width, height,
                    camera, scene);
            if (intersects.length() > 0) {
                //GWT.log(""+intersects.length());
            }
            for (int i = 0; i < intersects.length(); i++) {
                Intersect sect = intersects.get(i);
                //GWT.log(""+sect.getObject().getId()+" = "+sect.getObject().getName());

                final Mesh target = meshs.get(sect.getObject().getId());
                final int old = target.getMaterials().get(0).getColor().getHex();
                target.getMaterials().get(0).getColor().setHex(0xeeeeee);
                Timer timer = new Timer() {

                    @Override
                    public void run() {
                        target.getMaterials().get(0).getColor().setHex(old);
                    }

                };
                timer.schedule(1000);

            }
        }
    });
}

From source file:com.akjava.gwt.threetest.client.SimpleAnimation.java

License:Apache License

@Override
public void start(final WebGLRenderer renderer, final int width, final int height, FocusPanel panel) {
    if (timer != null) {
        timer.cancel();
        timer = null;//  ww w .j a va2  s  .  c  o m
    }
    renderer.setClearColorHex(0x333333, 1);

    final Scene scene = THREE.Scene();

    final Camera camera = THREE.PerspectiveCamera(35, (double) width / height, .1, 10000);
    camera.getPosition().set(0, 300, 0);
    final Vector3 target = THREE.Vector3(0, 150, 0);
    scene.add(camera);

    JSONLoader loader = THREE.JSONLoader();

    loader.load("models/animation.js", new LoadHandler() {

        @Override
        public void loaded(Geometry geometry) {
            Material material = THREE.MeshLambertMaterial().color(0xffffff).morphTargets(true)
                    .map(ImageUtils.loadTexture("img/uv.png")).build();
            animMesh = THREE.MorphAnimMesh(geometry, material);

            animMesh.setDuration(1000 * 5); //5sec
            animMesh.setMirrordLoop(true);//animation move forward and back

            animMesh.getScale().set(10, 10, 10);
            scene.add(animMesh);
            GWT.log("loaded:");
        }
    });

    final Light light = THREE.DirectionalLight(0xeeeeee, 2);
    light.setPosition(1, 1, 1);
    scene.add(light);

    scene.add(THREE.AmbientLight(0xcccccc));

    final int radius = 600;

    last = System.currentTimeMillis();
    Timer timer = new Timer() {
        double theta;

        public void run() {
            try {
                theta += 0.2;

                camera.getPosition().setX(radius * Math.sin(theta * Math.PI / 360));
                camera.getPosition().setZ(radius * Math.cos(theta * Math.PI / 360));
                camera.lookAt(target);

                if (animMesh != null) {
                    //TODO clock
                    long tmp = System.currentTimeMillis();
                    long delta = tmp - last;
                    animMesh.updateAnimation(delta);

                    last = tmp;
                }

                renderer.render(scene, camera);
                MainWidget.stats.update();
            } catch (Exception e) {
                GWT.log(e.getMessage());
            }
        }
    };

    startTimer(timer);
}

From source file:com.arcbees.gquery.appear.client.Appear.java

License:Apache License

private void maybeInitHandlers() {
    if (handlerRegistration == null) {
        final HandlerRegistration scrollHandler = addWindowScrollHandler();
        final HandlerRegistration resizeHandler = addWindowResizeHandler();
        mutationHandler = createMutationHandler();

        final Timer checkForEventsTimer = createEventsTimer();
        checkForEventsTimer.scheduleRepeating(200);

        handlerRegistration = new HandlerRegistration() {
            @Override/*from ww  w  . j  a v a  2 s.c o m*/
            public void removeHandler() {
                checkForEventsTimer.cancel();
                scrollHandler.removeHandler();
                resizeHandler.removeHandler();
                if (mutationHandler != null) {
                    mutationHandler.disconnect();
                }
            }
        };
    }

    refreshScrollEvents();
}

From source file:com.automaster.autoview.client.Info.java

public static void fecharJanelaCarrgando() {

    Info.janelaCarregando.setAnimateTime(800);
    Info.janelaCarregando.animateHide(AnimationEffect.FADE);
    for (Timer t : arrayTimer) {
        t.cancel();
        GWT.log("CANCELANDO A TIMER!");
    }// w  ww .j ava2s.  c o  m
    arrayTimer.clear();
    for (HLayout hl : arrayHlayout) {
        hl.destroy();
        GWT.log("CANCELANDO A HLAYOUT!");
    }
    arrayHlayout.clear();
    //        Info.startTread = true;

}