Subversion Repository Public Repository

litesoft

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
// This Source Code is in the Public Domain per: http://unlicense.org
package org.litesoft.GWT.client.widgets.nonpublic;

import java.util.*;

import org.litesoft.GWT.client.widgets.*;
import org.litesoft.core.delayed.*;

import com.google.gwt.user.client.ui.*;
import com.google.gwt.user.client.*;

public abstract class AbstractSizeableDockingPanel extends AbstractSizeablePanel implements IndexedPanel
{
    private abstract static class ExtendedDockPosition
    {
        private NEWSposition mPosition;
        private int mChildIndex;
        private boolean mHorizontal;

        public ExtendedDockPosition( NEWSposition pPosition, int pChildIndex, boolean pHorizontal )
        {
            mPosition = pPosition;
            mChildIndex = pChildIndex;
            mHorizontal = pHorizontal;
        }

        public NEWSposition getPosition()
        {
            return mPosition;
        }

        public int getChildIndex()
        {
            return mChildIndex;
        }

        public boolean isHorizontal()
        {
            return mHorizontal;
        }

        public void checkAcceptability( ISizeableWidget pWidget )
        {
            if ( mHorizontal && !pWidget.getHeightHelper().isStretchable() )
            {
                throw new IllegalArgumentException( "Docked Widget not Vertically Stretchable" );
            }
            if ( !mHorizontal && !pWidget.getWidthHelper().isStretchable() )
            {
                throw new IllegalArgumentException( "Docked Widget not Horizontally Stretchable" );
            }
        }

        public void add( Element pTD, Widget pWidget, WidgetCollection pChildren, Element pContainerElement )
        {
            if ( pChildren.size() == 0 )
            {
                pChildren.add( pWidget );
                appendChild( pContainerElement, appendChild( DOM.createTR(), pTD ) );
            }
            else
            {
                LLadd( pTD, pWidget, pChildren, pContainerElement, pChildren.get( 0 ) );
            }
        }

        abstract protected void LLadd( Element pTD, Widget pWidget, WidgetCollection pChildren,
                                       Element pContainerElement, Widget pContentWidget );
    }

    private static final ExtendedDockPosition NORTH = new ExtendedDockPosition( NEWSposition.NORTH, 0, false )
    {
        protected void LLadd( Element pTD, Widget pWidget, WidgetCollection pChildren,
                              Element pContainerElement, Widget pContentWidget )
        {
            pChildren.insert( pWidget, 0 );
            prependChild( pContainerElement, appendChild( DOM.createTR(), pTD ) );
        }
    };

    private static final ExtendedDockPosition EAST = new ExtendedDockPosition( NEWSposition.EAST, 1, true )
    {
        protected void LLadd( Element pTD, Widget pWidget, WidgetCollection pChildren,
                              Element pContainerElement, Widget pContentWidget )
        {
            pChildren.add( pWidget );
            appendChild( getGrandParentElement( pContentWidget ), pTD );
        }
    };

    private static final ExtendedDockPosition WEST = new ExtendedDockPosition( NEWSposition.WEST, 0, true )
    {
        protected void LLadd( Element pTD, Widget pWidget, WidgetCollection pChildren,
                              Element pContainerElement, Widget pContentWidget )
        {
            pChildren.insert( pWidget, 0 );
            prependChild( getGrandParentElement( pContentWidget ), pTD );
        }
    };

    private static final ExtendedDockPosition SOUTH = new ExtendedDockPosition( NEWSposition.SOUTH, 1, false )
    {
        protected void LLadd( Element pTD, Widget pWidget, WidgetCollection pChildren,
                              Element pContainerElement, Widget pContentWidget )
        {
            pChildren.add( pWidget );
            appendChild( pContainerElement, appendChild( DOM.createTR(), pTD ) );
        }
    };

    private ExtendedDockPosition mCurrentDockPosition = null;
    private WidgetCollection mChildren = new WidgetCollection( this );

    public NEWSposition getDockedPosition()
    {
        return (mCurrentDockPosition == null) ? null : mCurrentDockPosition.getPosition();
    }

    private boolean isHorizontal()
    {
        return (mCurrentDockPosition != null) && mCurrentDockPosition.isHorizontal();
    }

    public boolean anyChildren()
    {
        return (mChildren.size() != 0);
    }

    /**
     * Gets the list of children contained in this panel.
     *
     * @return a collection of child widgets
     */
    protected WidgetCollection getChildren()
    {
        return mChildren;
    }

