1 16 package com.google.gwt.user.client.ui; 17 18 import com.google.gwt.user.client.DOM; 19 import com.google.gwt.user.client.Event; 20 21 37 public class DialogBox extends PopupPanel implements HasHTML, MouseListener { 38 39 private HTML caption = new HTML(); 40 private Widget child; 41 private boolean dragging; 42 private int dragStartX, dragStartY; 43 private FlexTable panel = new FlexTable(); 44 45 49 public DialogBox() { 50 this(false); 51 } 52 53 61 public DialogBox(boolean autoHide) { 62 this(autoHide, true); 63 } 64 65 75 public DialogBox(boolean autoHide, boolean modal) { 76 super(autoHide, modal); 77 panel.setWidget(0, 0, caption); 78 panel.setHeight("100%"); 79 panel.setBorderWidth(0); 80 panel.setCellPadding(0); 81 panel.setCellSpacing(0); 82 panel.getCellFormatter().setHeight(1, 0, "100%"); 83 panel.getCellFormatter().setWidth(1, 0, "100%"); 84 panel.getCellFormatter().setAlignment(1, 0, 85 HasHorizontalAlignment.ALIGN_CENTER, HasVerticalAlignment.ALIGN_MIDDLE); 86 super.setWidget(panel); 87 88 setStyleName("gwt-DialogBox"); 89 caption.setStyleName("Caption"); 90 caption.addMouseListener(this); 91 } 92 93 public String getHTML() { 94 return caption.getHTML(); 95 } 96 97 public String getText() { 98 return caption.getText(); 99 } 100 101 public boolean onEventPreview(Event event) { 102 if (DOM.eventGetType(event) == Event.ONMOUSEDOWN) { 106 if (DOM.isOrHasChild(caption.getElement(), DOM.eventGetTarget(event))) { 107 DOM.eventPreventDefault(event); 108 } 109 } 110 111 return super.onEventPreview(event); 112 } 113 114 public void onMouseDown(Widget sender, int x, int y) { 115 dragging = true; 116 DOM.setCapture(caption.getElement()); 117 dragStartX = x; 118 dragStartY = y; 119 } 120 121 public void onMouseEnter(Widget sender) { 122 } 123 124 public void onMouseLeave(Widget sender) { 125 } 126 127 public void onMouseMove(Widget sender, int x, int y) { 128 if (dragging) { 129 int absX = x + getAbsoluteLeft(); 130 int absY = y + getAbsoluteTop(); 131 setPopupPosition(absX - dragStartX, absY - dragStartY); 132 } 133 } 134 135 public void onMouseUp(Widget sender, int x, int y) { 136 dragging = false; 137 DOM.releaseCapture(caption.getElement()); 138 } 139 140 public boolean remove(Widget w) { 141 if (child != w) { 142 return false; 143 } 144 145 panel.remove(w); 146 return true; 147 } 148 149 public void setHTML(String html) { 150 caption.setHTML(html); 151 } 152 153 public void setText(String text) { 154 caption.setText(text); 155 } 156 157 public void setWidget(Widget w) { 158 if (child != null) { 160 panel.remove(child); 161 } 162 163 if (w != null) { 165 panel.setWidget(1, 0, w); 166 } 167 168 child = w; 169 } 170 171 176 public void setWidth(String width) { 177 super.setWidth(width); 178 179 panel.setWidth("100%"); 184 } 185 } 186 | Popular Tags |