List of usage examples for com.google.gwt.user.client Timer Timer
Timer
From source file:$.ResizableMapLayout.java
License:Open Source License
/** * Create a resizable map layout for the given map. The map will be added to this layout. * /*from w w w. j a v a 2 s .c o m*/ * @param mapPresenter * The map to add. */ public ResizableMapLayout(final MapPresenter mapPresenter) { this.mapPresenter = mapPresenter; mapPresenter.getEventBus().addHandler(MapInitializationHandler.TYPE, new RedrawMapInitializationHandler()); layout = new ResizeLayoutPanel(); layout.setSize("100%", "100%"); layout.add(mapPresenter.asWidget()); // Add an automatic resize handler to set the correct size when the window resizes: Window.addResizeHandler(new ResizeHandler() { public void onResize(ResizeEvent event) { applySize(); } }); // Calculate the correct size on load: layout.addAttachHandler(new AttachEvent.Handler() { public void onAttachOrDetach(AttachEvent event) { Timer timer = new Timer() { @Override public void run() { if (!applySize()) { schedule(50); } } }; timer.run(); } }); }
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;//from w w w. ja va 2s . co 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:asquare.gwt.tkdemo.client.demos.DialogPanel.java
License:Apache License
private Widget createModalDialogDemo() { BasicPanel panel = new BasicPanel("div", "block"); panel.setStyleName("example division"); DomUtil.setStyleAttribute(panel, "whiteSpace", "nowrap"); panel.add(new HTML("<h4>ModalDialog examples</h4>")); class CloseListener implements ClickHandler { private final ModalDialog m_dialog; public CloseListener(ModalDialog dialog) { m_dialog = dialog;/*from w w w. jav a2 s .c o m*/ } public void onClick(ClickEvent event) { m_dialog.hide(); } } class CloseButton extends Button { public CloseButton(ModalDialog dialog) { super("Close"); addClickHandler(new CloseListener(dialog)); } public CloseButton(ModalDialog dialog, String text) { super(text); addClickHandler(new CloseListener(dialog)); } } final Button plainDialog = new Button("Plain"); plainDialog.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { final ModalDialog dialog = new ModalDialog(); dialog.setCaption("Caption area", false); dialog.add(new Label("Content area")); dialog.add(new CloseButton(dialog)); dialog.show(plainDialog); } }); panel.add(plainDialog); final Button verboseDialog = new Button("Verbose"); verboseDialog.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { final ModalDialog dialog = new ModalDialog(); dialog.setCaption("Verbose dialog", false); dialog.add(new Label("Twas brillig, and the slithy toves " + " Did gyre and gimble in the wabe: " + "All mimsy were the borogoves, " + " And the mome raths outgrabe " + "Beware the Jabberwock, my son! " + "The jaws that bite, the claws that catch! " + "Beware the Jubjub bird, and shun " + "The frumious Bandersnatch!")); dialog.add(new CloseButton(dialog)); dialog.show(verboseDialog); } }); panel.add(verboseDialog); final Button captionLessDialog = new Button("No caption"); captionLessDialog.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { final ModalDialog dialog = new ModalDialog(); dialog.add(new Label("Captionless dialog")); dialog.add(new CloseButton(dialog)); dialog.show(captionLessDialog); } }); panel.add(captionLessDialog); final Button loadingDialog = new Button("Loading..."); loadingDialog.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { final ModalDialog dialog = new ModalDialog(); final Label label = new Label("0% loaded"); dialog.add(label); dialog.show(loadingDialog); new Timer() { private int m_count = 0; public void run() { label.setText(++m_count + "% loaded"); if (m_count == 100) { dialog.hide(); cancel(); } } }.scheduleRepeating(1); } }); panel.add(loadingDialog); final Button undraggableDialog = new Button("Drag disabled"); undraggableDialog.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { final ModalDialog dialog = new ModalDialog() { protected List<Controller> createCaptionControllers() { List<Controller> result = new ArrayList<Controller>(); result.add(ControlSurfaceController.getInstance()); return result; } }; dialog.setCaption("Drag disabled", false); dialog.add(new Label( "This dialog uses a custom controller in the header which does not provide drag support.")); dialog.add(new CloseButton(dialog)); dialog.show(undraggableDialog); } }); panel.add(undraggableDialog); final Button styledDragDialog = new Button("Drag style"); styledDragDialog.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { final ModalDialog dialog = new ModalDialog(); String oldPrimaryName = dialog.getStylePrimaryName(); dialog.setStylePrimaryName("dialog-dragstyle"); dialog.addStyleName(oldPrimaryName); dialog.setCaption("Drag me", false); dialog.add(new Label( "This dialog employs the \"tk-ModalDialog-dragging\" style which is applied while dragging. ")); dialog.add(new CloseButton(dialog)); dialog.show(styledDragDialog); } }); panel.add(styledDragDialog); final Button focusManagementDialog = new Button("Focus management"); focusManagementDialog.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { final ModalDialog dialog = new ModalDialog(); dialog.setCaption("Register", false); FocusModel fModel = dialog.getFocusModel(); final int FIELD_COUNT = 3; Grid table = new Grid(FIELD_COUNT, 2); dialog.add(table); Widget[] labels = new Widget[FIELD_COUNT]; labels[0] = new Label("User name: "); labels[1] = new Label("Password: "); labels[2] = new Label("Retype password: "); FocusWidget[] fields = new FocusWidget[FIELD_COUNT]; fields[0] = new TextBox(); fields[1] = new PasswordTextBox(); fields[2] = new PasswordTextBox(); CellFormatter formatter = table.getCellFormatter(); for (int i = 0; i < labels.length; i++) { table.setWidget(i, 0, labels[i]); formatter.setHorizontalAlignment(i, 0, HasHorizontalAlignment.ALIGN_LEFT); table.setWidget(i, 1, fields[i]); /* * Manually add fields to focus cycle. (The dialog does not * scan the children of panels for focusable widgets.) */ fModel.add(fields[i]); } // this widget will be focused when the dialog is shown fModel.setFocusWidget(fields[0]); ColumnPanel buttonPanel = new ColumnPanel(); buttonPanel.setWidth("100%"); dialog.add(buttonPanel); Button closeButton = new CloseButton(dialog, "Register!"); fModel.add(closeButton); buttonPanel.add(closeButton); Button cancelButton = new CloseButton(dialog, "Cancel"); fModel.add(cancelButton); buttonPanel.addWidget(cancelButton, false); buttonPanel.setCellHorizontalAlignment(ColumnPanel.ALIGN_RIGHT); dialog.show(focusManagementDialog); } }); panel.add(focusManagementDialog); final Button explicitlyPositionedDialog = new Button("Explicitly positioned"); explicitlyPositionedDialog.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { final ModalDialog dialog = new ModalDialog(); dialog.removeController(dialog.getController(ModalDialog.PositionDialogController.class)); int contentWidth = 300; int contentHeight = 100; dialog.setContentWidth(contentWidth + "px"); dialog.setContentHeight(contentHeight + "px"); dialog.setPopupPosition(100, 100); dialog.setCaption("Explicitly positioned dialog", false); dialog.add(new Label( "Automatic positioning is disabled. Dimensions and position are set explicitly. ")); dialog.add(new CloseButton(dialog)); dialog.show(explicitlyPositionedDialog); } }); panel.add(explicitlyPositionedDialog); final Button multipleDialogs = new Button("Multiple dialogs"); multipleDialogs.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { ModalDialog dialog = new ModalDialog(); dialog.setCaption("First dialog", false); FocusModel fModel = dialog.getFocusModel(); RowPanel outer = new RowPanel(); dialog.add(new HTML("")); final UrlLocation urlBox = new UrlLocation(); urlBox.setText("http://www.asquare.net"); urlBox.setWidth("350px"); fModel.add(urlBox); outer.add(urlBox); Button goButton = new Button("Go"); fModel.add(goButton); fModel.setFocusWidget(goButton); outer.addWidget(goButton, false); ListBox addressList = new ListBox(); addressList.addItem("Select an address"); addressList.addItem("http://www.asquare.net"); addressList.addItem("http://www.google.com"); addressList.addItem("http://www.sourceforge.net"); addressList.addItem("http://www.apache.org"); fModel.add(addressList); outer.add(addressList); final Frame frame = new Frame(); frame.setSize("400px", "200px"); outer.add(frame); urlBox.addChangeHandler(new ChangeHandler() { public void onChange(ChangeEvent event) { frame.setUrl(urlBox.getURL()); } }); goButton.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { frame.setUrl(urlBox.getURL()); } }); addressList.addChangeHandler(new ChangeHandler() { public void onChange(ChangeEvent event) { ListBox list = (ListBox) event.getSource(); if (list.getSelectedIndex() > 0) { urlBox.setText(list.getItemText(list.getSelectedIndex())); frame.setUrl(list.getItemText(list.getSelectedIndex())); } } }); final Button secondDialog = new Button("Show second dialog"); secondDialog.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { final ModalDialog dialog = new ModalDialog(); dialog.setCaption("Second dialog", false); dialog.add(new Label("Note that you cannot manipulate the widgets in the first dialog. ")); dialog.add(new CloseButton(dialog)); dialog.show(secondDialog); } }); fModel.add(secondDialog); outer.add(secondDialog); Button closeButton = new CloseButton(dialog); fModel.add(closeButton); outer.add(closeButton); dialog.add(outer); dialog.show(multipleDialogs); } }); panel.add(multipleDialogs); final Button styledDialog = new Button("Styled"); styledDialog.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { final ModalDialog dialog = new ModalDialog(); dialog.addStyleName("dialog-styled"); HorizontalPanel caption = new HorizontalPanel(); caption.setWidth("100%"); Label captionText = new Label("Oopsie!"); caption.add(captionText); caption.setCellWidth(captionText, "100%"); Image close = new Image("close.gif"); close.addClickHandler(new CloseListener(dialog)); caption.add(close); dialog.setCaption(caption); dialog.add(new Label("I've been a bad, bad browser.")); dialog.add(new Button("Deny ice cream", new CloseListener(dialog))); dialog.show(styledDialog); } }); panel.add(styledDialog); return panel; }
From source file:at.ait.dme.yuma.client.map.annotation.AnnotationLayer.java
License:EUPL
public void showActiveFragmentPanel(ImageAnnotation annotation, boolean forceVisible) { if (editedFeature != null) hideActiveFragmentPanel();//from w w w .j a v a 2 s . co m if (annotation == null) { // New annotation -> enable toolbar if (currentDrawingTool != null) currentDrawingTool.activate(); } else { // Edit existing feature -> add to editing layer editedFeature = fragments.get(annotation); Timer t = new Timer() { @Override public void run() { lAnnotationEditing.addFeature(editedFeature); } }; t.schedule(1); modifyControl.activate(); modifyControl.selectFeature(editedFeature); } lAnnotationEditing.setVisibility(true); }
From source file:at.ait.dme.yuma.client.map.annotation.ControlPointLayer.java
License:EUPL
@Override public void showActiveFragmentPanel(ImageAnnotation annotation, boolean forceVisible) { // Stop editing any other annotation first if (editedFeature != null) hideActiveFragmentPanel();//from w ww.ja v a2 s. co m if (annotation == null) { editedFeature = VectorFeature.create( Point.create(mapComponent.getMap().getCenterLon(), mapComponent.getMap().getCenterLat())); } else { editedFeature = fragments.get(annotation); } Timer t = new Timer() { @Override public void run() { lAnnotationEditing.addFeature(editedFeature); } }; t.schedule(1); modifyControl.activate(); modifyControl.selectFeature(editedFeature); lAnnotationEditing.setVisibility(true); }
From source file:at.ait.dme.yuma.client.map.TiledImageComposite.java
License:EUPL
@SuppressWarnings("unchecked") private void generateTiles(final String url) { loadMask.hide();/* ww w.j a va2 s . co m*/ loadMask = new LoadMask("Generating Tiles..."); loadMask.show(); final ImageTilesetProviderServiceAsync tileService = (ImageTilesetProviderServiceAsync) GWT .create(ImageTilesetProviderService.class); tileService.generateTileset(url, new AsyncCallback() { public void onFailure(Throwable caught) { try { throw caught; } catch (Throwable t) { loadMask.hide(); ErrorMessages errorMessages = (ErrorMessages) GWT.create(ErrorMessages.class); MessageBox.error(errorMessages.error(), t.getMessage()); } } public void onSuccess(Object result) { Timer timer = new Timer() { public void run() { pollForTiles(url, this); } }; timer.schedule(1000); } }); }
From source file:at.ait.dme.yuma.suite.apps.map.client.TileBasedImageViewer.java
License:EUPL
@SuppressWarnings({ "unchecked", "rawtypes" }) private void startOnTheFlyTiler(final String url) { loadMask.hide();/*from ww w . j a va 2s .c o m*/ loadMask = new LoadingPopup("Generating Tiles..."); loadMask.show(); final TilesetServiceAsync tileService = (TilesetServiceAsync) GWT.create(TilesetService.class); tileService.startOnTheFlyTiler(url, new AsyncCallback() { public void onFailure(Throwable t) { loadMask.hide(); I18NErrorMessages errorMessages = (I18NErrorMessages) GWT.create(I18NErrorMessages.class); MessageBox.error(errorMessages.error(), t.getMessage()); } public void onSuccess(Object result) { Timer timer = new Timer() { public void run() { pollOnTheFlyTiler(url, this); } }; timer.schedule(1000); } }); }
From source file:be.progs.routeshare.client.MenuMapGadget.java
License:Open Source License
@Override public Widget asWidget() { if (menu == null) { menu = new RouteShareMenu(mapPresenter); // Stop propagation of mouse events to the map: menu.addDomHandler(new MouseDownHandler() { public void onMouseDown(MouseDownEvent event) { event.stopPropagation(); }//from w w w .j av a2 s . c o m }, MouseDownEvent.getType()); menu.addDomHandler(new ClickHandler() { public void onClick(ClickEvent event) { event.stopPropagation(); } }, ClickEvent.getType()); menu.addDomHandler(new MouseUpHandler() { public void onMouseUp(MouseUpEvent event) { event.stopPropagation(); } }, MouseUpEvent.getType()); menu.addDomHandler(new DoubleClickHandler() { public void onDoubleClick(DoubleClickEvent event) { event.stopPropagation(); } }, DoubleClickEvent.getType()); // Install a timer for automatic closing when the mouse leaves us: menu.addDomHandler(new MouseOutHandler() { public void onMouseOut(MouseOutEvent event) { if (menu.isOpen() && closeDelay > 0) { timer = new Timer() { public void run() { menu.setOpen(false); } }; timer.schedule(closeDelay); } } }, MouseOutEvent.getType()); menu.addDomHandler(new MouseOverHandler() { public void onMouseOver(MouseOverEvent event) { if (timer != null) { timer.cancel(); } } }, MouseOverEvent.getType()); } return menu; }
From source file:be.progs.routeshare.client.ResizableMapLayout.java
License:Open Source License
/** * Create a resizable map layout for the given map. The map will be added to this layout. * * @param mapPresenter The map to add./*from ww w. jav a 2s .c o m*/ */ public ResizableMapLayout(final MapPresenter mapPresenter) { this.mapPresenter = mapPresenter; mapPresenter.getEventBus().addHandler(MapInitializationHandler.TYPE, new RedrawMapInitializationHandler()); layout = new ResizeLayoutPanel(); layout.setSize("100%", "100%"); layout.add(mapPresenter.asWidget()); // Add an automatic resize handler to set the correct size when the window resizes: Window.addResizeHandler(new ResizeHandler() { @Override public void onResize(ResizeEvent event) { applySize(); } }); // Calculate the correct size on load: layout.addAttachHandler(new AttachEvent.Handler() { public void onAttachOrDetach(AttachEvent event) { Timer timer = new Timer() { @Override public void run() { if (!applySize()) { schedule(50); } } }; timer.run(); } }); }
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/* ww w . j av 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); }