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:com.google.gwt.sample.stockwatcher.client.Pages.java

private static void stopGaugeTimers() {
    for (Timer t : Data.gaugeTimers) {
        t.cancel();
    }
}

From source file:com.google.gwt.sample.stockwatcher.client.SitePage.java

public static void stop() {
    for (Timer ti : timers) {
        ti.cancel();
    }
    timers.clear();
}

From source file:com.gwttest.client.Demo.java

License:Open Source License

public void onModuleLoad() {
    final ChartWidget chart = new ChartWidget();

    HorizontalPanel hp = new HorizontalPanel();
    hp.setSpacing(10);//from   ww  w  .  j a v  a 2 s.  c  o m

    VerticalPanel vp = new VerticalPanel();
    vp.setSpacing(20);
    // add home page
    HTML homeText = new HTML("<h2>Welcome to OFCGWT</h2>"
            + "<i>....the OpenFlashChart GWT Library</i></br></br>"
            + "This demonstration site will showcase the many different types of charts that can be inserted into a GWT application.");
    vp.add(homeText);
    vp.setCellHeight(homeText, "100");

    createPopupDialog();
    Button popup = new Button("Show 2nd Chart in Dialog");
    popup.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent event) {
            popupDb.center();
            popupDb.show();
        }
    });
    vp.add(popup);

    Button image = new Button("Show Image of Chart");
    image.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent event) {

            ImageServiceAsync imgService = (ImageServiceAsync) GWT.create(ImageService.class);
            ServiceDefTarget target = (ServiceDefTarget) imgService;
            target.setServiceEntryPoint(GWT.getHostPageBaseURL() + "ImageService");

            imgService.getImageToken(chart.getImageData(), new AsyncCallback<String>() {
                public void onFailure(Throwable caught) {
                }

                public void onSuccess(String result) {
                    createImageDialog(GWT.getHostPageBaseURL() + "image?var=img_" + result);
                }
            });
        }
    });
    vp.add(image);

    vp.add(new HTML("Update Speed <i>(0-off, 4-max)</i>"));
    final SliderBar slider = new SliderBar(0.0, 4.0);
    slider.setStepSize(1.0);
    slider.setCurrentValue(1.0);
    slider.setNumTicks(4);
    slider.setNumLabels(4);
    slider.setWidth("100%");
    vp.add(slider);

    hp.add(vp);
    hp.setCellWidth(vp, "300");

    // add chart
    VerticalPanel vp2 = new VerticalPanel();
    DecoratorPanel dp = new DecoratorPanel();
    SimplePanel chartPanel = new SimplePanel();
    chartPanel.setStylePrimaryName("chartPanel");
    chart.setSize("500", "400");
    chart.setChartData(getPieChartData());
    chartPanel.add(chart);
    dp.add(chartPanel);
    vp2.add(dp);
    vp2.add(new HTML("Chart's JSON data:"));
    ta = new TextArea();
    ta.setWidth("400");
    ta.setHeight("100");
    ta.setText(chart.getJsonData());
    vp2.add(ta);
    hp.add(vp2);

    VerticalPanel chartlist = new VerticalPanel();
    chartlist.setSpacing(5);
    Command cmd = new Command() {
        public void execute() {
            chart.setChartData(getPieChartData());
            ta.setText(chart.getJsonData());
        }
    };
    RadioButton rb = createRadioButton("PieChart - No Labels", cmd);
    updateCmd = cmd;
    rb.setValue(true);
    chartlist.add(rb);

    chartlist.add(createRadioButton("PieChart - Animate", new Command() {
        public void execute() {
            chart.setChartData(getAniPieChartData());
            ta.setText(chart.getJsonData());
        }
    }));

    chartlist.add(createRadioButton("BarChart - Transparent", new Command() {
        public void execute() {
            chart.setChartData(getBarChartTransparentData());
            ta.setText(chart.getJsonData());
        }
    }));

    chartlist.add(createRadioButton("BarChart - Glass", new Command() {
        public void execute() {
            chart.setChartData(getBarChartGlassData());
            ta.setText(chart.getJsonData());
        }
    }));

    chartlist.add(createRadioButton("3DBarChart + Line", new Command() {
        public void execute() {
            chart.setChartData(get3DBarLineChartData());
            ta.setText(chart.getJsonData());
        }
    }));

    chartlist.add(createRadioButton("CylinderChart", new Command() {
        public void execute() {
            chart.setChartData(getCylinderChartData());
            ta.setText(chart.getJsonData());
        }
    }));

    chartlist.add(createRadioButton("CylinderChart - RoundGlass", new Command() {
        public void execute() {
            chart.setChartData(getCylinderChartGlassData());
            ta.setText(chart.getJsonData());
        }
    }));

    chartlist.add(createRadioButton("LineChart - 3 Dot Types", new Command() {
        public void execute() {
            chart.setChartData(getLineChartData());
            ta.setText(chart.getJsonData());
        }
    }));

    chartlist.add(createRadioButton("ScatterChart - Star Dot", new Command() {
        public void execute() {
            chart.setChartData(getScatterPointChartData());
            ta.setText(chart.getJsonData());
        }
    }));

    chartlist.add(createRadioButton("ScatterChart - Line", new Command() {
        public void execute() {
            chart.setChartData(getScatterLineChartData());
            ta.setText(chart.getJsonData());
        }
    }));

    chartlist.add(createRadioButton("RadarChart", new Command() {
        public void execute() {
            chart.setChartData(getRadarChartData());
            ta.setText(chart.getJsonData());
        }
    }));

    chartlist.add(createRadioButton("Horizontal-BarChart", new Command() {
        public void execute() {
            chart.setChartData(getHorizBarChartData());
            ta.setText(chart.getJsonData());
        }
    }));

    chartlist.add(createRadioButton("AreaChart - Hollow", new Command() {
        public void execute() {
            chart.setChartData(getAreaHollowChartData());
            ta.setText(chart.getJsonData());
        }
    }));

    chartlist.add(createRadioButton("AreaChart - Line", new Command() {
        public void execute() {
            chart.setChartData(getAreaLineChartData());
            ta.setText(chart.getJsonData());
        }
    }));

    chartlist.add(createRadioButton("SketchChart", new Command() {
        public void execute() {
            chart.setChartData(getSketchChartData());
            ta.setText(chart.getJsonData());
        }
    }));

    chartlist.add(createRadioButton("StackChart", new Command() {
        public void execute() {
            chart.setChartData(getStackChartData());
            ta.setText(chart.getJsonData());
        }
    }));

    chartlist.add(createRadioButton("HorizontalStackChart", new Command() {
        public void execute() {
            chart.setChartData(getHorizontalStackChartData());
            ta.setText(chart.getJsonData());
        }
    }));

    hp.add(chartlist);
    hp.setCellWidth(chartlist, "300");

    RootPanel.get().add(hp);

    final Timer updater = new Timer() {
        public void run() {
            updateCmd.execute();
        }
    };
    updater.scheduleRepeating(3000);

    slider.addChangeListener(new ChangeListener() {
        public void onChange(Widget sender) {
            switch ((int) (slider.getCurrentValue())) {
            case 0:
                updater.cancel();
                break;

            case 1:
                updater.scheduleRepeating(3000);
                break;

            case 2:
                updater.scheduleRepeating(1000);
                break;

            case 3:
                updater.scheduleRepeating(200);
                break;

            case 4:
                updater.scheduleRepeating(50);
                break;
            }
        }
    });
}

