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
// This Source Code is in the Public Domain per: http://unlicense.org
package org.litesoft.GWT.client.widgets.nonpublic;

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

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

import java.util.*;

public abstract class AbstractSizeableSimplePanel extends AbstractSizeablePanel implements SizeableSingleWidgetContainer {
    private Widget mWidget;

    @Override
    public boolean anyChildren() {
        return (mWidget != null);
    }

    // vvvvvvvvvvv HasWidgets

    /**
     * Removes all child widgets.
     */
    @Override
    public void clear() {
        if ( anyChildren() ) {
            remove( mWidget );
        }
    }

    /**
     * Gets an iterator for the contained widgets. This iterator is required to
     * implement {@link Iterator#remove()}.
     */
    @Override
    public Iterator<Widget> iterator() {
        // Return a simple iterator that enumerates the 0 or 1 elements in this
        // panel.
        return new SingleWidgetIterator( mWidget ) {
            @Override
            public void remove() {
                clear();
            }
        };
    }

    /**
     * Adds a widget to this panel.
     *
     * @param pWidget the child widget to be added
     */
    @Override
    public void add( Widget pWidget ) {
        // Can't add() more than one widget to a SimplePanel.
        if ( getWidget() != null ) {
            throw new IllegalStateException( "SimplePanel can only contain one child widget" );
        }
        setWidget( pWidget );
    }

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

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

    // vvvvvvvvvvv SingleWidgetContainer

    /**
     * Gets the panel's child widget.
     *
     * @return the child widget, or <code>null</code> if none is present
     */
    @Override
    public Widget getWidget() {
        return mWidget;
    }

    /**
     * Sets this panel's widget. Any existing child widget will be removed.
     */
    @Override
    public void setWidget( Widget pWidget ) {
        // If there is already a widget attached, remove it.
        if ( mWidget != null ) {
            disown( mWidget );
        }

        if ( pWidget != null ) {
            // Adopt the child.
            adopt( pWidget );
        }
    }

    // ^^^^^^^^^^^ SingleWidgetContainer

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

    /**
     * Do everything to add pWidget
     *
     * @param pWidget !null
     */
    protected void adopt( Widget pWidget ) {
        if ( aboutToAdopt( pWidget ) ) {
            LLadopt( pWidget );
            justAdopted( pWidget );
        }
    }

    /**
     * Do everything to remove pWidget
     *
     * @param pWidget !null
     */
    @Override
    protected Element disown( Widget pWidget ) {
        if ( aboutToDisown( pWidget ) ) {
            LLdisown( pWidget );
            justDisowned( pWidget );
        }
        return null; // Don't care
    }

    protected void LLdisown( Widget pWidget ) {
        super.disown( pWidget ); // remove Widget from td
        mWidget = null;
    }

    protected void LLadopt( Widget pWidget ) {
        pWidget.removeFromParent();
        super.adopt( pWidget, getContainerElement() ); // put Widget in TD
        mWidget = pWidget;
    }

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

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

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

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

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

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

    @Override
    protected void distributeToChildrenChangedWidth() {
        getHelper().applyChangedDimensionToChild( getWidget(), getWidthHelper() );
    }

    @Override
    protected void distributeToChildrenChangedHeight() {
        getHelper().applyChangedDimensionToChild( getWidget(), getHeightHelper() );
    }
}

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

Diff revisions: vs.
Revision Author Commited Message
948 Diff Diff GeorgeS picture GeorgeS Sat 07 Jun, 2014 23:42:39 +0000

Jusefuls Formatter Updated to New Code Format

947 Diff Diff GeorgeS picture GeorgeS Fri 06 Jun, 2014 23:36:56 +0000

Correct Spelling of package!

49 Diff Diff GeorgeS picture GeorgeS Mon 12 Apr, 2010 02:59:10 +0000

License Text

23 Diff Diff GeorgeS picture GeorgeS Wed 24 Feb, 2010 00:34:32 +0000
2 GeorgeS picture GeorgeS Sun 07 Feb, 2010 12:50:58 +0000