    // vvvvvvvvvvv HasWidgets

    /**
     * Removes all child widgets.
     */
    public void clear()
    {
        // Reverse order for SplitPairs
        while ( anyChildren() )
        {
            remove( getWidgetCount() - 1 );
        }
    }

    /**
     * Gets an iterator for the contained widgets. This iterator is required to
     * implement {@link Iterator#remove()}.
     */
    public Iterator iterator()
    {
        return mChildren.iterator();
    }

    /**
     * Adds a child widget.
     *
     * @param pWidget the widget to be added
     *
     * @throws UnsupportedOperationException if this method is not supported (most
     *                                       often this means that a specific overload must be called)
     */
    public void add( Widget pWidget )
    {
        throw new UnsupportedOperationException(
                "SizeableDockingPanel does NOT support generic add(), please use the specific set...()" );
    }

    /**
     * Removes a child widget.
     *
     * @param pWidget the widget to be removed
     *
     * @return <code>true</code> if the widget was present
     */
    public boolean remove( Widget pWidget )
    {
        if ( pWidget == getContentWidget() )
        {
            removeContentWidget();
            return true;
        }
        if ( pWidget == getDockedWidget() )
        {
            removeDockedWidget();
            return true;
        }
        return true;
    }

    // ^^^^^^^^^^^ HasWidgets

    // vvvvvvvvvvv IndexedPanel

    public Widget getWidget( int pIndex )
    {
        return getChildren().get( pIndex );
    }

    public int getWidgetCount()
    {
        return getChildren().size();
    }

    public int getWidgetIndex( Widget pChild )
    {
        return getChildren().indexOf( pChild );
    }

    public boolean remove( int pIndex )
    {
        return remove( getWidget( pIndex ) );
    }

    // ^^^^^^^^^^^ IndexedPanel

    /**
     * @return the content widget, or <code>null</code> if none is present
     */
    public Widget getContentWidget()
    {
        switch ( getWidgetCount() )
        {
            case 2:
                return getWidget( 1 - mCurrentDockPosition.getChildIndex() );
            case 1:
                if ( mCurrentDockPosition == null )
                {
                    return getWidget( 0 );
                }
                // Fall Thru
            case 0:
            default:
                return null;
        }
    }

    /**
     * Sets this panel's content widget. Any existing content widget will be removed.
     */
    public void setContentWidget( ISizeableWidget pWidget )
    {
        // If there is already a widget attached, remove it.
        LLremoveContentWidget();

        if ( pWidget != null )
        {
            if ( !pWidget.getHeightHelper().isStretchable() )
            {
                throw new IllegalArgumentException( "Content Widget not Vertically Stretchable" );
            }
            if ( !pWidget.getWidthHelper().isStretchable() )
            {
                throw new IllegalArgumentException( "Content Widget not Horizontally Stretchable" );
            }
            // Adopt the child.
            Widget zWidget = (Widget) pWidget;
            if ( !aboutToAdopt( zWidget ) )
            {
                return;
            }
            Element td = LLadopt( zWidget );

            switch ( NEWSposition.deNull( getDockedPosition(), NEWSposition.NORTH ) )
            {
                default:
                case NORTH: // Simply Append Row on End
                    mChildren.add( zWidget );
                    appendChild( getContainerElement(), appendChild( DOM.createTR(), td ) );
                    break;
                case WEST: // Append Column after DockWidget
                    mChildren.add( zWidget );
                    appendChild( getGrandParentElement( getDockedWidget() ), td );
                    break;
                case EAST: // Insert Column before DockWidget
                    mChildren.insert( zWidget, 0 );
                    prependChild( getGrandParentElement( getDockedWidget() ), td );
                    break;
                case SOUTH: // Insert Row before DockWidget
                    mChildren.insert( zWidget, 0 );
                    prependChild( getContainerElement(), appendChild( DOM.createTR(), td ) );
                    break;
            }
            justAdopted( zWidget );
        }
        relayout();
    }

    public void removeContentWidget()
    {
        LLremoveContentWidget();
        relayout();
    }

    private void LLremoveContentWidget()
    {
        // If there is a widget attached, remove it.
        Widget zWidget = getContentWidget();
        if ( (zWidget != null) && aboutToDisown( zWidget ) )
        {
            mChildren.remove( zWidget );
            Element td = super.disown( zWidget );// remove Widget from td
            Element tr = removeAsChildAndGetParent( td );// remove td

            if ( !isHorizontal() || (mChildren.size() == 0) )
            {
                removeAsChildAndGetParent( tr );// remove tr
            }
            justDisowned( zWidget );
        }
    }