From source file:com.moesol.gwt.maps.client.controls.MapPanZoomControl.java

License:Open Source License

private void stopZoomLoop(Timer zoomTimer) {
    zoomTimer.cancel();
    if (m_doingMapAction) {
        m_doingMapAction = false;//from w ww. ja v a2 s  .  c  o  m
        m_map.updateView();
    }
}

From source file:com.moesol.gwt.maps.client.MapSingleClickDetector.java

License:Open Source License

public void bind() {
    if (bound) {/*from   w  w w  . ja  v  a 2  s  .  c  o m*/
        return;
    }

    this.mapMouseDownHandlerRegistration = map.addDomHandler(new MouseDownHandler() {
        @Override
        public void onMouseDown(final MouseDownEvent event) {
            if (doubleClickTimer != null && !timerExpired) {
                isDoubleClick = true;
                eventThrottler.get(eventBus).cancel();
                timerExpired = false;
                doubleClickTimer.cancel();
                doubleClickTimer = null;
                return;
            } else if (doubleClickTimer != null) {
                isDoubleClick = false;
                doubleClickTimer.cancel();
                doubleClickTimer = null;
            }

            isDoubleClick = false;
            timerExpired = false;
            doubleClickTimer = new Timer() {
                @Override
                public void run() {
                    timerExpired = true;
                }
            };
            doubleClickTimer.schedule(doubleClickThresholdTimeMilli);
            clickStartPositionX = event.getX();
            clickStartPositionY = event.getY();
        }
    }, MouseDownEvent.getType());

    this.mapMouseUpHandlerRegistration = map.addDomHandler(new MouseUpHandler() {
        @Override
        public void onMouseUp(final MouseUpEvent event) {
            if (isWithinAcceptableErrorMargin(event)) {
                Timer runningEvent = eventThrottler.get(eventBus);
                if (runningEvent != null) {
                    runningEvent.cancel();
                }

                runningEvent = new Timer() {
                    @Override
                    public void run() {
                        if (!isDoubleClick) {
                            MapSingleClickEvent.fire(eventBus, clickStartPositionX, clickStartPositionY);
                        }
                    }
                };

                runningEvent.schedule(minTimeBetweenEvents);
                eventThrottler.put(eventBus, runningEvent);
            }
        }
    }, MouseUpEvent.getType());

    this.bound = true;
}

