List of usage examples for com.google.gwt.user.client.ui Button Button
public Button(String html, ClickHandler handler)
From source file:com.google.gwt.gen2.demo.datepicker.client.DatePickerDemo.java
License:Apache License
private Widget dateRange() { VerticalPanel v = new VerticalPanel(); HorizontalPanel p = new HorizontalPanel(); v.add(p);/*w w w . ja v a 2s.co m*/ start = new DateBox(); start.setAnimationEnabled(true); final DateBox end = new DateBox(); end.setAnimationEnabled(true); start.addKeyDownHandler(new KeyDownHandler() { public void onKeyDown(KeyDownEvent e) { if (e.isRightKeyCode() && start.getCursorPos() == start.getText().length()) { start.hideDatePicker(); end.setFocus(true); } } }); end.addKeyDownHandler(new KeyDownHandler() { public void onKeyDown(KeyDownEvent e) { if ((e.isLeftKeyCode()) && end.getCursorPos() == 0) { start.setFocus(true); end.hideDatePicker(); } } }); end.getDatePicker().addSelectionHandler(new SelectionHandler<Date>() { public void onSelection(SelectionEvent<Date> event) { start.removeStyleName("user-modified"); } }); start.showDate(new Date()); p.add(start); Label l = new Label(" - "); l.setStyleName("filler"); p.add(l); p.add(end); HorizontalPanel h2 = new HorizontalPanel(); v.add(h2); h2.add(new Button("Short format", new ClickListener() { public void onClick(Widget sender) { start.setDateFormat(DateTimeFormat.getShortDateFormat()); end.setDateFormat(DateTimeFormat.getShortDateFormat()); } })); h2.add(new Button("Long format", new ClickListener() { public void onClick(Widget sender) { start.setDateFormat(DateTimeFormat.getLongDateFormat()); end.setDateFormat(DateTimeFormat.getLongDateFormat()); } })); h2.add(new Button("clear", new ClickListener() { public void onClick(Widget sender) { start.clear(); end.clear(); } })); return v; }
From source file:com.google.gwt.gen2.demo.fasttree.client.FastTreeDemo.java
License:Apache License
private Widget dynamicTree() { FlowPanel container = new FlowPanel(); // Add Tree//w w w . j a va 2s . co m final FastTree topTree = new FastTree(); FastTreeItem firstBranch = topTree.addItem("Inbox (3)"); firstBranch.addItem("Urgent"); FastTreeItem familyBranch = firstBranch.addItem("Family"); familyBranch.becomeInteriorNode(); familyBranch.addItem("Mom"); familyBranch.addItem("Brosef"); FastTreeItem secondBranch = firstBranch.addItem("Calendar"); secondBranch.addItem("Important Meetings"); container.add(topTree); final Button btnAdd = new Button("Add to Family Branch", new ClickHandler() { public void onClick(ClickEvent event) { FastTreeItem selectedItem = topTree.getChild(0).getChild(1); Window.alert("Adding new " + selectedItem.getText() + " Child Nodes"); selectedItem.addItem("Dad"); selectedItem.addItem("Sissef"); } }); final Button btnKill = new Button("Disown Family Branch", new ClickHandler() { public void onClick(ClickEvent event) { FastTreeItem selectedItem = topTree.getChild(0).getChild(1); Window.alert("Disowning " + selectedItem.getText() + " Child Nodes"); selectedItem.becomeLeaf(); btnAdd.setVisible(true); } }); topTree.addBeforeCloseHandler(new BeforeCloseHandler<FastTreeItem>() { public void onBeforeClose(BeforeCloseEvent<FastTreeItem> event) { btnKill.setVisible(event.getTarget().getText().equals("Family")); } }); btnKill.setVisible(false); btnAdd.setVisible(false); container.add(btnKill); container.add(btnAdd); return container; }
From source file:com.google.gwt.gen2.demo.logging.client.LoggingDemo.java
License:Apache License
private void addLevelControls(final FlexTable control) { final TextBox box = new TextBox(); box.setText("message 0"); VerticalPanel loggingMessage = new VerticalPanel(); loggingMessage.add(new Label("Message to log")); loggingMessage.add(box);//w ww. ja v a 2 s . c o m control.setWidget(0, 1, loggingMessage); Iterator<Level> levels = Log.levelIterator(); final DropDownListBox<Level> levelList = new DropDownListBox<Level>(); while (levels.hasNext()) { final Level level = levels.next(); if (level != Level.ALL || level != Level.OFF) { levelList.addItem(level.getName(), level, "logging level " + level.getName().toLowerCase(), "use <b> " + level.getName().toLowerCase() + "</b> level"); } } control.setWidget(0, 2, levelList); levelList.setValue(Level.INFO); Button log = new Button("Log message", new ClickListener() { public void onClick(Widget sender) { Log.log(box.getText(), levelList.getValue(), "user", null); box.setText("message " + messageNumber++); } }); control.setWidget(0, 3, log); Button error = new Button("Log error", new ClickListener() { public void onClick(Widget sender) { Log.log(box.getText(), levelList.getValue(), "user.error", new NullPointerException()); box.setText("message " + messageNumber++); } }); control.setWidget(0, 4, error); }
From source file:com.google.gwt.gen2.demo.picker.client.SliderBarDemo.java
License:Apache License
/** * This is the entry point method./*from www. ja v a 2s . c om*/ */ public void onModuleLoad() { SliderBar.injectDefaultCss(); // 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.addValueChangeHandler(new ValueChangeHandler<Double>() { public void onValueChange(ValueChangeEvent<Double> event) { curBox.setText(event.getValue().toString()); } }); 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 ClickHandler() { public void onClick(ClickEvent event) { 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 ClickHandler() { public void onClick(ClickEvent event) { 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 ClickHandler() { public void onClick(ClickEvent event) { 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 ClickHandler() { public void onClick(ClickEvent event) { 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 ClickHandler() { public void onClick(ClickEvent event) { 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 ClickHandler() { public void onClick(ClickEvent event) { 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 ClickHandler() { public void onClick(ClickEvent event) { 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 ClickHandler() { public void onClick(ClickEvent event) { 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 ClickHandler() { public void onClick(ClickEvent event) { 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.gen2.demo.scrolltable.client.option.column.CellPaddingAndSpacingOption.java
License:Apache License
@Override protected Widget onInitialize() { CustomForm form = new CustomForm(); // Padding selection final TextBox paddingBox = new TextBox(); paddingBox.setText("3"); paddingBox.setWidth("50px"); form.addLabeledWidget("Cell Padding:", paddingBox); // Spacing selection final TextBox spacingBox = new TextBox(); spacingBox.setText("3"); spacingBox.setWidth("50px"); form.addLabeledWidget("Cell Spacing:", spacingBox); // Add button to set padding and spacing {// www . j a v a 2 s. co m Button button = new Button("Set Padding and Spacing", new ClickHandler() { public void onClick(ClickEvent event) { try { int padding = Integer.parseInt(paddingBox.getText()); int spacing = Integer.parseInt(spacingBox.getText()); ScrollTableDemo.get().getScrollTable().setCellPadding(padding); ScrollTableDemo.get().getScrollTable().setCellSpacing(spacing); } catch (NumberFormatException e) { Window.alert("Please enter valid integers for the row and column."); } catch (IndexOutOfBoundsException e) { Window.alert("The row or column index you entered is out of bounds."); } } }); form.addButton(button); } return form; }
From source file:com.google.gwt.gen2.demo.scrolltable.client.option.column.ColumnResizePolicyOption.java
License:Apache License
@Override protected Widget onInitialize() { CustomForm form = new CustomForm(); // Add the current policy policyBox = new ListBox(); policyBox.addItem("Disabled"); policyBox.addItem("Single Cell"); policyBox.addItem("Multi Cell"); form.addLabeledWidget("Column Resize Policy:", policyBox); refreshPolicy();/*from w ww. j a va 2 s.c o m*/ // Add button to change status { Button button = new Button("Set Resize Policy", new ClickHandler() { public void onClick(ClickEvent event) { AbstractScrollTable scrollTable = ScrollTableDemo.get().getScrollTable(); switch (policyBox.getSelectedIndex()) { case 0: scrollTable.setColumnResizePolicy(ScrollTable.ColumnResizePolicy.DISABLED); break; case 1: scrollTable.setColumnResizePolicy(ScrollTable.ColumnResizePolicy.SINGLE_CELL); break; case 2: scrollTable.setColumnResizePolicy(ScrollTable.ColumnResizePolicy.MULTI_CELL); break; } } }); form.addButton(button); } // Add button to reset column widths { Button button = new Button("Reset Column Widths", new ClickHandler() { public void onClick(ClickEvent event) { AbstractScrollTable scrollTable = ScrollTableDemo.get().getScrollTable(); scrollTable.resetColumnWidths(); } }); form.addButton(button); } return form; }
From source file:com.google.gwt.gen2.demo.scrolltable.client.option.column.ResizeColumnOption.java
License:Apache License
@Override protected Widget onInitialize() { CustomForm form = new CustomForm(); // Column selection final TextBox columnBox = new TextBox(); columnBox.setText("3"); columnBox.setWidth("50px"); form.addLabeledWidget("Column Index:", columnBox); // Width selection final TextBox widthBox = new TextBox(); widthBox.setText("25"); widthBox.setWidth("50px"); form.addLabeledWidget("Width (pixels):", widthBox); // Add button to set column size {//from w w w. jav a 2 s . c om Button button = new Button("Set Actual Column Width", new ClickHandler() { public void onClick(ClickEvent event) { try { int column = Integer.parseInt(columnBox.getText()); int width = Integer.parseInt(widthBox.getText()); if (column >= 0) { ScrollTableDemo.get().getScrollTable().setColumnWidth(column, width); } } catch (NumberFormatException e) { Window.alert("Please enter valid integers for the row and column."); } catch (IndexOutOfBoundsException e) { Window.alert("The row or column index you entered is out of bounds."); } } }); form.addButton(button); } // Add button to set preferred column size if (PagingScrollTableDemo.get() == null) { Button button = new Button("Set Preferred Column Width", new ClickHandler() { public void onClick(ClickEvent event) { try { int column = Integer.parseInt(columnBox.getText()); int width = Integer.parseInt(widthBox.getText()); if (column >= 0) { ((ScrollTable) ScrollTableDemo.get().getScrollTable()).setPreferredColumnWidth(column, width); } } catch (NumberFormatException e) { Window.alert("Please enter valid integers for the row and column."); } catch (IndexOutOfBoundsException e) { Window.alert("The row or column index you entered is out of bounds."); } } }); form.addButton(button); } // Add button to set min column size if (PagingScrollTableDemo.get() == null) { Button button = new Button("Set Minimum Column Width", new ClickHandler() { public void onClick(ClickEvent event) { try { int column = Integer.parseInt(columnBox.getText()); int width = Integer.parseInt(widthBox.getText()); if (column >= 0) { ((ScrollTable) ScrollTableDemo.get().getScrollTable()).setMinimumColumnWidth(column, width); } } catch (NumberFormatException e) { Window.alert("Please enter valid integers for the row and column."); } catch (IndexOutOfBoundsException e) { Window.alert("The row or column index you entered is out of bounds."); } } }); form.addButton(button); } // Add button to set max column size if (PagingScrollTableDemo.get() == null) { Button button = new Button("Set Maximum Column Width", new ClickHandler() { public void onClick(ClickEvent event) { try { int column = Integer.parseInt(columnBox.getText()); int width = Integer.parseInt(widthBox.getText()); if (column >= 0) { ((ScrollTable) ScrollTableDemo.get().getScrollTable()).setMaximumColumnWidth(column, width); } } catch (NumberFormatException e) { Window.alert("Please enter valid integers for the row and column."); } catch (IndexOutOfBoundsException e) { Window.alert("The row or column index you entered is out of bounds."); } } }); form.addButton(button); } return form; }
From source file:com.google.gwt.gen2.demo.scrolltable.client.option.column.TableResizePolicyOption.java
License:Apache License
@Override protected Widget onInitialize() { CustomForm form = new CustomForm(); // Add the current policy policyBox = new ListBox(); policyBox.addItem("Unconstrained"); policyBox.addItem("Flow"); policyBox.addItem("Fixed"); policyBox.addItem("Fill"); form.addLabeledWidget("Resize Policy:", policyBox); refreshPolicy();//from w w w. j a v a2 s .c o m // Add button to change status { Button button = new Button("Set Resize Policy", new ClickHandler() { public void onClick(ClickEvent event) { AbstractScrollTable scrollTable = ScrollTableDemo.get().getScrollTable(); switch (policyBox.getSelectedIndex()) { case 0: scrollTable.setResizePolicy(ScrollTable.ResizePolicy.UNCONSTRAINED); break; case 1: scrollTable.setResizePolicy(ScrollTable.ResizePolicy.FLOW); break; case 2: scrollTable.setResizePolicy(ScrollTable.ResizePolicy.FIXED_WIDTH); break; case 3: scrollTable.setResizePolicy(ScrollTable.ResizePolicy.FILL_WIDTH); break; } } }); form.addButton(button); } return form; }
From source file:com.google.gwt.gen2.demo.scrolltable.client.option.data.InsertDataRowOption.java
License:Apache License
@Override protected Widget onInitialize() { CustomForm form = new CustomForm(); // Row selection final TextBox rowBox = new TextBox(); rowBox.setText("3"); rowBox.setWidth("50px"); form.addLabeledWidget("Row Index:", rowBox); // Add button to insert one row {// ww w.j a v a 2 s .c o m Button button = new Button("Insert 1 Row", new ClickHandler() { public void onClick(ClickEvent event) { try { int row = Integer.parseInt(rowBox.getText()); insertDataRows(row, 1); } catch (NumberFormatException e) { Window.alert("Please enter valid integers for the row and column."); } catch (IndexOutOfBoundsException e) { Window.alert("The row or column index you entered is out of bounds."); } } }); form.addButton(button); } // Add button to insert 10 rows { Button button = new Button("Insert 10 Rows", new ClickHandler() { public void onClick(ClickEvent event) { try { int row = Integer.parseInt(rowBox.getText()); insertDataRows(row, 10); } catch (NumberFormatException e) { Window.alert("Please enter valid integers for the row and column."); } catch (IndexOutOfBoundsException e) { Window.alert("The row or column index you entered is out of bounds."); } } }); form.addButton(button); } // Add button to insert 100 rows { Button button = new Button("Insert 100 Rows", new ClickHandler() { public void onClick(ClickEvent event) { try { int row = Integer.parseInt(rowBox.getText()); insertDataRows(row, 100); } catch (NumberFormatException e) { Window.alert("Please enter valid integers for the row and column."); } catch (IndexOutOfBoundsException e) { Window.alert("The row or column index you entered is out of bounds."); } } }); form.addButton(button); } // Add button to remove a row { Button button = new Button("Remove Row", new ClickHandler() { public void onClick(ClickEvent event) { try { int row = Integer.parseInt(rowBox.getText()); ScrollTableDemo.get().getDataTable().removeRow(row); } catch (NumberFormatException e) { Window.alert("Please enter valid integers for the row and column."); } catch (IndexOutOfBoundsException e) { Window.alert("The row or column index you entered is out of bounds."); } } }); form.addButton(button); } return form; }
From source file:com.google.gwt.gen2.demo.scrolltable.client.option.data.SetDataTextOption.java
License:Apache License
@Override protected Widget onInitialize() { CustomForm form = new CustomForm(); // Row selection final TextBox rowBox = new TextBox(); rowBox.setText("3"); rowBox.setWidth("50px"); form.addLabeledWidget("Row Index", rowBox); // Column selection final TextBox columnBox = new TextBox(); columnBox.setText("4"); columnBox.setWidth("50px"); form.addLabeledWidget("Column Index", columnBox); // Text selection final TextBox textBox = new TextBox(); textBox.setText("<b>Hello World</b>"); form.addLabeledWidget("Text:", textBox); // Add button to set text {//from w ww .j a va 2 s. c o m Button button = new Button("Set Cell Text", new ClickHandler() { public void onClick(ClickEvent event) { try { int row = Integer.parseInt(rowBox.getText()); int column = Integer.parseInt(columnBox.getText()); String text = textBox.getText(); ScrollTableDemo.get().getDataTable().setText(row, column, text); } catch (NumberFormatException e) { Window.alert("Please enter valid integers for the row and column."); } catch (IndexOutOfBoundsException e) { Window.alert("The row or column index you entered is out of bounds."); } } }); form.addButton(button); } // Add button to set html { Button button = new Button("Set Cell HTML", new ClickHandler() { public void onClick(ClickEvent event) { try { int row = Integer.parseInt(rowBox.getText()); int column = Integer.parseInt(columnBox.getText()); String text = textBox.getText(); ScrollTableDemo.get().getDataTable().setHTML(row, column, text); } catch (NumberFormatException e) { Window.alert("Please enter valid integers for the row and column."); } catch (IndexOutOfBoundsException e) { Window.alert("The row or column index you entered is out of bounds."); } } }); form.addButton(button); } return form; }