Subversion Repository Public Repository

litesoft

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

Diff revisions: vs.
  @@ -8,34 +8,29 @@
8 8
9 9 import com.google.gwt.user.client.ui.*;
10 10
11 - public class SizeableVerticalFlowPanel extends SizeableHorizontalPanel
12 - {
11 + public class SizeableVerticalFlowPanel extends SizeableHorizontalPanel {
13 12 private boolean mSizesDetermined = false;
14 13 private int mMaxWidgetWidth;
15 14 private int mMaxWidgetHeight;
16 15 private WidgetPlus[] mWidgets;
17 16
18 - public SizeableVerticalFlowPanel( Widget... pChildren )
19 - {
17 + public SizeableVerticalFlowPanel( Widget... pChildren ) {
20 18 VerticalPanel zSizeDeterminer = new VerticalPanel();
21 19
22 20 LLadd( new SizeableSpacer().stretchableVertically() );
23 21 LLadd( new MyHtmlPanel( StaticSimpleIdSource.getNext(), zSizeDeterminer ) );
24 22
25 - if ( pChildren == null )
26 - {
23 + if ( pChildren == null ) {
27 24 pChildren = new Widget[]{null};
28 25 }
29 26 mWidgets = new WidgetPlus[pChildren.length];
30 - for ( int i = 0; i < pChildren.length; i++ )
31 - {
27 + for ( int i = 0; i < pChildren.length; i++ ) {
32 28 zSizeDeterminer.add( (mWidgets[i] = new WidgetPlus( pChildren[i] )).getWidget() );
33 29 }
34 30 }
35 31
36 32 @Override
37 - public SizeableVerticalFlowPanel style( String pStyleName )
38 - {
33 + public SizeableVerticalFlowPanel style( String pStyleName ) {
39 34 addStyleName( pStyleName );
40 35 return this;
41 36 }
  @@ -43,64 +38,51 @@
43 38 //****** Implementation Code Block to support delegation to AbsoluteSizeHelper
44 39
45 40 @Override
46 - public SizeableVerticalFlowPanel stretchable()
47 - {
41 + public SizeableVerticalFlowPanel stretchable() {
48 42 LLstretchable();
49 43 return this;
50 44 }
51 45
52 - private void LLadd( Widget pWidget )
53 - {
46 + private void LLadd( Widget pWidget ) {
54 47 LLinsert( pWidget, getWidgetCount() );
55 48 }
56 49
57 - private void LLinsert( Widget pWidget, int pBeforeIndex )
58 - {
59 - if ( pWidget != null )
60 - {
50 + private void LLinsert( Widget pWidget, int pBeforeIndex ) {
51 + if ( pWidget != null ) {
61 52 adopt( pWidget, pBeforeIndex );
62 53 }
63 54 }
64 55
65 56 @Override
66 - public void add( Widget pWidget )
67 - {
57 + public void add( Widget pWidget ) {
68 58 throw new UnsupportedOperationException( "Children may NOT be added except via the Constructor" );
69 59 }
70 60
71 61 @Override
72 - public void insert( Widget pWidget, int pBeforeIndex )
73 - {
62 + public void insert( Widget pWidget, int pBeforeIndex ) {
74 63 throw new UnsupportedOperationException( "Children may NOT be added except via the Constructor" );
75 64 }
76 65
77 66 /**
78 67 * @return False if need to try later, True if success / Can't proceed now
79 68 */
80 - private boolean LLreflow()
81 - {
82 - if ( !isAttached() )
83 - {
69 + private boolean LLreflow() {
70 + if ( !isAttached() ) {
84 71 return true;
85 72 }
86 - if ( !mSizesDetermined )
87 - {
73 + if ( !mSizesDetermined ) {
88 74 mMaxWidgetWidth = mMaxWidgetHeight = 0;
89 - for ( WidgetPlus zPlus : mWidgets )
90 - {
75 + for ( WidgetPlus zPlus : mWidgets ) {
91 76 Widget zWidget = zPlus.getWidget();
92 - if ( !zPlus.hasHeight() )
93 - {
77 + if ( !zPlus.hasHeight() ) {
94 78 int zHeight = zWidget.getOffsetHeight();
95 - if ( zHeight < 1 )
96 - {
79 + if ( zHeight < 1 ) {
97 80 return false;
98 81 }
99 82 zPlus.setHeight( zHeight );
100 83 }
101 84 int zWidth = zWidget.getOffsetWidth();
102 - if ( zWidth < 1 )
103 - {
85 + if ( zWidth < 1 ) {
104 86 return false;
105 87 }
106 88 mMaxWidgetWidth = Math.max( mMaxWidgetWidth, zWidth );
  @@ -116,10 +98,8 @@
116 98 clear();
117 99 LLadd( new SizeableSpacer().stretchableVertically() );
118 100 MyColumn zColumn = new MyColumn( zWorkingHeight, mMaxWidgetWidth );
119 - for ( WidgetPlus zPlus : mWidgets )
120 - {
121 - if ( !zColumn.added( zPlus ) )
122 - {
101 + for ( WidgetPlus zPlus : mWidgets ) {
102 + if ( !zColumn.added( zPlus ) ) {
123 103 LLadd( zColumn );
124 104 zColumn = new MyColumn( zWorkingHeight, mMaxWidgetWidth );
125 105 zColumn.added( zPlus );
  @@ -129,21 +109,17 @@
129 109 return true;
130 110 }
131 111
132 - private static class MyColumn extends VerticalPanel
133 - {
112 + private static class MyColumn extends VerticalPanel {
134 113 private int mHeightRemaining;
135 114
136 - public MyColumn( int pHeightRemaining, int pDesiredWidth )
137 - {
115 + public MyColumn( int pHeightRemaining, int pDesiredWidth ) {
138 116 mHeightRemaining = pHeightRemaining - 1;
139 117 add( new Spacer().height( 1 ).width( pDesiredWidth ) );
140 118 }
141 119
142 - public boolean added( WidgetPlus pPlus )
143 - {
120 + public boolean added( WidgetPlus pPlus ) {
144 121 int zHeight = pPlus.getHeight();
145 - if ( mHeightRemaining >= zHeight )
146 - {
122 + if ( mHeightRemaining >= zHeight ) {
147 123 mHeightRemaining -= zHeight;
148 124 add( pPlus.getWidget() );
149 125 return true;
  @@ -152,39 +128,30 @@
152 128 }
153 129 }
154 130
155 - private long LLreflowLater()
156 - {
131 + private long LLreflowLater() {
157 132 Long zOnOrAfter = mReflowOnOrAfter;
158 133 mReflowOnOrAfter = System.currentTimeMillis() + 50;
159 - if ( zOnOrAfter == null )
160 - {
134 + if ( zOnOrAfter == null ) {
161 135 TimedRunnableManager.INSTANCE.runIn( mLaterReflow, 50 );
162 136 }
163 137 return mReflowOnOrAfter;
164 138 }
165 139
166 140 private Long mReflowOnOrAfter = null;
167 - private TimedRunnable mLaterReflow = new TimedRunnable()
168 - {
141 + private TimedRunnable mLaterReflow = new TimedRunnable() {
169 142 @Override
170 - public Again runOnce()
171 - {
172 - if ( mReflowOnOrAfter != null )
173 - {
143 + public Again runOnce() {
144 + if ( mReflowOnOrAfter != null ) {
174 145 long zNow = System.currentTimeMillis();
175 - if ( zNow < mReflowOnOrAfter )
176 - {
146 + if ( zNow < mReflowOnOrAfter ) {
177 147 return new RunAgainOnOrAfter( mReflowOnOrAfter );
178 148 }
179 - try
180 - {
181 - if ( !LLreflow() )
182 - {
149 + try {
150 + if ( !LLreflow() ) {
183 151 return new RunAgainOnOrAfter( LLreflowLater() );
184 152 }
185 153 }
186 - catch ( Exception e )
187 - {
154 + catch ( Exception e ) {
188 155 e.printStackTrace();
189 156 }
190 157 mReflowOnOrAfter = null;
  @@ -198,26 +165,20 @@
198 165 private String mLastWidth;
199 166
200 167 @Override
201 - public void setWidth( String width )
202 - {
168 + public void setWidth( String width ) {
203 169 super.setWidth( width );
204 - if ( !Objects.areNonArraysEqual( mLastWidth, width ) )
205 - {
170 + if ( !Objects.areNonArraysEqual( mLastWidth, width ) ) {
206 171 mLastWidth = width;
207 172 LLreflowLater();
208 173 }
209 174 }
210 175
211 - private int getLastSetHeight()
212 - {
213 - if ( mLastHeight != null )
214 - {
215 - try
216 - {
176 + private int getLastSetHeight() {
177 + if ( mLastHeight != null ) {
178 + try {
217 179 return parse( mLastHeight );
218 180 }
219 - catch ( NumberFormatException e )
220 - {
181 + catch ( NumberFormatException e ) {
221 182 // Fall Thru
222 183 }
223 184 }
  @@ -227,62 +188,51 @@
227 188 private String mLastHeight;
228 189
229 190 @Override
230 - public void setHeight( String height )
231 - {
191 + public void setHeight( String height ) {
232 192 super.setHeight( height );
233 - if ( !Objects.areNonArraysEqual( mLastHeight, height ) )
234 - {
193 + if ( !Objects.areNonArraysEqual( mLastHeight, height ) ) {
235 194 mLastHeight = height;
236 195 LLreflowLater();
237 196 }
238 197 }
239 198
240 199 @Override
241 - protected void onAttach()
242 - {
200 + protected void onAttach() {
243 201 super.onAttach();
244 202 LLreflowLater();
245 203 }
246 204
247 - private static class WidgetPlus
248 - {
205 + private static class WidgetPlus {
249 206 private Widget mWidget;
250 207 private Integer mHeight = null;
251 208
252 - public WidgetPlus( Widget pWidget )
253 - {
209 + public WidgetPlus( Widget pWidget ) {
254 210 mWidget = (pWidget != null) ? pWidget : new Spacer();
255 211 }
256 212
257 - public Widget getWidget()
258 - {
213 + public Widget getWidget() {
259 214 return mWidget;
260 215 }
261 216
262 - public boolean hasHeight()
263 - {
217 + public boolean hasHeight() {
264 218 return (mHeight != null);
265 219 }
266 220
267 - public int getHeight()
268 - {
221 + public int getHeight() {
269 222 return mHeight;
270 223 }
271 224
272 - public void setHeight( int pHeight )
273 - {
225 + public void setHeight( int pHeight ) {
274 226 mHeight = pHeight;
275 227 }
276 228 }
277 229
278 - private static class MyHtmlPanel extends HTMLPanel
279 - {
230 + private static class MyHtmlPanel extends HTMLPanel {
280 231 private static final String DIV_ID_PREFIX = "SVFP_";
281 232
282 233 private static final String TRANSPARENT_SPACER = "<img width='1' height='1' src='" + TransparentImage.URL + "'>";
283 234
284 - public MyHtmlPanel( int zUniqueID, VerticalPanel pSizeDeterminer )
285 - {
235 + public MyHtmlPanel( int zUniqueID, VerticalPanel pSizeDeterminer ) {
286 236 super( "<div id='" + DIV_ID_PREFIX + zUniqueID + "' style='height:1px; width:1px; overflow:hidden;'>" + TRANSPARENT_SPACER + "<br></div>" );
287 237
288 238 add( pSizeDeterminer, DIV_ID_PREFIX + zUniqueID );