    /**
     * Sets this panel's content widget. Any existing content widget will be removed.
     */
    public void removeDockedWidget()
    {
        LLremoveDockedWidget();
        relayout();
    }

    private void LLremoveDockedWidget()
    {
        // If there is a widget attached, remove it.
        Widget zWidget = getDockedWidget();
        if ( (zWidget != null) && aboutToDisown( zWidget ) )
        {
            mChildren.remove( zWidget );
            Element td = super.disown( zWidget );// remove Widget from td
            Element tr = removeAsChildAndGetParent( td );// remove td

            if ( !mCurrentDockPosition.isHorizontal() || (mChildren.size() == 0) )
            {
                removeAsChildAndGetParent( tr );// remove tr
            }
            mCurrentDockPosition = null;
            justDisowned( zWidget );
        }
    }

    /**
     * @return the content widget, or <code>null</code> if none is present
     */
    public Widget getDockedWidget()
    {
        switch ( getWidgetCount() )
        {
            case 2:
                return getWidget( mCurrentDockPosition.getChildIndex() );
            case 1:
                if ( mCurrentDockPosition != null )
                {
                    return getWidget( 0 );
                }
                // Fall Thru
            case 0:
            default:
                return null;
        }
    }

    public NEWSposition getDockedWidgetPosition()
    {
        return mCurrentDockPosition != null ? mCurrentDockPosition.getPosition() : null;
    }

    public void setDockedWidget( NEWSposition pPosition, ISizeableWidget pWidget )
    {
        // If there is already a widget attached, remove it.
        LLremoveDockedWidget();

        if ( (pPosition != null) && (pWidget != null) )
        {
            ExtendedDockPosition zExtPosition = convert( pPosition );

            zExtPosition.checkAcceptability( pWidget );

            // Adopt the child.
            Widget zWidget = (Widget) pWidget;
            if ( !aboutToAdopt( zWidget ) )
            {
                return;
            }
            Element td = LLadopt( zWidget );

            zExtPosition.add( td, zWidget, mChildren, getContainerElement() );
            mCurrentDockPosition = zExtPosition;
            justAdopted( zWidget );
        }
        relayout();
    }

    private ExtendedDockPosition convert( NEWSposition pPosition )
    {
        switch ( NEWSposition.deNull( pPosition, NEWSposition.NORTH ) )
        {
            default:
            case NORTH:
                return NORTH;
            case EAST:
                return EAST;
            case WEST:
                return WEST;
            case SOUTH:
                return SOUTH;
        }
    }

    /**
     * @return TD
     */
    private Element LLadopt( Widget pWidget )
    {
        return super.adopt( pWidget, DOM.createTD() ); // put Widget in TD
    }

    protected final Element adopt( Widget w, Element container )
    {
        throw new IllegalStateException( "Inappropriate use of raw adopt( Widget w, Element container )" );
    }

    protected Element disown( Widget w )
    {
        throw new IllegalStateException( "Inappropriate use of raw disown( Widget w )" );
    }

    /**
     * Override point for special behavior of addition, before adding.
     * Could throw an exception!
     *
     * @return true if OK to add
     */
    protected boolean aboutToAdopt( Widget pWidget )
    {
        return true;
    }

    /**
     * Override point for special behavior of addition.
     * Should not throw an exception!
     */
    protected void justAdopted( Widget pWidget )
    {
    }

    /**
     * Override point for special behavior of removal, before removing.
     * Could throw an exception!
     *
     * @return true if OK to add
     */
    protected boolean aboutToDisown( Widget pWidget )
    {
        return true;
    }

    /**
     * Override point for special behavior of removal.
     * Should not throw an exception!
     */
    protected void justDisowned( Widget pWidget )
    {
    }

    public void setWidth( String width )
    {
        super.setWidth( width ); // for stacktrace Debugging
    }

    public void setHeight( String height )
    {
        super.setHeight( height ); // for stacktrace Debugging
    }

    private MyDistributeToChildren mWidthDistributeToChildren =
            new MyDistributeToChildren( getWidthHelper(), true );

