List of usage examples for com.google.gwt.user.client Timer schedule
public synchronized void schedule(int delayMs)
From source file:com.kk_electronic.kkportal.timereg.model.TimeServiceMock.java
License:Open Source License
@Override public void get(Long begin, Long end, final AsyncCallback<List<TimeEntry>> callback) { Timer t = new Timer() { @Override//from w ww . j av a 2s . c o m public void run() { callback.onSuccess(entries); } }; t.schedule(1000); }
From source file:com.koobe.editor.admin.client.application.ApplicationView.java
License:Apache License
@Override public void showLoading(final boolean visibile) { Timer timer = new Timer() { public void run() { loadingPanel.setVisible(visibile); }//from w w w .j a va 2 s . c o m }; timer.schedule(visibile ? 0 : 500); }
From source file:com.mclub.client.app.LoginDialog.java
License:GNU General Public License
/** * Login icin server a danisilir, asenkron programlamada sonucun gelmesi beklenemez * fakat bu kisimda bu lazim, bu yuzden timer ile 1 saniye kadar beklendikten sonra * devam ediliyor/*from w w w . j av a2 s .c o m*/ * */ protected void onSubmit() { status.show(); UserController.login(userName.getValue(), password.getValue()); Timer t = new Timer() { @Override public void run() { status.hide(); login.enable(); AppController.fireEvent(new Event(SpecialEvent.Login)); } }; t.schedule(1000); login.enable(); }
From source file:com.mecatran.otp.gwt.client.view.ItineraryDetailsWidget.java
License:Open Source License
/** * Build the background image for the widget, according to the mode. Draw * the mode image and a solid line below it with the route color (if in * transit mode) or a dotted line (if in road mode). Set the * background-image to the generated image for the given widget. *///w w w .ja v a2s. c o m public static void styleComponentWithMode(final Widget widget, TransportMode mode, String color) { PlannerResources resources = PlannerResources.INSTANCE; ImageResource baseImage = null; boolean road = false; switch (mode) { case WALK: road = true; color = "#666666"; baseImage = resources.modeWalkPng(); break; case BICYCLE: road = true; color = "#23C30B"; baseImage = resources.modeBicyclePng(); break; case BICYCLE_RENTAL: road = true; color = "#23C30B"; baseImage = resources.modeBikeRentalPng(); break; case CAR: road = true; color = "#333333"; baseImage = resources.modeCarPng(); break; default: case BUS: baseImage = resources.modeBusPng(); break; case TRAM: baseImage = resources.modeTramPng(); break; case FERRY: baseImage = resources.modeFerryPng(); break; case GONDOLA: baseImage = resources.modeGondolaPng(); break; case PLANE: baseImage = resources.modePlanePng(); break; case RAIL: baseImage = resources.modeRailPng(); break; case SUBWAY: baseImage = resources.modeSubwayPng(); break; case TROLLEY: baseImage = resources.modeTrolleyPng(); break; } final String url = baseImage.getSafeUri().asString(); final Canvas canvas = Canvas.createIfSupported(); if (canvas != null) { int width = baseImage.getWidth(); int height = 1000; canvas.setCoordinateSpaceWidth(width); canvas.setCoordinateSpaceHeight(height); final Context2d context = canvas.getContext2d(); context.setLineCap(LineCap.BUTT); if (road) { context.setStrokeStyle(CssColor.make(color)); context.setLineWidth(4); for (int y = baseImage.getHeight(); y < 1000; y += 7) { context.moveTo(width / 2, y); context.lineTo(width / 2, y + 5); } context.stroke(); } else { context.setStrokeStyle(CssColor.make("#000000")); context.setLineWidth(5); context.moveTo(width / 2, 0); context.lineTo(width / 2, height - 1); context.stroke(); context.setStrokeStyle(CssColor.make(color)); context.setLineWidth(4); context.moveTo(width / 2, 0); context.lineTo(width / 2, height - 1); context.stroke(); } /* * HACK ALERT! Image.onLoad event does not fire up when using * internal resources (URL is internal data), but using the image * immediately does not work (image does not seems to be ready). We * defer the processing of the image rendering to a timer delayed a * bit. */ Timer timer = new Timer() { @Override public void run() { Image image = new Image(url); ImageElement e = ImageElement.as(image.getElement()); context.drawImage(e, 0, 0); String url2 = canvas.toDataUrl("image/png"); widget.getElement().getStyle().setBackgroundImage("url('" + url2 + "')"); } }; timer.schedule(500); } else { widget.getElement().getStyle().setBackgroundImage("url('" + url + "')"); } }
From source file:com.mg.search.client.application.map.service.AStarSearchService.java
License:Open Source License
public Timer findPath(final boolean[][] m, final int starti, final int startj, final int desti, final int destj, final FindPathCallback callback) { final List<Square> openList = new ArrayList<Square>(); final List<Square> closedList = new ArrayList<Square>(); Square startSquare = new Square(starti, startj); startSquare.setHcost(hcost(starti, startj, desti, destj)); openList.add(startSquare);/*from w ww .j av a2 s . c o m*/ final int straightDistance = 10; final int diagonalDistance = 14; Timer timer = new Timer() { @Override public void run() { if (openList.size() == 0) { // there are no more nodes to investigate, no path to the destination was found callback.onPathNotFound(); return; } // Sort the elements of the open list after the lowest cost of the squares Collections.sort(openList, new Comparator<Square>() { @Override public int compare(Square arg0, Square arg1) { int arg0Cost = arg0.getGcost() + arg0.getHcost(); int arg1Cost = arg1.getGcost() + arg1.getHcost(); if (arg0Cost > arg1Cost) { return 1; } else if (arg0Cost < arg1Cost) { return -1; } return 0; } }); Square currentSquare = openList.get(0); if (callback != null) { callback.onSquareAddedToClosedList(currentSquare); } // switch currentSquare from openList to closeList openList.remove(0); closedList.add(currentSquare); if (currentSquare.getI() == desti && currentSquare.getJ() == destj) { // path to the destination was found callback.onPathFound(buildPath(currentSquare)); return; } // retrieve the adjacent nodes and add them to the open list // . . . // . x . // . . . if (currentSquare.getJ() > 0) { if (currentSquare.getI() > 0) { if (m[currentSquare.getI() - 1][currentSquare.getJ()] != true && m[currentSquare.getI()][currentSquare.getJ() - 1] != true) { // avoid doing diagonal steps next to the obtactles (when going upwards-back on // the // diagonal) // . | // | x addToOpenList(openList, closedList, m, currentSquare, currentSquare.getI() - 1, currentSquare.getJ() - 1, diagonalDistance, desti, destj, callback); } } addToOpenList(openList, closedList, m, currentSquare, currentSquare.getI(), currentSquare.getJ() - 1, straightDistance, desti, destj, callback); if (currentSquare.getI() < m.length - 1) { if (m[currentSquare.getI() + 1][currentSquare.getJ()] != true && m[currentSquare.getI()][currentSquare.getJ() - 1] != true) { addToOpenList(openList, closedList, m, currentSquare, currentSquare.getI() + 1, currentSquare.getJ() - 1, diagonalDistance, desti, destj, callback); } } } if (currentSquare.getI() > 0) { addToOpenList(openList, closedList, m, currentSquare, currentSquare.getI() - 1, currentSquare.getJ(), straightDistance, desti, destj, callback); } if (currentSquare.getI() < m.length - 1) { addToOpenList(openList, closedList, m, currentSquare, currentSquare.getI() + 1, currentSquare.getJ(), straightDistance, desti, destj, callback); } if (currentSquare.getJ() < m[0].length - 1) { if (currentSquare.getI() > 0) { if (m[currentSquare.getI() - 1][currentSquare.getJ()] != true && m[currentSquare.getI()][currentSquare.getJ() + 1] != true) { addToOpenList(openList, closedList, m, currentSquare, currentSquare.getI() - 1, currentSquare.getJ() + 1, diagonalDistance, desti, destj, callback); } } addToOpenList(openList, closedList, m, currentSquare, currentSquare.getI(), currentSquare.getJ() + 1, straightDistance, desti, destj, callback); if (currentSquare.getI() < m.length - 1) { if (m[currentSquare.getI() + 1][currentSquare.getJ()] != true && m[currentSquare.getI()][currentSquare.getJ() + 1] != true) { addToOpenList(openList, closedList, m, currentSquare, currentSquare.getI() + 1, currentSquare.getJ() + 1, diagonalDistance, desti, destj, callback); } } } this.schedule(speed); } }; timer.schedule(speed); return timer; }
From source file:com.moesol.gwt.maps.client.MapSingleClickDetector.java
License:Open Source License
public void bind() { if (bound) {//from ww w. j ava2 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.msco.mil.client.com.sencha.gxt.explorer.client.grid.PagingGridUiBinderExample.java
License:sencha.com license
@Override public Widget asWidget() { final ExampleServiceAsync service = GWT.create(ExampleService.class); RpcProxy<PagingLoadConfig, PagingLoadResult<Post>> proxy = new RpcProxy<PagingLoadConfig, PagingLoadResult<Post>>() { @Override/*from w ww.j ava2 s . co m*/ public void load(PagingLoadConfig loadConfig, AsyncCallback<PagingLoadResult<Post>> callback) { service.getPosts(loadConfig, callback); } }; PostProperties props = GWT.create(PostProperties.class); store = new ListStore<Post>(new ModelKeyProvider<Post>() { @Override public String getKey(Post item) { return "" + item.getId(); } }); final PagingLoader<PagingLoadConfig, PagingLoadResult<Post>> loader = new PagingLoader<PagingLoadConfig, PagingLoadResult<Post>>( proxy); loader.setRemoteSort(true); loader.addLoadHandler( new LoadResultListStoreBinding<PagingLoadConfig, Post, PagingLoadResult<Post>>(store)); ColumnConfig<Post, String> forumColumn = new ColumnConfig<Post, String>(props.forum(), 150, "Forum"); ColumnConfig<Post, String> usernameColumn = new ColumnConfig<Post, String>(props.username(), 150, "Username"); ColumnConfig<Post, String> subjectColumn = new ColumnConfig<Post, String>(props.subject(), 150, "Subject"); ColumnConfig<Post, Date> dateColumn = new ColumnConfig<Post, Date>(props.date(), 150, "Date"); dateColumn.setCell(new DateCell(DateTimeFormat.getFormat(PredefinedFormat.DATE_SHORT))); List<ColumnConfig<Post, ?>> l = new ArrayList<ColumnConfig<Post, ?>>(); l.add(forumColumn); l.add(usernameColumn); l.add(subjectColumn); l.add(dateColumn); cm = new ColumnModel<Post>(l); Widget component = uiBinder.createAndBindUi(this); grid.setLoader(loader); Timer t = new Timer() { @Override public void run() { loader.load(); } }; t.schedule(100); toolBar.getElement().getStyle().setProperty("borderBottom", "none"); toolBar.bind(loader); return component; }
From source file:com.msco.mil.client.com.sencha.gxt.explorer.client.window.MessageBoxExample.java
License:sencha.com license
public Widget asWidget() { final HideHandler hideHandler = new HideHandler() { @Override/*ww w . ja va2s.c o m*/ public void onHide(HideEvent event) { Dialog btn = (Dialog) event.getSource(); String msg = Format.substitute("The '{0}' button was pressed", btn.getHideButton().getText()); Info.display("MessageBox", msg); } }; final ButtonBar buttonBar = new ButtonBar(); buttonBar.setMinButtonWidth(75); buttonBar.getElement().setMargins(10); TextButton b = new TextButton("Confirm"); b.addSelectHandler(new SelectHandler() { @Override public void onSelect(SelectEvent event) { ConfirmMessageBox box = new ConfirmMessageBox("Confirm", "Are you sure you want to do that?"); box.addHideHandler(hideHandler); box.show(); } }); buttonBar.add(b); b = new TextButton("Prompt"); b.addSelectHandler(new SelectHandler() { @Override public void onSelect(SelectEvent event) { final PromptMessageBox box = new PromptMessageBox("Name", "Please enter your name:"); box.addHideHandler(new HideHandler() { @Override public void onHide(HideEvent event) { Info.display("MessageBox", "You entered " + box.getValue()); } }); box.show(); } }); buttonBar.add(b); b = new TextButton("Multiline Prompt"); b.addSelectHandler(new SelectHandler() { @Override public void onSelect(SelectEvent event) { final MultiLinePromptMessageBox box = new MultiLinePromptMessageBox("Address", "Please enter your address:"); box.addHideHandler(new HideHandler() { @Override public void onHide(HideEvent event) { String v = Format.ellipse(box.getValue(), 80); String msg = Format.substitute("You entered '{0}'", new Params(v)); Info.display("MessageBox", msg); } }); box.show(); } }); buttonBar.add(b); b = new TextButton("Yes/No/Cancel"); b.addSelectHandler(new SelectHandler() { @Override public void onSelect(SelectEvent event) { MessageBox box = new MessageBox("Save Changes?", ""); box.setPredefinedButtons(PredefinedButton.YES, PredefinedButton.NO, PredefinedButton.CANCEL); box.setIcon(MessageBox.ICONS.question()); box.setMessage( "You are closing a tab that has unsaved changes. Would you like to save your changes?"); box.addHideHandler(new HideHandler() { @Override public void onHide(HideEvent event) { Dialog btn = (Dialog) event.getSource(); String msg = Format.substitute("The '{0}' button was pressed", btn.getHideButton().getText()); Info.display("MessageBox", msg); } }); box.show(); } }); buttonBar.add(b); b = new TextButton("Progress"); b.addSelectHandler(new SelectHandler() { @Override public void onSelect(SelectEvent event) { final ProgressMessageBox box = new ProgressMessageBox("Please wait", "Loading items..."); box.setProgressText("Initializing..."); box.show(); final Timer t = new Timer() { float i; @Override public void run() { box.updateProgress(i / 100, "{0}% Complete"); i += 5; if (i > 100) { cancel(); Info.display("Message", "Items were loaded"); } } }; t.scheduleRepeating(500); } }); buttonBar.add(b); b = new TextButton("Wait"); b.addSelectHandler(new SelectHandler() { @Override public void onSelect(SelectEvent event) { final AutoProgressMessageBox box = new AutoProgressMessageBox("Progress", "Saving your data, please wait..."); box.setProgressText("Saving..."); box.auto(); box.show(); Timer t = new Timer() { @Override public void run() { Info.display("Message", "Your fake data was saved"); box.hide(); } }; t.schedule(5000); } }); buttonBar.add(b); b = new TextButton("Alert"); b.addSelectHandler(new SelectHandler() { @Override public void onSelect(SelectEvent event) { AlertMessageBox d = new AlertMessageBox("Alert", "Access Denied"); d.addHideHandler(hideHandler); d.show(); } }); buttonBar.add(b); return buttonBar; }
From source file:com.nitrous.gwt.earth.client.demo.MoveCameraWithTimerDemo.java
License:Apache License
private void moveCamera(final int count) { GEPlugin ge = earth.getGEPlugin();//w ww. java 2s . c om KmlLookAt lookAt = ge.getView().copyAsLookAt(KmlAltitudeMode.ALTITUDE_RELATIVE_TO_GROUND); lookAt.setLatitude(lookAt.getLatitude() + .1); lookAt.setLongitude(lookAt.getLongitude() + 5); ge.getView().setAbstractView(lookAt); if (count < 40) { // if we haven't already moved the camera 40 times // schedule the next movement in 50ms Timer t = new Timer() { @Override public void run() { moveCamera(count + 1); } }; t.schedule(50); } else { // Done moving the camera. // Restore old flyTo speed ge.getOptions().setFlyToSpeed(oldFlyToSpeed); } }
From source file:com.nitrous.gwt.earth.client.demo.MovingPlacemarkDemo.java
License:Apache License
/** * Display content on the map//from ww w . j ava2 s. c o m */ private void loadMapContent() { // The GEPlugin is the core class and is a great place to start browsing the API GEPlugin ge = earth.getGEPlugin(); ge.getWindow().setVisibility(true); // show some layers ge.enableLayer(GELayerId.LAYER_BUILDINGS, true); ge.enableLayer(GELayerId.LAYER_BORDERS, true); ge.enableLayer(GELayerId.LAYER_ROADS, true); ge.enableLayer(GELayerId.LAYER_TERRAIN, true); ge.enableLayer(GELayerId.LAYER_TREES, true); // show an over-view pane ge.getOptions().setOverviewMapVisibility(true); // plot a placemark final String placemarkId = "MyPlacemark1"; final KmlPlacemark placemark = ge.createPlacemark(placemarkId); KmlPoint kmlPoint = ge.createPoint(""); kmlPoint.setLatLng(34.73D, -86.59D); kmlPoint.setAltitudeMode(KmlAltitudeMode.ALTITUDE_CLAMP_TO_GROUND); placemark.setGeometry(kmlPoint); // configure a popup balloon for the placemark final GEHtmlStringBalloon balloon = ge.createHtmlStringBalloon("MyBalloon1"); balloon.setContentString("This is a test"); balloon.setFeature(placemark); ge.getFeatures().appendChild(placemark); // give the map 2 seconds to pan and then show the balloon Timer timer = new Timer() { @Override public void run() { earth.getGEPlugin().setBalloon(balloon); } }; timer.schedule(2000); // look at the placemark KmlLookAt lookAt = ge.getView().copyAsLookAt(KmlAltitudeMode.ALTITUDE_RELATIVE_TO_GROUND); lookAt.setLatitude(kmlPoint.getLatitude()); lookAt.setLongitude(kmlPoint.getLongitude()); lookAt.setRange(500000D); ge.getView().setAbstractView(lookAt); // move the placemark once every second Timer t = new Timer() { @Override public void run() { KmlObject obj = earth.getGEPlugin().getElementById(placemarkId); KmlPlacemark placemark = (KmlPlacemark) obj; KmlPoint point = (KmlPoint) placemark.getGeometry(); point.setLatitude(point.getLatitude() + .1D); } }; t.scheduleRepeating(1000); }