KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > google > gwt > sample > kitchensink > client > Widgets


1 /*
2  * Copyright 2007 Google Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5  * use this file except in compliance with the License. You may obtain a copy of
6  * the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13  * License for the specific language governing permissions and limitations under
14  * the License.
15  */

16 package com.google.gwt.sample.kitchensink.client;
17
18 import com.google.gwt.user.client.Command;
19 import com.google.gwt.user.client.Window;
20 import com.google.gwt.user.client.ui.Button;
21 import com.google.gwt.user.client.ui.CheckBox;
22 import com.google.gwt.user.client.ui.HorizontalPanel;
23 import com.google.gwt.user.client.ui.MenuBar;
24 import com.google.gwt.user.client.ui.MenuItem;
25 import com.google.gwt.user.client.ui.PushButton;
26 import com.google.gwt.user.client.ui.RadioButton;
27 import com.google.gwt.user.client.ui.ToggleButton;
28 import com.google.gwt.user.client.ui.VerticalPanel;
29
30 /**
31  * Demonstrates the various button widgets.
32  */

33 public class Widgets extends Sink implements Command {
34
35   public static SinkInfo init(final Sink.Images images) {
36     return new SinkInfo("Widgets", "<h2>Basic Widgets</h2>" +
37       "<p>GWT has all sorts of the basic widgets you would expect from any " +
38       "toolkit.</p><p>Below, you can see various kinds of buttons, check boxes, " +
39       "radio buttons, and menus.</p>") {
40
41       public Sink createInstance() {
42         return new Widgets(images);
43       }
44
45       public String JavaDoc getColor() {
46         return "#bf2a2a";
47       }
48     };
49   }
50
51   private Button disabledButton = new Button("Disabled Button");
52   private CheckBox disabledCheck = new CheckBox("Disabled Check");
53   private Button normalButton = new Button("Normal Button");
54   private CheckBox normalCheck = new CheckBox("Normal Check");
55   private VerticalPanel panel = new VerticalPanel();
56   private RadioButton radio0 = new RadioButton("group0", "Choice 0");
57   private RadioButton radio1 = new RadioButton("group0", "Choice 1");
58   private RadioButton radio2 = new RadioButton("group0", "Choice 2 (Disabled)");
59   private RadioButton radio3 = new RadioButton("group0", "Choice 3");
60   private PushButton pushButton;
61   private ToggleButton toggleButton;
62
63   public Widgets(Sink.Images images) {
64     pushButton = new PushButton(images.gwtLogo().createImage());
65     toggleButton = new ToggleButton(images.gwtLogo().createImage());
66
67     HorizontalPanel hp;
68
69     panel.add(createMenu());
70
71     panel.add(hp = new HorizontalPanel());
72     hp.setSpacing(8);
73     hp.add(normalButton);
74     hp.add(disabledButton);
75
76     panel.add(hp = new HorizontalPanel());
77     hp.setSpacing(8);
78     hp.add(normalCheck);
79     hp.add(disabledCheck);
80
81     panel.add(hp = new HorizontalPanel());
82     hp.setSpacing(8);
83     hp.add(radio0);
84     hp.add(radio1);
85     hp.add(radio2);
86     hp.add(radio3);
87
88     panel.add(hp = new HorizontalPanel());
89     hp.setSpacing(8);
90     hp.add(pushButton);
91     hp.add(toggleButton);
92
93     disabledButton.setEnabled(false);
94     disabledCheck.setEnabled(false);
95     radio2.setEnabled(false);
96
97     panel.setSpacing(8);
98     initWidget(panel);
99   }
100
101   public MenuBar createMenu() {
102     MenuBar menu = new MenuBar();
103     menu.setAutoOpen(true);
104
105     MenuBar subMenu = new MenuBar(true);
106     subMenu.addItem("<code>Code</code>", true, this);
107     subMenu.addItem("<strike>Strikethrough</strike>", true, this);
108     subMenu.addItem("<u>Underlined</u>", true, this);
109
110     MenuBar menu0 = new MenuBar(true);
111     menu0.addItem("<b>Bold</b>", true, this);
112     menu0.addItem("<i>Italicized</i>", true, this);
113     menu0.addItem("More &#187;", true, subMenu);
114     MenuBar menu1 = new MenuBar(true);
115     menu1.addItem("<font color='#FF0000'><b>Apple</b></font>", true, this);
116     menu1.addItem("<font color='#FFFF00'><b>Banana</b></font>", true, this);
117     menu1.addItem("<font color='#FFFFFF'><b>Coconut</b></font>", true, this);
118     menu1.addItem("<font color='#8B4513'><b>Donut</b></font>", true, this);
119     MenuBar menu2 = new MenuBar(true);
120     menu2.addItem("Bling", this);
121     menu2.addItem("Ginormous", this);
122     menu2.addItem("<code>w00t!</code>", true, this);
123
124     menu.addItem(new MenuItem("Style", menu0));
125     menu.addItem(new MenuItem("Fruit", menu1));
126     menu.addItem(new MenuItem("Term", menu2));
127
128     menu.setWidth("100%");
129
130     return menu;
131   }
132
133   public void execute() {
134     Window.alert("Thank you for selecting a menu item.");
135   }
136
137   public void onShow() {
138   }
139 }
140
Popular Tags