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.ui.Button;
019: import com.google.gwt.user.client.ui.ClickListener;
020: import com.google.gwt.user.client.ui.DialogBox;
021: import com.google.gwt.user.client.ui.DockPanel;
022: import com.google.gwt.user.client.ui.HTML;
023: import com.google.gwt.user.client.ui.Image;
024: import com.google.gwt.user.client.ui.ListBox;
025: import com.google.gwt.user.client.ui.PopupPanel;
026: import com.google.gwt.user.client.ui.VerticalPanel;
027: import com.google.gwt.user.client.ui.Widget;
028:
029: /**
030: * Demonstrates {@link com.google.gwt.user.client.ui.PopupPanel} and
031: * {@link com.google.gwt.user.client.ui.DialogBox}.
032: */
033: public class Popups extends Sink implements ClickListener {
034:
035: /**
036: * A simple dialog box that displays a message, a Frame, and a close button.
037: */
038: private static class MyDialog extends DialogBox implements
039: ClickListener {
040: public MyDialog() {
041: setText("Sample DialogBox");
042:
043: Button closeButton = new Button("Close", this );
044: HTML msg = new HTML(
045: "<center>This is an example of a standard dialog box component.</center>",
046: true);
047:
048: DockPanel dock = new DockPanel();
049: dock.setSpacing(4);
050:
051: dock.add(closeButton, DockPanel.SOUTH);
052: dock.add(msg, DockPanel.NORTH);
053: dock.add(new Image("images/jimmy.jpg"), DockPanel.CENTER);
054:
055: dock.setCellHorizontalAlignment(closeButton,
056: DockPanel.ALIGN_RIGHT);
057: dock.setWidth("100%");
058: setWidget(dock);
059: }
060:
061: public void onClick(Widget sender) {
062: hide();
063: }
064: }
065:
066: /**
067: * A very simple popup that closes automatically when you click off of it.
068: */
069: private static class MyPopup extends PopupPanel {
070: public MyPopup() {
071: super (true);
072:
073: HTML contents = new HTML(
074: "Click anywhere outside this popup to make it disappear.");
075: contents.setWidth("128px");
076: setWidget(contents);
077:
078: setStyleName("ks-popups-Popup");
079: }
080: }
081:
082: public static SinkInfo init() {
083: return new SinkInfo(
084: "Popups",
085: "<h2>Popups and Dialog Boxes</h2>"
086: + "<p>This page demonstrates GWT's built-in support for in-page "
087: + "popups. The first is a very simple informational popup that closes "
088: + "itself automatically when you click off of it. The second is a more "
089: + "complex draggable dialog box. If you're wondering why there's "
090: + "a list box at the bottom, it's to demonstrate that you can drag the "
091: + "dialog box over it (this obscure corner case often renders incorrectly "
092: + "on some browsers).</p>") {
093:
094: @Override
095: public Sink createInstance() {
096: return new Popups();
097: }
098:
099: @Override
100: public String getColor() {
101: return "#bf2a2a";
102: }
103: };
104: }
105:
106: private Button dialogButton = new Button("Show Dialog", this );
107: private Button popupButton = new Button("Show Popup", this );
108:
109: public Popups() {
110: VerticalPanel panel = new VerticalPanel();
111: panel.add(popupButton);
112: panel.add(dialogButton);
113:
114: ListBox list = new ListBox();
115: list.setVisibleItemCount(1);
116: for (int i = 0; i < 10; ++i) {
117: list.addItem("list item " + i);
118: }
119: panel.add(list);
120:
121: panel.setSpacing(8);
122: initWidget(panel);
123: }
124:
125: public void onClick(Widget sender) {
126: if (sender == popupButton) {
127: MyPopup p = new MyPopup();
128: int left = sender.getAbsoluteLeft() + 10;
129: int top = sender.getAbsoluteTop() + 10;
130: p.setPopupPosition(left, top);
131: p.show();
132: } else if (sender == dialogButton) {
133: DialogBox dlg = new MyDialog();
134: dlg.center();
135: }
136: }
137:
138: @Override
139: public void onShow() {
140: }
141: }
|