From source file:com.retech.reader.web.client.home.MyDownLoadPanel.java

License:Apache License

private void displayIssue(final List<IssueProxy> proxys, final boolean isDownloadFinish) {
    for (final IssueProxy issue : proxys) {
        final HTMLPanel issuePanel = new HTMLPanel("");
        final HTMLPanel imagePanel = new HTMLPanel("");
        issuePanel.add(imagePanel);/*from   ww  w.jav a  2s  .c  o m*/
        issuePanel.add(new Label(issue.getTitle()));

        final String myDownLoadPanelStyleName = res.mydownloadStyle().myDownLoadPanel();
        final Timer timer = new Timer() {

            @Override
            public void run() {
                isStart = false;
                if (myDownLoadPanel.getStyleName().contains(myDownLoadPanelStyleName)) {
                    myDownLoadPanel.removeStyleName(myDownLoadPanelStyleName);
                } else {
                    myDownLoadPanel.addStyleName(myDownLoadPanelStyleName);
                }
            }

        };

        issuePanel.addDomHandler(new TouchStartHandler() {

            @Override
            public void onTouchStart(final TouchStartEvent event) {
                timer.schedule(700);

            }
        }, TouchStartEvent.getType());

        issuePanel.addDomHandler(new TouchEndHandler() {

            @Override
            public void onTouchEnd(final TouchEndEvent event) {
                timer.cancel();
            }

        }, TouchEndEvent.getType());

        issuePanel.addDomHandler(new MouseDownHandler() {

            @Override
            public void onMouseDown(final MouseDownEvent event) {
                timer.schedule(700);
            }

        }, MouseDownEvent.getType());

        issuePanel.addDomHandler(new MouseUpHandler() {

            @Override
            public void onMouseUp(final MouseUpEvent event) {
                timer.cancel();
            }
        }, MouseUpEvent.getType());

        issuePanel.addDomHandler(new ClickHandler() {
            @Override
            public void onClick(final ClickEvent event) {
                if (myDownLoadPanel.getStyleName().contains(myDownLoadPanelStyleName)) {
                    if (event.getX() < 12 && event.getY() < 12) {
                        List<IssueProxy> issueDownloadFinish = storage
                                .get(keyUtil.listKey(IssueProxy.ISSUE_DOWN_FINISH));
                        if (issueDownloadFinish == null) {
                            return;
                        }
                        if (issueDownloadFinish.contains(issue)) {
                            issueDownloadFinish.remove(issue);
                            myDownLoadPanel.remove(issuePanel);
                        }
                        if (issueDownloadFinish.size() == 0) {
                            Storage.getLocalStorageIfSupported()
                                    .removeItem(keyUtil.listKey(IssueProxy.ISSUE_DOWN_FINISH));
                            return;
                        }
                        storage.put(keyUtil.listKey(IssueProxy.ISSUE_DOWN_FINISH), issueDownloadFinish);
                    }
                    return;
                }
                if (isStart) {
                    EntityProxyId<IssueProxy> stableId = issue.stableId();
                    placeController
                            .goTo(places.get().setPath(IssueNews.class.getName()).setParameter(stableId));
                }
                isStart = true;
            }
        }, ClickEvent.getType());

        if (isDownloadFinish) {
            ProgressWidget progressWidget = progresses.get();
            IssueDownloadMessage issueDownloadMessage = new IssueDownloadMessage();
            issueDownloadMessage.setProgress(progressWidget);
            issueDownloadMessage.setIssueProxy(issue);
            issuePanel.add(progressWidget);
            downLoadIssue(issueDownloadMessage, issue.stableId());
        } else if (issuePanel.getWidgetCount() == 3) {
            issuePanel.remove(2);
        }

        myDownLoadPanel.add(issuePanel);

        new BaseReceiver<ResourceProxy>() {
            @Override
            public void onSuccessAndCached(final ResourceProxy response) {
                displayResource(response, imagePanel);
            }

            @Override
            public Request<ResourceProxy> provideRequest() {
                return f.resource().getImage(issue);
            }
        }.setKeyForProxy(issue.stableId(), ResourceProxy.class.getName()).fire();
    }
}

