|
@@ -1,368 +1,368 @@ |
1 |
|
- |
// This Source Code is in the Public Domain per: http://unlicense.org |
2 |
|
- |
package org.litesoft.GWT.client.nonpublic; |
3 |
|
- |
|
4 |
|
- |
import org.litesoft.GWT.client.*; |
5 |
|
- |
import org.litesoft.GWT.client.widgets.*; |
6 |
|
- |
import org.litesoft.GWT.client.widgets.nonpublic.*; |
7 |
|
- |
import org.litesoft.GWT.client.widgets.nonpublic.external.*; |
8 |
|
- |
import org.litesoft.commonfoundation.typeutils.*; |
9 |
|
- |
import org.litesoft.core.delayed.*; |
10 |
|
- |
|
11 |
|
- |
import com.google.gwt.core.client.*; |
12 |
|
- |
import com.google.gwt.event.shared.*; |
13 |
|
- |
import com.google.gwt.user.client.*; |
14 |
|
- |
import com.google.gwt.user.client.Event.*; |
15 |
|
- |
import com.google.gwt.user.client.ui.*; |
16 |
|
- |
import com.google.gwt.widgetideas.client.*; |
17 |
|
- |
|
18 |
|
- |
public abstract class AbstractDialog extends PopupPanel // PopupPanel is a SimplePanel |
19 |
|
- |
implements Dialog, |
20 |
|
- |
UiPositionAndSizeAdjustable { |
21 |
|
- |
private static final String TOP = "Top"; |
22 |
|
- |
private static final String LEFT = "Left"; |
23 |
|
- |
private static final String RIGHT = "Right"; |
24 |
|
- |
private static final String BOTTOM = "Bottom"; |
25 |
|
- |
|
26 |
|
- |
protected String mDefaultTitle; |
27 |
|
- |
private Opaqueness mOpaqueness; |
28 |
|
- |
|
29 |
|
- |
private AbstractFloaterPanel mOuterPanel; |
30 |
|
- |
private DialogCloseCallBack mCloseCallBack = null; |
31 |
|
- |
protected boolean mShowing = false; |
32 |
|
- |
private int mMinimumMarginWidth = 1; |
33 |
|
- |
private int mMinimumMarginHeight = 1; |
34 |
|
- |
private boolean mMaximize = false; |
35 |
|
- |
|
36 |
|
- |
public AbstractDialog( String pDefaultTitle, Opaqueness pOpaqueness ) { |
37 |
|
- |
super( false, true ); |
38 |
|
- |
|
39 |
|
- |
mDefaultTitle = pDefaultTitle; |
40 |
|
- |
mOpaqueness = (pOpaqueness != null) ? pOpaqueness : Opaqueness.Full; |
41 |
|
- |
} |
42 |
|
- |
|
43 |
|
- |
public boolean isCancelable() { |
44 |
|
- |
return true; |
45 |
|
- |
} |
46 |
|
- |
|
47 |
|
- |
private void setBorder( Grid pGrid, int pRow, String pRowClass, int pCol, String pColClass ) { |
48 |
|
- |
TransparentImage zWidget = new TransparentImage(); |
49 |
|
- |
pGrid.setWidget( pRow, pCol, zWidget ); |
50 |
|
- |
Element zParent = DOM.getParent( zWidget.getElement() ); |
51 |
|
- |
CommonElementHelper.setStyleClass( zParent, "litesoft-DialogOuterBorder" + pColClass + pRowClass ); |
52 |
|
- |
} |
53 |
|
- |
|
54 |
|
- |
private void setBorderRow( Grid pGrid, int pRow, String pRowClass ) { |
55 |
|
- |
setBorder( pGrid, pRow, pRowClass, 0, LEFT ); |
56 |
|
- |
setBorder( pGrid, pRow, pRowClass, 1, "" ); |
57 |
|
- |
setBorder( pGrid, pRow, pRowClass, 2, RIGHT ); |
58 |
|
- |
} |
59 |
|
- |
|
60 |
|
- |
public AbstractDialog initialize( String pTitle, DialogCloseCallBack pCloseCallBack ) { |
61 |
|
- |
mCloseCallBack = pCloseCallBack; |
62 |
|
- |
mOuterPanel = new FloaterPanelBody( this ); |
63 |
|
- |
Grid zGrid = new TightGrid( 3, 3 ); |
64 |
|
- |
setBorderRow( zGrid, 0, TOP ); |
65 |
|
- |
setBorder( zGrid, 1, "", 0, LEFT ); |
66 |
|
- |
zGrid.setWidget( 1, 1, mOuterPanel ); |
67 |
|
- |
setBorder( zGrid, 1, "", 2, RIGHT ); |
68 |
|
- |
setBorderRow( zGrid, 2, BOTTOM ); |
69 |
|
- |
setWidget( zGrid ); |
70 |
|
- |
|
71 |
|
- |
HideCommand zCloseCommand = isCancelable() ? new HideCommand() : null; |
72 |
|
- |
mOuterPanel.setTitleBar( new CloseableFloaterPanelTitleBar( "Dialog", Strings.deEmpty( pTitle, mDefaultTitle ), zCloseCommand ) ); |
73 |
|
- |
mOuterPanel.setWidget( createBodyPanel() ); |
74 |
|
- |
|
75 |
|
- |
return this; |
76 |
|
- |
} |
77 |
|
- |
|
78 |
|
- |
@Override |
79 |
|
- |
public String getTitle() { |
80 |
|
- |
return mOuterPanel.getTitle(); |
81 |
|
- |
} |
82 |
|
- |
|
83 |
|
- |
@Override |
84 |
|
- |
public void setTitle( String pTitle ) { |
85 |
|
- |
if ( null != (pTitle = Strings.noEmpty( pTitle )) ) { |
86 |
|
- |
mOuterPanel.setTitle( pTitle ); |
87 |
|
- |
} |
88 |
|
- |
} |
89 |
|
- |
|
90 |
|
- |
abstract protected Widget createBodyPanel(); |
91 |
|
- |
|
92 |
|
- |
public int getMinimumMarginWidth() { |
93 |
|
- |
return mMinimumMarginWidth; |
94 |
|
- |
} |
95 |
|
- |
|
96 |
|
- |
public void setMinimumMarginWidth( int pMinimumMarginWidth ) { |
97 |
|
- |
mMinimumMarginWidth = pMinimumMarginWidth; |
98 |
|
- |
} |
99 |
|
- |
|
100 |
|
- |
public int getMinimumMarginHeight() { |
101 |
|
- |
return mMinimumMarginHeight; |
102 |
|
- |
} |
103 |
|
- |
|
104 |
|
- |
public void setMinimumMarginHeight( int pMinimumMarginHeight ) { |
105 |
|
- |
mMinimumMarginHeight = pMinimumMarginHeight; |
106 |
|
- |
} |
107 |
|
- |
|
108 |
|
- |
public void setMinimumMargin( int pHeight, int pWidth ) { |
109 |
|
- |
setMinimumMarginHeight( pHeight ); |
110 |
|
- |
setMinimumMarginWidth( pWidth ); |
111 |
|
- |
} |
112 |
|
- |
|
113 |
|
- |
public void setMaximize() { |
114 |
|
- |
mMaximize = true; |
115 |
|
- |
} |
116 |
|
- |
|
117 |
|
- |
@Override |
118 |
|
- |
public void setWidth( String width ) { |
119 |
|
- |
// super.setWidth( width ); |
120 |
|
- |
mOuterPanel.setWidth( width ); |
121 |
|
- |
} |
122 |
|
- |
|
123 |
|
- |
@Override |
124 |
|
- |
public void setHeight( String height ) { |
125 |
|
- |
// super.setHeight( height ); |
126 |
|
- |
mOuterPanel.setHeight( height ); |
127 |
|
- |
} |
128 |
|
- |
|
129 |
|
- |
@Override |
130 |
|
- |
public void show() { |
131 |
|
- |
if ( !mShowing ) { |
132 |
|
- |
mShowing = true; |
133 |
|
- |
Scheduler.get().scheduleDeferred( new Command() { |
134 |
|
- |
@Override |
135 |
|
- |
public void execute() { |
136 |
|
- |
showDeferred(); |
137 |
|
- |
} |
138 |
|
- |
} ); |
139 |
|
- |
} |
140 |
|
- |
} |
141 |
|
- |
|
142 |
|
- |
private void showDeferred() { |
143 |
|
- |
addGlassPane(); |
144 |
|
- |
setVisible( false ); |
145 |
|
- |
setAnimationEnabled( false ); |
146 |
|
- |
if ( mMaximize ) { |
147 |
|
- |
mOuterPanel.setWidth( "" + (Window.getClientWidth() - (mMinimumMarginWidth + mMinimumMarginWidth)) ); |
148 |
|
- |
mOuterPanel.setHeight( "" + (Window.getClientHeight() - (mMinimumMarginHeight + mMinimumMarginHeight)) ); |
149 |
|
- |
} |
150 |
|
- |
super.show(); |
151 |
|
- |
final HandlerRegistration[] previewRegistration = new HandlerRegistration[1]; |
152 |
|
- |
previewRegistration[0] = Event.addNativePreviewHandler( new NativePreviewHandler() { |
153 |
|
- |
@Override |
154 |
|
- |
public void onPreviewNativeEvent( NativePreviewEvent pEvent ) { |
155 |
|
- |
if ( pEvent.getTypeInt() == Event.ONMOUSEOUT ) { |
156 |
|
- |
pEvent.consume(); // direct to continue propagation |
157 |
|
- |
previewRegistration[0].removeHandler(); |
158 |
|
- |
} |
159 |
|
- |
} |
160 |
|
- |
} ); |
161 |
|
- |
mOuterPanel.relayout(); |
162 |
|
- |
TimedRunnableManager.INSTANCE.runIn( new Centerer(), 20 ); |
163 |
|
- |
} |
164 |
|
- |
|
165 |
|
- |
private void finiShowCenter() { |
166 |
|
- |
int zClientWidth = Window.getClientWidth(); |
167 |
|
- |
int zClientHeight = Window.getClientHeight(); |
168 |
|
- |
|
169 |
|
- |
int zDialogWidth = mOuterPanel.getOffsetWidth(); |
170 |
|
- |
int zDialogHeight = mOuterPanel.getOffsetHeight(); |
171 |
|
- |
|
172 |
|
- |
int zActualWidth = getOffsetWidth(); |
173 |
|
- |
int zActualHeight = getOffsetHeight(); |
174 |
|
- |
|
175 |
|
- |
int zMaxWidth = zClientWidth - (mMinimumMarginWidth + mMinimumMarginWidth); |
176 |
|
- |
if ( zDialogWidth > zMaxWidth ) { |
177 |
|
- |
mOuterPanel.setWidth( "" + zMaxWidth ); |
178 |
|
- |
zActualWidth -= zDialogWidth - zMaxWidth; |
179 |
|
- |
} |
180 |
|
- |
int zMaxHeight = zClientHeight - (mMinimumMarginHeight + mMinimumMarginHeight); |
181 |
|
- |
if ( zDialogHeight > zMaxHeight ) { |
182 |
|
- |
setHeight( "" + zMaxHeight ); |
183 |
|
- |
zActualHeight -= zDialogHeight - zMaxHeight; |
184 |
|
- |
} |
185 |
|
- |
|
186 |
|
- |
int left = (zClientWidth - zActualWidth) >> 1; |
187 |
|
- |
int top = (zClientHeight - zActualHeight) >> 1; |
188 |
|
- |
setPopupPosition( Window.getScrollLeft() + left, Window.getScrollTop() + top ); |
189 |
|
- |
|
190 |
|
- |
setVisible( true ); |
191 |
|
- |
} |
192 |
|
- |
|
193 |
|
- |
private class Centerer implements TimedRunnable { |
194 |
|
- |
private boolean mSizingPending = true; |
195 |
|
- |
|
196 |
|
- |
@Override |
197 |
|
- |
public Again runOnce() { |
198 |
|
- |
if ( mSizingPending ) { |
199 |
|
- |
mSizingPending = mOuterPanel.isSizingPending(); |
200 |
|
- |
return new RunAgainIn( 20 ); |
201 |
|
- |
} |
202 |
|
- |
finiShowCenter(); |
203 |
|
- |
return null; |
204 |
|
- |
} |
205 |
|
- |
} |
206 |
|
- |
|
207 |
|
- |
@Override |
208 |
|
- |
public void hide() { |
209 |
|
- |
if ( mShowing ) { |
210 |
|
- |
mShowing = false; |
211 |
|
- |
super.hide(); |
212 |
|
- |
removeGlassPane(); |
213 |
|
- |
if ( mCloseCallBack != null ) { |
214 |
|
- |
mCloseCallBack.dialogClosed(); |
215 |
|
- |
} |
216 |
|
- |
} |
217 |
|
- |
} |
218 |
|
- |
|
219 |
|
- |
@Override |
220 |
|
- |
public boolean adjustWidthBy( int pDelta ) { |
221 |
|
- |
return mOuterPanel.adjustWidthBy( pDelta ); |
222 |
|
- |
} |
223 |
|
- |
|
224 |
|
- |
@Override |
225 |
|
- |
public boolean adjustHeightBy( int pDelta ) { |
226 |
|
- |
return mOuterPanel.adjustHeightBy( pDelta ); |
227 |
|
- |
} |
228 |
|
- |
|
229 |
|
- |
@Override |
230 |
|
- |
public void setPosition( int pLeft, int pTop ) { |
231 |
|
- |
setPosLeft( pLeft ); |
232 |
|
- |
setPosTop( pTop ); |
233 |
|
- |
} |
234 |
|
- |
|
235 |
|
- |
@Override |
236 |
|
- |
public void setPosLeft( int pPosLeft ) { |
237 |
|
- |
CommonElementHelper.setLeft( getElement(), pPosLeft ); |
238 |
|
- |
} |
239 |
|
- |
|
240 |
|
- |
@Override |
241 |
|
- |
public void setPosTop( int pPosTop ) { |
242 |
|
- |
CommonElementHelper.setTop( getElement(), pPosTop ); |
243 |
|
- |
} |
244 |
|
- |
|
245 |
|
- |
@Override |
246 |
|
- |
public int getPosLeft() { |
247 |
|
- |
return parse( getElement().getStyle().getLeft() ); |
248 |
|
- |
} |
249 |
|
- |
|
250 |
|
- |
@Override |
251 |
|
- |
public int getPosTop() { |
252 |
|
- |
return parse( getElement().getStyle().getTop() ); |
253 |
|
- |
} |
254 |
|
- |
|
255 |
|
- |
@Override |
256 |
|
- |
public int minPosLeft() { |
257 |
|
- |
return 0; |
258 |
|
- |
} |
259 |
|
- |
|
260 |
|
- |
@Override |
261 |
|
- |
public int minPosTop() { |
262 |
|
- |
return 0; |
263 |
|
- |
} |
264 |
|
- |
|
265 |
|
- |
@Override |
266 |
|
- |
public int maxPosLeft() { |
267 |
|
- |
return WindowSizingPanel.width - getOffsetWidth(); |
268 |
|
- |
} |
269 |
|
- |
|
270 |
|
- |
@Override |
271 |
|
- |
public int maxPosTop() { |
272 |
|
- |
return WindowSizingPanel.height - getOffsetHeight(); |
273 |
|
- |
} |
274 |
|
- |
|
275 |
|
- |
private int parse( String pSize_1D ) { |
276 |
|
- |
try { |
277 |
|
- |
return AbstractSizeableWidget.parse( pSize_1D ); |
278 |
|
- |
} |
279 |
|
- |
catch ( NumberFormatException e ) { |
280 |
|
- |
return -9999; |
281 |
|
- |
} |
282 |
|
- |
} |
283 |
|
- |
|
284 |
|
- |
private static class FloaterPanelBody extends AbstractFloaterPanel { |
285 |
|
- |
private UiPositionAndSizeAdjustable mPopupWrapper; |
286 |
|
- |
|
287 |
|
- |
public FloaterPanelBody( UiPositionAndSizeAdjustable pPopupWrapper ) { |
288 |
|
- |
super( "Dialog" ); |
289 |
|
- |
mPopupWrapper = pPopupWrapper; |
290 |
|
- |
|
291 |
|
- |
mTitleBarPanel.addController( mDragController = createTitleBarDragController( pPopupWrapper ) ); |
292 |
|
- |
|
293 |
|
- |
finishContainerTable( pPopupWrapper ); |
294 |
|
- |
} |
295 |
|
- |
|
296 |
|
- |
private DragController createTitleBarDragController( UiPositionable pUiPositionable ) { |
297 |
|
- |
return createDragController( createThresholdFilter( createTitleBarDragGesture( pUiPositionable ) ) ); |
298 |
|
- |
} |
299 |
|
- |
|
300 |
|
- |
@Override |
301 |
|
- |
protected DragController createBorderDragController( DragGesture pResizer ) { |
302 |
|
- |
return createDragController( createThresholdFilter( pResizer ) ); |
303 |
|
- |
} |
304 |
|
- |
|
305 |
|
- |
@Override |
306 |
|
- |
public void setPosLeft( int pPosLeft ) { |
307 |
|
- |
mPopupWrapper.setPosLeft( pPosLeft ); |
308 |
|
- |
} |
309 |
|
- |
|
310 |
|
- |
@Override |
311 |
|
- |
public void setPosTop( int pPosTop ) { |
312 |
|
- |
mPopupWrapper.setPosTop( pPosTop ); |
313 |
|
- |
} |
314 |
|
- |
|
315 |
|
- |
@Override |
316 |
|
- |
public int getPosLeft() { |
317 |
|
- |
return mPopupWrapper.getPosLeft(); |
318 |
|
- |
} |
319 |
|
- |
|
320 |
|
- |
@Override |
321 |
|
- |
public int getPosTop() { |
322 |
|
- |
return mPopupWrapper.getPosTop(); |
323 |
|
- |
} |
324 |
|
- |
|
325 |
|
- |
@Override |
326 |
|
- |
public int minPosLeft() { |
327 |
|
- |
return mPopupWrapper.minPosLeft(); |
328 |
|
- |
} |
329 |
|
- |
|
330 |
|
- |
@Override |
331 |
|
- |
public int minPosTop() { |
332 |
|
- |
return mPopupWrapper.minPosTop(); |
333 |
|
- |
} |
334 |
|
- |
|
335 |
|
- |
@Override |
336 |
|
- |
public int maxPosLeft() { |
337 |
|
- |
return mPopupWrapper.maxPosLeft(); |
338 |
|
- |
} |
339 |
|
- |
|
340 |
|
- |
@Override |
341 |
|
- |
public int maxPosTop() { |
342 |
|
- |
return mPopupWrapper.maxPosTop(); |
343 |
|
- |
} |
344 |
|
- |
} |
345 |
|
- |
|
346 |
|
- |
private GlassPanel mGlassPanel = null; |
347 |
|
- |
|
348 |
|
- |
private void addGlassPane() { |
349 |
|
- |
removeGlassPane(); |
350 |
|
- |
mGlassPanel = new GlassPanel( false ); |
351 |
|
- |
mGlassPanel.addStyleName( "DialogGlassPaneOpaqueness" + mOpaqueness ); |
352 |
|
- |
RootPanel.get().add( mGlassPanel, 0, 0 ); |
353 |
|
- |
} |
354 |
|
- |
|
355 |
|
- |
private void removeGlassPane() { |
356 |
|
- |
if ( mGlassPanel != null ) { |
357 |
|
- |
mGlassPanel.removeFromParent(); |
358 |
|
- |
mGlassPanel = null; |
359 |
|
- |
} |
360 |
|
- |
} |
361 |
|
- |
|
362 |
|
- |
public class HideCommand implements Command { |
363 |
|
- |
@Override |
364 |
|
- |
public void execute() { |
365 |
|
- |
hide(); |
366 |
|
- |
} |
367 |
|
- |
} |
368 |
|
- |
} |
|
1 |
+ |
// This Source Code is in the Public Domain per: http://unlicense.org |
|
2 |
+ |
package org.litesoft.GWT.client.nonpublic; |
|
3 |
+ |
|
|
4 |
+ |
import org.litesoft.GWT.client.*; |
|
5 |
+ |
import org.litesoft.GWT.client.widgets.*; |
|
6 |
+ |
import org.litesoft.GWT.client.widgets.nonpublic.*; |
|
7 |
+ |
import org.litesoft.GWT.client.widgets.nonpublic.external.*; |
|
8 |
+ |
import org.litesoft.commonfoundation.base.*; |
|
9 |
+ |
import org.litesoft.core.delayed.*; |
|
10 |
+ |
|
|
11 |
+ |
import com.google.gwt.core.client.*; |
|
12 |
+ |
import com.google.gwt.event.shared.*; |
|
13 |
+ |
import com.google.gwt.user.client.*; |
|
14 |
+ |
import com.google.gwt.user.client.Event.*; |
|
15 |
+ |
import com.google.gwt.user.client.ui.*; |
|
16 |
+ |
import com.google.gwt.widgetideas.client.*; |
|
17 |
+ |
|
|
18 |
+ |
public abstract class AbstractDialog extends PopupPanel // PopupPanel is a SimplePanel |
|
19 |
+ |
implements Dialog, |
|
20 |
+ |
UiPositionAndSizeAdjustable { |
|
21 |
+ |
private static final String TOP = "Top"; |
|
22 |
+ |
private static final String LEFT = "Left"; |
|
23 |
+ |
private static final String RIGHT = "Right"; |
|
24 |
+ |
private static final String BOTTOM = "Bottom"; |
|
25 |
+ |
|
|
26 |
+ |
protected String mDefaultTitle; |
|
27 |
+ |
private Opaqueness mOpaqueness; |
|
28 |
+ |
|
|
29 |
+ |
private AbstractFloaterPanel mOuterPanel; |
|
30 |
+ |
private DialogCloseCallBack mCloseCallBack = null; |
|
31 |
+ |
protected boolean mShowing = false; |
|
32 |
+ |
private int mMinimumMarginWidth = 1; |
|
33 |
+ |
private int mMinimumMarginHeight = 1; |
|
34 |
+ |
private boolean mMaximize = false; |
|
35 |
+ |
|
|
36 |
+ |
public AbstractDialog( String pDefaultTitle, Opaqueness pOpaqueness ) { |
|
37 |
+ |
super( false, true ); |
|
38 |
+ |
|
|
39 |
+ |
mDefaultTitle = pDefaultTitle; |
|
40 |
+ |
mOpaqueness = (pOpaqueness != null) ? pOpaqueness : Opaqueness.Full; |
|
41 |
+ |
} |
|
42 |
+ |
|
|
43 |
+ |
public boolean isCancelable() { |
|
44 |
+ |
return true; |
|
45 |
+ |
} |
|
46 |
+ |
|
|
47 |
+ |
private void setBorder( Grid pGrid, int pRow, String pRowClass, int pCol, String pColClass ) { |
|
48 |
+ |
TransparentImage zWidget = new TransparentImage(); |
|
49 |
+ |
pGrid.setWidget( pRow, pCol, zWidget ); |
|
50 |
+ |
Element zParent = DOM.getParent( zWidget.getElement() ); |
|
51 |
+ |
CommonElementHelper.setStyleClass( zParent, "litesoft-DialogOuterBorder" + pColClass + pRowClass ); |
|
52 |
+ |
} |
|
53 |
+ |
|
|
54 |
+ |
private void setBorderRow( Grid pGrid, int pRow, String pRowClass ) { |
|
55 |
+ |
setBorder( pGrid, pRow, pRowClass, 0, LEFT ); |
|
56 |
+ |
setBorder( pGrid, pRow, pRowClass, 1, "" ); |
|
57 |
+ |
setBorder( pGrid, pRow, pRowClass, 2, RIGHT ); |
|
58 |
+ |
} |
|
59 |
+ |
|
|
60 |
+ |
public AbstractDialog initialize( String pTitle, DialogCloseCallBack pCloseCallBack ) { |
|
61 |
+ |
mCloseCallBack = pCloseCallBack; |
|
62 |
+ |
mOuterPanel = new FloaterPanelBody( this ); |
|
63 |
+ |
Grid zGrid = new TightGrid( 3, 3 ); |
|
64 |
+ |
setBorderRow( zGrid, 0, TOP ); |
|
65 |
+ |
setBorder( zGrid, 1, "", 0, LEFT ); |
|
66 |
+ |
zGrid.setWidget( 1, 1, mOuterPanel ); |
|
67 |
+ |
setBorder( zGrid, 1, "", 2, RIGHT ); |
|
68 |
+ |
setBorderRow( zGrid, 2, BOTTOM ); |
|
69 |
+ |
setWidget( zGrid ); |
|
70 |
+ |
|
|
71 |
+ |
HideCommand zCloseCommand = isCancelable() ? new HideCommand() : null; |
|
72 |
+ |
mOuterPanel.setTitleBar( new CloseableFloaterPanelTitleBar( "Dialog", ConstrainTo.significantOrNull( pTitle, mDefaultTitle ), zCloseCommand ) ); |
|
73 |
+ |
mOuterPanel.setWidget( createBodyPanel() ); |
|
74 |
+ |
|
|
75 |
+ |
return this; |
|
76 |
+ |
} |
|
77 |
+ |
|
|
78 |
+ |
@Override |
|
79 |
+ |
public String getTitle() { |
|
80 |
+ |
return mOuterPanel.getTitle(); |
|
81 |
+ |
} |
|
82 |
+ |
|
|
83 |
+ |
@Override |
|
84 |
+ |
public void setTitle( String pTitle ) { |
|
85 |
+ |
if ( null != (pTitle = ConstrainTo.significantOrNull( pTitle )) ) { |
|
86 |
+ |
mOuterPanel.setTitle( pTitle ); |
|
87 |
+ |
} |
|
88 |
+ |
} |
|
89 |
+ |
|
|
90 |
+ |
abstract protected Widget createBodyPanel(); |
|
91 |
+ |
|
|
92 |
+ |
public int getMinimumMarginWidth() { |
|
93 |
+ |
return mMinimumMarginWidth; |
|
94 |
+ |
} |
|
95 |
+ |
|
|
96 |
+ |
public void setMinimumMarginWidth( int pMinimumMarginWidth ) { |
|
97 |
+ |
mMinimumMarginWidth = pMinimumMarginWidth; |
|
98 |
+ |
} |
|
99 |
+ |
|
|
100 |
+ |
public int getMinimumMarginHeight() { |
|
101 |
+ |
return mMinimumMarginHeight; |
|
102 |
+ |
} |
|
103 |
+ |
|
|
104 |
+ |
public void setMinimumMarginHeight( int pMinimumMarginHeight ) { |
|
105 |
+ |
mMinimumMarginHeight = pMinimumMarginHeight; |
|
106 |
+ |
} |
|
107 |
+ |
|
|
108 |
+ |
public void setMinimumMargin( int pHeight, int pWidth ) { |
|
109 |
+ |
setMinimumMarginHeight( pHeight ); |
|
110 |
+ |
setMinimumMarginWidth( pWidth ); |
|
111 |
+ |
} |
|
112 |
+ |
|
|
113 |
+ |
public void setMaximize() { |
|
114 |
+ |
mMaximize = true; |
|
115 |
+ |
} |
|
116 |
+ |
|
|
117 |
+ |
@Override |
|
118 |
+ |
public void setWidth( String width ) { |
|
119 |
+ |
// super.setWidth( width ); |
|
120 |
+ |
mOuterPanel.setWidth( width ); |
|
121 |
+ |
} |
|
122 |
+ |
|
|
123 |
+ |
@Override |
|
124 |
+ |
public void setHeight( String height ) { |
|
125 |
+ |
// super.setHeight( height ); |
|
126 |
+ |
mOuterPanel.setHeight( height ); |
|
127 |
+ |
} |
|
128 |
+ |
|
|
129 |
+ |
@Override |
|
130 |
+ |
public void show() { |
|
131 |
+ |
if ( !mShowing ) { |
|
132 |
+ |
mShowing = true; |
|
133 |
+ |
Scheduler.get().scheduleDeferred( new Command() { |
|
134 |
+ |
@Override |
|
135 |
+ |
public void execute() { |
|
136 |
+ |
showDeferred(); |
|
137 |
+ |
} |
|
138 |
+ |
} ); |
|
139 |
+ |
} |
|
140 |
+ |
} |
|
141 |
+ |
|
|
142 |
+ |
private void showDeferred() { |
|
143 |
+ |
addGlassPane(); |
|
144 |
+ |
setVisible( false ); |
|
145 |
+ |
setAnimationEnabled( false ); |
|
146 |
+ |
if ( mMaximize ) { |
|
147 |
+ |
mOuterPanel.setWidth( "" + (Window.getClientWidth() - (mMinimumMarginWidth + mMinimumMarginWidth)) ); |
|
148 |
+ |
mOuterPanel.setHeight( "" + (Window.getClientHeight() - (mMinimumMarginHeight + mMinimumMarginHeight)) ); |
|
149 |
+ |
} |
|
150 |
+ |
super.show(); |
|
151 |
+ |
final HandlerRegistration[] previewRegistration = new HandlerRegistration[1]; |
|
152 |
+ |
previewRegistration[0] = Event.addNativePreviewHandler( new NativePreviewHandler() { |
|
153 |
+ |
@Override |
|
154 |
+ |
public void onPreviewNativeEvent( NativePreviewEvent pEvent ) { |
|
155 |
+ |
if ( pEvent.getTypeInt() == Event.ONMOUSEOUT ) { |
|
156 |
+ |
pEvent.consume(); // direct to continue propagation |
|
157 |
+ |
previewRegistration[0].removeHandler(); |
|
158 |
+ |
} |
|
159 |
+ |
} |
|
160 |
+ |
} ); |
|
161 |
+ |
mOuterPanel.relayout(); |
|
162 |
+ |
TimedRunnableManager.INSTANCE.runIn( new Centerer(), 20 ); |
|
163 |
+ |
} |
|
164 |
+ |
|
|
165 |
+ |
private void finiShowCenter() { |
|
166 |
+ |
int zClientWidth = Window.getClientWidth(); |
|
167 |
+ |
int zClientHeight = Window.getClientHeight(); |
|
168 |
+ |
|
|
169 |
+ |
int zDialogWidth = mOuterPanel.getOffsetWidth(); |
|
170 |
+ |
int zDialogHeight = mOuterPanel.getOffsetHeight(); |
|
171 |
+ |
|
|
172 |
+ |
int zActualWidth = getOffsetWidth(); |
|
173 |
+ |
int zActualHeight = getOffsetHeight(); |
|
174 |
+ |
|
|
175 |
+ |
int zMaxWidth = zClientWidth - (mMinimumMarginWidth + mMinimumMarginWidth); |
|
176 |
+ |
if ( zDialogWidth > zMaxWidth ) { |
|
177 |
+ |
mOuterPanel.setWidth( "" + zMaxWidth ); |
|
178 |
+ |
zActualWidth -= zDialogWidth - zMaxWidth; |
|
179 |
+ |
} |
|
180 |
+ |
int zMaxHeight = zClientHeight - (mMinimumMarginHeight + mMinimumMarginHeight); |
|
181 |
+ |
if ( zDialogHeight > zMaxHeight ) { |
|
182 |
+ |
setHeight( "" + zMaxHeight ); |
|
183 |
+ |
zActualHeight -= zDialogHeight - zMaxHeight; |
|
184 |
+ |
} |
|
185 |
+ |
|
|
186 |
+ |
int left = (zClientWidth - zActualWidth) >> 1; |
|
187 |
+ |
int top = (zClientHeight - zActualHeight) >> 1; |
|
188 |
+ |
setPopupPosition( Window.getScrollLeft() + left, Window.getScrollTop() + top ); |
|
189 |
+ |
|
|
190 |
+ |
setVisible( true ); |
|
191 |
+ |
} |
|
192 |
+ |
|
|
193 |
+ |
private class Centerer implements TimedRunnable { |
|
194 |
+ |
private boolean mSizingPending = true; |
|
195 |
+ |
|
|
196 |
+ |
@Override |
|
197 |
+ |
public Again runOnce() { |
|
198 |
+ |
if ( mSizingPending ) { |
|
199 |
+ |
mSizingPending = mOuterPanel.isSizingPending(); |
|
200 |
+ |
return new RunAgainIn( 20 ); |
|
201 |
+ |
} |
|
202 |
+ |
finiShowCenter(); |
|
203 |
+ |
return null; |
|
204 |
+ |
} |
|
205 |
+ |
} |
|
206 |
+ |
|
|
207 |
+ |
@Override |
|
208 |
+ |
public void hide() { |
|
209 |
+ |
if ( mShowing ) { |
|
210 |
+ |
mShowing = false; |
|
211 |
+ |
super.hide(); |
|
212 |
+ |
removeGlassPane(); |
|
213 |
+ |
if ( mCloseCallBack != null ) { |
|
214 |
+ |
mCloseCallBack.dialogClosed(); |
|
215 |
+ |
} |
|
216 |
+ |
} |
|
217 |
+ |
} |
|
218 |
+ |
|
|
219 |
+ |
@Override |
|
220 |
+ |
public boolean adjustWidthBy( int pDelta ) { |
|
221 |
+ |
return mOuterPanel.adjustWidthBy( pDelta ); |
|
222 |
+ |
} |
|
223 |
+ |
|
|
224 |
+ |
@Override |
|
225 |
+ |
public boolean adjustHeightBy( int pDelta ) { |
|
226 |
+ |
return mOuterPanel.adjustHeightBy( pDelta ); |
|
227 |
+ |
} |
|
228 |
+ |
|
|
229 |
+ |
@Override |
|
230 |
+ |
public void setPosition( int pLeft, int pTop ) { |
|
231 |
+ |
setPosLeft( pLeft ); |
|
232 |
+ |
setPosTop( pTop ); |
|
233 |
+ |
} |
|
234 |
+ |
|
|
235 |
+ |
@Override |
|
236 |
+ |
public void setPosLeft( int pPosLeft ) { |
|
237 |
+ |
CommonElementHelper.setLeft( getElement(), pPosLeft ); |
|
238 |
+ |
} |
|
239 |
+ |
|
|
240 |
+ |
@Override |
|
241 |
+ |
public void setPosTop( int pPosTop ) { |
|
242 |
+ |
CommonElementHelper.setTop( getElement(), pPosTop ); |
|
243 |
+ |
} |
|
244 |
+ |
|
|
245 |
+ |
@Override |
|
246 |
+ |
public int getPosLeft() { |
|
247 |
+ |
return parse( getElement().getStyle().getLeft() ); |
|
248 |
+ |
} |
|
249 |
+ |
|
|
250 |
+ |
@Override |
|
251 |
+ |
public int getPosTop() { |
|
252 |
+ |
return parse( getElement().getStyle().getTop() ); |
|
253 |
+ |
} |
|
254 |
+ |
|
|
255 |
+ |
@Override |
|
256 |
+ |
public int minPosLeft() { |
|
257 |
+ |
return 0; |
|
258 |
+ |
} |
|
259 |
+ |
|
|
260 |
+ |
@Override |
|
261 |
+ |
public int minPosTop() { |
|
262 |
+ |
return 0; |
|
263 |
+ |
} |
|
264 |
+ |
|
|
265 |
+ |
@Override |
|
266 |
+ |
public int maxPosLeft() { |
|
267 |
+ |
return WindowSizingPanel.width - getOffsetWidth(); |
|
268 |
+ |
} |
|
269 |
+ |
|
|
270 |
+ |
@Override |
|
271 |
+ |
public int maxPosTop() { |
|
272 |
+ |
return WindowSizingPanel.height - getOffsetHeight(); |
|
273 |
+ |
} |
|
274 |
+ |
|
|
275 |
+ |
private int parse( String pSize_1D ) { |
|
276 |
+ |
try { |
|
277 |
+ |
return AbstractSizeableWidget.parse( pSize_1D ); |
|
278 |
+ |
} |
|
279 |
+ |
catch ( NumberFormatException e ) { |
|
280 |
+ |
return -9999; |
|
281 |
+ |
} |
|
282 |
+ |
} |
|
283 |
+ |
|
|
284 |
+ |
private static class FloaterPanelBody extends AbstractFloaterPanel { |
|
285 |
+ |
private UiPositionAndSizeAdjustable mPopupWrapper; |
|
286 |
+ |
|
|
287 |
+ |
public FloaterPanelBody( UiPositionAndSizeAdjustable pPopupWrapper ) { |
|
288 |
+ |
super( "Dialog" ); |
|
289 |
+ |
mPopupWrapper = pPopupWrapper; |
|
290 |
+ |
|
|
291 |
+ |
mTitleBarPanel.addController( mDragController = createTitleBarDragController( pPopupWrapper ) ); |
|
292 |
+ |
|
|
293 |
+ |
finishContainerTable( pPopupWrapper ); |
|
294 |
+ |
} |
|
295 |
+ |
|
|
296 |
+ |
private DragController createTitleBarDragController( UiPositionable pUiPositionable ) { |
|
297 |
+ |
return createDragController( createThresholdFilter( createTitleBarDragGesture( pUiPositionable ) ) ); |
|
298 |
+ |
} |
|
299 |
+ |
|
|
300 |
+ |
@Override |
|
301 |
+ |
protected DragController createBorderDragController( DragGesture pResizer ) { |
|
302 |
+ |
return createDragController( createThresholdFilter( pResizer ) ); |
|
303 |
+ |
} |
|
304 |
+ |
|
|
305 |
+ |
@Override |
|
306 |
+ |
public void setPosLeft( int pPosLeft ) { |
|
307 |
+ |
mPopupWrapper.setPosLeft( pPosLeft ); |
|
308 |
+ |
} |
|
309 |
+ |
|
|
310 |
+ |
@Override |
|
311 |
+ |
public void setPosTop( int pPosTop ) { |
|
312 |
+ |
mPopupWrapper.setPosTop( pPosTop ); |
|
313 |
+ |
} |
|
314 |
+ |
|
|
315 |
+ |
@Override |
|
316 |
+ |
public int getPosLeft() { |
|
317 |
+ |
return mPopupWrapper.getPosLeft(); |
|
318 |
+ |
} |
|
319 |
+ |
|
|
320 |
+ |
@Override |
|
321 |
+ |
public int getPosTop() { |
|
322 |
+ |
return mPopupWrapper.getPosTop(); |
|
323 |
+ |
} |
|
324 |
+ |
|
|
325 |
+ |
@Override |
|
326 |
+ |
public int minPosLeft() { |
|
327 |
+ |
return mPopupWrapper.minPosLeft(); |
|
328 |
+ |
} |
|
329 |
+ |
|
|
330 |
+ |
@Override |
|
331 |
+ |
public int minPosTop() { |
|
332 |
+ |
return mPopupWrapper.minPosTop(); |
|
333 |
+ |
} |
|
334 |
+ |
|
|
335 |
+ |
@Override |
|
336 |
+ |
public int maxPosLeft() { |
|
337 |
+ |
return mPopupWrapper.maxPosLeft(); |
|
338 |
+ |
} |
|
339 |
+ |
|
|
340 |
+ |
@Override |
|
341 |
+ |
public int maxPosTop() { |
|
342 |
+ |
return mPopupWrapper.maxPosTop(); |
|
343 |
+ |
} |
|
344 |
+ |
} |
|
345 |
+ |
|
|
346 |
+ |
private GlassPanel mGlassPanel = null; |
|
347 |
+ |
|
|
348 |
+ |
private void addGlassPane() { |
|
349 |
+ |
removeGlassPane(); |
|
350 |
+ |
mGlassPanel = new GlassPanel( false ); |
|
351 |
+ |
mGlassPanel.addStyleName( "DialogGlassPaneOpaqueness" + mOpaqueness ); |
|
352 |
+ |
RootPanel.get().add( mGlassPanel, 0, 0 ); |
|
353 |
+ |
} |
|
354 |
+ |
|
|
355 |
+ |
private void removeGlassPane() { |
|
356 |
+ |
if ( mGlassPanel != null ) { |
|
357 |
+ |
mGlassPanel.removeFromParent(); |
|
358 |
+ |
mGlassPanel = null; |
|
359 |
+ |
} |
|
360 |
+ |
} |
|
361 |
+ |
|
|
362 |
+ |
public class HideCommand implements Command { |
|
363 |
+ |
@Override |
|
364 |
+ |
public void execute() { |
|
365 |
+ |
hide(); |
|
366 |
+ |
} |
|
367 |
+ |
} |
|
368 |
+ |
} |