List of usage examples for com.google.gwt.user.client Timer scheduleRepeating
public synchronized void scheduleRepeating(final int periodMs)
From source file:anagram.client.GwtCanvasDemo.java
License:Apache License
public void onModuleLoad() { canvas = Canvas.createIfSupported(); backBuffer = Canvas.createIfSupported(); if (canvas == null) { RootPanel.get(holderId).add(new Label(upgradeMessage)); return;// w w w . j a va2 s . c o m } // init the canvases canvas.setWidth(width + "px"); canvas.setHeight(height + "px"); canvas.setCoordinateSpaceWidth(width); canvas.setCoordinateSpaceHeight(height); backBuffer.setCoordinateSpaceWidth(width); backBuffer.setCoordinateSpaceHeight(height); RootPanel.get(holderId).add(canvas); context = canvas.getContext2d(); backBufferContext = backBuffer.getContext2d(); // init the objects logoGroup = new LogoGroup(width, height, 18, 165); ballGroup = new BallGroup(width, height); lens = new Lens(35, 15, width, height, new Vector(320, 150), new Vector(1, 1)); // init handlers initHandlers(); // setup timer final Timer timer = new Timer() { @Override public void run() { doUpdate(); } }; timer.scheduleRepeating(refreshRate); }
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 w w. ja v a 2s . 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 += " " + 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 initUserGrid(final BingoGrid bingoGrid) { bingoGrid.addClickHandler(new ClickHandler() { @Override//from w w w. j av a 2 s.c o m public void onClick(ClickEvent event) { Cell cell = bingoGrid.getCellForEvent(event); if (cell != null) { final int row = cell.getRowIndex(); final int col = cell.getCellIndex(); if (!bingoGrid.cellHasBeenVoted(row, col)) { bingoGrid.voteForCell(row, col); bingoService.voteCell(userId, row, col, new AsyncCallback<Long>() { @Override public void onFailure(Throwable caught) { message.setText(strings.errorUserVote()); bingoGrid.voteAgainstCell(row, col); } @Override public void onSuccess(Long result) { // For now, no control of lines completed // bingoGrid.colorLines(result); } }); } else { message.setText(strings.alreadyVoted()); } } } }); Timer timer = new Timer() { @Override public void run() { updateUserGrid(bingoGrid, this); } }; timer.scheduleRepeating(USER_TIMER); RootPanel.get("buttons").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 ww . java2 s . 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 w ww . jav a2 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:ch.heftix.mailxel.client.MailxelMainToolBar.java
License:Open Source License
public void startDownloadTimer(int delay) { // schedule mail download if (delay > 0) { Timer timer = new Timer() { public void run() { ScanMailFolderCommand cmd = new ScanMailFolderCommand(mailxelService, mailxelPanel, null, null); cmd.execute();/* w w w .j ava 2 s. c o m*/ } }; timer.scheduleRepeating(delay * 60 * 1000); } }
From source file:com.achow101.bctalkaccountpricer.client.Bitcointalk_Account_Pricer.java
License:Open Source License
/** * This is the entry point method./*from ww w .ja v a 2s . c o m*/ */ public void onModuleLoad() { // Add Gui stuff final Button sendButton = new Button("Estimate Price"); final TextBox nameField = new TextBox(); nameField.setText("User ID/Token"); final Label errorLabel = new Label(); final Label uidLabel = new Label(); final Label usernameLabel = new Label(); final Label postsLabel = new Label(); final Label activityLabel = new Label(); final Label potActivityLabel = new Label(); final Label postQualityLabel = new Label(); final Label trustLabel = new Label(); final Label priceLabel = new Label(); final Label loadingLabel = new Label(); final Label tokenLabel = new Label(); final InlineHTML estimateShareLabel = new InlineHTML(); final InlineHTML reportTimeStamp = new InlineHTML(); final RadioButton radioNormal = new RadioButton("merch", "Normal"); final RadioButton radioMerchant = new RadioButton("merch", "Merchant"); // We can add style names to widgets sendButton.addStyleName("sendButton"); radioNormal.setValue(true); radioMerchant.setValue(false); // 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); RootPanel.get("uidLabelContainer").add(uidLabel); RootPanel.get("usernameLabelContainer").add(usernameLabel); RootPanel.get("postsLabelContainer").add(postsLabel); RootPanel.get("activityLabelContainer").add(activityLabel); RootPanel.get("potActivityLabelContainer").add(potActivityLabel); RootPanel.get("postQualityLabelContainer").add(postQualityLabel); RootPanel.get("trustLabelContainer").add(trustLabel); RootPanel.get("priceLabelContainer").add(priceLabel); RootPanel.get("loadingLabelContainer").add(loadingLabel); RootPanel.get("tokenLabelContainer").add(tokenLabel); RootPanel.get("tokenShareLabelContainer").add(estimateShareLabel); RootPanel.get("radioNormalContainer").add(radioNormal); RootPanel.get("radioMerchantContainer").add(radioMerchant); RootPanel.get("reportTimeStamp").add(reportTimeStamp); // Create activity breakdown panel final VerticalPanel actPanel = new VerticalPanel(); final FlexTable actTable = new FlexTable(); actPanel.add(actTable); RootPanel.get("activityBreakdown").add(actPanel); // Create posts breakdown panel final VerticalPanel postsPanel = new VerticalPanel(); final FlexTable postsTable = new FlexTable(); postsPanel.add(postsTable); RootPanel.get("postsBreakdown").add(postsPanel); // Create addresses breakdown panel final VerticalPanel addrPanel = new VerticalPanel(); final FlexTable addrTable = new FlexTable(); postsPanel.add(addrTable); RootPanel.get("addrBreakdown").add(addrTable); // Focus the cursor on the name field when the app loads nameField.setFocus(true); nameField.selectAll(); // 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) { // Add request to queue addToQueue(); } /** * Fired when the user types in the nameField. */ public void onKeyUp(KeyUpEvent event) { if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER) { addToQueue(); } } // Adds the request to server queue private void addToQueue() { // Clear previous output uidLabel.setText(""); usernameLabel.setText(""); postsLabel.setText(""); activityLabel.setText(""); potActivityLabel.setText(""); postQualityLabel.setText(""); trustLabel.setText(""); priceLabel.setText(""); sendButton.setEnabled(false); errorLabel.setText(""); loadingLabel.setText(""); tokenLabel.setText(""); estimateShareLabel.setText(""); reportTimeStamp.setText(""); actTable.removeAllRows(); postsTable.removeAllRows(); addrTable.removeAllRows(); // Create and add request request = new QueueRequest(); request.setMerchant(radioMerchant.getValue()); if (nameField.getText().matches("^[0-9]+$")) request.setUid(Integer.parseInt(escapeHtml(nameField.getText()))); else { request.setToken(escapeHtml(nameField.getText())); request.setOldReq(); } final String urlPath = com.google.gwt.user.client.Window.Location.getPath(); final String host = com.google.gwt.user.client.Window.Location.getHost(); final String protocol = com.google.gwt.user.client.Window.Location.getProtocol(); final String url = protocol + "//" + host + urlPath + "?token="; // Request check loop Timer requestTimer = new Timer() { public void run() { // send request to server pricingService.queueServer(request, new AsyncCallback<QueueRequest>() { @Override public void onFailure(Throwable caught) { errorLabel.setText("Request Queuing failed. Please try again."); sendButton.setEnabled(true); pricingService.removeRequest(request, null); cancel(); } @Override public void onSuccess(QueueRequest result) { if (result.getQueuePos() == -3) { loadingLabel.setText( "Please wait for your previous request to finish and try again"); sendButton.setEnabled(true); cancel(); } else if (result.getQueuePos() == -2) { loadingLabel.setText("Please wait 2 minutes before requesting again."); sendButton.setEnabled(true); cancel(); } else if (result.getQueuePos() == -4) { loadingLabel.setText("Invalid token"); sendButton.setEnabled(true); cancel(); } else { tokenLabel.setText("Your token is " + result.getToken()); estimateShareLabel.setHTML("Share this estimate: <a href=\"" + url + result.getToken() + "\">" + url + result.getToken() + "</a>"); if (!result.isProcessing() && !result.isDone()) { loadingLabel.setText("Please wait. You are number " + result.getQueuePos() + " in the queue."); } if (result.isProcessing()) { loadingLabel.setText("Request is processing. Please wait."); } if (result.isDone()) { // Clear other messages errorLabel.setText(""); loadingLabel.setText(""); // Output results uidLabel.setText(result.getResult()[0]); usernameLabel.setText(result.getResult()[1]); postsLabel.setText(result.getResult()[2]); activityLabel.setText(result.getResult()[3]); potActivityLabel.setText(result.getResult()[4]); postQualityLabel.setText(result.getResult()[5]); trustLabel.setText(result.getResult()[6]); priceLabel.setText(result.getResult()[7]); int indexOfLastAct = 0; int startAddrIndex = 0; for (int i = 8; i < result.getResult().length; i++) { if (result.getResult()[i].equals("<b>Post Sections Breakdown</b>")) { indexOfLastAct = i; break; } actTable.setHTML(i - 8, 0, result.getResult()[i]); } for (int i = indexOfLastAct; i < result.getResult().length; i++) { if (result.getResult()[i] .contains("<b>Addresses posted in non-quoted text</b>")) { startAddrIndex = i; break; } postsTable.setHTML(i - indexOfLastAct, 0, result.getResult()[i]); } if (!result.isMerchant()) { for (int i = startAddrIndex; i < result.getResult().length; i++) { addrTable.setHTML(i - startAddrIndex, 0, result.getResult()[i]); } } // Set the right radio radioMerchant.setValue(result.isMerchant()); radioNormal.setValue(!result.isMerchant()); // Report the time stamp DateTimeFormat fmt = DateTimeFormat.getFormat("MMMM dd, yyyy, hh:mm:ss a"); Date completedDate = new Date(1000L * result.getCompletedTime()); Date expireDate = new Date( 1000L * (result.getCompletedTime() + result.getExpirationTime())); reportTimeStamp .setHTML("<i>Report generated at " + fmt.format(completedDate) + " and expires at " + fmt.format(expireDate) + "</i>"); // Kill the timer after everything is done cancel(); } request = result; request.setPoll(true); sendButton.setEnabled(true); } } }); } }; requestTimer.scheduleRepeating(2000); } } // Add a handler to send the name to the server MyHandler handler = new MyHandler(); sendButton.addClickHandler(handler); nameField.addKeyUpHandler(handler); // Check the URL for URL parameters String urlTokenParam = com.google.gwt.user.client.Window.Location.getParameter("token"); if (!urlTokenParam.isEmpty()) { nameField.setText(urlTokenParam); handler.addToQueue(); } }
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();/*from w w w . jav a 2s .c o m*/ timer = null; } //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.arcbees.facebook.client.JavaScriptFacebook.java
License:Apache License
@Override public void injectFacebookApi(final FacebookCallback facebookCallback) { String locale = "en_US"; // get the correct locale from meta tag gwt:property facebooklocale final NodeList<Element> metas = Document.get().getElementsByTagName("meta"); for (int i = 0; i < metas.getLength(); i++) { final MetaElement m = MetaElement.as(metas.getItem(i)); if ("gwt:property".equals(m.getName())) { String content = m.getContent(); if (content.contains("facebooklocale")) { locale = content.replaceFirst(".*\\=", "").trim(); }/*from ww w.j ava2s .co m*/ } } Element firstElement = Document.get().getBody().getFirstChildElement(); Element fbRoot = Document.get().createDivElement(); fbRoot.setId(FB_ROOT); firstElement.getParentNode().insertBefore(fbRoot, firstElement); ScriptElement fbScript = Document.get().createScriptElement(); fbScript.setSrc(FB_SCRIPT_SRC1 + locale + FB_SCRIPT_SRC2); fbScript.setType(FB_SCRIPT_TYPE); fbRoot.getParentNode().insertAfter(fbScript, fbRoot); Timer ensureFbIsLoaded = new Timer() { @Override public void run() { if (isLoaded()) { facebookCallback.onSuccess(); cancel(); } } }; ensureFbIsLoaded.scheduleRepeating(100); }
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/* w w w . j ava 2 s.c o m*/ public void removeHandler() { checkForEventsTimer.cancel(); scrollHandler.removeHandler(); resizeHandler.removeHandler(); if (mutationHandler != null) { mutationHandler.disconnect(); } } }; } refreshScrollEvents(); }