From source file:com.square.client.gwt.client.presenter.personne.PersonneActionsPresenter.java

License:Open Source License

@Override
public void onBind() {
    view.getBtnAfficherActions().addClickHandler(new ClickHandler() {
        @Override//from  ww w  .  j  ava2  s. c  o m
        public void onClick(ClickEvent event) {
            // Suppression du filtre de recherche d'actions  partir d'une opportunit
            view.masquerFiltre();
            initListeActions(null, null, null);
        }
    });
    addEventHandlerToLocalBus(ActionZoomOverEvent.TYPE, new ActionZoomOverEventHandler() {
        @Override
        public void onMouseOver(final ActionZoomOverEvent event) {
            if (!event.isOpen()) {
                // on lance le timer pour afficher l'info bulle si bloc annul ou termin
                if (event.getActionZoomOver().getViewAction().isAnnuleOuTermine()) {
                    final Timer timerAffichageInfoBulle = new Timer() {
                        @Override
                        public void run() {
                            actionServiceRpc.rechercherActionParIdentifiant(
                                    event.getActionZoomOver().getIdAction(), new AsyncCallback<ActionModel>() {
                                        @Override
                                        public void onFailure(Throwable caught) {
                                            view.onRpcServiceFailure(new ErrorPopupConfiguration(caught));
                                        }

                                        @Override
                                        public void onSuccess(final ActionModel result) {
                                            view.afficherInfoBulleAction(result,
                                                    event.getActionZoomOver().getViewAction());
                                        }
                                    });
                        }
                    };
                    timerAffichageInfoBulle
                            .schedule(PersonneActionsPresenterConstants.DELAI_AFFICHAGE_INFOBULLE);
                    mapTimersAffichageInfoBulle.put(event.getActionZoomOver().getIdAction(),
                            timerAffichageInfoBulle);
                }
            }
            for (ActionZoomModel actionZoom : mapActionsZoom.get(event.getActionZoomOver().getIndexBloc())) {
                if (!event.getActionZoomOver().getIdAction().equals(actionZoom.getIdAction())) {
                    // on verifie si l'action parcourue est la mere ou un enfant de l'action survole
                    final boolean actionFils = event.getActionZoomOver().getIdAction()
                            .equals(actionZoom.getIdActionMere());
                    final boolean actionMere = event.getActionZoomOver().getIdActionMere() != null
                            && event.getActionZoomOver().getIdActionMere().equals(actionZoom.getIdAction());
                    if (!actionFils && !actionMere) {
                        // si ce n'est ni l'un ni l'autre, on ajoute le style pastel
                        actionZoom.getViewAction().appliquerStylePastel(true);
                    }
                }
            }
        }
    });
    addEventHandlerToLocalBus(ActionZoomOutEvent.TYPE, new ActionZoomOutEventHandler() {
        @Override
        public void onMouseOut(ActionZoomOutEvent event) {
            if (!event.isOpen()) {
                // On masque l'info bulle du bloc annul ou termin, ou on dsactive le timer
                if (event.getActionZoomOut().getViewAction().isAnnuleOuTermine()) {
                    if (mapTimersAffichageInfoBulle.get(event.getActionZoomOut().getIdAction()) != null) {
                        final Timer timerAffichageInfoBulle = mapTimersAffichageInfoBulle
                                .get(event.getActionZoomOut().getIdAction());
                        timerAffichageInfoBulle.cancel();
                        mapTimersAffichageInfoBulle.remove(timerAffichageInfoBulle);
                    }
                    view.masquerInfoBulleAction();
                }
            }
            for (ActionZoomModel actionZoom : mapActionsZoom.get(event.getActionZoomOut().getIndexBloc())) {
                // on informe les vues d'enlever le style pastel
                actionZoom.getViewAction().appliquerStylePastel(false);
            }
        }
    });
}

From source file:edu.caltech.ipac.firefly.ui.panels.SearchSummaryPanel.java

