List of usage examples for com.google.gwt.user.client.ui Button Button
public Button(String html, ClickHandler handler)
From source file:com.google.code.gwt.geolocation.sample.hellogeolocation.client.HelloGeolocation.java
License:Apache License
/** * This is the entry point method.//w w w .jav a 2 s .c o m */ public void onModuleLoad() { GWT.setUncaughtExceptionHandler(new UncaughtExceptionHandler() { public void onUncaughtException(Throwable e) { RootPanel.get().add(new Label("Uncaught exception: " + e)); } }); final VerticalPanel main = new VerticalPanel(); RootPanel.get().add(main); main.add(new Label("Geolocation provider: " + Geolocation.getProviderName())); //main.add(new Label("GWT strongname: " + GWT.getPermutationStrongName())); // GWT2.0! Label l1 = new Label("Obtaining Geolocation..."); main.add(l1); if (!Geolocation.isSupported()) { l1.setText("Obtaining Geolocation FAILED! Geolocation API is not supported."); return; } final Geolocation geo = Geolocation.getGeolocation(); if (geo == null) { l1.setText("Obtaining Geolocation FAILED! Object is null."); return; } l1.setText("Obtaining Geolocation DONE!"); main.add(new Button("Get Location", new ClickHandler() { public void onClick(ClickEvent event) { obtainPosition(main, geo); } })); obtainPosition(main, geo); }
From source file:com.google.code.gwt.storage.sample.hellostorage.client.HelloStorage.java
License:Apache License
/** * This is the entry point method./*from w w w . j a v a2s . c om*/ */ public void onModuleLoad() { VerticalPanel main = new VerticalPanel(); RootPanel.get().add(main); RootPanel.get().setWidgetPosition(main, 10, 10); eventArea = new TextArea(); eventArea.setStyleName("widePanel"); eventArea.setHeight("60px"); eventArea.setText("[StorageEvent info]"); main.add(eventArea); HorizontalPanel eventPanel = new HorizontalPanel(); eventPanel.setStyleName("widePanel"); main.add(eventPanel); handlersLabel = new Label("#Handlers: 0"); eventPanel.add(new Button("Add a Handler", new ClickHandler() { public void onClick(ClickEvent event) { StorageEventHandler handler = new MyHandler(handlers.size() + 1); handlers.add(handler); Storage.addStorageEventHandler(handler); handlersLabel.setText("#Handlers: " + handlers.size()); } })); eventPanel.add(new Button("Delete a Handler", new ClickHandler() { public void onClick(ClickEvent event) { if (handlers.size() > 0) { StorageEventHandler handler = handlers.remove(handlers.size() - 1); Storage.removeStorageEventHandler(handler); handlersLabel.setText("#Handlers: " + handlers.size()); } } })); eventPanel.add(handlersLabel); eventPanel.setCellHorizontalAlignment(handlersLabel, HasHorizontalAlignment.ALIGN_RIGHT); if (!Storage.isLocalStorageSupported() && !Storage.isSessionStorageSupported()) { Window.alert("Web Storage NOT supported in this browser!"); return; } Storage local = Storage.getLocalStorage(); Storage session = Storage.getSessionStorage(); TabPanel tabs = new TabPanel(); main.add(tabs); tabs.add(createStorageTab(local, Storage.isLocalStorageSupported()), "localStorage"); tabs.add(createStorageTab(session, Storage.isSessionStorageSupported()), "sessionStorage"); tabs.selectTab(0); }
From source file:com.google.code.gwt.storage.sample.hellostorage.client.HelloStorage.java
License:Apache License
private Widget createStorageTab(final Storage storage, final boolean isSupported) { VerticalPanel p = new VerticalPanel(); if (isSupported) { HorizontalPanel hp = new HorizontalPanel(); p.add(hp);//from www . ja va 2s . co m hp.add(new Label("key:")); final TextBox keyInput = new TextBox(); hp.add(keyInput); hp.add(new Label("data:")); final TextBox dataInput = new TextBox(); hp.add(dataInput); final Grid grid = new Grid(); grid.setCellPadding(5); grid.setBorderWidth(1); renderGrid(grid, storage); hp.add(new Button("Put in storage", new ClickHandler() { public void onClick(ClickEvent event) { storage.setItem(keyInput.getText(), dataInput.getText()); renderGrid(grid, storage); } })); p.add(new Button("Clear storage", new ClickHandler() { public void onClick(ClickEvent event) { storage.clear(); renderGrid(grid, storage); } })); p.add(grid); } else { p.add(new Label("This Storage is NOT supported in this browser.")); } return p; }
From source file:com.google.gwt.demos.bulkloadingtable.client.BulkLoadingTableDemo.java
License:Apache License
public void onModuleLoad() { panel = new VerticalPanel(); RootPanel.get().add(panel);/*w ww. j av a2 s .co m*/ panel.add( new HTML("<h2>A very boring demo showing the speed difference of using bulk loading tables.</h2>")); panel.add(new Label("Number of rows")); final TextBox rows = new TextBox(); panel.add(rows); rows.setText(numRows + ""); rows.addChangeListener(new ChangeListener() { public void onChange(Widget sender) { numRows = Integer.parseInt(rows.getText().trim()); } }); panel.add(new Label("Number of columns")); final TextBox columns = new TextBox(); panel.add(columns); columns.addChangeListener(new ChangeListener() { public void onChange(Widget sender) { numColumns = Integer.parseInt(columns.getText()); } }); columns.setText(numColumns + ""); panel.add(new HTML( "<p/><p/><b>Clear Table now </b> (clearing will also happen if the buttons are clicked below)")); panel.add(new Button("Go", new ClickListener() { public void onClick(Widget sender) { clearTable(); } })); panel.add(new HTML("<p/><p/><b> Use the traditional FlexTable API</b>")); Button flexTableAPI = new Button("Go", new ClickListener() { public void onClick(Widget sender) { clearTable(); long milli = System.currentTimeMillis(); FlexTable newTable = new FlexTable(); usingFlexTableAPI(newTable); finishTable(newTable, milli); } }); panel.add(flexTableAPI); panel.add(new HTML("<p/><p/><b> Use the traditional Grid API</b>")); Button gridAPI = new Button("Go", new ClickListener() { public void onClick(Widget sender) { clearTable(); long milli = System.currentTimeMillis(); Grid newTable = new Grid(); usingGridAPI(newTable); finishTable(newTable, milli); } }); panel.add(gridAPI); panel.add(new HTML("<p/><p/><b> Use the attached Grid API</b>")); Button detachedGridAPI = new Button("Go", new ClickListener() { public void onClick(Widget sender) { clearTable(); long milli = System.currentTimeMillis(); Grid table = new Grid(); curTable = table; table.setBorderWidth(2); panel.add(table); usingGridAPI(table); log("Finished in " + (System.currentTimeMillis() - milli) + " milliseconds"); } }); panel.add(detachedGridAPI); panel.add(new HTML("<p/><p/><b> Use Async BulkLoadedTable API</b>")); Button asyncAPI = new Button("Go", new ClickListener() { public void onClick(Widget sender) { clearTable(); long milli = System.currentTimeMillis(); FlexTable table = new FlexTable(); usingBulkLoadedTableAPI(table, milli); } }); panel.add(asyncAPI); panel.add(new HTML("<p/><p/><b> Use the PreloadedTable API</b>")); Button pendingAPI = new Button("Go", new ClickListener() { public void onClick(Widget sender) { clearTable(); long milli = System.currentTimeMillis(); PreloadedTable table = new PreloadedTable(); usingPreloadedTableAPI(table); finishTable(table, milli); } }); panel.add(pendingAPI); }
From source file:com.google.gwt.demos.fasttree.client.FastTreeDemo.java
License:Apache License
protected Widget profileTree() { final FlexTable table = new FlexTable(); final TextBox branches = new TextBox(); int row = 0;/* w w w .j a v a2 s. c o m*/ table.setText(row, 0, "children per node"); table.setText(row, 1, "total number of rows"); table.setText(row, 2, "what type of node"); ++row; table.setWidget(row, 0, branches); branches.setText("5"); final TextBox nodes = new TextBox(); table.setWidget(row, 1, nodes); nodes.setText("2000"); table.setTitle("Number of nodes"); final ListBox type = new ListBox(); type.addItem("Text"); type.addItem("HTML"); type.addItem("CheckBox"); type.setSelectedIndex(1); table.setWidget(row, 2, type); ++row; final int widgetRow = row + 1; table.setWidget(row, 0, new Button("Normal tree", new ClickListener() { public void onClick(Widget sender) { long time = System.currentTimeMillis(); Tree t = new Tree(); profileCreateTree(t, Integer.parseInt(branches.getText()), Integer.parseInt(nodes.getText()), TreeType.getType(type.getSelectedIndex())); table.setWidget(widgetRow, 0, t); Window.alert("Elapsed time: " + (System.currentTimeMillis() - time)); } })); table.setWidget(row, 1, new Button("Fast tree", new ClickListener() { public void onClick(Widget sender) { long time = System.currentTimeMillis(); FastTree t = new FastTree(); profileCreateTree(t, Integer.parseInt(branches.getText()), Integer.parseInt(nodes.getText()), TreeType.getType(type.getSelectedIndex())); table.setWidget(widgetRow, 1, t); Window.alert("Elapsed time: " + (System.currentTimeMillis() - time)); } })); ++row; table.setText(row, 0, "tree results"); table.getCellFormatter().setVerticalAlignment(row, 0, HasAlignment.ALIGN_TOP); table.setText(row, 1, "fasttree results"); table.getCellFormatter().setVerticalAlignment(row, 1, HasAlignment.ALIGN_TOP); return table; }
From source file:com.google.gwt.demos.progressbar.client.ProgressBarDemo.java
License:Apache License
/** * This is the entry point method./* w w w . jav a2 s. c o m*/ */ public void onModuleLoad() { // Setup the progress bars exampleBar2.setTextVisible(false); exampleBar2.addStyleName("gwt-ProgressBar-thin"); // Place everything in a nice looking grid Grid grid = new Grid(7, 3); grid.setBorderWidth(1); grid.setCellPadding(3); // Set the current progress final TextBox curBox = new TextBox(); curBox.setText("0.0"); grid.setWidget(0, 1, curBox); grid.setHTML(0, 2, "The current progress."); grid.setWidget(0, 0, new Button("Set Progress", new ClickListener() { public void onClick(Widget sender) { simulationTimer.cancel(); mainProgressBar.setProgress(new Float(curBox.getText()).floatValue()); } })); // Set the minimum progress final TextBox minBox = new TextBox(); minBox.setText(mainProgressBar.getMinProgress() + ""); grid.setWidget(1, 1, minBox); grid.setHTML(1, 2, "The minimum progress progress."); grid.setWidget(1, 0, new Button("Set Min Progress", new ClickListener() { public void onClick(Widget sender) { simulationTimer.cancel(); mainProgressBar.setMinProgress(new Float(minBox.getText()).floatValue()); } })); // Set the maximum progress final TextBox maxBox = new TextBox(); maxBox.setText(mainProgressBar.getMaxProgress() + ""); grid.setWidget(2, 1, maxBox); grid.setHTML(2, 2, "The maximum progress."); grid.setWidget(2, 0, new Button("Set Max Progress", new ClickListener() { public void onClick(Widget sender) { simulationTimer.cancel(); mainProgressBar.setMaxProgress(new Float(maxBox.getText()).floatValue()); } })); // Show or hide the text final HTML textVisibleLabel = new HTML("visible"); grid.setWidget(3, 1, textVisibleLabel); grid.setHTML(3, 2, "Show or hide the text in the progress bar."); grid.setWidget(3, 0, new Button("Toggle Text", new ClickListener() { public void onClick(Widget sender) { if (mainProgressBar.isTextVisible()) { textVisibleLabel.setHTML("hidden"); mainProgressBar.setTextVisible(false); } else { textVisibleLabel.setHTML("visible"); mainProgressBar.setTextVisible(true); } } })); // Add the default text option final HTML defaultTextLabel = new HTML("custom"); grid.setWidget(4, 1, defaultTextLabel); grid.setHTML(4, 2, "Override the format of the text with a custom" + "format."); grid.setWidget(4, 0, new Button("Toggle Custom Text", new ClickListener() { public void onClick(Widget sender) { if (useCustomText) { defaultTextLabel.setHTML("default"); useCustomText = false; mainProgressBar.setProgress(mainProgressBar.getProgress()); } else { defaultTextLabel.setHTML("custom"); useCustomText = true; mainProgressBar.setProgress(mainProgressBar.getProgress()); } } })); // Add static resize timer methods final HTML resizeCheckLabel = new HTML("enabled"); grid.setWidget(5, 1, resizeCheckLabel); grid.setHTML(5, 2, "When resize checking is enabled, a Timer will " + "periodically check if the Widget's dimensions have changed. If " + "they change, the widget will be redrawn."); grid.setWidget(5, 0, new Button("Toggle Resize Checking", new ClickListener() { public void onClick(Widget sender) { if (ResizableWidgetCollection.get().isResizeCheckingEnabled()) { ResizableWidgetCollection.get().setResizeCheckingEnabled(false); resizeCheckLabel.setHTML("disabled"); } else { ResizableWidgetCollection.get().setResizeCheckingEnabled(true); resizeCheckLabel.setHTML("enabled"); } } })); // Create a form to set width of element final TextBox widthBox = new TextBox(); widthBox.setText("50%"); grid.setWidget(6, 1, widthBox); grid.setHTML(6, 2, "Set the width of the widget. Use this to see how " + "resize checking detects the new dimensions and redraws the widget."); grid.setWidget(6, 0, new Button("Set Width", new ClickListener() { public void onClick(Widget sender) { mainProgressBar.setWidth(widthBox.getText()); } })); // Add all components to the page RootPanel.get().add(mainProgressBar); RootPanel.get().add(new HTML("<BR>")); RootPanel.get().add(grid); RootPanel.get().add(new HTML("<BR>Additional Progress Bars:<BR>")); RootPanel.get().add(exampleBar1); RootPanel.get().add(new HTML("<BR>")); RootPanel.get().add(exampleBar2); // Simulate progress over time simulateProgress(); }
From source file:com.google.gwt.demos.sliderbar.client.SliderBarDemo.java
License:Apache License
/** * This is the entry point method./*from w ww . ja va 2s.c om*/ */ public void onModuleLoad() { // TextBox to display or set current value final TextBox curBox = new TextBox(); // Setup the slider bars mainSliderBar.setStepSize(5.0); mainSliderBar.setCurrentValue(50.0); mainSliderBar.setNumTicks(10); mainSliderBar.setNumLabels(5); mainSliderBar.addChangeListener(new ChangeListener() { public void onChange(Widget sender) { curBox.setText(mainSliderBar.getCurrentValue() + ""); } }); exampleBar1.setStepSize(0.1); exampleBar1.setCurrentValue(0.5); exampleBar1.setNumTicks(10); exampleBar1.setNumLabels(10); exampleBar2.setStepSize(1.0); exampleBar2.setCurrentValue(13.0); exampleBar2.setNumTicks(25); exampleBar2.setNumLabels(25); // Place everything in a nice looking grid Grid grid = new Grid(9, 3); grid.setBorderWidth(1); grid.setCellPadding(3); // The type of text to display final HTML defaultTextLabel = new HTML("custom"); // Set the current slider position curBox.setText("50.0"); grid.setWidget(0, 1, curBox); grid.setHTML(0, 2, "The current value of the knob."); grid.setWidget(0, 0, new Button("Set Current Value", new ClickListener() { public void onClick(Widget sender) { mainSliderBar.setCurrentValue(new Float(curBox.getText()).floatValue()); } })); // Set the minimum value final TextBox minBox = new TextBox(); minBox.setText("0.0"); grid.setWidget(1, 1, minBox); grid.setHTML(1, 2, "The lower bounds (minimum) of the range."); grid.setWidget(1, 0, new Button("Set Min Value", new ClickListener() { public void onClick(Widget sender) { mainSliderBar.setMinValue(new Float(minBox.getText()).floatValue()); } })); // Set the maximum value final TextBox maxBox = new TextBox(); maxBox.setText("100.0"); grid.setWidget(2, 1, maxBox); grid.setHTML(2, 2, "The upper bounds (maximum) of the range."); grid.setWidget(2, 0, new Button("Set Max Value", new ClickListener() { public void onClick(Widget sender) { mainSliderBar.setMaxValue(new Float(maxBox.getText()).floatValue()); } })); // Set the step size final TextBox stepSizeBox = new TextBox(); stepSizeBox.setText("1.0"); grid.setWidget(3, 1, stepSizeBox); grid.setHTML(3, 2, "The increments between each knob position."); grid.setWidget(3, 0, new Button("Set Step Size", new ClickListener() { public void onClick(Widget sender) { mainSliderBar.setStepSize(new Float(stepSizeBox.getText()).floatValue()); } })); // Set the number of tick marks final TextBox numTicksBox = new TextBox(); numTicksBox.setText("10"); grid.setWidget(4, 1, numTicksBox); grid.setHTML(4, 2, "The vertical black lines along the range of value. Note that the " + "number of ticks is actually one more than the number you " + "specify, so setting the number of ticks to one will display a " + "tick at each end of the slider."); grid.setWidget(4, 0, new Button("Set Num Ticks", new ClickListener() { public void onClick(Widget sender) { mainSliderBar.setNumTicks(new Integer(numTicksBox.getText()).intValue()); } })); // Set the number of labels final TextBox numLabelsBox = new TextBox(); numLabelsBox.setText("5"); grid.setWidget(5, 1, numLabelsBox); grid.setHTML(5, 2, "The labels above the ticks."); grid.setWidget(5, 0, new Button("Set Num Labels", new ClickListener() { public void onClick(Widget sender) { mainSliderBar.setNumLabels(new Integer(numLabelsBox.getText()).intValue()); } })); // Create a form to set width of element final TextBox widthBox = new TextBox(); widthBox.setText("50%"); grid.setWidget(6, 1, widthBox); grid.setHTML(6, 2, "Set the width of the slider. Use this to see how " + "resize checking detects the new dimensions and redraws the widget."); grid.setWidget(6, 0, new Button("Set Width", new ClickListener() { public void onClick(Widget sender) { mainSliderBar.setWidth(widthBox.getText()); } })); // Add the default text option grid.setWidget(7, 1, defaultTextLabel); grid.setHTML(7, 2, "Override the format of the labels with a custom" + "format."); grid.setWidget(7, 0, new Button("Toggle Custom Text", new ClickListener() { public void onClick(Widget sender) { if (useCustomText) { defaultTextLabel.setHTML("default"); useCustomText = false; mainSliderBar.redraw(); } else { defaultTextLabel.setHTML("custom"); useCustomText = true; mainSliderBar.redraw(); } } })); // Add static resize timer methods final HTML resizeCheckLabel = new HTML("enabled"); grid.setWidget(8, 1, resizeCheckLabel); grid.setHTML(8, 2, "When resize checking is enabled, a Timer will " + "periodically check if the Widget's dimensions have changed. If " + "they change, the widget will be redrawn."); grid.setWidget(8, 0, new Button("Toggle Resize Checking", new ClickListener() { public void onClick(Widget sender) { if (ResizableWidgetCollection.get().isResizeCheckingEnabled()) { ResizableWidgetCollection.get().setResizeCheckingEnabled(false); resizeCheckLabel.setHTML("disabled"); } else { ResizableWidgetCollection.get().setResizeCheckingEnabled(true); resizeCheckLabel.setHTML("enabled"); } } })); // Add elements to page RootPanel.get().add(mainSliderBar); RootPanel.get().add(new HTML("<BR>")); RootPanel.get().add(grid); RootPanel.get().add(new HTML("<BR>Additional SliderBars:<BR>")); RootPanel.get().add(exampleBar1); RootPanel.get().add(new HTML("<BR>")); RootPanel.get().add(exampleBar2); }
From source file:com.google.gwt.examples.ButtonExample.java
License:Apache License
public void onModuleLoad() { // Make a new button that does something when you click it. Button b = new Button("Jump!", new ClickHandler() { public void onClick(ClickEvent event) { Window.alert("How high?"); }//from ww w. jav a2 s . c om }); // Add it to the root panel. RootPanel.get().add(b); }
From source file:com.google.gwt.examples.FormPanelExample.java
License:Apache License
public void onModuleLoad() { // Create a FormPanel and point it at a service. final FormPanel form = new FormPanel(); form.setAction("/myFormHandler"); // Because we're going to add a FileUpload widget, we'll need to set the // form to use the POST method, and multipart MIME encoding. form.setEncoding(FormPanel.ENCODING_MULTIPART); form.setMethod(FormPanel.METHOD_POST); // Create a panel to hold all of the form widgets. VerticalPanel panel = new VerticalPanel(); form.setWidget(panel);/*from www. j a va 2 s . c o m*/ // Create a TextBox, giving it a name so that it will be submitted. final TextBox tb = new TextBox(); tb.setName("textBoxFormElement"); panel.add(tb); // Create a ListBox, giving it a name and some values to be associated with // its options. ListBox lb = new ListBox(); lb.setName("listBoxFormElement"); lb.addItem("foo", "fooValue"); lb.addItem("bar", "barValue"); lb.addItem("baz", "bazValue"); panel.add(lb); // Create a FileUpload widget. FileUpload upload = new FileUpload(); upload.setName("uploadFormElement"); panel.add(upload); // Add a 'submit' button. panel.add(new Button("Submit", new ClickHandler() { public void onClick(ClickEvent event) { form.submit(); } })); // Add an event handler to the form. form.addSubmitHandler(new FormPanel.SubmitHandler() { public void onSubmit(SubmitEvent event) { // This event is fired just before the form is submitted. We can take // this opportunity to perform validation. if (tb.getText().length() == 0) { Window.alert("The text box must not be empty"); event.cancel(); } } }); form.addSubmitCompleteHandler(new FormPanel.SubmitCompleteHandler() { public void onSubmitComplete(SubmitCompleteEvent event) { // When the form submission is successfully completed, this event is // fired. Assuming the service returned a response of type text/html, // we can get the result text here (see the FormPanel documentation for // further explanation). Window.alert(event.getResults()); } }); RootPanel.get().add(form); }
From source file:com.google.gwt.examples.view.ListDataProviderExample.java
License:Apache License
public void onModuleLoad() { // Create a CellList. CellList<String> cellList = new CellList<String>(new TextCell()); // Create a list data provider. final ListDataProvider<String> dataProvider = new ListDataProvider<String>(); // Add the cellList to the dataProvider. dataProvider.addDataDisplay(cellList); // Create a form to add values to the data provider. final TextBox valueBox = new TextBox(); valueBox.setText("Enter new value"); Button addButton = new Button("Add value", new ClickHandler() { public void onClick(ClickEvent event) { // Get the value from the text box. String newValue = valueBox.getText(); // Get the underlying list from data dataProvider. List<String> list = dataProvider.getList(); // Add the value to the list. The dataProvider will update the cellList. list.add(newValue);/* w ww . j a v a2 s. c o m*/ } }); // Add the widgets to the root panel. VerticalPanel vPanel = new VerticalPanel(); vPanel.add(valueBox); vPanel.add(addButton); vPanel.add(cellList); RootPanel.get().add(vPanel); }