List of usage examples for com.google.gwt.user.client Timer Timer
Timer
From source file:com.google.gwt.sample.feedreader.client.ManifestPanel.java
License:Apache License
public ManifestPanel(final Configuration configuration) { super("Feeds", null); this.configuration = configuration; setEditCommand("Edit", "Edits feeds", new Command() { public void execute() { History.newItem("configuration"); }/* www . j a v a 2 s. c o m*/ }); // Start a timer to refresh the feed data. (new Timer() { public void run() { refresh(); } }).scheduleRepeating(5 * 60 * 1000); addStyleName("ManifestPanel"); }
From source file:com.google.gwt.sample.guestbook.client.Orbital.java
public Orbital(int width, int height) { this.width = width; this.height = height; orbiter.mass = 1;/*ww w.j a v a 2 s . co m*/ setBodyNumber(BodyNumber.ONE); init(); timer = new Timer() { @Override public void run() { iterate(); } }; }
From source file:com.google.gwt.sample.mobilewebapp.presenter.tasklist.TaskListPresenter.java
License:Apache License
@Override public void start(EventBus eventBus) { this.eventBus = eventBus; // Add a handler to the 'add' button in the shell. clientFactory.getShell().setAddButtonVisible(true); // Clear the task list and display it. if (clearTaskList) { getView().clearList();/*from w ww .j a va2 s.co m*/ } // Create a timer to periodically refresh the task list. refreshTimer = new Timer() { @Override public void run() { refreshTaskList(); } }; // Load the saved task list from storage List<TaskProxy> list = clientFactory.getTaskProxyLocalStorage().getTasks(); setTasks(list); // Request the task list now. refreshTaskList(); }
From source file:com.google.gwt.sample.showcase.client.content.cell.AsyncContactProvider.java
@Override protected void onRangeChanged(final HasData<ContactInfo> display) { requestCount++;//w w w . jav a2s. com Timer timer = new Timer() { int rc = requestCount; @Override public void run() { int size = serverContacts.size(); if (size > 0) { // Do not push data if the data set is empty. updateRowData(display, 0, serverContacts.subList(0, display.getVisibleRange().getStart() + display.getVisibleRange().getLength())); updateRowCount(serverContacts.size(), true); } loadingStatus.setVisible(false); logger.info("...RPC " + rc); } }; // Simulate the delay incurred by a remote procedure call. loadingStatus.setVisible(true); loadingStatus.setText("RPC " + requestCount + "..."); logger.info("RPC " + requestCount + "..."); timer.schedule(requestCount == 1 ? 4000 : 2000); }
From source file:com.google.gwt.sample.showcase.client.content.cell.CwCellValidation.java
License:Apache License
/** * Initialize this example.//www.j a va 2 s .c o m */ @ShowcaseSource @Override public Widget onInitialize() { // Create a table. final CellTable<ContactInfo> table = new CellTable<ContactInfo>(10, ContactInfo.KEY_PROVIDER); // Add the Name column. table.addColumn(new Column<ContactInfo, String>(new TextCell()) { @Override public String getValue(ContactInfo object) { return object.getFullName(); } }, constants.cwCellValidationColumnName()); // Add an editable address column. final ValidatableInputCell addressCell = new ValidatableInputCell(constants.cwCellValidationError()); Column<ContactInfo, String> addressColumn = new Column<ContactInfo, String>(addressCell) { @Override public String getValue(ContactInfo object) { return object.getAddress(); } }; table.addColumn(addressColumn, constants.cwCellValidationColumnAddress()); addressColumn.setFieldUpdater(new FieldUpdater<ContactInfo, String>() { public void update(int index, final ContactInfo object, final String value) { // Perform validation after 2 seconds to simulate network delay. new Timer() { @Override public void run() { if (isAddressValid(value)) { // The cell will clear the view data when it sees the updated // value. object.setAddress(value); // Push the change to the views. ContactDatabase.get().refreshDisplays(); } else { // Update the view data to mark the pending value as invalid. ValidationData viewData = addressCell .getViewData(ContactInfo.KEY_PROVIDER.getKey(object)); viewData.setInvalid(true); // We only modified the cell, so do a local redraw. table.redraw(); } } }.schedule(1000); } }); // Add the table to the database. ContactDatabase.get().addDataDisplay(table); return table; }
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 w ww . jav a 2 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 StockChart createLiveChart(final String sensorName, Number[][] data, String title, final Boolean predictionIsEnabled, final Boolean isLiveUpdate, int steps) { Utility.hideTimer();//ww w. ja v a 2 s . c o m final StockChart chart = new StockChart(); chart.setType(Series.Type.SPLINE).setMarginRight(30) .setBarPlotOptions(new BarPlotOptions().setDataLabels(new DataLabels().setEnabled(true))) .setChartTitleText(title).setLegend(new Legend().setEnabled(false)) .setCredits(new Credits().setEnabled(false)).setSplinePlotOptions( new SplinePlotOptions().setMarker(new Marker().setEnabled(true).setRadius(3))); 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.getXAxis().setDateTimeLabelFormats(new DateTimeLabelFormats().setMinute("%l:%M %p")); ArrayList<String> attributes = Data.sensorAttributeList.get(sensorName); String unit = attributes.get(5); chart.getYAxis().setAxisTitleText(unit) .setPlotLines(chart.getYAxis().createPlotLine().setValue(0).setWidth(1).setColor("#808080")); final Series series = chart.createSeries(); chart.addSeries(series.setName("Data")); final Series predictionSeries = chart.createSeries(); int lastRow = data.length - 1; if (predictionIsEnabled) { lastRow -= steps; chart.addSeries(predictionSeries.setName("Prediction")); for (int i = lastRow; i < data.length; i++) { predictionSeries.addPoint(data[i][0], data[i][1]); } } for (int i = 0; i < lastRow; i++) { series.addPoint(data[i][0], data[i][1]); } if (isLiveUpdate) { final Timer tempTimer = new Timer() { java.sql.Date lastRequestTime = new java.sql.Date(System.currentTimeMillis()); @Override public void run() { if (chart.isAttached()) { if (chart.isRendered()) { long currTime = System.currentTimeMillis(); getAppendData(series, sensorName, lastRequestTime, new java.sql.Date(currTime), predictionIsEnabled, predictionSeries); lastRequestTime = new java.sql.Date(currTime + 1); } schedule(6000); } else { cancel(); } } }; tempTimer.schedule(0); } chart.setSize(Window.getClientWidth() * 2 / 3, Window.getClientHeight() * 2 / 3); return chart; }
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);// w w w . j a va 2 s. co 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/* ww w . ja v a 2s. co m*/ 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//from w w w . j a va2 s .co m public void run() { if (opacity == 1) { cancel(); } element.getStyle().setOpacity(opacity + 0.1); } }; tempTimer.scheduleRepeating(10); }