List of usage examples for com.google.gwt.user.client Timer scheduleRepeating
public synchronized void scheduleRepeating(final int periodMs)
From source file:com.google.gwt.example.stockwatcher.client.StockWatcher.java
/** * Entry point method.// w w w . ja v a 2 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.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.)/*from w ww.j a v a2s .c om*/ */ 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 w w w .ja va2 s. co 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.maps.testing.client.maps.TransitDirectionsServiceMapWidget.java
License:Apache License
private void draw() { pWidget.clear();/*from www . ja v a 2s . co m*/ pWidget.add(new HTML("<br/>")); HorizontalPanel hp = new HorizontalPanel(); pWidget.add(hp); hp.add(new HTML("Transit Directions Service ")); hp.add(htmlStatus); drawMap(); htmlSummary = new HTML(); pWidget.add(htmlSummary); nRequests = 0; Timer directionsTimer = new Timer() { @Override public void run() { drawRandomDirections(); /* * We do not want to make the client to be blacklisted by Google if its browser window is left open for too * long... :) */ if (nRequests++ > 10) cancel(); } }; directionsTimer.scheduleRepeating(10000); drawRandomDirections(); }
From source file:com.google.gwt.sample.client.mystockwatcherEntryPoint.java
/** * The entry point method, called automatically by loading a module * that declares an implementing class as an entry-point *//* w w w .j a va2 s . c o m*/ public void onModuleLoad() { // TODO 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"); //stocksFlexTable.setText(0, 4, JSON_URL); // Add styles to elements in the stock list table. stocksFlexTable.setCellPadding(6); 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"); // TODO Assemble Add Stock panel. addPanel.add(newSymbolTextBox); addPanel.add(addStockButton); addPanel.addStyleName("addPanel"); // TODO Assemble Main panel. errorMsgLabel.setStyleName("errorMessage"); errorMsgLabel.setVisible(false); mainPanel.add(errorMsgLabel); mainPanel.add(stocksFlexTable); mainPanel.add(addPanel); mainPanel.add(lastUpdatedLabel); // TODO Associate the Main panel with the HTML host page. RootPanel.get("stockList").add(mainPanel); // TODO 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 event) { addStock(); } }); // Listen for keyboard events in the input box. newSymbolTextBox.addKeyPressHandler(new KeyPressHandler() { @Override public void onKeyPress(KeyPressEvent event) { if (event.getCharCode() == KeyCodes.KEY_ENTER) { addStock(); } } }); }
From source file:com.google.gwt.sample.compraventa.client.Compraventa.java
public void onModuleLoad() { ofertasFlexTable.setText(0, 0, "Oferta Compra"); ofertasFlexTable.setText(0, 1, "Oferta Venta"); System.out.println("Estoy adentro del onModuleLoad"); // GWT.log("estoy en el onModuleLoad"); agregarPanel.add(cuotaTextBox);//from w ww . ja va 2 s .c o m agregarPanel.add(montoTextBox); agregarPanel.add(comprarRadioButton); agregarPanel.add(venderRadioButton); agregarPanel.add(agregarButton); agregarPanel.add(actualizarButton); // Assemble Main panel. mainPanel.add(agregarPanel); mainPanel.add(lastUpdatedLabel); mainPanel.add(ofertasFlexTable); RootPanel.get("ofertasList").add(mainPanel); agregarButton.setFocus(true); comprarRadioButton.setEnabled(true); // Escuchamos por el evento de agregar agregarButton.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { agregarOferta(); actualizarDatos(); } }); actualizarButton.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { actualizarDatos(); } }); montoTextBox.addKeyPressHandler(new KeyPressHandler() { public void onKeyPress(KeyPressEvent event) { if (event.getCharCode() == KeyCodes.KEY_ENTER) { agregarOferta(); } } }); cargarDatos(); Timer refreshTimer = new Timer() { @Override public void run() { agregarDatosFantasia(); actualizarDatos(); } }; refreshTimer.scheduleRepeating(REFRESH_INTERVAL); }
From source file:com.google.gwt.sample.stockwatch.client.StockWatcher.java
private void loadStockWatcher() { //Set up Sign Out hyperlink signOutLink.setHref(loginInfo.getLogoutUrl()); //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"); stocksFlexTable.setCellPadding(6);//from ww w . j av a2 s. c o m loadStocks(); //Assemble Add Stock Panel addPanel.add(newSymbolTextBox); addPanel.add(addStockButton); addPanel.addStyleName("addPanel"); //Assemble Main Panel mainPanel.add(signOutLink); mainPanel.add(stocksFlexTable); mainPanel.add(addPanel); mainPanel.add(lastUpdatedLabel); //Assemble the Main panel with the HTML host page RootPanel.get("stockList").add(mainPanel); //Move cursor focus to the input box. newSymbolTextBox.setFocus(true); //Set 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() { public void onClick(ClickEvent event) { addStock(); } }); //Listen for keyboard events in the input box newSymbolTextBox.addKeyDownHandler(new KeyDownHandler() { public void onKeyDown(KeyDownEvent event) { if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER) { addStock(); } } }); }
From source file:com.google.gwt.sample.stockwatcher.client.ChartUtilities.java
public static HorizontalPanel createGaugeChart(final String name, final int size) { final HorizontalPanel lol = new HorizontalPanel(); final Chart chart = new Chart(); chart.setType(Series.Type.SOLID_GAUGE).setLegend(new Legend().setEnabled(false)) .setCredits(new Credits().setEnabled(false)).setAlignTicks(false).setPlotBackgroundImage(null) .setBorderWidth(0).setPlotShadow(false).setExporting(new Exporting().setEnabled(false)) .setChartTitle(new ChartTitle().setText("Latest " + name + " sensor reading")) .setPane(new Pane().setStartAngle(-90).setEndAngle(90).setCenter("50%", "85%") .setBackground(new PaneBackground().setInnerRadius("60%").setOuterRadius("100%") .setShape(PaneBackground.Shape.ARC).setBackgroundColor("rgba(0,0,0,0)"))) .setSolidGaugePlotOptions(new SolidGaugePlotOptions().setAnimation(false)); final ArrayList<String> attributes = Data.sensorAttributeList.get(name); final Number maxTreshold = (Number) Double.parseDouble(attributes.get(8)); chart.getYAxis().setMin(0);/*from w ww .j a va 2s .c o m*/ chart.getYAxis().setMax(maxTreshold); chart.getYAxis().setLineColor("gray"); chart.setBackgroundColor(new Color().setLinearGradient(0.0, 0.0, 1.0, 1.0).addColorStop(0, 0, 0, 0, 1) .addColorStop(0, 0, 0, 0, 0)); chart.getYAxis().setTickPosition(Axis.TickPosition.INSIDE).setMinorTickPosition(Axis.TickPosition.INSIDE) .setLineColor("white").setTickColor("white").setMinorTickColor("white").setLineWidth(2) .setEndOnTick(true).setLabels(new YAxisLabels() // There is no documented "distance" option for gauge chart axes .setOption("distance", -20)); final Series series = chart.createSeries(); chart.addSeries(series.setName("Reading").addPoint(0)); final Timer tempTimer = new Timer() { @Override public void run() { if (MainMenuPage.mainPanel.isVisible()) Utility.newRequestObj().getLatestReading(name, new AsyncCallback<Double>() { public void onFailure(Throwable caught) { // Window.alert("Unable to get "+Data.currentUser+"'s sensor subscription"); } public void onSuccess(Double reply) { if (lol.isVisible()) { // double temp = Utility.round(new Random().nextDouble()*Double.parseDouble(attributes.get(8))); double temp = Utility.round(reply); series.getPoints()[0].update(temp); chart.setColors(updateColor(temp, maxTreshold)); lol.add(chart); } else { cancel(); } } }); } }; tempTimer.scheduleRepeating(2000); Data.gaugeTimers.add(tempTimer); chart.setSize(Window.getClientWidth() * 1 / size, Window.getClientHeight() * 1 / size); if (size > 4) { chart.setSize(Window.getClientWidth() * 1 / 4, Window.getClientHeight() * 1 / 4); } lol.add(chart); return lol; }
From source file:com.google.gwt.sample.stockwatcher.client.ChartUtilities.java
private static void doFadeOut(HorizontalPanel panel) { final Element element = panel.getElement(); final double opacity = Double.parseDouble(element.getStyle().getOpacity()); final Timer tempTimer = new Timer() { @Override//from w w w. ja va2 s . c om public void run() { if (opacity == 0) { cancel(); } element.getStyle().setOpacity(opacity - 0.1); } }; tempTimer.scheduleRepeating(10); }
From source file:com.google.gwt.sample.stockwatcher.client.ChartUtilities.java
private static void doFadeIn(HorizontalPanel panel) { final Element element = panel.getElement(); final double opacity = Double.parseDouble(element.getStyle().getOpacity()); final Timer tempTimer = new Timer() { @Override/* w w w . jav a 2 s. c o m*/ public void run() { if (opacity == 1) { cancel(); } element.getStyle().setOpacity(opacity + 0.1); } }; tempTimer.scheduleRepeating(10); }