KickJava   Java API By Example, From Geeks To Geeks.

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


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.ui.Button;
19 import com.google.gwt.user.client.ui.CheckBox;
20 import com.google.gwt.user.client.ui.DisclosurePanel;
21 import com.google.gwt.user.client.ui.DockPanel;
22 import com.google.gwt.user.client.ui.FlowPanel;
23 import com.google.gwt.user.client.ui.Grid;
24 import com.google.gwt.user.client.ui.HTML;
25 import com.google.gwt.user.client.ui.HorizontalPanel;
26 import com.google.gwt.user.client.ui.HorizontalSplitPanel;
27 import com.google.gwt.user.client.ui.ScrollPanel;
28 import com.google.gwt.user.client.ui.TabPanel;
29 import com.google.gwt.user.client.ui.VerticalPanel;
30
31 /**
32  * Demonstrates various panels and the way they lay widgets out.
33  */

34 public class Panels extends Sink {
35
36   public static SinkInfo init(final Sink.Images images) {
37     return new SinkInfo(
38         "Panels",
39         "<h2>Panels</h2><p>This page demonstrates some of the basic GWT panels, each of which "
40             + "arranges its contained widgets differently. "
41             + "These panels are designed to take advantage of the browser's "
42             + "built-in layout mechanics, which keeps the user interface snappy "
43             + "and helps your AJAX code play nicely with existing HTML. "
44             + "On the other hand, if you need pixel-perfect control, "
45             + "you can tweak things at a low level using the "
46             + "<code>DOM</code> class.</p>") {
47
48       public Sink createInstance() {
49         return new Panels(images);
50       }
51
52       public String JavaDoc getColor() {
53         return "#fe9915";
54       }
55     };
56   }
57
58   public Panels(Sink.Images images) {
59     HTML contents = new HTML("This is a <code>ScrollPanel</code> contained at "
60         + "the center of a <code>DockPanel</code>. "
61         + "By putting some fairly large contents "
62         + "in the middle and setting its size explicitly, it becomes a "
63         + "scrollable area within the page, but without requiring the use of "
64         + "an IFRAME."
65         + "Here's quite a bit more meaningless text that will serve primarily "
66         + "to make this thing scroll off the bottom of its visible area. "
67         + "Otherwise, you might have to make it really, really small in order "
68         + "to see the nifty scroll bars!");
69     ScrollPanel scroller = new ScrollPanel(contents);
70     scroller.setStyleName("ks-layouts-Scroller");
71
72     DockPanel dock = new DockPanel();
73     dock.setHorizontalAlignment(DockPanel.ALIGN_CENTER);
74     HTML north0 = new HTML("This is the <i>first</i> north component", true);
75     HTML east = new HTML(
76         "<center>This<br>is<br>the<br>east<br>component</center>", true);
77     HTML south = new HTML("This is the south component");
78     HTML west = new HTML(
79         "<center>This<br>is<br>the<br>west<br>component</center>", true);
80     HTML north1 = new HTML("This is the <b>second</b> north component", true);
81     dock.add(north0, DockPanel.NORTH);
82     dock.add(east, DockPanel.EAST);
83     dock.add(south, DockPanel.SOUTH);
84     dock.add(west, DockPanel.WEST);
85     dock.add(north1, DockPanel.NORTH);
86     dock.add(scroller, DockPanel.CENTER);
87
88     DisclosurePanel disc = new DisclosurePanel("Click to disclose something:");
89     disc.setContent(new HTML("This widget is is shown and hidden<br>by the "
90         + "disclosure panel that wraps it."));
91
92     FlowPanel flow = new FlowPanel();
93     for (int i = 0; i < 8; ++i) {
94       flow.add(new CheckBox("Flow " + i));
95     }
96
97     HorizontalPanel horz = new HorizontalPanel();
98     horz.setVerticalAlignment(VerticalPanel.ALIGN_MIDDLE);
99     horz.add(new Button("Button"));
100     horz.add(new HTML("<center>This is a<br>very<br>tall thing</center>", true));
101     horz.add(new Button("Button"));
102
103     VerticalPanel vert = new VerticalPanel();
104     vert.setHorizontalAlignment(VerticalPanel.ALIGN_CENTER);
105     vert.add(new Button("Small"));
106     vert.add(new Button("--- BigBigBigBig ---"));
107     vert.add(new Button("tiny"));
108
109     VerticalPanel vp = new VerticalPanel();
110     vp.setHorizontalAlignment(VerticalPanel.ALIGN_CENTER);
111     vp.setSpacing(8);
112     vp.add(makeLabel("Disclosure Panel"));
113     vp.add(disc);
114     vp.add(makeLabel("Flow Panel"));
115     vp.add(flow);
116     vp.add(makeLabel("Horizontal Panel"));
117     vp.add(horz);
118     vp.add(makeLabel("Vertical Panel"));
119     vp.add(vert);
120
121     Grid grid = new Grid(4, 4);
122     for (int r = 0; r < 4; ++r) {
123       for (int c = 0; c < 4; ++c) {
124         grid.setWidget(r, c, images.gwtLogo().createImage());
125       }
126     }
127
128     TabPanel tabs = new TabPanel();
129     tabs.add(vp, "Basic Panels");
130     tabs.add(dock, "Dock Panel");
131     tabs.add(grid, "Tables");
132     tabs.setWidth("100%");
133     tabs.selectTab(0);
134
135     HorizontalSplitPanel hSplit = new HorizontalSplitPanel();
136     hSplit.setLeftWidget(tabs);
137     hSplit.setRightWidget(new HTML(
138       "This is some text to make the right side of this " +
139       "splitter look a bit more interesting... " +
140       "This is some text to make the right side of this " +
141       "splitter look a bit more interesting... " +
142       "This is some text to make the right side of this " +
143       "splitter look a bit more interesting... " +
144       "This is some text to make the right side of this " +
145       "splitter look a bit more interesting... "));
146
147     initWidget(hSplit);
148     hSplit.setSize("100%", "450px");
149   }
150
151   public void onShow() {
152   }
153
154   private HTML makeLabel(String JavaDoc caption) {
155     HTML html = new HTML(caption);
156     html.setStyleName("ks-layouts-Label");
157     return html;
158   }
159 }
160
Popular Tags