    protected void distributeToChildrenChangedWidth()
    {
        mWidthDistributeToChildren.distributeToChildren();
//        if ( getDockedWidget() instanceof AbstractSizeableWidget)
//        {
// 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 Hidden to the smaller of whatever space is left or its natural size!
//            AbstractSizeableWidget zSDW = (AbstractSizeableWidget) getDockedWidget();
//            AbstractSizeableHelper zHelper = zSDW.getHelper();
//            int zOuter = dimensionHelper.getDimension( zHelper.getOuterElement() );
//            int zStyle = dimensionHelper.getDimension( zHelper.getStyleElement() );
//            int zInner = dimensionHelper.getDimension( zHelper.getInnerElement() );
//            StatusBar.set( "Outer: " + zOuter + "  Style: " + zStyle + "  Inner: " + zInner );
//            if ( zStyle < zInner )
//            {
//                getDockedWidget().setWidth( "" + (zStyle + zInner) );
//            }
//        }
    }

    private MyDistributeToChildren mHeightDistributeToChildren =
            new MyDistributeToChildren( getHeightHelper(), false );

    protected void distributeToChildrenChangedHeight()
    {
        mHeightDistributeToChildren.distributeToChildren();
    }

    private boolean needToDelaySizeDistribution( ISizeableDimensionHelper pDimensionHelper )
    {
        Widget zDockedWidget = getDockedWidget();
        if ( zDockedWidget != null )
        {
            int zDockedSize = pDimensionHelper.getDimension( zDockedWidget );
            return zDockedSize == 0;
        }
        return false;
    }

    protected void distributeToChildrenChangedDimension( ISizeableDimensionHelper pDimensionHelper,
                                                         boolean pDistributeOverTheTwoIfThere )
    {
        if ( anyChildren() )
        {
            Widget zContentWidget, zDockedWidget = getDockedWidget();
            if ( !pDistributeOverTheTwoIfThere || (zDockedWidget == null) )
            {
                getHelper().applyChangedDimensionToChildren( this, pDimensionHelper );
            }
            else if ( null != (zContentWidget = getContentWidget()) )
            {
                int zOurSize = pDimensionHelper.getDimension( this );
                int zDockedSize = pDimensionHelper.getDimension( zDockedWidget );
                int zContentSize = zOurSize - zDockedSize;
//                StatusBar.set( pDimensionHelper.getWhat() + " OurSize:" + zOurSize + " DockedSize:" +
//                               zDockedSize + " ContentSize:" + zContentSize );
                pDimensionHelper.setDimension( zContentWidget, zContentSize );
            }
        }
    }

    private class MyDistributeToChildren implements DelayedProcess
    {
        private EscalatingProcess mEscalatingProcess = null;
        private ISizeableDimensionHelper mDimensionHelper;
        private boolean mDistributeIfHorizontal;

        public MyDistributeToChildren( ISizeableDimensionHelper pDimensionHelper,
                                       boolean pDistributeIfHorizontal )
        {
            mDimensionHelper = pDimensionHelper;
            mDistributeIfHorizontal = pDistributeIfHorizontal;
        }

        public boolean process()
        {
            if ( !needToDelaySizeDistribution( mDimensionHelper ) )
            {
                distributeToChildrenChangedDimension( mDimensionHelper,
                                                      mDistributeIfHorizontal == isHorizontal() );
                return true;
            }
            return false;
        }

        public void distributeToChildren()
        {
            if ( process() )
            {
                if ( mEscalatingProcess != null )
                {
                    mEscalatingProcess.cancel();
                }
            }
            else
            {
                if ( mEscalatingProcess == null )
                {
                    mEscalatingProcess = new EscalatingProcess( this );
                }
                if ( !mEscalatingProcess.isLive() )
                {
                    mEscalatingProcess.schedule();
                }
            }
        }
    }
}

Commits for litesoft/trunk/Java/GWT/OldClient/src/org/litesoft/GWT/client/widgets/nonpublic/AbstractSizeableDockingPanel.java

Diff revisions: vs.
Revision Author Commited Message
947 Diff Diff GeorgeS picture GeorgeS Fri 06 Jun, 2014 23:36:56 +0000

Correct Spelling of package!

60 Diff Diff GeorgeS picture GeorgeS Tue 24 Aug, 2010 00:37:36 +0000
49 Diff Diff GeorgeS picture GeorgeS Mon 12 Apr, 2010 02:59:10 +0000

License Text

2 GeorgeS picture GeorgeS Sun 07 Feb, 2010 12:50:58 +0000