Subversion Repository Public Repository

litesoft

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

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