List of usage examples for com.google.gwt.user.client Timer schedule
public synchronized void schedule(int delayMs)
From source file:com.google.gwt.sample.showcase.client.content.cell.AsyncContactProvider.java
@Override protected void onRangeChanged(final HasData<ContactInfo> display) { requestCount++;//from w w w. j a va 2 s.c o m 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.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();/*from w w w .j av 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.maps.gwt.samples.events.client.EventSimple.java
License:Apache License
@Override public void onModuleLoad() { LatLng myLatLng = LatLng.create(-25.363882, 131.044922); MapOptions myOptions = MapOptions.create(); myOptions.setZoom(4.0);//from w w w .ja v a2 s .c o m myOptions.setCenter(myLatLng); myOptions.setMapTypeId(MapTypeId.ROADMAP); map = GoogleMap.create(Document.get().getElementById("map_canvas"), myOptions); map.addZoomChangedListener(new GoogleMap.ZoomChangedHandler() { public void handle() { Timer moveToDarwinTimer = new Timer() { public void run() { map.setCenter(DARWIN); } }; moveToDarwinTimer.schedule(3000); } }); MarkerOptions markerOptions = MarkerOptions.create(); markerOptions.setPosition(myLatLng); markerOptions.setMap(map); markerOptions.setTitle("Hello World!"); Marker myMarker = Marker.create(markerOptions); myMarker.addClickListener(new Marker.ClickHandler() { @Override public void handle(MouseEvent event) { map.setZoom(8); } }); }
From source file:com.google.speedtracer.client.MonitorVisualizationsPanel.java
License:Apache License
private void createVisualizations(ApplicationState initialState, MainTimeLine.Resources resources) { // Sluggishness SluggishnessModel sluggishnessModel = (SluggishnessModel) initialState .getVisualizationModel(SluggishnessVisualization.TITLE); SluggishnessVisualization sluggishnessVisualization = new SluggishnessVisualization(mainTimeLine, sluggishnessModel, detailsViewPanel.getContainer(), resources); // Network Visualization NetworkVisualizationModel networkModel = (NetworkVisualizationModel) initialState .getVisualizationModel(NetworkVisualization.TITLE); NetworkVisualization networkVisualization = new NetworkVisualization(mainTimeLine, networkModel, detailsViewPanel.getContainer(), resources); // Load the visualization that we just added. loadVisualization(sluggishnessVisualization); loadVisualization(networkVisualization); // Setup the graphs to refresh when hintlet data arrives. Buffer the data // so that the screen doesn't jump from rapid hintlet data coming in. initialState.getDataDispatcher().getHintletEngineHost() .addHintListener(new HintletInterface.HintListener() { boolean queued = false; public void onHint(HintRecord hintlet) { if (queued) { return; }//from w w w . ja v a 2s . c o m double hintletTime = hintlet.getTimestamp(); if (hintletTime < mainTimeLineModel.getLeftBound() || hintletTime > mainTimeLineModel.getRightBound()) { // out of bounds - no need to refresh return; } Timer t = new Timer() { @Override public void run() { mainTimeLineModel.refresh(); queued = false; } }; t.schedule(HINTLET_REFRESH_DELAY_MS); queued = true; } }); }
From source file:com.google.testing.testify.risk.frontend.client.view.impl.ProjectSettingsViewImpl.java
License:Apache License
@Override public void showSaved() { updateProjectInfoButton.setEnabled(true); savedPanel.setVisible(true);//ww w .ja va 2 s . c om Timer timer = new Timer() { @Override public void run() { savedPanel.setVisible(false); } }; // Make the saved item disappear after 10 seconds. timer.schedule(10000); }
From source file:com.google.testing.testify.risk.frontend.client.view.widgets.EditCapabilityWidget.java
License:Apache License
public void showSaved() { // Show saved message. savedPanel.setVisible(true);/* w ww . jav a 2s . c o m*/ Timer timer = new Timer() { @Override public void run() { savedPanel.setVisible(false); } }; // Make the saved text disappear after 10 seconds. timer.schedule(5000); }
From source file:com.googlecode.gwtphonegap.client.PhoneGapStandardImpl.java
License:Apache License
@Override public void initializePhoneGap(final int timeoutInMs) { final long end = System.currentTimeMillis() + timeoutInMs; if (isPhoneGapInitialized()) { firePhoneGapAvailable();/*from w ww . j av a2s . c om*/ } else { Timer timer = new Timer() { @Override public void run() { if (isPhoneGapInitialized()) { firePhoneGapAvailable(); return; } if (System.currentTimeMillis() - end > 0) { handlerManager.fireEvent(new PhoneGapTimeoutEvent()); } else { schedule(INIT_TICK); } } }; timer.schedule(INIT_TICK); } }
From source file:com.googlecode.konamigwt.hadoken.client.Hadoken.java
License:BEER-WARE LICENSE
/** * This is the entry point method./* w w w . j a va 2 s. c o m*/ */ public void onModuleLoad() { final Button sendButton = new Button("Send"); final TextBox nameField = new TextBox(); nameField.setText("GWT User"); final Label errorLabel = new Label(); // We can add style names to widgets sendButton.addStyleName("sendButton"); // Add the nameField and sendButton to the RootPanel // Use RootPanel.get() to get the entire body element RootPanel.get("nameFieldContainer").add(nameField); RootPanel.get("sendButtonContainer").add(sendButton); RootPanel.get("errorLabelContainer").add(errorLabel); // Focus the cursor on the name field when the app loads nameField.setFocus(true); nameField.selectAll(); // Create the popup dialog box final DialogBox dialogBox = new DialogBox(); dialogBox.setText("Remote Procedure Call"); dialogBox.setAnimationEnabled(true); final Button closeButton = new Button("Close"); // We can set the id of a widget by accessing its Element closeButton.getElement().setId("closeButton"); final Label textToServerLabel = new Label(); final HTML serverResponseLabel = new HTML(); VerticalPanel dialogVPanel = new VerticalPanel(); dialogVPanel.addStyleName("dialogVPanel"); dialogVPanel.add(new HTML("<b>Sending name to the server:</b>")); dialogVPanel.add(textToServerLabel); dialogVPanel.add(new HTML("<br><b>Server replies:</b>")); dialogVPanel.add(serverResponseLabel); dialogVPanel.setHorizontalAlignment(VerticalPanel.ALIGN_RIGHT); dialogVPanel.add(closeButton); dialogBox.setWidget(dialogVPanel); // Add a handler to close the DialogBox closeButton.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { dialogBox.hide(); sendButton.setEnabled(true); sendButton.setFocus(true); } }); // Quick and Dirty implementation new Konami(new KonamiHandler() { @Override public void onKonamiCodePerformed() { final Image image = new Image("media/ryu.gif"); DOM.appendChild(RootPanel.get().getElement(), image.getElement()); final Audio audio = Audio.createIfSupported(); if (audio != null) { audio.setSrc("media/hadoken.ogg"); DOM.appendChild(RootPanel.get().getElement(), audio.getElement()); audio.play(); } Timer timer = new Timer() { @Override public void run() { DOM.removeChild(RootPanel.get().getElement(), image.getElement()); if (audio != null) { DOM.removeChild(RootPanel.get().getElement(), audio.getElement()); } } }; timer.schedule(1100); } }).start(); // Create a handler for the sendButton and nameField class MyHandler implements ClickHandler, KeyUpHandler { /** * Fired when the user clicks on the sendButton. */ public void onClick(ClickEvent event) { sendNameToServer(); } /** * Fired when the user types in the nameField. */ public void onKeyUp(KeyUpEvent event) { if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER) { sendNameToServer(); } } /** * Send the name from the nameField to the server and wait for a response. */ private void sendNameToServer() { // First, we validate the input. errorLabel.setText(""); String textToServer = nameField.getText(); if (!FieldVerifier.isValidName(textToServer)) { errorLabel.setText("Please enter at least four characters"); return; } // Then, we send the input to the server. sendButton.setEnabled(false); textToServerLabel.setText(textToServer); serverResponseLabel.setText(""); serverResponseLabel.removeStyleName("serverResponseLabelError"); serverResponseLabel.setHTML("Hello " + textToServer); dialogBox.center(); closeButton.setFocus(true); } } // Add a handler to send the name to the server MyHandler handler = new MyHandler(); sendButton.addClickHandler(handler); nameField.addKeyUpHandler(handler); }
From source file:com.gwtcx.sample.serendipity.client.view.AmChartsDashboardsView.java
License:Open Source License
public void loadAmChart() { Timer t = new Timer() { public void run() { Log.debug("run()"); Element div = DOM.getElementById("chart_nested_div"); if (div != null) { Log.debug("DOM.getElementById(\"chart_nested_div\") - " + div.getId()); }/*from w w w . j a v a 2s .c o m*/ Log.debug("drawAmChart()"); drawAmChart(); } }; // Schedule the timer to run once after waiting 2 seconds t.schedule(2000); }
From source file:com.gwtext.client.widgets.grid.GridPanel.java
License:Open Source License
/** * Hides the specified column./*from ww w. j a v a 2 s . c o m*/ * * @param colIndex the column index */ public void hideColumn(int colIndex) { getColumnModel().setHidden(colIndex, true); if (isRendered() && Ext.isIE()) { Timer t = new Timer() { public void run() { getView().refresh(); getView().updateHeaderSortState(); } }; t.schedule(10); } }