|
@@ -1,501 +1,501 @@ |
1 |
|
- |
// This Source Code is in the Public Domain per: http://unlicense.org |
2 |
|
- |
package org.litesoft.GWT.client.widgets.nonpublic; |
3 |
|
- |
|
4 |
|
- |
import org.litesoft.GWT.client.widgets.*; |
5 |
|
- |
import org.litesoft.core.delayed.*; |
6 |
|
- |
|
7 |
|
- |
import com.google.gwt.user.client.*; |
8 |
|
- |
import com.google.gwt.user.client.ui.*; |
9 |
|
- |
|
10 |
|
- |
import java.util.*; |
11 |
|
- |
|
12 |
|
- |
public abstract class AbstractSizeableDockingPanel extends AbstractSizeablePanel implements IndexedPanel { |
13 |
|
- |
private abstract static class ExtendedDockPosition { |
14 |
|
- |
private NEWSposition mPosition; |
15 |
|
- |
private int mChildIndex; |
16 |
|
- |
private boolean mHorizontal; |
17 |
|
- |
|
18 |
|
- |
public ExtendedDockPosition( NEWSposition pPosition, int pChildIndex, boolean pHorizontal ) { |
19 |
|
- |
mPosition = pPosition; |
20 |
|
- |
mChildIndex = pChildIndex; |
21 |
|
- |
mHorizontal = pHorizontal; |
22 |
|
- |
} |
23 |
|
- |
|
24 |
|
- |
public NEWSposition getPosition() { |
25 |
|
- |
return mPosition; |
26 |
|
- |
} |
27 |
|
- |
|
28 |
|
- |
public int getChildIndex() { |
29 |
|
- |
return mChildIndex; |
30 |
|
- |
} |
31 |
|
- |
|
32 |
|
- |
public boolean isHorizontal() { |
33 |
|
- |
return mHorizontal; |
34 |
|
- |
} |
35 |
|
- |
|
36 |
|
- |
public void checkAcceptability( ISizeableWidget pWidget ) { |
37 |
|
- |
if ( mHorizontal && !pWidget.getHeightHelper().isStretchable() ) { |
38 |
|
- |
throw new IllegalArgumentException( "Docked Widget not Vertically Stretchable" ); |
39 |
|
- |
} |
40 |
|
- |
if ( !mHorizontal && !pWidget.getWidthHelper().isStretchable() ) { |
41 |
|
- |
throw new IllegalArgumentException( "Docked Widget not Horizontally Stretchable" ); |
42 |
|
- |
} |
43 |
|
- |
} |
44 |
|
- |
|
45 |
|
- |
public void add( Element pTD, Widget pWidget, WidgetCollection pChildren, Element pContainerElement ) { |
46 |
|
- |
if ( pChildren.size() == 0 ) { |
47 |
|
- |
pChildren.add( pWidget ); |
48 |
|
- |
appendChild( pContainerElement, appendChild( DOM.createTR(), pTD ) ); |
49 |
|
- |
} else { |
50 |
|
- |
LLadd( pTD, pWidget, pChildren, pContainerElement, pChildren.get( 0 ) ); |
51 |
|
- |
} |
52 |
|
- |
} |
53 |
|
- |
|
54 |
|
- |
abstract protected void LLadd( Element pTD, Widget pWidget, WidgetCollection pChildren, |
55 |
|
- |
Element pContainerElement, Widget pContentWidget ); |
56 |
|
- |
} |
57 |
|
- |
|
58 |
|
- |
private static final ExtendedDockPosition NORTH = new ExtendedDockPosition( NEWSposition.NORTH, 0, false ) { |
59 |
|
- |
protected void LLadd( Element pTD, Widget pWidget, WidgetCollection pChildren, |
60 |
|
- |
Element pContainerElement, Widget pContentWidget ) { |
61 |
|
- |
pChildren.insert( pWidget, 0 ); |
62 |
|
- |
prependChild( pContainerElement, appendChild( DOM.createTR(), pTD ) ); |
63 |
|
- |
} |
64 |
|
- |
}; |
65 |
|
- |
|
66 |
|
- |
private static final ExtendedDockPosition EAST = new ExtendedDockPosition( NEWSposition.EAST, 1, true ) { |
67 |
|
- |
protected void LLadd( Element pTD, Widget pWidget, WidgetCollection pChildren, |
68 |
|
- |
Element pContainerElement, Widget pContentWidget ) { |
69 |
|
- |
pChildren.add( pWidget ); |
70 |
|
- |
appendChild( getGrandParentElement( pContentWidget ), pTD ); |
71 |
|
- |
} |
72 |
|
- |
}; |
73 |
|
- |
|
74 |
|
- |
private static final ExtendedDockPosition WEST = new ExtendedDockPosition( NEWSposition.WEST, 0, true ) { |
75 |
|
- |
protected void LLadd( Element pTD, Widget pWidget, WidgetCollection pChildren, |
76 |
|
- |
Element pContainerElement, Widget pContentWidget ) { |
77 |
|
- |
pChildren.insert( pWidget, 0 ); |
78 |
|
- |
prependChild( getGrandParentElement( pContentWidget ), pTD ); |
79 |
|
- |
} |
80 |
|
- |
}; |
81 |
|
- |
|
82 |
|
- |
private static final ExtendedDockPosition SOUTH = new ExtendedDockPosition( NEWSposition.SOUTH, 1, false ) { |
83 |
|
- |
protected void LLadd( Element pTD, Widget pWidget, WidgetCollection pChildren, |
84 |
|
- |
Element pContainerElement, Widget pContentWidget ) { |
85 |
|
- |
pChildren.add( pWidget ); |
86 |
|
- |
appendChild( pContainerElement, appendChild( DOM.createTR(), pTD ) ); |
87 |
|
- |
} |
88 |
|
- |
}; |
89 |
|
- |
|
90 |
|
- |
private ExtendedDockPosition mCurrentDockPosition = null; |
91 |
|
- |
private WidgetCollection mChildren = new WidgetCollection( this ); |
92 |
|
- |
|
93 |
|
- |
public NEWSposition getDockedPosition() { |
94 |
|
- |
return (mCurrentDockPosition == null) ? null : mCurrentDockPosition.getPosition(); |
95 |
|
- |
} |
96 |
|
- |
|
97 |
|
- |
private boolean isHorizontal() { |
98 |
|
- |
return (mCurrentDockPosition != null) && mCurrentDockPosition.isHorizontal(); |
99 |
|
- |
} |
100 |
|
- |
|
101 |
|
- |
public boolean anyChildren() { |
102 |
|
- |
return (mChildren.size() != 0); |
103 |
|
- |
} |
104 |
|
- |
|
105 |
|
- |
/** |
106 |
|
- |
* Gets the list of children contained in this panel. |
107 |
|
- |
* |
108 |
|
- |
* @return a collection of child widgets |
109 |
|
- |
*/ |
110 |
|
- |
protected WidgetCollection getChildren() { |
111 |
|
- |
return mChildren; |
112 |
|
- |
} |
113 |
|
- |
|
114 |
|
- |
// vvvvvvvvvvv HasWidgets |
115 |
|
- |
|
116 |
|
- |
/** |
117 |
|
- |
* Removes all child widgets. |
118 |
|
- |
*/ |
119 |
|
- |
public void clear() { |
120 |
|
- |
// Reverse order for SplitPairs |
121 |
|
- |
while ( anyChildren() ) { |
122 |
|
- |
remove( getWidgetCount() - 1 ); |
123 |
|
- |
} |
124 |
|
- |
} |
125 |
|
- |
|
126 |
|
- |
/** |
127 |
|
- |
* Gets an iterator for the contained widgets. This iterator is required to |
128 |
|
- |
* implement {@link Iterator#remove()}. |
129 |
|
- |
*/ |
130 |
|
- |
public Iterator iterator() { |
131 |
|
- |
return mChildren.iterator(); |
132 |
|
- |
} |
133 |
|
- |
|
134 |
|
- |
/** |
135 |
|
- |
* Adds a child widget. |
136 |
|
- |
* |
137 |
|
- |
* @param pWidget the widget to be added |
138 |
|
- |
* |
139 |
|
- |
* @throws UnsupportedOperationException if this method is not supported (most |
140 |
|
- |
* often this means that a specific overload must be called) |
141 |
|
- |
*/ |
142 |
|
- |
public void add( Widget pWidget ) { |
143 |
|
- |
throw new UnsupportedOperationException( |
144 |
|
- |
"SizeableDockingPanel does NOT support generic add(), please use the specific set...()" ); |
145 |
|
- |
} |
146 |
|
- |
|
147 |
|
- |
/** |
148 |
|
- |
* Removes a child widget. |
149 |
|
- |
* |
150 |
|
- |
* @param pWidget the widget to be removed |
151 |
|
- |
* |
152 |
|
- |
* @return <code>true</code> if the widget was present |
153 |
|
- |
*/ |
154 |
|
- |
public boolean remove( Widget pWidget ) { |
155 |
|
- |
if ( pWidget == getContentWidget() ) { |
156 |
|
- |
removeContentWidget(); |
157 |
|
- |
return true; |
158 |
|
- |
} |
159 |
|
- |
if ( pWidget == getDockedWidget() ) { |
160 |
|
- |
removeDockedWidget(); |
161 |
|
- |
return true; |
162 |
|
- |
} |
163 |
|
- |
return true; |
164 |
|
- |
} |
165 |
|
- |
|
166 |
|
- |
// ^^^^^^^^^^^ HasWidgets |
167 |
|
- |
|
168 |
|
- |
// vvvvvvvvvvv IndexedPanel |
169 |
|
- |
|
170 |
|
- |
public Widget getWidget( int pIndex ) { |
171 |
|
- |
return getChildren().get( pIndex ); |
172 |
|
- |
} |
173 |
|
- |
|
174 |
|
- |
public int getWidgetCount() { |
175 |
|
- |
return getChildren().size(); |
176 |
|
- |
} |
177 |
|
- |
|
178 |
|
- |
public int getWidgetIndex( Widget pChild ) { |
179 |
|
- |
return getChildren().indexOf( pChild ); |
180 |
|
- |
} |
181 |
|
- |
|
182 |
|
- |
public boolean remove( int pIndex ) { |
183 |
|
- |
return remove( getWidget( pIndex ) ); |
184 |
|
- |
} |
185 |
|
- |
|
186 |
|
- |
// ^^^^^^^^^^^ IndexedPanel |
187 |
|
- |
|
188 |
|
- |
/** |
189 |
|
- |
* @return the content widget, or <code>null</code> if none is present |
190 |
|
- |
*/ |
191 |
|
- |
public Widget getContentWidget() { |
192 |
|
- |
switch ( getWidgetCount() ) { |
193 |
|
- |
case 2: |
194 |
|
- |
return getWidget( 1 - mCurrentDockPosition.getChildIndex() ); |
195 |
|
- |
case 1: |
196 |
|
- |
if ( mCurrentDockPosition == null ) { |
197 |
|
- |
return getWidget( 0 ); |
198 |
|
- |
} |
199 |
|
- |
// Fall Thru |
200 |
|
- |
case 0: |
201 |
|
- |
default: |
202 |
|
- |
return null; |
203 |
|
- |
} |
204 |
|
- |
} |
205 |
|
- |
|
206 |
|
- |
/** |
207 |
|
- |
* Sets this panel's content widget. Any existing content widget will be removed. |
208 |
|
- |
*/ |
209 |
|
- |
public void setContentWidget( ISizeableWidget pWidget ) { |
210 |
|
- |
// If there is already a widget attached, remove it. |
211 |
|
- |
LLremoveContentWidget(); |
212 |
|
- |
|
213 |
|
- |
if ( pWidget != null ) { |
214 |
|
- |
if ( !pWidget.getHeightHelper().isStretchable() ) { |
215 |
|
- |
throw new IllegalArgumentException( "Content Widget not Vertically Stretchable" ); |
216 |
|
- |
} |
217 |
|
- |
if ( !pWidget.getWidthHelper().isStretchable() ) { |
218 |
|
- |
throw new IllegalArgumentException( "Content Widget not Horizontally Stretchable" ); |
219 |
|
- |
} |
220 |
|
- |
// Adopt the child. |
221 |
|
- |
Widget zWidget = (Widget) pWidget; |
222 |
|
- |
if ( !aboutToAdopt( zWidget ) ) { |
223 |
|
- |
return; |
224 |
|
- |
} |
225 |
|
- |
Element td = LLadopt( zWidget ); |
226 |
|
- |
|
227 |
|
- |
switch ( NEWSposition.deNull( getDockedPosition(), NEWSposition.NORTH ) ) { |
228 |
|
- |
default: |
229 |
|
- |
case NORTH: // Simply Append Row on End |
230 |
|
- |
mChildren.add( zWidget ); |
231 |
|
- |
appendChild( getContainerElement(), appendChild( DOM.createTR(), td ) ); |
232 |
|
- |
break; |
233 |
|
- |
case WEST: // Append Column after DockWidget |
234 |
|
- |
mChildren.add( zWidget ); |
235 |
|
- |
appendChild( getGrandParentElement( getDockedWidget() ), td ); |
236 |
|
- |
break; |
237 |
|
- |
case EAST: // Insert Column before DockWidget |
238 |
|
- |
mChildren.insert( zWidget, 0 ); |
239 |
|
- |
prependChild( getGrandParentElement( getDockedWidget() ), td ); |
240 |
|
- |
break; |
241 |
|
- |
case SOUTH: // Insert Row before DockWidget |
242 |
|
- |
mChildren.insert( zWidget, 0 ); |
243 |
|
- |
prependChild( getContainerElement(), appendChild( DOM.createTR(), td ) ); |
244 |
|
- |
break; |
245 |
|
- |
} |
246 |
|
- |
justAdopted( zWidget ); |
247 |
|
- |
} |
248 |
|
- |
relayout(); |
249 |
|
- |
} |
250 |
|
- |
|
251 |
|
- |
public void removeContentWidget() { |
252 |
|
- |
LLremoveContentWidget(); |
253 |
|
- |
relayout(); |
254 |
|
- |
} |
255 |
|
- |
|
256 |
|
- |
private void LLremoveContentWidget() { |
257 |
|
- |
// If there is a widget attached, remove it. |
258 |
|
- |
Widget zWidget = getContentWidget(); |
259 |
|
- |
if ( (zWidget != null) && aboutToDisown( zWidget ) ) { |
260 |
|
- |
mChildren.remove( zWidget ); |
261 |
|
- |
Element td = super.disown( zWidget );// remove Widget from td |
262 |
|
- |
Element tr = removeAsChildAndGetParent( td );// remove td |
263 |
|
- |
|
264 |
|
- |
if ( !isHorizontal() || (mChildren.size() == 0) ) { |
265 |
|
- |
removeAsChildAndGetParent( tr );// remove tr |
266 |
|
- |
} |
267 |
|
- |
justDisowned( zWidget ); |
268 |
|
- |
} |
269 |
|
- |
} |
270 |
|
- |
|
271 |
|
- |
/** |
272 |
|
- |
* Sets this panel's content widget. Any existing content widget will be removed. |
273 |
|
- |
*/ |
274 |
|
- |
public void removeDockedWidget() { |
275 |
|
- |
LLremoveDockedWidget(); |
276 |
|
- |
relayout(); |
277 |
|
- |
} |
278 |
|
- |
|
279 |
|
- |
private void LLremoveDockedWidget() { |
280 |
|
- |
// If there is a widget attached, remove it. |
281 |
|
- |
Widget zWidget = getDockedWidget(); |
282 |
|
- |
if ( (zWidget != null) && aboutToDisown( zWidget ) ) { |
283 |
|
- |
mChildren.remove( zWidget ); |
284 |
|
- |
Element td = super.disown( zWidget );// remove Widget from td |
285 |
|
- |
Element tr = removeAsChildAndGetParent( td );// remove td |
286 |
|
- |
|
287 |
|
- |
if ( !mCurrentDockPosition.isHorizontal() || (mChildren.size() == 0) ) { |
288 |
|
- |
removeAsChildAndGetParent( tr );// remove tr |
289 |
|
- |
} |
290 |
|
- |
mCurrentDockPosition = null; |
291 |
|
- |
justDisowned( zWidget ); |
292 |
|
- |
} |
293 |
|
- |
} |
294 |
|
- |
|
295 |
|
- |
/** |
296 |
|
- |
* @return the content widget, or <code>null</code> if none is present |
297 |
|
- |
*/ |
298 |
|
- |
public Widget getDockedWidget() { |
299 |
|
- |
switch ( getWidgetCount() ) { |
300 |
|
- |
case 2: |
301 |
|
- |
return getWidget( mCurrentDockPosition.getChildIndex() ); |
302 |
|
- |
case 1: |
303 |
|
- |
if ( mCurrentDockPosition != null ) { |
304 |
|
- |
return getWidget( 0 ); |
305 |
|
- |
} |
306 |
|
- |
// Fall Thru |
307 |
|
- |
case 0: |
308 |
|
- |
default: |
309 |
|
- |
return null; |
310 |
|
- |
} |
311 |
|
- |
} |
312 |
|
- |
|
313 |
|
- |
public NEWSposition getDockedWidgetPosition() { |
314 |
|
- |
return mCurrentDockPosition != null ? mCurrentDockPosition.getPosition() : null; |
315 |
|
- |
} |
316 |
|
- |
|
317 |
|
- |
public void setDockedWidget( NEWSposition pPosition, ISizeableWidget pWidget ) { |
318 |
|
- |
// If there is already a widget attached, remove it. |
319 |
|
- |
LLremoveDockedWidget(); |
320 |
|
- |
|
321 |
|
- |
if ( (pPosition != null) && (pWidget != null) ) { |
322 |
|
- |
ExtendedDockPosition zExtPosition = convert( pPosition ); |
323 |
|
- |
|
324 |
|
- |
zExtPosition.checkAcceptability( pWidget ); |
325 |
|
- |
|
326 |
|
- |
// Adopt the child. |
327 |
|
- |
Widget zWidget = (Widget) pWidget; |
328 |
|
- |
if ( !aboutToAdopt( zWidget ) ) { |
329 |
|
- |
return; |
330 |
|
- |
} |
331 |
|
- |
Element td = LLadopt( zWidget ); |
332 |
|
- |
|
333 |
|
- |
zExtPosition.add( td, zWidget, mChildren, getContainerElement() ); |
334 |
|
- |
mCurrentDockPosition = zExtPosition; |
335 |
|
- |
justAdopted( zWidget ); |
336 |
|
- |
} |
337 |
|
- |
relayout(); |
338 |
|
- |
} |
339 |
|
- |
|
340 |
|
- |
private ExtendedDockPosition convert( NEWSposition pPosition ) { |
341 |
|
- |
switch ( NEWSposition.deNull( pPosition, NEWSposition.NORTH ) ) { |
342 |
|
- |
default: |
343 |
|
- |
case NORTH: |
344 |
|
- |
return NORTH; |
345 |
|
- |
case EAST: |
346 |
|
- |
return EAST; |
347 |
|
- |
case WEST: |
348 |
|
- |
return WEST; |
349 |
|
- |
case SOUTH: |
350 |
|
- |
return SOUTH; |
351 |
|
- |
} |
352 |
|
- |
} |
353 |
|
- |
|
354 |
|
- |
/** |
355 |
|
- |
* @return TD |
356 |
|
- |
*/ |
357 |
|
- |
private Element LLadopt( Widget pWidget ) { |
358 |
|
- |
return super.adopt( pWidget, DOM.createTD() ); // put Widget in TD |
359 |
|
- |
} |
360 |
|
- |
|
361 |
|
- |
protected final Element adopt( Widget w, Element container ) { |
362 |
|
- |
throw new IllegalStateException( "Inappropriate use of raw adopt( Widget w, Element container )" ); |
363 |
|
- |
} |
364 |
|
- |
|
365 |
|
- |
protected Element disown( Widget w ) { |
366 |
|
- |
throw new IllegalStateException( "Inappropriate use of raw disown( Widget w )" ); |
367 |
|
- |
} |
368 |
|
- |
|
369 |
|
- |
/** |
370 |
|
- |
* Override point for special behavior of addition, before adding. |
371 |
|
- |
* Could throw an exception! |
372 |
|
- |
* |
373 |
|
- |
* @return true if OK to add |
374 |
|
- |
*/ |
375 |
|
- |
protected boolean aboutToAdopt( Widget pWidget ) { |
376 |
|
- |
return true; |
377 |
|
- |
} |
378 |
|
- |
|
379 |
|
- |
/** |
380 |
|
- |
* Override point for special behavior of addition. |
381 |
|
- |
* Should not throw an exception! |
382 |
|
- |
*/ |
383 |
|
- |
protected void justAdopted( Widget pWidget ) { |
384 |
|
- |
} |
385 |
|
- |
|
386 |
|
- |
/** |
387 |
|
- |
* Override point for special behavior of removal, before removing. |
388 |
|
- |
* Could throw an exception! |
389 |
|
- |
* |
390 |
|
- |
* @return true if OK to add |
391 |
|
- |
*/ |
392 |
|
- |
protected boolean aboutToDisown( Widget pWidget ) { |
393 |
|
- |
return true; |
394 |
|
- |
} |
395 |
|
- |
|
396 |
|
- |
/** |
397 |
|
- |
* Override point for special behavior of removal. |
398 |
|
- |
* Should not throw an exception! |
399 |
|
- |
*/ |
400 |
|
- |
protected void justDisowned( Widget pWidget ) { |
401 |
|
- |
} |
402 |
|
- |
|
403 |
|
- |
public void setWidth( String width ) { |
404 |
|
- |
super.setWidth( width ); // for stacktrace Debugging |
405 |
|
- |
} |
406 |
|
- |
|
407 |
|
- |
public void setHeight( String height ) { |
408 |
|
- |
super.setHeight( height ); // for stacktrace Debugging |
409 |
|
- |
} |
410 |
|
- |
|
411 |
|
- |
private MyDistributeToChildren mWidthDistributeToChildren = |
412 |
|
- |
new MyDistributeToChildren( getWidthHelper(), true ); |
413 |
|
- |
|
414 |
|
- |
protected void distributeToChildrenChangedWidth() { |
415 |
|
- |
mWidthDistributeToChildren.distributeToChildren(); |
416 |
|
- |
// if ( getDockedWidget() instanceof AbstractSizeableWidget) |
417 |
|
- |
// { |
418 |
|
- |
// todo: Firefox 'bug': When adding an Overflow Hidden horizontally to a table in an Overflow Hidden will automatically set the size of the new/inner Overflow |
419 |
|
- |
// Hidden to the smaller of whatever space is left or its natural size! |
420 |
|
- |
// AbstractSizeableWidget zSDW = (AbstractSizeableWidget) getDockedWidget(); |
421 |
|
- |
// AbstractSizeableHelper zHelper = zSDW.getHelper(); |
422 |
|
- |
// int zOuter = dimensionHelper.getDimension( zHelper.getOuterElement() ); |
423 |
|
- |
// int zStyle = dimensionHelper.getDimension( zHelper.getStyleElement() ); |
424 |
|
- |
// int zInner = dimensionHelper.getDimension( zHelper.getInnerElement() ); |
425 |
|
- |
// StatusBar.set( "Outer: " + zOuter + " Style: " + zStyle + " Inner: " + zInner ); |
426 |
|
- |
// if ( zStyle < zInner ) |
427 |
|
- |
// { |
428 |
|
- |
// getDockedWidget().setWidth( "" + (zStyle + zInner) ); |
429 |
|
- |
// } |
430 |
|
- |
// } |
431 |
|
- |
} |
432 |
|
- |
|
433 |
|
- |
private MyDistributeToChildren mHeightDistributeToChildren = |
434 |
|
- |
new MyDistributeToChildren( getHeightHelper(), false ); |
435 |
|
- |
|
436 |
|
- |
protected void distributeToChildrenChangedHeight() { |
437 |
|
- |
mHeightDistributeToChildren.distributeToChildren(); |
438 |
|
- |
} |
439 |
|
- |
|
440 |
|
- |
private boolean needToDelaySizeDistribution( ISizeableDimensionHelper pDimensionHelper ) { |
441 |
|
- |
Widget zDockedWidget = getDockedWidget(); |
442 |
|
- |
if ( zDockedWidget != null ) { |
443 |
|
- |
int zDockedSize = pDimensionHelper.getDimension( zDockedWidget ); |
444 |
|
- |
return zDockedSize == 0; |
445 |
|
- |
} |
446 |
|
- |
return false; |
447 |
|
- |
} |
448 |
|
- |
|
449 |
|
- |
protected void distributeToChildrenChangedDimension( ISizeableDimensionHelper pDimensionHelper, |
450 |
|
- |
boolean pDistributeOverTheTwoIfThere ) { |
451 |
|
- |
if ( anyChildren() ) { |
452 |
|
- |
Widget zContentWidget, zDockedWidget = getDockedWidget(); |
453 |
|
- |
if ( !pDistributeOverTheTwoIfThere || (zDockedWidget == null) ) { |
454 |
|
- |
getHelper().applyChangedDimensionToChildren( this, pDimensionHelper ); |
455 |
|
- |
} else if ( null != (zContentWidget = getContentWidget()) ) { |
456 |
|
- |
int zOurSize = pDimensionHelper.getDimension( this ); |
457 |
|
- |
int zDockedSize = pDimensionHelper.getDimension( zDockedWidget ); |
458 |
|
- |
int zContentSize = zOurSize - zDockedSize; |
459 |
|
- |
// StatusBar.set( pDimensionHelper.getWhat() + " OurSize:" + zOurSize + " DockedSize:" + |
460 |
|
- |
// zDockedSize + " ContentSize:" + zContentSize ); |
461 |
|
- |
pDimensionHelper.setDimension( zContentWidget, zContentSize ); |
462 |
|
- |
} |
463 |
|
- |
} |
464 |
|
- |
} |
465 |
|
- |
|
466 |
|
- |
private class MyDistributeToChildren implements DelayedProcess { |
467 |
|
- |
private EscalatingProcess mEscalatingProcess = null; |
468 |
|
- |
private ISizeableDimensionHelper mDimensionHelper; |
469 |
|
- |
private boolean mDistributeIfHorizontal; |
470 |
|
- |
|
471 |
|
- |
public MyDistributeToChildren( ISizeableDimensionHelper pDimensionHelper, |
472 |
|
- |
boolean pDistributeIfHorizontal ) { |
473 |
|
- |
mDimensionHelper = pDimensionHelper; |
474 |
|
- |
mDistributeIfHorizontal = pDistributeIfHorizontal; |
475 |
|
- |
} |
476 |
|
- |
|
477 |
|
- |
public boolean process() { |
478 |
|
- |
if ( !needToDelaySizeDistribution( mDimensionHelper ) ) { |
479 |
|
- |
distributeToChildrenChangedDimension( mDimensionHelper, |
480 |
|
- |
mDistributeIfHorizontal == isHorizontal() ); |
481 |
|
- |
return true; |
482 |
|
- |
} |
483 |
|
- |
return false; |
484 |
|
- |
} |
485 |
|
- |
|
486 |
|
- |
public void distributeToChildren() { |
487 |
|
- |
if ( process() ) { |
488 |
|
- |
if ( mEscalatingProcess != null ) { |
489 |
|
- |
mEscalatingProcess.cancel(); |
490 |
|
- |
} |
491 |
|
- |
} else { |
492 |
|
- |
if ( mEscalatingProcess == null ) { |
493 |
|
- |
mEscalatingProcess = new EscalatingProcess( this ); |
494 |
|
- |
} |
495 |
|
- |
if ( !mEscalatingProcess.isLive() ) { |
496 |
|
- |
mEscalatingProcess.schedule(); |
497 |
|
- |
} |
498 |
|
- |
} |
499 |
|
- |
} |
500 |
|
- |
} |
501 |
|
- |
} |
|
1 |
+ |
// This Source Code is in the Public Domain per: http://unlicense.org |
|
2 |
+ |
package org.litesoft.GWT.client.widgets.nonpublic; |
|
3 |
+ |
|
|
4 |
+ |
import org.litesoft.GWT.client.widgets.*; |
|
5 |
+ |
import org.litesoft.core.delayed.*; |
|
6 |
+ |
|
|
7 |
+ |
import com.google.gwt.user.client.*; |
|
8 |
+ |
import com.google.gwt.user.client.ui.*; |
|
9 |
+ |
|
|
10 |
+ |
import java.util.*; |
|
11 |
+ |
|
|
12 |
+ |
public abstract class AbstractSizeableDockingPanel extends AbstractSizeablePanel implements IndexedPanel { |
|
13 |
+ |
private abstract static class ExtendedDockPosition { |
|
14 |
+ |
private NEWSposition mPosition; |
|
15 |
+ |
private int mChildIndex; |
|
16 |
+ |
private boolean mHorizontal; |
|
17 |
+ |
|
|
18 |
+ |
public ExtendedDockPosition( NEWSposition pPosition, int pChildIndex, boolean pHorizontal ) { |
|
19 |
+ |
mPosition = pPosition; |
|
20 |
+ |
mChildIndex = pChildIndex; |
|
21 |
+ |
mHorizontal = pHorizontal; |
|
22 |
+ |
} |
|
23 |
+ |
|
|
24 |
+ |
public NEWSposition getPosition() { |
|
25 |
+ |
return mPosition; |
|
26 |
+ |
} |
|
27 |
+ |
|
|
28 |
+ |
public int getChildIndex() { |
|
29 |
+ |
return mChildIndex; |
|
30 |
+ |
} |
|
31 |
+ |
|
|
32 |
+ |
public boolean isHorizontal() { |
|
33 |
+ |
return mHorizontal; |
|
34 |
+ |
} |
|
35 |
+ |
|
|
36 |
+ |
public void checkAcceptability( ISizeableWidget pWidget ) { |
|
37 |
+ |
if ( mHorizontal && !pWidget.getHeightHelper().isStretchable() ) { |
|
38 |
+ |
throw new IllegalArgumentException( "Docked Widget not Vertically Stretchable" ); |
|
39 |
+ |
} |
|
40 |
+ |
if ( !mHorizontal && !pWidget.getWidthHelper().isStretchable() ) { |
|
41 |
+ |
throw new IllegalArgumentException( "Docked Widget not Horizontally Stretchable" ); |
|
42 |
+ |
} |
|
43 |
+ |
} |
|
44 |
+ |
|
|
45 |
+ |
public void add( Element pTD, Widget pWidget, WidgetCollection pChildren, Element pContainerElement ) { |
|
46 |
+ |
if ( pChildren.size() == 0 ) { |
|
47 |
+ |
pChildren.add( pWidget ); |
|
48 |
+ |
appendChild( pContainerElement, appendChild( DOM.createTR(), pTD ) ); |
|
49 |
+ |
} else { |
|
50 |
+ |
LLadd( pTD, pWidget, pChildren, pContainerElement, pChildren.get( 0 ) ); |
|
51 |
+ |
} |
|
52 |
+ |
} |
|
53 |
+ |
|
|
54 |
+ |
abstract protected void LLadd( Element pTD, Widget pWidget, WidgetCollection pChildren, |
|
55 |
+ |
Element pContainerElement, Widget pContentWidget ); |
|
56 |
+ |
} |
|
57 |
+ |
|
|
58 |
+ |
private static final ExtendedDockPosition NORTH = new ExtendedDockPosition( NEWSposition.NORTH, 0, false ) { |
|
59 |
+ |
protected void LLadd( Element pTD, Widget pWidget, WidgetCollection pChildren, |
|
60 |
+ |
Element pContainerElement, Widget pContentWidget ) { |
|
61 |
+ |
pChildren.insert( pWidget, 0 ); |
|
62 |
+ |
prependChild( pContainerElement, appendChild( DOM.createTR(), pTD ) ); |
|
63 |
+ |
} |
|
64 |
+ |
}; |
|
65 |
+ |
|
|
66 |
+ |
private static final ExtendedDockPosition EAST = new ExtendedDockPosition( NEWSposition.EAST, 1, true ) { |
|
67 |
+ |
protected void LLadd( Element pTD, Widget pWidget, WidgetCollection pChildren, |
|
68 |
+ |
Element pContainerElement, Widget pContentWidget ) { |
|
69 |
+ |
pChildren.add( pWidget ); |
|
70 |
+ |
appendChild( getGrandParentElement( pContentWidget ), pTD ); |
|
71 |
+ |
} |
|
72 |
+ |
}; |
|
73 |
+ |
|
|
74 |
+ |
private static final ExtendedDockPosition WEST = new ExtendedDockPosition( NEWSposition.WEST, 0, true ) { |
|
75 |
+ |
protected void LLadd( Element pTD, Widget pWidget, WidgetCollection pChildren, |
|
76 |
+ |
Element pContainerElement, Widget pContentWidget ) { |
|
77 |
+ |
pChildren.insert( pWidget, 0 ); |
|
78 |
+ |
prependChild( getGrandParentElement( pContentWidget ), pTD ); |
|
79 |
+ |
} |
|
80 |
+ |
}; |
|
81 |
+ |
|
|
82 |
+ |
private static final ExtendedDockPosition SOUTH = new ExtendedDockPosition( NEWSposition.SOUTH, 1, false ) { |
|
83 |
+ |
protected void LLadd( Element pTD, Widget pWidget, WidgetCollection pChildren, |
|
84 |
+ |
Element pContainerElement, Widget pContentWidget ) { |
|
85 |
+ |
pChildren.add( pWidget ); |
|
86 |
+ |
appendChild( pContainerElement, appendChild( DOM.createTR(), pTD ) ); |
|
87 |
+ |
} |
|
88 |
+ |
}; |
|
89 |
+ |
|
|
90 |
+ |
private ExtendedDockPosition mCurrentDockPosition = null; |
|
91 |
+ |
private WidgetCollection mChildren = new WidgetCollection( this ); |
|
92 |
+ |
|
|
93 |
+ |
public NEWSposition getDockedPosition() { |
|
94 |
+ |
return (mCurrentDockPosition == null) ? null : mCurrentDockPosition.getPosition(); |
|
95 |
+ |
} |
|
96 |
+ |
|
|
97 |
+ |
private boolean isHorizontal() { |
|
98 |
+ |
return (mCurrentDockPosition != null) && mCurrentDockPosition.isHorizontal(); |
|
99 |
+ |
} |
|
100 |
+ |
|
|
101 |
+ |
public boolean anyChildren() { |
|
102 |
+ |
return (mChildren.size() != 0); |
|
103 |
+ |
} |
|
104 |
+ |
|
|
105 |
+ |
/** |
|
106 |
+ |
* Gets the list of children contained in this panel. |
|
107 |
+ |
* |
|
108 |
+ |
* @return a collection of child widgets |
|
109 |
+ |
*/ |
|
110 |
+ |
protected WidgetCollection getChildren() { |
|
111 |
+ |
return mChildren; |
|
112 |
+ |
} |
|
113 |
+ |
|
|
114 |
+ |
// vvvvvvvvvvv HasWidgets |
|
115 |
+ |
|
|
116 |
+ |
/** |
|
117 |
+ |
* Removes all child widgets. |
|
118 |
+ |
*/ |
|
119 |
+ |
public void clear() { |
|
120 |
+ |
// Reverse order for SplitPairs |
|
121 |
+ |
while ( anyChildren() ) { |
|
122 |
+ |
remove( getWidgetCount() - 1 ); |
|
123 |
+ |
} |
|
124 |
+ |
} |
|
125 |
+ |
|
|
126 |
+ |
/** |
|
127 |
+ |
* Gets an iterator for the contained widgets. This iterator is required to |
|
128 |
+ |
* implement {@link Iterator#remove()}. |
|
129 |
+ |
*/ |
|
130 |
+ |
public Iterator iterator() { |
|
131 |
+ |
return mChildren.iterator(); |
|
132 |
+ |
} |
|
133 |
+ |
|
|
134 |
+ |
/** |
|
135 |
+ |
* Adds a child widget. |
|
136 |
+ |
* |
|
137 |
+ |
* @param pWidget the widget to be added |
|
138 |
+ |
* |
|
139 |
+ |
* @throws UnsupportedOperationException if this method is not supported (most |
|
140 |
+ |
* often this means that a specific overload must be called) |
|
141 |
+ |
*/ |
|
142 |
+ |
public void add( Widget pWidget ) { |
|
143 |
+ |
throw new UnsupportedOperationException( |
|
144 |
+ |
"SizeableDockingPanel does NOT support generic add(), please use the specific set...()" ); |
|
145 |
+ |
} |
|
146 |
+ |
|
|
147 |
+ |
/** |
|
148 |
+ |
* Removes a child widget. |
|
149 |
+ |
* |
|
150 |
+ |
* @param pWidget the widget to be removed |
|
151 |
+ |
* |
|
152 |
+ |
* @return <code>true</code> if the widget was present |
|
153 |
+ |
*/ |
|
154 |
+ |
public boolean remove( Widget pWidget ) { |
|
155 |
+ |
if ( pWidget == getContentWidget() ) { |
|
156 |
+ |
removeContentWidget(); |
|
157 |
+ |
return true; |
|
158 |
+ |
} |
|
159 |
+ |
if ( pWidget == getDockedWidget() ) { |
|
160 |
+ |
removeDockedWidget(); |
|
161 |
+ |
return true; |
|
162 |
+ |
} |
|
163 |
+ |
return true; |
|
164 |
+ |
} |
|
165 |
+ |
|
|
166 |
+ |
// ^^^^^^^^^^^ HasWidgets |
|
167 |
+ |
|
|
168 |
+ |
// vvvvvvvvvvv IndexedPanel |
|
169 |
+ |
|
|
170 |
+ |
public Widget getWidget( int pIndex ) { |
|
171 |
+ |
return getChildren().get( pIndex ); |
|
172 |
+ |
} |
|
173 |
+ |
|
|
174 |
+ |
public int getWidgetCount() { |
|
175 |
+ |
return getChildren().size(); |
|
176 |
+ |
} |
|
177 |
+ |
|
|
178 |
+ |
public int getWidgetIndex( Widget pChild ) { |
|
179 |
+ |
return getChildren().indexOf( pChild ); |
|
180 |
+ |
} |
|
181 |
+ |
|
|
182 |
+ |
public boolean remove( int pIndex ) { |
|
183 |
+ |
return remove( getWidget( pIndex ) ); |
|
184 |
+ |
} |
|
185 |
+ |
|
|
186 |
+ |
// ^^^^^^^^^^^ IndexedPanel |
|
187 |
+ |
|
|
188 |
+ |
/** |
|
189 |
+ |
* @return the content widget, or <code>null</code> if none is present |
|
190 |
+ |
*/ |
|
191 |
+ |
public Widget getContentWidget() { |
|
192 |
+ |
switch ( getWidgetCount() ) { |
|
193 |
+ |
case 2: |
|
194 |
+ |
return getWidget( 1 - mCurrentDockPosition.getChildIndex() ); |
|
195 |
+ |
case 1: |
|
196 |
+ |
if ( mCurrentDockPosition == null ) { |
|
197 |
+ |
return getWidget( 0 ); |
|
198 |
+ |
} |
|
199 |
+ |
// Fall Thru |
|
200 |
+ |
case 0: |
|
201 |
+ |
default: |
|
202 |
+ |
return null; |
|
203 |
+ |
} |
|
204 |
+ |
} |
|
205 |
+ |
|
|
206 |
+ |
/** |
|
207 |
+ |
* Sets this panel's content widget. Any existing content widget will be removed. |
|
208 |
+ |
*/ |
|
209 |
+ |
public void setContentWidget( ISizeableWidget pWidget ) { |
|
210 |
+ |
// If there is already a widget attached, remove it. |
|
211 |
+ |
LLremoveContentWidget(); |
|
212 |
+ |
|
|
213 |
+ |
if ( pWidget != null ) { |
|
214 |
+ |
if ( !pWidget.getHeightHelper().isStretchable() ) { |
|
215 |
+ |
throw new IllegalArgumentException( "Content Widget not Vertically Stretchable" ); |
|
216 |
+ |
} |
|
217 |
+ |
if ( !pWidget.getWidthHelper().isStretchable() ) { |
|
218 |
+ |
throw new IllegalArgumentException( "Content Widget not Horizontally Stretchable" ); |
|
219 |
+ |
} |
|
220 |
+ |
// Adopt the child. |
|
221 |
+ |
Widget zWidget = (Widget) pWidget; |
|
222 |
+ |
if ( !aboutToAdopt( zWidget ) ) { |
|
223 |
+ |
return; |
|
224 |
+ |
} |
|
225 |
+ |
Element td = LLadopt( zWidget ); |
|
226 |
+ |
|
|
227 |
+ |
switch ( NEWSposition.deNull( getDockedPosition(), NEWSposition.NORTH ) ) { |
|
228 |
+ |
default: |
|
229 |
+ |
case NORTH: // Simply Append Row on End |
|
230 |
+ |
mChildren.add( zWidget ); |
|
231 |
+ |
appendChild( getContainerElement(), appendChild( DOM.createTR(), td ) ); |
|
232 |
+ |
break; |
|
233 |
+ |
case WEST: // Append Column after DockWidget |
|
234 |
+ |
mChildren.add( zWidget ); |
|
235 |
+ |
appendChild( getGrandParentElement( getDockedWidget() ), td ); |
|
236 |
+ |
break; |
|
237 |
+ |
case EAST: // Insert Column before DockWidget |
|
238 |
+ |
mChildren.insert( zWidget, 0 ); |
|
239 |
+ |
prependChild( getGrandParentElement( getDockedWidget() ), td ); |
|
240 |
+ |
break; |
|
241 |
+ |
case SOUTH: // Insert Row before DockWidget |
|
242 |
+ |
mChildren.insert( zWidget, 0 ); |
|
243 |
+ |
prependChild( getContainerElement(), appendChild( DOM.createTR(), td ) ); |
|
244 |
+ |
break; |
|
245 |
+ |
} |
|
246 |
+ |
justAdopted( zWidget ); |
|
247 |
+ |
} |
|
248 |
+ |
relayout(); |
|
249 |
+ |
} |
|
250 |
+ |
|
|
251 |
+ |
public void removeContentWidget() { |
|
252 |
+ |
LLremoveContentWidget(); |
|
253 |
+ |
relayout(); |
|
254 |
+ |
} |
|
255 |
+ |
|
|
256 |
+ |
private void LLremoveContentWidget() { |
|
257 |
+ |
// If there is a widget attached, remove it. |
|
258 |
+ |
Widget zWidget = getContentWidget(); |
|
259 |
+ |
if ( (zWidget != null) && aboutToDisown( zWidget ) ) { |
|
260 |
+ |
mChildren.remove( zWidget ); |
|
261 |
+ |
Element td = super.disown( zWidget );// remove Widget from td |
|
262 |
+ |
Element tr = removeAsChildAndGetParent( td );// remove td |
|
263 |
+ |
|
|
264 |
+ |
if ( !isHorizontal() || (mChildren.size() == 0) ) { |
|
265 |
+ |
removeAsChildAndGetParent( tr );// remove tr |
|
266 |
+ |
} |
|
267 |
+ |
justDisowned( zWidget ); |
|
268 |
+ |
} |
|
269 |
+ |
} |
|
270 |
+ |
|
|
271 |
+ |
/** |
|
272 |
+ |
* Sets this panel's content widget. Any existing content widget will be removed. |
|
273 |
+ |
*/ |
|
274 |
+ |
public void removeDockedWidget() { |
|
275 |
+ |
LLremoveDockedWidget(); |
|
276 |
+ |
relayout(); |
|
277 |
+ |
} |
|
278 |
+ |
|
|
279 |
+ |
private void LLremoveDockedWidget() { |
|
280 |
+ |
// If there is a widget attached, remove it. |
|
281 |
+ |
Widget zWidget = getDockedWidget(); |
|
282 |
+ |
if ( (zWidget != null) && aboutToDisown( zWidget ) ) { |
|
283 |
+ |
mChildren.remove( zWidget ); |
|
284 |
+ |
Element td = super.disown( zWidget );// remove Widget from td |
|
285 |
+ |
Element tr = removeAsChildAndGetParent( td );// remove td |
|
286 |
+ |
|
|
287 |
+ |
if ( !mCurrentDockPosition.isHorizontal() || (mChildren.size() == 0) ) { |
|
288 |
+ |
removeAsChildAndGetParent( tr );// remove tr |
|
289 |
+ |
} |
|
290 |
+ |
mCurrentDockPosition = null; |
|
291 |
+ |
justDisowned( zWidget ); |
|
292 |
+ |
} |
|
293 |
+ |
} |
|
294 |
+ |
|
|
295 |
+ |
/** |
|
296 |
+ |
* @return the content widget, or <code>null</code> if none is present |
|
297 |
+ |
*/ |
|
298 |
+ |
public Widget getDockedWidget() { |
|
299 |
+ |
switch ( getWidgetCount() ) { |
|
300 |
+ |
case 2: |
|
301 |
+ |
return getWidget( mCurrentDockPosition.getChildIndex() ); |
|
302 |
+ |
case 1: |
|
303 |
+ |
if ( mCurrentDockPosition != null ) { |
|
304 |
+ |
return getWidget( 0 ); |
|
305 |
+ |
} |
|
306 |
+ |
// Fall Thru |
|
307 |
+ |
case 0: |
|
308 |
+ |
default: |
|
309 |
+ |
return null; |
|
310 |
+ |
} |
|
311 |
+ |
} |
|
312 |
+ |
|
|
313 |
+ |
public NEWSposition getDockedWidgetPosition() { |
|
314 |
+ |
return mCurrentDockPosition != null ? mCurrentDockPosition.getPosition() : null; |
|
315 |
+ |
} |
|
316 |
+ |
|
|
317 |
+ |
public void setDockedWidget( NEWSposition pPosition, ISizeableWidget pWidget ) { |
|
318 |
+ |
// If there is already a widget attached, remove it. |
|
319 |
+ |
LLremoveDockedWidget(); |
|
320 |
+ |
|
|
321 |
+ |
if ( (pPosition != null) && (pWidget != null) ) { |
|
322 |
+ |
ExtendedDockPosition zExtPosition = convert( pPosition ); |
|
323 |
+ |
|
|
324 |
+ |
zExtPosition.checkAcceptability( pWidget ); |
|
325 |
+ |
|
|
326 |
+ |
// Adopt the child. |
|
327 |
+ |
Widget zWidget = (Widget) pWidget; |
|
328 |
+ |
if ( !aboutToAdopt( zWidget ) ) { |
|
329 |
+ |
return; |
|
330 |
+ |
} |
|
331 |
+ |
Element td = LLadopt( zWidget ); |
|
332 |
+ |
|
|
333 |
+ |
zExtPosition.add( td, zWidget, mChildren, getContainerElement() ); |
|
334 |
+ |
mCurrentDockPosition = zExtPosition; |
|
335 |
+ |
justAdopted( zWidget ); |
|
336 |
+ |
} |
|
337 |
+ |
relayout(); |
|
338 |
+ |
} |
|
339 |
+ |
|
|
340 |
+ |
private ExtendedDockPosition convert( NEWSposition pPosition ) { |
|
341 |
+ |
switch ( NEWSposition.deNull( pPosition, NEWSposition.NORTH ) ) { |
|
342 |
+ |
default: |
|
343 |
+ |
case NORTH: |
|
344 |
+ |
return NORTH; |
|
345 |
+ |
case EAST: |
|
346 |
+ |
return EAST; |
|
347 |
+ |
case WEST: |
|
348 |
+ |
return WEST; |
|
349 |
+ |
case SOUTH: |
|
350 |
+ |
return SOUTH; |
|
351 |
+ |
} |
|
352 |
+ |
} |
|
353 |
+ |
|
|
354 |
+ |
/** |
|
355 |
+ |
* @return TD |
|
356 |
+ |
*/ |
|
357 |
+ |
private Element LLadopt( Widget pWidget ) { |
|
358 |
+ |
return super.adopt( pWidget, DOM.createTD() ); // put Widget in TD |
|
359 |
+ |
} |
|
360 |
+ |
|
|
361 |
+ |
protected final Element adopt( Widget w, Element container ) { |
|
362 |
+ |
throw new IllegalStateException( "Inappropriate use of raw adopt( Widget w, Element container )" ); |
|
363 |
+ |
} |
|
364 |
+ |
|
|
365 |
+ |
protected Element disown( Widget w ) { |
|
366 |
+ |
throw new IllegalStateException( "Inappropriate use of raw disown( Widget w )" ); |
|
367 |
+ |
} |
|
368 |
+ |
|
|
369 |
+ |
/** |
|
370 |
+ |
* Override point for special behavior of addition, before adding. |
|
371 |
+ |
* Could throw an exception! |
|
372 |
+ |
* |
|
373 |
+ |
* @return true if OK to add |
|
374 |
+ |
*/ |
|
375 |
+ |
protected boolean aboutToAdopt( Widget pWidget ) { |
|
376 |
+ |
return true; |
|
377 |
+ |
} |
|
378 |
+ |
|
|
379 |
+ |
/** |
|
380 |
+ |
* Override point for special behavior of addition. |
|
381 |
+ |
* Should not throw an exception! |
|
382 |
+ |
*/ |
|
383 |
+ |
protected void justAdopted( Widget pWidget ) { |
|
384 |
+ |
} |
|
385 |
+ |
|
|
386 |
+ |
/** |
|
387 |
+ |
* Override point for special behavior of removal, before removing. |
|
388 |
+ |
* Could throw an exception! |
|
389 |
+ |
* |
|
390 |
+ |
* @return true if OK to add |
|
391 |
+ |
*/ |
|
392 |
+ |
protected boolean aboutToDisown( Widget pWidget ) { |
|
393 |
+ |
return true; |
|
394 |
+ |
} |
|
395 |
+ |
|
|
396 |
+ |
/** |
|
397 |
+ |
* Override point for special behavior of removal. |
|
398 |
+ |
* Should not throw an exception! |
|
399 |
+ |
*/ |
|
400 |
+ |
protected void justDisowned( Widget pWidget ) { |
|
401 |
+ |
} |
|
402 |
+ |
|
|
403 |
+ |
public void setWidth( String width ) { |
|
404 |
+ |
super.setWidth( width ); // for stacktrace Debugging |
|
405 |
+ |
} |
|
406 |
+ |
|
|
407 |
+ |
public void setHeight( String height ) { |
|
408 |
+ |
super.setHeight( height ); // for stacktrace Debugging |
|
409 |
+ |
} |
|
410 |
+ |
|
|
411 |
+ |
private MyDistributeToChildren mWidthDistributeToChildren = |
|
412 |
+ |
new MyDistributeToChildren( getWidthHelper(), true ); |
|
413 |
+ |
|
|
414 |
+ |
protected void distributeToChildrenChangedWidth() { |
|
415 |
+ |
mWidthDistributeToChildren.distributeToChildren(); |
|
416 |
+ |
// if ( getDockedWidget() instanceof AbstractSizeableWidget) |
|
417 |
+ |
// { |
|
418 |
+ |
// todo: Firefox 'bug': When adding an Overflow Hidden horizontally to a table in an Overflow Hidden will automatically set the size of the new/inner Overflow |
|
419 |
+ |
// Hidden to the smaller of whatever space is left or its natural size! |
|
420 |
+ |
// AbstractSizeableWidget zSDW = (AbstractSizeableWidget) getDockedWidget(); |
|
421 |
+ |
// AbstractSizeableHelper zHelper = zSDW.getHelper(); |
|
422 |
+ |
// int zOuter = dimensionHelper.getDimension( zHelper.getOuterElement() ); |
|
423 |
+ |
// int zStyle = dimensionHelper.getDimension( zHelper.getStyleElement() ); |
|
424 |
+ |
// int zInner = dimensionHelper.getDimension( zHelper.getInnerElement() ); |
|
425 |
+ |
// StatusBar.set( "Outer: " + zOuter + " Style: " + zStyle + " Inner: " + zInner ); |
|
426 |
+ |
// if ( zStyle < zInner ) |
|
427 |
+ |
// { |
|
428 |
+ |
// getDockedWidget().setWidth( "" + (zStyle + zInner) ); |
|
429 |
+ |
// } |
|
430 |
+ |
// } |
|
431 |
+ |
} |
|
432 |
+ |
|
|
433 |
+ |
private MyDistributeToChildren mHeightDistributeToChildren = |
|
434 |
+ |
new MyDistributeToChildren( getHeightHelper(), false ); |
|
435 |
+ |
|
|
436 |
+ |
protected void distributeToChildrenChangedHeight() { |
|
437 |
+ |
mHeightDistributeToChildren.distributeToChildren(); |
|
438 |
+ |
} |
|
439 |
+ |
|
|
440 |
+ |
private boolean needToDelaySizeDistribution( ISizeableDimensionHelper pDimensionHelper ) { |
|
441 |
+ |
Widget zDockedWidget = getDockedWidget(); |
|
442 |
+ |
if ( zDockedWidget != null ) { |
|
443 |
+ |
int zDockedSize = pDimensionHelper.getDimension( zDockedWidget ); |
|
444 |
+ |
return zDockedSize == 0; |
|
445 |
+ |
} |
|
446 |
+ |
return false; |
|
447 |
+ |
} |
|
448 |
+ |
|
|
449 |
+ |
protected void distributeToChildrenChangedDimension( ISizeableDimensionHelper pDimensionHelper, |
|
450 |
+ |
boolean pDistributeOverTheTwoIfThere ) { |
|
451 |
+ |
if ( anyChildren() ) { |
|
452 |
+ |
Widget zContentWidget, zDockedWidget = getDockedWidget(); |
|
453 |
+ |
if ( !pDistributeOverTheTwoIfThere || (zDockedWidget == null) ) { |
|
454 |
+ |
getHelper().applyChangedDimensionToChildren( this, pDimensionHelper ); |
|
455 |
+ |
} else if ( null != (zContentWidget = getContentWidget()) ) { |
|
456 |
+ |
int zOurSize = pDimensionHelper.getDimension( this ); |
|
457 |
+ |
int zDockedSize = pDimensionHelper.getDimension( zDockedWidget ); |
|
458 |
+ |
int zContentSize = zOurSize - zDockedSize; |
|
459 |
+ |
// StatusBar.set( pDimensionHelper.getWhat() + " OurSize:" + zOurSize + " DockedSize:" + |
|
460 |
+ |
// zDockedSize + " ContentSize:" + zContentSize ); |
|
461 |
+ |
pDimensionHelper.setDimension( zContentWidget, zContentSize ); |
|
462 |
+ |
} |
|
463 |
+ |
} |
|
464 |
+ |
} |
|
465 |
+ |
|
|
466 |
+ |
private class MyDistributeToChildren implements DelayedProcess { |
|
467 |
+ |
private EscalatingProcess mEscalatingProcess = null; |
|
468 |
+ |
private ISizeableDimensionHelper mDimensionHelper; |
|
469 |
+ |
private boolean mDistributeIfHorizontal; |
|
470 |
+ |
|
|
471 |
+ |
public MyDistributeToChildren( ISizeableDimensionHelper pDimensionHelper, |
|
472 |
+ |
boolean pDistributeIfHorizontal ) { |
|
473 |
+ |
mDimensionHelper = pDimensionHelper; |
|
474 |
+ |
mDistributeIfHorizontal = pDistributeIfHorizontal; |
|
475 |
+ |
} |
|
476 |
+ |
|
|
477 |
+ |
public boolean process() { |
|
478 |
+ |
if ( !needToDelaySizeDistribution( mDimensionHelper ) ) { |
|
479 |
+ |
distributeToChildrenChangedDimension( mDimensionHelper, |
|
480 |
+ |
mDistributeIfHorizontal == isHorizontal() ); |
|
481 |
+ |
return true; |
|
482 |
+ |
} |
|
483 |
+ |
return false; |
|
484 |
+ |
} |
|
485 |
+ |
|
|
486 |
+ |
public void distributeToChildren() { |
|
487 |
+ |
if ( process() ) { |
|
488 |
+ |
if ( mEscalatingProcess != null ) { |
|
489 |
+ |
mEscalatingProcess.cancel(); |
|
490 |
+ |
} |
|
491 |
+ |
} else { |
|
492 |
+ |
if ( mEscalatingProcess == null ) { |
|
493 |
+ |
mEscalatingProcess = new EscalatingProcess( this ); |
|
494 |
+ |
} |
|
495 |
+ |
if ( !mEscalatingProcess.isLive() ) { |
|
496 |
+ |
mEscalatingProcess.schedule(); |
|
497 |
+ |
} |
|
498 |
+ |
} |
|
499 |
+ |
} |
|
500 |
+ |
} |
|
501 |
+ |
} |