public void layout() {

    // clear any backgrounded processes.
    for (Timer t : bgList) {
        t.cancel();
    }/* w ww.  jav  a  2 s  .c  o m*/

    table = new FlexTable();
    mainPanel.clear();
    if (!StringUtils.isEmpty(name) || !StringUtils.isEmpty(helpId)) {

        String n = StringUtils.isEmpty(name) ? "" : name.trim();
        HorizontalPanel h = new HorizontalPanel();
        h.setWidth("100%");
        HTML lname = new HTML("<b>" + n + "</b>");
        if (shortDesc != null) {
            lname.setTitle(shortDesc);
        }
        GwtUtil.setStyles(lname, "textAlign", "center");
        h.add(lname);
        h.setCellWidth(lname, "100%");

        if (!StringUtils.isEmpty(helpId)) {
            final Widget helpIcon = HelpManager.makeHelpIcon(helpId);
            h.add(helpIcon);
            GwtUtil.setStyles(helpIcon, "marginRight", "11px");
        }
        mainPanel.addNorth(h, 20);
    }

    // setup group by selection
    if (groupByCols != null && groupByCols.size() > 1) {
        EnumFieldDef gb = new EnumFieldDef("groupBy");
        gb.setLabel("Group By");
        gb.setDesc("Select a group by column to update the data table");
        gb.setPreferWidth(200);
        gb.setDefaultValue(curGroupByName);
        for (TableDataView.Column item : headers) {
            if (groupByCols.contains(item.getName())) {
                gb.addItem(item.getName(), item.getTitle());
            }
        }
        final SimpleInputField sif = SimpleInputField.createByDef(gb);
        mainPanel.addNorth(sif, 28);
        sif.getField().addValueChangeHandler(new ValueChangeHandler() {
            public void onValueChange(ValueChangeEvent ve) {
                curGroupByName = sif.getValue();
                layout();
            }
        });
    }

    ScrollPanel sp = new ScrollPanel();
    sp.add(table);

    mainPanel.add(sp);

    table.setStyleName("firefly-summary-table");
    table.setSize("100%", "100%");
    iconColIdx = headers.size();
    String titleCol = null;

    // render headers
    int colIdx = 0;
    for (int i = 0; i < headers.size(); i++) {
        TableDataView.Column col = headers.get(i);
        if (curGroupByName == null || !curGroupByName.equals(col.getName())) {
            table.setText(0, colIdx, col.getTitle());
            table.getCellFormatter().setStyleName(0, colIdx, "title-bar");
            colIdx++;
            if (titleCol == null) {
                titleCol = col.getName();
            }
        }
    }
    table.setText(0, headers.size(), "");
    table.getCellFormatter().setWidth(0, headers.size(), "100%");

    ArrayList<SearchSummaryItem> itemList = searchItems;

    if (!StringUtils.isEmpty(curGroupByName)) {
        itemList = new ArrayList<SearchSummaryItem>();

        GroupFinder finder = new GroupFinder("");
        List<GroupedSummaryItem> groupList = new ArrayList<GroupedSummaryItem>();
        for (int i = 0; i < searchItems.size(); i++) {
            SearchSummaryItem dsi = searchItems.get(i);
            String cGroupValue = dsi.getValue(curGroupByName);
            GroupedSummaryItem cGroup = CollectionUtil.findFirst(groupList, finder.setName(cGroupValue));
            if (cGroup == null) {
                cGroup = new GroupedSummaryItem(cGroupValue);
                groupList.add(cGroup);
                itemList.add(cGroup);
            }
            cGroup.addChild(dsi);
        }
    }

    for (SearchSummaryItem ssi : itemList) {
        ssi.setTitleCol(titleCol);
        layout(ssi, 0);
    }
}

From source file:hu.akarnokd.reactive4java.util.DefaultGwtScheduler.java

License:Apache License

@Override
public Closeable schedule(final Runnable run) {
    final Timer timer = new Timer() {
        @Override/*w  w  w  .  jav a 2 s  . c  o m*/
        public void run() {
            run.run();
        }
    };
    timer.schedule(1);
    return new Closeable() {
        @Override
        public void close() throws IOException {
            timer.cancel();
        }
    };
}

From source file:hu.akarnokd.reactive4java.util.DefaultGwtScheduler.java

License:Apache License

@Override
public Closeable schedule(final Runnable run, long delay) {
    final Timer timer = new Timer() {
        @Override/*from   w w w  . j a va  2s . c om*/
        public void run() {
            run.run();
        }
    };
    timer.schedule((int) (delay / 1000000L));
    return new Closeable() {
        @Override
        public void close() throws IOException {
            timer.cancel();
        }
    };
}