001: /*
002: * Copyright 2007 Google Inc.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License"); you may not
005: * use this file except in compliance with the License. You may obtain a copy of
006: * the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
012: * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
013: * License for the specific language governing permissions and limitations under
014: * the License.
015: */
016: package com.google.gwt.sample.kitchensink.client;
017:
018: import com.google.gwt.user.client.Command;
019: import com.google.gwt.user.client.Window;
020: import com.google.gwt.user.client.ui.Button;
021: import com.google.gwt.user.client.ui.CheckBox;
022: import com.google.gwt.user.client.ui.HorizontalPanel;
023: import com.google.gwt.user.client.ui.MenuBar;
024: import com.google.gwt.user.client.ui.MenuItem;
025: import com.google.gwt.user.client.ui.PushButton;
026: import com.google.gwt.user.client.ui.RadioButton;
027: import com.google.gwt.user.client.ui.ToggleButton;
028: import com.google.gwt.user.client.ui.VerticalPanel;
029:
030: /**
031: * Demonstrates the various button widgets.
032: */
033: public class Widgets extends Sink implements Command {
034:
035: public static SinkInfo init(final Sink.Images images) {
036: return new SinkInfo(
037: "Widgets",
038: "<h2>Basic Widgets</h2>"
039: + "<p>GWT has all sorts of the basic widgets you would expect from any "
040: + "toolkit.</p><p>Below, you can see various kinds of buttons, check boxes, "
041: + "radio buttons, and menus.</p>") {
042:
043: @Override
044: public Sink createInstance() {
045: return new Widgets(images);
046: }
047:
048: @Override
049: public String getColor() {
050: return "#bf2a2a";
051: }
052: };
053: }
054:
055: private Button disabledButton = new Button("Disabled Button");
056: private CheckBox disabledCheck = new CheckBox("Disabled Check");
057: private Button normalButton = new Button("Normal Button");
058: private CheckBox normalCheck = new CheckBox("Normal Check");
059: private VerticalPanel panel = new VerticalPanel();
060: private RadioButton radio0 = new RadioButton("group0", "Choice 0");
061: private RadioButton radio1 = new RadioButton("group0", "Choice 1");
062: private RadioButton radio2 = new RadioButton("group0",
063: "Choice 2 (Disabled)");
064: private RadioButton radio3 = new RadioButton("group0", "Choice 3");
065: private PushButton pushButton;
066: private ToggleButton toggleButton;
067:
068: public Widgets(Sink.Images images) {
069: pushButton = new PushButton(images.gwtLogo().createImage());
070: toggleButton = new ToggleButton(images.gwtLogo().createImage());
071:
072: HorizontalPanel hp;
073:
074: panel.add(createMenu());
075:
076: panel.add(hp = new HorizontalPanel());
077: hp.setSpacing(8);
078: hp.add(normalButton);
079: hp.add(disabledButton);
080:
081: panel.add(hp = new HorizontalPanel());
082: hp.setSpacing(8);
083: hp.add(normalCheck);
084: hp.add(disabledCheck);
085:
086: panel.add(hp = new HorizontalPanel());
087: hp.setSpacing(8);
088: hp.add(radio0);
089: hp.add(radio1);
090: hp.add(radio2);
091: hp.add(radio3);
092:
093: panel.add(hp = new HorizontalPanel());
094: hp.setSpacing(8);
095: hp.add(pushButton);
096: hp.add(toggleButton);
097:
098: disabledButton.setEnabled(false);
099: disabledCheck.setEnabled(false);
100: radio2.setEnabled(false);
101:
102: panel.setSpacing(8);
103: initWidget(panel);
104: }
105:
106: public MenuBar createMenu() {
107: MenuBar menu = new MenuBar();
108: menu.setAutoOpen(true);
109:
110: MenuBar subMenu = new MenuBar(true);
111: subMenu.addItem("<code>Code</code>", true, this );
112: subMenu.addItem("<strike>Strikethrough</strike>", true, this );
113: subMenu.addItem("<u>Underlined</u>", true, this );
114:
115: MenuBar menu0 = new MenuBar(true);
116: menu0.addItem("<b>Bold</b>", true, this );
117: menu0.addItem("<i>Italicized</i>", true, this );
118: menu0.addItem("More »", true, subMenu);
119: MenuBar menu1 = new MenuBar(true);
120: menu1.addItem("<font color='#FF0000'><b>Apple</b></font>",
121: true, this );
122: menu1.addItem("<font color='#FFFF00'><b>Banana</b></font>",
123: true, this );
124: menu1.addItem("<font color='#FFFFFF'><b>Coconut</b></font>",
125: true, this );
126: menu1.addItem("<font color='#8B4513'><b>Donut</b></font>",
127: true, this );
128: MenuBar menu2 = new MenuBar(true);
129: menu2.addItem("Bling", this );
130: menu2.addItem("Ginormous", this );
131: menu2.addItem("<code>w00t!</code>", true, this );
132:
133: menu.addItem(new MenuItem("Style", menu0));
134: menu.addItem(new MenuItem("Fruit", menu1));
135: menu.addItem(new MenuItem("Term", menu2));
136:
137: menu.setWidth("100%");
138:
139: return menu;
140: }
141:
142: public void execute() {
143: Window.alert("Thank you for selecting a menu item.");
144: }
145:
146: @Override
147: public void onShow() {
148: }
149: }
|