1 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.ClickListener; 20 import com.google.gwt.user.client.ui.DialogBox; 21 import com.google.gwt.user.client.ui.DockPanel; 22 import com.google.gwt.user.client.ui.HTML; 23 import com.google.gwt.user.client.ui.Image; 24 import com.google.gwt.user.client.ui.ListBox; 25 import com.google.gwt.user.client.ui.PopupPanel; 26 import com.google.gwt.user.client.ui.VerticalPanel; 27 import com.google.gwt.user.client.ui.Widget; 28 29 33 public class Popups extends Sink implements ClickListener { 34 35 38 private static class MyDialog extends DialogBox implements ClickListener { 39 public MyDialog() { 40 setText("Sample DialogBox"); 41 42 Button closeButton = new Button("Close", this); 43 HTML msg = new HTML( 44 "<center>This is an example of a standard dialog box component.</center>", 45 true); 46 47 DockPanel dock = new DockPanel(); 48 dock.setSpacing(4); 49 50 dock.add(closeButton, DockPanel.SOUTH); 51 dock.add(msg, DockPanel.NORTH); 52 dock.add(new Image("images/jimmy.jpg"), DockPanel.CENTER); 53 54 dock.setCellHorizontalAlignment(closeButton, DockPanel.ALIGN_RIGHT); 55 dock.setWidth("100%"); 56 setWidget(dock); 57 } 58 59 public void onClick(Widget sender) { 60 hide(); 61 } 62 } 63 64 67 private static class MyPopup extends PopupPanel { 68 public MyPopup() { 69 super(true); 70 71 HTML contents = new HTML( 72 "Click anywhere outside this popup to make it disappear."); 73 contents.setWidth("128px"); 74 setWidget(contents); 75 76 setStyleName("ks-popups-Popup"); 77 } 78 } 79 80 public static SinkInfo init() { 81 return new SinkInfo( 82 "Popups", 83 "<h2>Popups and Dialog Boxes</h2>" 84 + "<p>This page demonstrates GWT's built-in support for in-page " 85 + "popups. The first is a very simple informational popup that closes " 86 + "itself automatically when you click off of it. The second is a more " 87 + "complex draggable dialog box. If you're wondering why there's " 88 + "a list box at the bottom, it's to demonstrate that you can drag the " 89 + "dialog box over it (this obscure corner case often renders incorrectly " 90 + "on some browsers).</p>") { 91 92 public Sink createInstance() { 93 return new Popups(); 94 } 95 96 public String getColor() { 97 return "#bf2a2a"; 98 } 99 }; 100 } 101 102 private Button dialogButton = new Button("Show Dialog", this); 103 private Button popupButton = new Button("Show Popup", this); 104 105 public Popups() { 106 VerticalPanel panel = new VerticalPanel(); 107 panel.add(popupButton); 108 panel.add(dialogButton); 109 110 ListBox list = new ListBox(); 111 list.setVisibleItemCount(1); 112 for (int i = 0; i < 10; ++i) { 113 list.addItem("list item " + i); 114 } 115 panel.add(list); 116 117 panel.setSpacing(8); 118 initWidget(panel); 119 } 120 121 public void onClick(Widget sender) { 122 if (sender == popupButton) { 123 MyPopup p = new MyPopup(); 124 int left = sender.getAbsoluteLeft() + 10; 125 int top = sender.getAbsoluteTop() + 10; 126 p.setPopupPosition(left, top); 127 p.show(); 128 } else if (sender == dialogButton) { 129 DialogBox dlg = new MyDialog(); 130 dlg.show(); 131 dlg.setVisible(false); 132 dlg.center(); 133 dlg.setVisible(true); 134 } 135 } 136 137 public void onShow() { 138 } 139 } 140 | Popular Tags |