Subversion Repository Public Repository

litesoft

Diff Revisions 949 vs 950 for /trunk/Java/GWT/Client/src/org/litesoft/GWT/client/widgets/nonpublic/AbstractSizeableSimplePanel.java

Diff revisions: vs.
  @@ -1,208 +1,208 @@
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 -
6 - import com.google.gwt.user.client.*;
7 - import com.google.gwt.user.client.ui.*;
8 -
9 - import java.util.*;
10 -
11 - public abstract class AbstractSizeableSimplePanel extends AbstractSizeablePanel implements SizeableSingleWidgetContainer {
12 - private Widget mWidget;
13 -
14 - @Override
15 - public boolean anyChildren() {
16 - return (mWidget != null);
17 - }
18 -
19 - // vvvvvvvvvvv HasWidgets
20 -
21 - /**
22 - * Removes all child widgets.
23 - */
24 - @Override
25 - public void clear() {
26 - if ( anyChildren() ) {
27 - remove( mWidget );
28 - }
29 - }
30 -
31 - /**
32 - * Gets an iterator for the contained widgets. This iterator is required to
33 - * implement {@link Iterator#remove()}.
34 - */
35 - @Override
36 - public Iterator<Widget> iterator() {
37 - // Return a simple iterator that enumerates the 0 or 1 elements in this
38 - // panel.
39 - return new SingleWidgetIterator( mWidget ) {
40 - @Override
41 - public void remove() {
42 - clear();
43 - }
44 - };
45 - }
46 -
47 - /**
48 - * Adds a widget to this panel.
49 - *
50 - * @param pWidget the child widget to be added
51 - */
52 - @Override
53 - public void add( Widget pWidget ) {
54 - // Can't add() more than one widget to a SimplePanel.
55 - if ( getWidget() != null ) {
56 - throw new IllegalStateException( "SimplePanel can only contain one child widget" );
57 - }
58 - setWidget( pWidget );
59 - }
60 -
61 - /**
62 - * Removes a child widget.
63 - *
64 - * @param pWidget the widget to be removed
65 - *
66 - * @return <code>true</code> if the widget was present
67 - */
68 - @Override
69 - public boolean remove( Widget pWidget ) {
70 - if ( mWidget == pWidget ) {
71 - disown( pWidget );
72 - return true;
73 - }
74 - return false;
75 - }
76 -
77 - // ^^^^^^^^^^^ HasWidgets
78 -
79 - // vvvvvvvvvvv SingleWidgetContainer
80 -
81 - /**
82 - * Gets the panel's child widget.
83 - *
84 - * @return the child widget, or <code>null</code> if none is present
85 - */
86 - @Override
87 - public Widget getWidget() {
88 - return mWidget;
89 - }
90 -
91 - /**
92 - * Sets this panel's widget. Any existing child widget will be removed.
93 - */
94 - @Override
95 - public void setWidget( Widget pWidget ) {
96 - // If there is already a widget attached, remove it.
97 - if ( mWidget != null ) {
98 - disown( mWidget );
99 - }
100 -
101 - if ( pWidget != null ) {
102 - // Adopt the child.
103 - adopt( pWidget );
104 - }
105 - }
106 -
107 - // ^^^^^^^^^^^ SingleWidgetContainer
108 -
109 - @Override
110 - protected final Element adopt( Widget w, Element container ) {
111 - throw new IllegalStateException( "Inappropriate use of raw adopt( Widget w, Element container )" );
112 - }
113 -
114 - /**
115 - * Do everything to add pWidget
116 - *
117 - * @param pWidget !null
118 - */
119 - protected void adopt( Widget pWidget ) {
120 - if ( aboutToAdopt( pWidget ) ) {
121 - LLadopt( pWidget );
122 - justAdopted( pWidget );
123 - }
124 - }
125 -
126 - /**
127 - * Do everything to remove pWidget
128 - *
129 - * @param pWidget !null
130 - */
131 - @Override
132 - protected Element disown( Widget pWidget ) {
133 - if ( aboutToDisown( pWidget ) ) {
134 - LLdisown( pWidget );
135 - justDisowned( pWidget );
136 - }
137 - return null; // Don't care
138 - }
139 -
140 - protected void LLdisown( Widget pWidget ) {
141 - super.disown( pWidget ); // remove Widget from td
142 - mWidget = null;
143 - }
144 -
145 - protected void LLadopt( Widget pWidget ) {
146 - pWidget.removeFromParent();
147 - super.adopt( pWidget, getContainerElement() ); // put Widget in TD
148 - mWidget = pWidget;
149 - }
150 -
151 - /**
152 - * Override point for special behavior of addition, before adding.
153 - * Could throw an exception!
154 - *
155 - * @return true if OK to add
156 - */
157 - @SuppressWarnings({"UnusedDeclaration"})
158 - protected boolean aboutToAdopt( Widget pWidget ) {
159 - return true;
160 - }
161 -
162 - /**
163 - * Override point for special behavior of addition.
164 - * Should not throw an exception!
165 - */
166 - @SuppressWarnings({"UnusedDeclaration"})
167 - protected void justAdopted( Widget pWidget ) {
168 - }
169 -
170 - /**
171 - * Override point for special behavior of removal, before removing.
172 - * Could throw an exception!
173 - *
174 - * @return true if OK to add
175 - */
176 - @SuppressWarnings({"UnusedDeclaration"})
177 - protected boolean aboutToDisown( Widget pWidget ) {
178 - return true;
179 - }
180 -
181 - /**
182 - * Override point for special behavior of removal.
183 - * Should not throw an exception!
184 - */
185 - @SuppressWarnings({"UnusedDeclaration"})
186 - protected void justDisowned( Widget pWidget ) {
187 - }
188 -
189 - @Override
190 - public void setWidth( String width ) {
191 - super.setWidth( width ); // for stacktrace Debugging
192 - }
193 -
194 - @Override
195 - public void setHeight( String height ) {
196 - super.setHeight( height ); // for stacktrace Debugging
197 - }
198 -
199 - @Override
200 - protected void distributeToChildrenChangedWidth() {
201 - getHelper().applyChangedDimensionToChild( getWidget(), getWidthHelper() );
202 - }
203 -
204 - @Override
205 - protected void distributeToChildrenChangedHeight() {
206 - getHelper().applyChangedDimensionToChild( getWidget(), getHeightHelper() );
207 - }
208 - }
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 +
6 + import com.google.gwt.user.client.*;
7 + import com.google.gwt.user.client.ui.*;
8 +
9 + import java.util.*;
10 +
11 + public abstract class AbstractSizeableSimplePanel extends AbstractSizeablePanel implements SizeableSingleWidgetContainer {
12 + private Widget mWidget;
13 +
14 + @Override
15 + public boolean anyChildren() {
16 + return (mWidget != null);
17 + }
18 +
19 + // vvvvvvvvvvv HasWidgets
20 +
21 + /**
22 + * Removes all child widgets.
23 + */
24 + @Override
25 + public void clear() {
26 + if ( anyChildren() ) {
27 + remove( mWidget );
28 + }
29 + }
30 +
31 + /**
32 + * Gets an iterator for the contained widgets. This iterator is required to
33 + * implement {@link Iterator#remove()}.
34 + */
35 + @Override
36 + public Iterator<Widget> iterator() {
37 + // Return a simple iterator that enumerates the 0 or 1 elements in this
38 + // panel.
39 + return new SingleWidgetIterator( mWidget ) {
40 + @Override
41 + public void remove() {
42 + clear();
43 + }
44 + };
45 + }
46 +
47 + /**
48 + * Adds a widget to this panel.
49 + *
50 + * @param pWidget the child widget to be added
51 + */
52 + @Override
53 + public void add( Widget pWidget ) {
54 + // Can't add() more than one widget to a SimplePanel.
55 + if ( getWidget() != null ) {
56 + throw new IllegalStateException( "SimplePanel can only contain one child widget" );
57 + }
58 + setWidget( pWidget );
59 + }
60 +
61 + /**
62 + * Removes a child widget.
63 + *
64 + * @param pWidget the widget to be removed
65 + *
66 + * @return <code>true</code> if the widget was present
67 + */
68 + @Override
69 + public boolean remove( Widget pWidget ) {
70 + if ( mWidget == pWidget ) {
71 + disown( pWidget );
72 + return true;
73 + }
74 + return false;
75 + }
76 +
77 + // ^^^^^^^^^^^ HasWidgets
78 +
79 + // vvvvvvvvvvv SingleWidgetContainer
80 +
81 + /**
82 + * Gets the panel's child widget.
83 + *
84 + * @return the child widget, or <code>null</code> if none is present
85 + */
86 + @Override
87 + public Widget getWidget() {
88 + return mWidget;
89 + }
90 +
91 + /**
92 + * Sets this panel's widget. Any existing child widget will be removed.
93 + */
94 + @Override
95 + public void setWidget( Widget pWidget ) {
96 + // If there is already a widget attached, remove it.
97 + if ( mWidget != null ) {
98 + disown( mWidget );
99 + }
100 +
101 + if ( pWidget != null ) {
102 + // Adopt the child.
103 + adopt( pWidget );
104 + }
105 + }
106 +
107 + // ^^^^^^^^^^^ SingleWidgetContainer
108 +
109 + @Override
110 + protected final Element adopt( Widget w, Element container ) {
111 + throw new IllegalStateException( "Inappropriate use of raw adopt( Widget w, Element container )" );
112 + }
113 +
114 + /**
115 + * Do everything to add pWidget
116 + *
117 + * @param pWidget !null
118 + */
119 + protected void adopt( Widget pWidget ) {
120 + if ( aboutToAdopt( pWidget ) ) {
121 + LLadopt( pWidget );
122 + justAdopted( pWidget );
123 + }
124 + }
125 +
126 + /**
127 + * Do everything to remove pWidget
128 + *
129 + * @param pWidget !null
130 + */
131 + @Override
132 + protected Element disown( Widget pWidget ) {
133 + if ( aboutToDisown( pWidget ) ) {
134 + LLdisown( pWidget );
135 + justDisowned( pWidget );
136 + }
137 + return null; // Don't care
138 + }
139 +
140 + protected void LLdisown( Widget pWidget ) {
141 + super.disown( pWidget ); // remove Widget from td
142 + mWidget = null;
143 + }
144 +
145 + protected void LLadopt( Widget pWidget ) {
146 + pWidget.removeFromParent();
147 + super.adopt( pWidget, getContainerElement() ); // put Widget in TD
148 + mWidget = pWidget;
149 + }
150 +
151 + /**
152 + * Override point for special behavior of addition, before adding.
153 + * Could throw an exception!
154 + *
155 + * @return true if OK to add
156 + */
157 + @SuppressWarnings({"UnusedDeclaration"})
158 + protected boolean aboutToAdopt( Widget pWidget ) {
159 + return true;
160 + }
161 +
162 + /**
163 + * Override point for special behavior of addition.
164 + * Should not throw an exception!
165 + */
166 + @SuppressWarnings({"UnusedDeclaration"})
167 + protected void justAdopted( Widget pWidget ) {
168 + }
169 +
170 + /**
171 + * Override point for special behavior of removal, before removing.
172 + * Could throw an exception!
173 + *
174 + * @return true if OK to add
175 + */
176 + @SuppressWarnings({"UnusedDeclaration"})
177 + protected boolean aboutToDisown( Widget pWidget ) {
178 + return true;
179 + }
180 +
181 + /**
182 + * Override point for special behavior of removal.
183 + * Should not throw an exception!
184 + */
185 + @SuppressWarnings({"UnusedDeclaration"})
186 + protected void justDisowned( Widget pWidget ) {
187 + }
188 +
189 + @Override
190 + public void setWidth( String width ) {
191 + super.setWidth( width ); // for stacktrace Debugging
192 + }
193 +
194 + @Override
195 + public void setHeight( String height ) {
196 + super.setHeight( height ); // for stacktrace Debugging
197 + }
198 +
199 + @Override
200 + protected void distributeToChildrenChangedWidth() {
201 + getHelper().applyChangedDimensionToChild( getWidget(), getWidthHelper() );
202 + }
203 +
204 + @Override
205 + protected void distributeToChildrenChangedHeight() {
206 + getHelper().applyChangedDimensionToChild( getWidget(), getHeightHelper() );
207 + }
208 + }