List of usage examples for com.google.gwt.user.client.ui Button Button
protected Button(com.google.gwt.dom.client.Element element)
From source file:com.ait.toolkit.ace.examples.client.AceDemo.java
License:Open Source License
/** * This method builds the UI. It creates UI widgets that exercise most/all of the AceEditor methods, so it's a bit of a kitchen sink. *//* w ww . jav a2s . co m*/ private void buildUI() { VerticalPanel mainPanel = new VerticalPanel(); mainPanel.setWidth("100%"); mainPanel.add(new Label("Label above!")); mainPanel.add(editor1); // Label to display current row/column rowColLabel = new InlineLabel(""); mainPanel.add(rowColLabel); // Create some buttons for testing various editor APIs HorizontalPanel buttonPanel = new HorizontalPanel(); // Add button to insert text at current cursor position Button insertTextButton = new Button("Insert"); insertTextButton.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { // Window.alert("Cursor at: " + editor1.getCursorPosition()); editor1.insertAtCursor("inserted text!"); } }); buttonPanel.add(insertTextButton); // Add check box to enable/disable soft tabs final CheckBox softTabsBox = new CheckBox("Soft tabs"); softTabsBox.setValue(true); // I think soft tabs is the default softTabsBox.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { editor1.setUseSoftTabs(softTabsBox.getValue()); } }); buttonPanel.add(softTabsBox); // add text box and button to set tab size final TextBox tabSizeTextBox = new TextBox(); tabSizeTextBox.setWidth("4em"); Button setTabSizeButton = new Button("Set tab size"); setTabSizeButton.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { editor1.setTabSize(Integer.parseInt(tabSizeTextBox.getText())); } }); buttonPanel.add(new InlineLabel("Tab size: ")); buttonPanel.add(tabSizeTextBox); buttonPanel.add(setTabSizeButton); // add text box and button to go to a given line final TextBox gotoLineTextBox = new TextBox(); gotoLineTextBox.setWidth("4em"); Button gotoLineButton = new Button("Go to line"); gotoLineButton.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { editor1.gotoLine(Integer.parseInt(gotoLineTextBox.getText())); } }); buttonPanel.add(new InlineLabel("Go to line: ")); buttonPanel.add(gotoLineTextBox); buttonPanel.add(gotoLineButton); // checkbox to set whether or not horizontal scrollbar is always visible final CheckBox hScrollBarAlwaysVisibleBox = new CheckBox("H scrollbar: "); hScrollBarAlwaysVisibleBox.setValue(true); hScrollBarAlwaysVisibleBox.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { editor1.setHScrollBarAlwaysVisible(hScrollBarAlwaysVisibleBox.getValue()); } }); buttonPanel.add(hScrollBarAlwaysVisibleBox); // checkbox to show/hide gutter final CheckBox showGutterBox = new CheckBox("Show gutter: "); showGutterBox.setValue(true); showGutterBox.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { editor1.setShowGutter(showGutterBox.getValue()); } }); buttonPanel.add(showGutterBox); // checkbox to set/unset readonly mode final CheckBox readOnlyBox = new CheckBox("Read only: "); readOnlyBox.setValue(false); readOnlyBox.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { editor1.setReadOnly(readOnlyBox.getValue()); } }); buttonPanel.add(readOnlyBox); // checkbox to show/hide print margin final CheckBox showPrintMarginBox = new CheckBox("Show print margin: "); showPrintMarginBox.setValue(true); showPrintMarginBox.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { editor1.setShowPrintMargin(showPrintMarginBox.getValue()); } }); buttonPanel.add(showPrintMarginBox); mainPanel.add(buttonPanel); mainPanel.add(editor2); mainPanel.add(new Label("Label below!")); RootPanel.get().add(mainPanel); }
From source file:com.akjava.gwt.threetest.client.CanvasDemo.java
License:Apache License
@Override public Widget getControler() { if (exportButton == null) { exportButton = new Button("Export Image"); exportButton.addClickHandler(new ClickHandler() { @Override/*from w w w .j av a2 s . c o m*/ public void onClick(ClickEvent event) { String url = canvas.toDataUrl(); ExportUtils.openTabAbsoluteURLImage(url, "canvastest"); } }); } return exportButton; }
From source file:com.akjava.gwt.volumegraph.client.LogBox.java
License:Apache License
public LogBox() { area = new TextArea(); area.setSize("100%", "100%"); add(area);/*from www .j ava 2 s . com*/ Button clearBt = new Button("Clear"); add(clearBt); clearBt.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { clear(); } }); }
From source file:com.akjava.gwt.volumegraph.client.VolumeGraph.java
License:Apache License
@Override protected void init(TestPreference preferences) { Hangout.setInjectHangoutService(injector.getHangoutService()); StyleInjector.inject(".grey{color:#666}"); HorizontalPanel root = new HorizontalPanel(); root.setSize("100%", "100%"); RootPanel.get().add(root);/*from w w w . j a va 2 s .com*/ VerticalPanel mainPanel = new VerticalPanel(); mainPanel.setSize("100%", "100%"); HorizontalPanel controler = new HorizontalPanel(); mainPanel.add(controler); Label label = new Label("Emulate Participant"); label.setStylePrimaryName("grey"); controler.add(label); Button plus = new Button("+"); plus.setStylePrimaryName("grey"); controler.add(plus); plus.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { dummyParticipant++; } }); Button clear = new Button("remove"); clear.setStylePrimaryName("grey"); controler.add(clear); clear.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { dummyParticipant = 0; } }); root.add(mainPanel); canvas = Canvas.createIfSupported(); canvas.setSize("100%", "400px"); canvas.getContext2d().setFillStyle(CssColor.make("#fff")); mainPanel.add(canvas); int w = canvas.getOffsetWidth(); int h = canvas.getOffsetHeight(); canvas.setCoordinateSpaceWidth(w); canvas.setCoordinateSpaceHeight(h); addReady(); }
From source file:com.allen_sauer.gwt.dnd.demo.client.DragDropDemo.java
License:Apache License
private void onModuleLoad2() { RootPanel mainPanel = RootPanel.get(DEMO_MAIN_PANEL); DOM.setInnerHTML(mainPanel.getElement(), ""); // create the main common boundary panel to which drag operations will be restricted AbsolutePanel boundaryPanel = new AbsolutePanel(); boundaryPanel.addStyleName(CSS_DEMO_MAIN_BOUNDARY_PANEL); boundaryPanel.setPixelSize(900, 600); // instantiate the common drag controller used the less specific examples dragController = new PickupDragController(boundaryPanel, true); dragController.setBehaviorMultipleSelection(false); mainPanel.add(new HTML( "<div style='font-weight: bold; font-size: 1.2em;'><a href='https://github.com/fredsa/gwt-dnd'>gwt-dnd</a>" + " - Drag-and-Drop for your Google Web Toolkit projects.</div>" + "<div style='font-style: italic; margin-bottom: 1em;'>by Fred Sauer</div>")); // Umbrella example illustrating basic drag and drop behavior HTML boundaryDescription = ExampleTabPanel.describe( new Class[] { DragDropDemo.class, PickupDragController.class, BoundaryDropController.class, }, "Most of the example drag operations are constrained to the panel below." + " Try to drag one of the widgets outside the area below."); boundaryDescription.addStyleName(CSS_DEMO_BOUNDARY); mainPanel.add(boundaryDescription);/*w w w. ja va2 s . c o m*/ mainPanel.add(boundaryPanel); // Add configuration panel for main drag controller VerticalPanel configurationPanel = new VerticalPanel(); configurationPanel.setWidth("200px"); configurationPanel.add(new MultipleSelectionBehaviorPanel(dragController)); configurationPanel.add(new DragStartSensitivityBehaviorPanel(dragController)); configurationPanel.add(new DragProxyBehaviorPanel(dragController)); configurationPanel.add(new ConstrainedToBoundaryBehaviorPanel(dragController)); configurationPanel.add(new BidiBehaviorPanel(dragController)); boundaryPanel.add(configurationPanel, 10, 0); // Create some draggable widgets to play with boundaryPanel.add(createDraggable(), 20, 530); boundaryPanel.add(createDraggable(), 60, 510); boundaryPanel.add(createDraggable(), 100, 520); boundaryPanel.add(createDraggable(), 140, 530); // TabPanel to hold our examples final ExampleTabPanel examples = new ExampleTabPanel(7); examples.setWidth("650px"); boundaryPanel.add(examples, 220, 10); // text area to log drag events as they are triggered final HTML eventTextArea = new HTML(); eventTextArea.addStyleName(CSS_DEMO_EVENT_TEXT_AREA); eventTextArea.setSize(boundaryPanel.getOffsetWidth() + "px", "10em"); // instantiate shared drag handler to listen for events final DemoDragHandler demoDragHandler = new DemoDragHandler(eventTextArea); dragController.addDragHandler(demoDragHandler); Button clearButton = new Button("clear"); clearButton.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { demoDragHandler.clear(); } }); mainPanel.add(new HTML("<br>Events received by registered <code>DragHandler</code>s")); mainPanel.add(clearButton); mainPanel.add(eventTextArea); // add our individual examples examples.add(new BinExample(dragController)); examples.add(new AbsolutePositionExample(dragController)); examples.add(new GridConstrainedExample(dragController)); examples.add(new FlowPanelExample(dragController)); examples.add(new InsertPanelExample(demoDragHandler)); examples.add(new FlexTableRowExample(demoDragHandler)); examples.add(new WindowExample(demoDragHandler)); examples.add(new DragHandleExample(demoDragHandler)); examples.add(new DualListExample(demoDragHandler)); examples.add(new PuzzleExample(demoDragHandler)); examples.add(new MatryoshkaExample(demoDragHandler)); examples.add(new ResetCacheExample(dragController)); examples.add(new PaletteExample(demoDragHandler)); examples.add(new ClickTouchExample(dragController, demoDragHandler)); mainPanel.add(new HTML( "<div style='color: gray; margin-top: 1em;'>Demo created with gwt-dnd @GWT_DND_VERSION@ and GWT " + GWT.getVersion() + "</div>")); Scheduler.get().scheduleDeferred(new ScheduledCommand() { @Override public void execute() { examples.selectTabByHistoryToken(History.getToken()); } }); }
From source file:com.allen_sauer.gwt.dnd.demo.client.example.draghandle.DragHandleExample.java
License:Apache License
public DragHandleExample(DemoDragHandler demoDragHandler) { addStyleName(CSS_DEMO_DRAG_HANDLE_EXAMPLE); // use the boundary panel as this composite's widget final AbsolutePanel boundaryPanel = new AbsolutePanel(); boundaryPanel.setPixelSize(600, 400); setWidget(boundaryPanel);// w ww . j a v a 2s .c o m // create the title bar HTML header = new HTML( "Title/Header (Drag Handle) with <a href='http://google.com/' target='_blank'>link</a>"); header.addStyleName(CSS_DEMO_DRAG_HANDLE_EXAMPLE_HEADER); // add some text HTML content = new HTML("This is a <code>VerticalPanel</code> which can be dragged by its header," + " i.e. the title/header widget."); // add an editable text area final TextArea textArea = new TextArea(); textArea.addStyleName(CSS_DEMO_DRAG_HANDLE_EXAMPLE_TEXTAREA); // textArea.setSize("20em", "5em"); textArea.setText("You can click in this TextArea to get focus without causing the panel to be dragged."); // add a clickable button Button button = new Button("Click me"); button.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { textArea.setText(textArea.getText() + " Click!"); } }); // create a panel to hold all our widgets VerticalPanel verticalPanel = new VerticalPanel(); verticalPanel.setSpacing(2); verticalPanel.addStyleName(CSS_DEMO_DRAG_HANDLE_EXAMPLE_PANEL); verticalPanel.add(header); verticalPanel.add(content); verticalPanel.add(textArea); verticalPanel.add(button); boundaryPanel.add(verticalPanel, 20, 20); // instantiate our drag controller dragController = new PickupDragController(boundaryPanel, true); dragController.addDragHandler(demoDragHandler); dragController.setBehaviorConstrainedToBoundaryPanel(true); dragController.setBehaviorMultipleSelection(false); dragController.setBehaviorDragStartSensitivity(5); // instantiate our drop controller AbsolutePositionDropController dropController = new AbsolutePositionDropController(boundaryPanel); dragController.registerDropController(dropController); // make the panel draggable by its header dragController.makeDraggable(verticalPanel, header); }
From source file:com.allen_sauer.gwt.dnd.demo.client.example.duallist.DualListBox.java
License:Apache License
public DualListBox(int visibleItems, String width) { HorizontalPanel horizontalPanel = new HorizontalPanel(); add(horizontalPanel);/* www . jav a 2 s . co m*/ horizontalPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE); VerticalPanel verticalPanel = new VerticalPanel(); verticalPanel.addStyleName(CSS_DEMO_DUAL_LIST_EXAMPLE_CENTER); verticalPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER); dragController = new ListBoxDragController(this); left = new MouseListBox(dragController, LIST_SIZE); right = new MouseListBox(dragController, LIST_SIZE); left.setWidth(width); right.setWidth(width); horizontalPanel.add(left); horizontalPanel.add(verticalPanel); horizontalPanel.add(right); oneRight = new Button(">"); oneLeft = new Button("<"); allRight = new Button(">>"); allLeft = new Button("<<"); verticalPanel.add(oneRight); verticalPanel.add(oneLeft); verticalPanel.add(new HTML(" ")); verticalPanel.add(allRight); verticalPanel.add(allLeft); allRight.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { moveItems(left, right, false); } }); allLeft.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { moveItems(right, left, false); } }); oneRight.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { moveItems(left, right, true); } }); oneLeft.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { moveItems(right, left, true); } }); ListBoxDropController leftDropController = new ListBoxDropController(left); ListBoxDropController rightDropController = new ListBoxDropController(right); dragController.registerDropController(leftDropController); dragController.registerDropController(rightDropController); }
From source file:com.allen_sauer.gwt.log.client.DivLogger.java
License:Apache License
/** * @deprecated// w w w.jav a2 s . c om */ @Deprecated private FocusPanel makeHeader() { FocusPanel header; header = new FocusPanel(); HorizontalPanel masterPanel = new HorizontalPanel(); masterPanel.setWidth("100%"); header.add(masterPanel); final Label titleLabel = new Label("gwt-log", false); titleLabel.setStylePrimaryName(LogClientBundle.INSTANCE.css().logTitle()); HorizontalPanel buttonPanel = new HorizontalPanel(); levelButtons = new Button[levels.length]; for (int i = 0; i < levels.length; i++) { final int level = levels[i]; levelButtons[i] = new Button(LogUtil.levelToString(level)); buttonPanel.add(levelButtons[i]); levelButtons[i].addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { ((Button) event.getSource()).setFocus(false); Log.setCurrentLogLevel(level); } }); } Button clearButton = new Button("Clear"); clearButton.addStyleName(LogClientBundle.INSTANCE.css().logClearButton()); DOM.setStyleAttribute(clearButton.getElement(), "color", "#00c"); clearButton.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { ((Button) event.getSource()).setFocus(false); Log.clear(); } }); buttonPanel.add(clearButton); Button aboutButton = new Button("About"); aboutButton.addStyleName(LogClientBundle.INSTANCE.css().logClearAbout()); aboutButton.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { ((Button) event.getSource()).setFocus(false); Log.diagnostic("\n" // + "gwt-log-" + Log.getVersion() // + " - Runtime logging for your Google Web Toolkit projects\n" + // "Copyright 2007 Fred Sauer\n" + // "The original software is available from:\n" + // "\u00a0\u00a0\u00a0\u00a0http://allen-sauer.com/gwt/\n", null); } }); Button closeButton = new Button("X"); closeButton.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { logDockPanel.removeFromParent(); } }); masterPanel.add(titleLabel); masterPanel.add(buttonPanel); masterPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT); masterPanel.add(aboutButton); masterPanel.add(closeButton); masterPanel.setCellHeight(titleLabel, "100%"); masterPanel.setCellWidth(titleLabel, "50%"); masterPanel.setCellWidth(aboutButton, "50%"); new MouseDragHandler(titleLabel); return header; }
From source file:com.allen_sauer.gwt.log.demo.client.InteractiveDemoPanel.java
License:Apache License
/** * Default constructor.//from w w w .j a v a 2 s . c o m */ public InteractiveDemoPanel() { add(new HTML("Log a message:")); for (int i = 0; i < levels.length - 1; i++) { final int level = levels[i]; final String levelString = levelTexts[i]; messageButtons[i] = new Button("Log." + levelString.toLowerCase() + "(...)"); add(messageButtons[i]); messageButtons[i].addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { String msg = "This is a '" + levelString + "' test message"; switch (level) { case Log.LOG_LEVEL_TRACE: Log.trace(msg); break; case Log.LOG_LEVEL_DEBUG: Log.debug(msg); break; case Log.LOG_LEVEL_INFO: Log.info(msg); break; case Log.LOG_LEVEL_WARN: Log.warn(msg); break; case Log.LOG_LEVEL_ERROR: Log.error(msg); break; case Log.LOG_LEVEL_FATAL: Log.fatal(msg); break; } } }); } add(new HTML("<br>")); add(new HTML("Catch some exceptions:")); jsniCatchButtonFatal = new Button("JSNI with try/catch"); add(jsniCatchButtonFatal); jsniCatchButtonFatal.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { jsniCatch(); } }); jsniNoCatchButtonFatal = new Button("JSNI without try/catch"); add(jsniNoCatchButtonFatal); jsniNoCatchButtonFatal.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { jsniNoCatch(); } }); clinitButtonFatal = new Button("static (class) initialization failure"); add(clinitButtonFatal); clinitButtonFatal.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { new Broken(); } }); add(new HTML("<br>")); npeButtonFatal = new Button("NullPointerException"); add(npeButtonFatal); npeButtonFatal.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { throw new NullPointerException(); } }); jsTimeoutExceptionButtonFatal = new Button("JavaScript setTimeout() exception [FF/IE/Chrome only]"); add(jsTimeoutExceptionButtonFatal); jsTimeoutExceptionButtonFatal.addClickHandler(new ClickHandler() { @Override public native void onClick(ClickEvent event) /*-{ setTimeout(function() { my_non_existant_variable.my_non_existant_method(); }, 1); }-*/; }); nullButtonDebug = new Button("Log.debug(null)"); add(nullButtonDebug); nullButtonDebug.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { Log.debug(null); } }); add(new HTML("<br>")); add(new HTML("Clear log output (on supported destinations):")); Button clearButton = new Button("clear()"); add(clearButton); clearButton.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { Log.clear(); } }); // add(new HTML("<br>")); // add(new HTML("Set runtime log level to:")); // // for (int i = 0; i < levels.length; i++) { // final int level = levels[i]; // levelButtons[i] = new Button(levelTexts[i]); // levelButtons[i].addClickHandler(new ClickHandler() { // public void onClick(ClickEvent event) { // Log.setCurrentLogLevel(level); // updateLogLevelLabels(); // } // }); // add(levelButtons[i]); // } add(new HTML("<br>")); add(new HTML("Change the compile time <code>log_level</code> URL parameter to:")); for (int i = 0; i < levels.length; i++) { final int level = levels[i]; final String url = makePageURL(levelTexts[i]); Anchor anchor = new Anchor(levelTexts[i], url); anchor.getElement().getStyle().setPadding(0.3, Unit.EM); anchor.setTitle("Switch to '" + levelTexts[i] + "' compile time log level"); add(anchor); if (level == Log.getLowestLogLevel()) { anchor.addStyleDependentName(CSS_CURRENT); } } add(new HTML("<br>")); add(new HTML("Launch server side JavaScript stack trace deobfuscation demo:")); add(new HTML("<a href='LogClientServerDemo.html" + Window.Location.getQueryString() + "'>Client server demo</a>")); updateLogLevelLabels(); if (Log.isLoggingEnabled()) { initDivLogger(); } }
From source file:com.allen_sauer.gwt.voices.demo.client.DemoSoundPanel.java
License:Apache License
public DemoSoundPanel(final ThirdPartySound thirdPartySound) { // use a horizontal panel to hold our content HorizontalPanel horizontalPanel = new HorizontalPanel(); initWidget(horizontalPanel);/*w w w. j a v a 2 s .c o m*/ // add a (temporarily disabled) play button final Button playButton = new Button("wait..."); playButton.setEnabled(false); playButton.addStyleName("voices-button"); horizontalPanel.add(playButton); final Button stopButton = new Button("wait..."); stopButton.setEnabled(false); stopButton.addStyleName("voices-button"); horizontalPanel.add(stopButton); // display a description of the sound next to the button horizontalPanel.add(new HTML(" " + thirdPartySound.toHTMLString())); // display a load state status final HTML loadStateHTML = new HTML(); horizontalPanel.add(loadStateHTML); // enable the play button once the sound has loaded thirdPartySound.getSound().addEventHandler(new SoundHandler() { @Override public void onPlaybackComplete(PlaybackCompleteEvent event) { } @Override public void onSoundLoadStateChange(final SoundLoadStateChangeEvent event) { // simulate a slight variable delay for local development new Timer() { @Override public void run() { loadStateHTML.setHTML(" (<code>" + event.getLoadState().name() + "</code>)"); switch (event.getLoadState()) { case LOAD_STATE_SUPPORTED_AND_READY: case LOAD_STATE_SUPPORTED_NOT_READY: case LOAD_STATE_SUPPORTED_MAYBE_READY: playButton.setEnabled(true); playButton.setText("play"); stopButton.setEnabled(true); stopButton.setText("stop"); break; case LOAD_STATE_NOT_SUPPORTED: playButton.setText("(sound or plugin unavailable)"); break; case LOAD_STATE_SUPPORT_NOT_KNOWN: playButton.setEnabled(true); playButton.setText("play (may not work)"); stopButton.setEnabled(true); stopButton.setText("stop"); break; case LOAD_STATE_UNINITIALIZED: default: throw new IllegalArgumentException("Unhandled state " + event.getLoadState()); } } }.schedule(Random.nextInt(500) + 200); } }); // play the sound when button is clicked playButton.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { thirdPartySound.getSound().play(); } }); stopButton.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { thirdPartySound.getSound().stop(); } }); }