Subversion Repository Public Repository

litesoft

Diff Revisions 947 vs 948 for /trunk/Java/GWT/Client/src/org/litesoft/GWT/client/widgets/nonpublic/AbstractSizeableOneDimensionalPanel.java

Diff revisions: vs.
  @@ -1,18 +1,16 @@
1 1 // This Source Code is in the Public Domain per: http://unlicense.org
2 2 package org.litesoft.GWT.client.widgets.nonpublic;
3 3
4 - import java.util.*;
5 -
6 4 import com.google.gwt.user.client.*;
7 5 import com.google.gwt.user.client.ui.*;
8 6
9 - public abstract class AbstractSizeableOneDimensionalPanel extends AbstractSizeableHasAlignmentPanel implements IndexedPanel
10 - {
7 + import java.util.*;
8 +
9 + public abstract class AbstractSizeableOneDimensionalPanel extends AbstractSizeableHasAlignmentPanel implements IndexedPanel {
11 10 private WidgetCollection mChildren = new WidgetCollection( this );
12 11
13 12 @Override
14 - public boolean anyChildren()
15 - {
13 + public boolean anyChildren() {
16 14 return (mChildren.size() != 0);
17 15 }
18 16
  @@ -21,8 +19,7 @@
21 19 *
22 20 * @return a collection of child widgets
23 21 */
24 - protected WidgetCollection getChildren()
25 - {
22 + protected WidgetCollection getChildren() {
26 23 return mChildren;
27 24 }
28 25
  @@ -32,11 +29,9 @@
32 29 * Removes all child widgets.
33 30 */
34 31 @Override
35 - public void clear()
36 - {
32 + public void clear() {
37 33 // Reverse order for SplitPairs
38 - while ( anyChildren() )
39 - {
34 + while ( anyChildren() ) {
40 35 remove( getWidgetCount() - 1 );
41 36 }
42 37 }
  @@ -46,8 +41,7 @@
46 41 * implement {@link Iterator#remove()}.
47 42 */
48 43 @Override
49 - public Iterator<Widget> iterator()
50 - {
44 + public Iterator<Widget> iterator() {
51 45 return mChildren.iterator();
52 46 }
53 47
  @@ -60,8 +54,7 @@
60 54 * often this means that a specific overload must be called)
61 55 */
62 56 @Override
63 - public void add( Widget pWidget )
64 - {
57 + public void add( Widget pWidget ) {
65 58 insert( pWidget, getWidgetCount() );
66 59 }
67 60
  @@ -73,11 +66,9 @@
73 66 * @return <code>true</code> if the widget was present
74 67 */
75 68 @Override
76 - public boolean remove( Widget pWidget )
77 - {
69 + public boolean remove( Widget pWidget ) {
78 70 // Make sure this panel actually contains the child widget.
79 - if ( !mChildren.contains( pWidget ) )
80 - {
71 + if ( !mChildren.contains( pWidget ) ) {
81 72 return false;
82 73 }
83 74
  @@ -97,55 +88,46 @@
97 88 * @throws IndexOutOfBoundsException if <code>beforeIndex</code> is out of
98 89 * range
99 90 */
100 - public void insert( Widget pWidget, int pBeforeIndex )
101 - {
102 - if ( pWidget != null )
103 - {
91 + public void insert( Widget pWidget, int pBeforeIndex ) {
92 + if ( pWidget != null ) {
104 93 adopt( pWidget, pBeforeIndex );
105 94 }
106 95 }
107 96
108 - protected Widget getFirstWidget()
109 - {
97 + protected Widget getFirstWidget() {
110 98 return anyChildren() ? getWidget( 0 ) : null;
111 99 }
112 100
113 - protected Widget getLastWidget()
114 - {
101 + protected Widget getLastWidget() {
115 102 return anyChildren() ? getWidget( getWidgetCount() - 1 ) : null;
116 103 }
117 104
118 105 // vvvvvvvvvvv IndexedPanel
119 106
120 107 @Override
121 - public Widget getWidget( int pIndex )
122 - {
108 + public Widget getWidget( int pIndex ) {
123 109 return getChildren().get( pIndex );
124 110 }
125 111
126 112 @Override
127 - public int getWidgetCount()
128 - {
113 + public int getWidgetCount() {
129 114 return getChildren().size();
130 115 }
131 116
132 117 @Override
133 - public int getWidgetIndex( Widget pChild )
134 - {
118 + public int getWidgetIndex( Widget pChild ) {
135 119 return getChildren().indexOf( pChild );
136 120 }
137 121
138 122 @Override
139 - public boolean remove( int pIndex )
140 - {
123 + public boolean remove( int pIndex ) {
141 124 return remove( getWidget( pIndex ) );
142 125 }
143 126
144 127 // ^^^^^^^^^^^ IndexedPanel
145 128
146 129 @Override
147 - protected final Element adopt( Widget w, Element container )
148 - {
130 + protected final Element adopt( Widget w, Element container ) {
149 131 throw new IllegalStateException( "Inappropriate use of raw adopt( Widget w, Element container )" );
150 132 }
151 133
  @@ -154,10 +136,8 @@
154 136 *
155 137 * @param pWidget !null
156 138 */
157 - protected void adopt( Widget pWidget, int pBeforeIndex )
158 - {
159 - if ( aboutToAdopt( pWidget, pBeforeIndex ) )
160 - {
139 + protected void adopt( Widget pWidget, int pBeforeIndex ) {
140 + if ( aboutToAdopt( pWidget, pBeforeIndex ) ) {
161 141 LLadopt( pWidget, pBeforeIndex );
162 142 justAdopted( pWidget, pBeforeIndex );
163 143 }
  @@ -169,30 +149,25 @@
169 149 * @param pWidget !null
170 150 */
171 151 @Override
172 - protected Element disown( Widget pWidget )
173 - {
152 + protected Element disown( Widget pWidget ) {
174 153 int index = mChildren.indexOf( pWidget );
175 - if ( index == -1 )
176 - {
154 + if ( index == -1 ) {
177 155 throw new IllegalStateException( "Attempt to 'disown' widget (" + pWidget + ") not owned by: " + this );
178 156 }
179 - if ( aboutToDisown( pWidget, index ) )
180 - {
157 + if ( aboutToDisown( pWidget, index ) ) {
181 158 LLdisown( pWidget, index );
182 159 justDisowned( pWidget, index );
183 160 }
184 161 return null; // We Don't Care
185 162 }
186 163
187 - protected void LLdisown( Widget pWidget, int pIndex )
188 - {
164 + protected void LLdisown( Widget pWidget, int pIndex ) {
189 165 Element td = abstractSizeablePanel_disown( pWidget ); // remove Widget from td
190 166 DOM.removeChild( getContainerElement(), unwrap( td ) );
191 167 mChildren.remove( pIndex );
192 168 }
193 169
194 - protected void LLadopt( Widget pWidget, int pBeforeIndex )
195 - {
170 + protected void LLadopt( Widget pWidget, int pBeforeIndex ) {
196 171 pWidget.removeFromParent();
197 172 Element td = DOM.createTD();
198 173 abstractSizeablePanel_adopt( pWidget, td ); // put Widget in TD
  @@ -200,13 +175,11 @@
200 175 mChildren.insert( pWidget, pBeforeIndex );
201 176 }
202 177
203 - protected Element abstractSizeablePanel_disown( Widget pWidget )
204 - {
178 + protected Element abstractSizeablePanel_disown( Widget pWidget ) {
205 179 return super.disown( pWidget );
206 180 }
207 181
208 - protected void abstractSizeablePanel_adopt( Widget pWidget, Element pContainer )
209 - {
182 + protected void abstractSizeablePanel_adopt( Widget pWidget, Element pContainer ) {
210 183 super.adopt( pWidget, pContainer );
211 184 }
212 185
  @@ -216,8 +189,7 @@
216 189 *
217 190 * @return true if OK to add
218 191 */
219 - protected boolean aboutToAdopt( Widget pWidget, int pBeforeIndex )
220 - {
192 + protected boolean aboutToAdopt( Widget pWidget, int pBeforeIndex ) {
221 193 return true;
222 194 }
223 195
  @@ -225,8 +197,7 @@
225 197 * Override point for special behavior of index based addition.
226 198 * Should not throw an exception!
227 199 */
228 - protected void justAdopted( Widget pWidget, int pWidgetIndex )
229 - {
200 + protected void justAdopted( Widget pWidget, int pWidgetIndex ) {
230 201 }
231 202
232 203 /**
  @@ -235,8 +206,7 @@
235 206 *
236 207 * @return true if OK to add
237 208 */
238 - protected boolean aboutToDisown( Widget pWidget, int pBeforeIndex )
239 - {
209 + protected boolean aboutToDisown( Widget pWidget, int pBeforeIndex ) {
240 210 return true;
241 211 }
242 212
  @@ -244,8 +214,7 @@
244 214 * Override point for special behavior of index based removal.
245 215 * Should not throw an exception!
246 216 */
247 - protected void justDisowned( Widget pWidget, int pWidgetIndex )
248 - {
217 + protected void justDisowned( Widget pWidget, int pWidgetIndex ) {
249 218 }
250 219
251 220 abstract protected Element unwrap( Element pTD );