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
package org.litesoft.GWT.client.widgets;

import com.google.gwt.user.client.ui.*;
import org.litesoft.GWT.client.widgets.nonpublic.*;

public class SizeableDeckPanel extends AbstractSizeableComplexPanel implements IndexedPanel
{
    private Widget mVisibleWidget;

    public SizeableDeckPanel()
    {
        initializeElements( getHelper().create_OeTable_SeDiv_IeDiv( true ), "LayoutSizeableDeckPanel" );
    }

    public SizeableDeckPanel style( String pStyleName )
    {
        addStyleName( pStyleName );
        return this;
    }

    /**
     * Adds the specified widget to the deck.
     *
     * @param w the widget to be added
     */
    public void add( Widget w )
    {
        insert( w, getWidgetCount() );
    }

    /**
     * Gets the index of the currently-visible widget.
     *
     * @return the visible widget's index
     */
    public int getVisibleWidget()
    {
        return getWidgetIndex( mVisibleWidget );
    }

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

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

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

    /**
     * Inserts a widget before the specified index.
     *
     * @param w           the widget to be inserted
     * @param beforeIndex the index before which it will be inserted
     *
     * @throws IndexOutOfBoundsException if <code>beforeIndex</code> is out of
     *                                   range
     */
    public void insert( Widget w, int beforeIndex )
    {
        if ( (beforeIndex < 0) || (beforeIndex > getWidgetCount()) )
        {
            throw new IndexOutOfBoundsException( String.valueOf( beforeIndex ) );
        }

        super.insert( w, getContainerElement(), beforeIndex );

        if ( mVisibleWidget == null )
        {
            showAwidget( 0 );
        }
        else
        {
            w.setVisible( false );
        }
    }

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

    public boolean remove( Widget w )
    {
        if ( !super.remove( w ) )
        {
            return false;
        }

        if ( mVisibleWidget == w )
        {
            mVisibleWidget = null;
            if ( getWidgetCount() != 0 )
            {
                showAwidget( 0 );
            }
        }

        return true;
    }

    /**
     * Shows the widget at the specified index. This causes the currently- visible
     * widget to be hidden.
     *
     * @param index the index of the widget to be shown
     */
    public void showWidget( int index )
    {
        checkIndex( index );

        if ( mVisibleWidget != null )
        {
            mVisibleWidget.setVisible( false );
        }
        showAwidget( index );
    }

    private void checkIndex( int index )
    {
        if ( (index < 0) || (index >= getWidgetCount()) )
        {
            throw new IndexOutOfBoundsException( String.valueOf( index ) );
        }
    }

    //****** Implementation Code Block to support delegation to AbsoluteSizeHelper

    public SizeableDeckPanel stretchable()
    {
        LLstretchable();
        return this;
    }

    public SizeableDeckPanel stretchableVertically()
    {
        LLstretchableVertically();
        return this;
    }

    public SizeableDeckPanel stretchableHorizontally()
    {
        LLstretchableHorizontally();
        return this;
    }

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

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

    private void showAwidget( int index )
    {
        mVisibleWidget = getWidget( index );
        mVisibleWidget.setVisible( true );

        distributeToChildrenChangedWidth();
        distributeToChildrenChangedHeight();
    }

    protected void distributeToChildrenChangedWidth()
    {
        if ( anyChildren() )
        {
            adjustSizeOnShownWidget( getWidthHelper() );
        }
    }

    protected void distributeToChildrenChangedHeight()
    {
        if ( anyChildren() )
        {
            adjustSizeOnShownWidget( getHeightHelper() );
        }
    }

    private void adjustSizeOnShownWidget( ISizeableDimensionHelper pDimensionHelper )
    {
        getHelper().applyChangedDimensionToChild( mVisibleWidget, pDimensionHelper );
    }
}

Commits for litesoft/trunk/Java/GWT/Client/src/org/litesoft/GWT/client/widgets/SizeableDeckPanel.java

Diff revisions: vs.
Revision Author Commited Message
2 GeorgeS picture GeorgeS Sun 07 Feb, 2010 12:50:58 +0000