Subversion Repository Public Repository

litesoft

Diff Revisions 947 vs 948 for /trunk/Java/core/Anywhere/src/org/litesoft/render/AbstractRenderHelper.java

Diff revisions: vs.
  @@ -5,8 +5,7 @@
5 5
6 6 import java.util.*;
7 7
8 - public abstract class AbstractRenderHelper implements RenderHelper
9 - {
8 + public abstract class AbstractRenderHelper implements RenderHelper {
10 9 private Object mRectangularRenderableObject;
11 10 private RenderAccessor mRenderAccessor;
12 11 private RenderSizingApproach mSizingApproach;
  @@ -31,8 +30,7 @@
31 30 RenderAccessor pRenderAccessor, //
32 31 RenderSizingApproach pSizingApproach, //
33 32 RenderParticipatingAdapter pParticipatingAdapter, //
34 - RenderDimensionAdapter pDimensionAdapter )
35 - {
33 + RenderDimensionAdapter pDimensionAdapter ) {
36 34 Objects.assertNotNull( "RRO", mRectangularRenderableObject = pRectangularRenderableObject );
37 35 Objects.assertNotNull( "RenderAccessor", mRenderAccessor = pRenderAccessor );
38 36 Objects.assertNotNull( "SizingApproach", mSizingApproach = pSizingApproach );
  @@ -43,14 +41,12 @@
43 41
44 42 mDetermineRectSizeNow = new DetermineRectSizeNowRHP( mRROname, this );
45 43
46 - if ( sTraceLogger == null )
47 - {
44 + if ( sTraceLogger == null ) {
48 45 sTraceLogger = LOGGER.trace.isEnabled() ? RealTraceLogger.INSTANCE : NullTraceLogger.INSTANCE;
49 46 }
50 47 }
51 48
52 - protected Object getRectangularRenderableObject()
53 - {
49 + protected Object getRectangularRenderableObject() {
54 50 return mRectangularRenderableObject;
55 51 }
56 52
  @@ -68,39 +64,31 @@
68 64
69 65 abstract protected RenderHelperProcess requestAdjustSizeBy( int pRequestedSizeChange );
70 66
71 - protected final void assertSizableAndAtLeastOne( String pWhat, int pSize )
72 - {
73 - if ( pSize < 1 )
74 - {
67 + protected final void assertSizableAndAtLeastOne( String pWhat, int pSize ) {
68 + if ( pSize < 1 ) {
75 69 throw new IllegalArgumentException( "Can Not " + pWhat + " '" + pSize + "', < 1 on: " + getRectangularRenderableObject() );
76 70 }
77 71 assertSizable();
78 72 }
79 73
80 - protected final void assertSizable()
81 - {
82 - if ( !isSizable() )
83 - {
74 + protected final void assertSizable() {
75 + if ( !isSizable() ) {
84 76 throw exceptionOnSizeChange();
85 77 }
86 78 }
87 79
88 - protected UnsupportedOperationException exceptionOnSizeChange()
89 - {
80 + protected UnsupportedOperationException exceptionOnSizeChange() {
90 81 return new UnsupportedOperationException( "SizingApproach '" + mSizingApproach + //
91 82 "' on: " + getRectangularRenderableObject() );
92 83 }
93 84
94 - public final boolean renderingParticipationChanged()
95 - {
85 + public final boolean renderingParticipationChanged() {
96 86 return chkForRenderingParticipationChanged();
97 87 }
98 88
99 - private boolean chkForRenderingParticipationChanged()
100 - {
89 + private boolean chkForRenderingParticipationChanged() {
101 90 Boolean zNewParticipating = mParticipatingAdapter.isParticipatingInRendering( getRectangularRenderableObject() );
102 - if ( zNewParticipating.equals( mParticipatingInRendering ) )
103 - {
91 + if ( zNewParticipating.equals( mParticipatingInRendering ) ) {
104 92 return false;
105 93 }
106 94 mParticipatingInRendering = zNewParticipating;
  @@ -111,16 +99,13 @@
111 99 /**
112 100 * Clear Our State
113 101 */
114 - protected void LLrenderingParticipationChanged()
115 - {
116 - if ( mParticipatingInRendering )
117 - {
102 + protected void LLrenderingParticipationChanged() {
103 + if ( mParticipatingInRendering ) {
118 104 LLjustParticipatingInRendering();
119 105 }
120 106 }
121 107
122 - protected void LLjustParticipatingInRendering()
123 - {
108 + protected void LLjustParticipatingInRendering() {
124 109 mDetermineRectSizeNow.startingToParticipateInRendering();
125 110 layout();
126 111 }
  @@ -128,29 +113,24 @@
128 113 /**
129 114 * Participating? (GWT attached & ! "Display=None")
130 115 */
131 - public final boolean isParticipatingInRendering()
132 - {
116 + public final boolean isParticipatingInRendering() {
133 117 chkForRenderingParticipationChanged();
134 118 return mParticipatingInRendering;
135 119 }
136 120
137 - public final RenderSizingApproach getSizingApproach()
138 - {
121 + public final RenderSizingApproach getSizingApproach() {
139 122 return mSizingApproach;
140 123 }
141 124
142 - public boolean isSizable()
143 - {
125 + public boolean isSizable() {
144 126 return !RenderSizingApproach.None.equals( mSizingApproach );
145 127 }
146 128
147 - public final RenderDimensionAdapter getDimensionAdapter()
148 - {
129 + public final RenderDimensionAdapter getDimensionAdapter() {
149 130 return mDimensionAdapter;
150 131 }
151 132
152 - public RenderHelper getParentHelper()
153 - {
133 + public RenderHelper getParentHelper() {
154 134 Object zParent = getDimensionAdapter().getParent( getRectangularRenderableObject() );
155 135 return (zParent != null) ? mRenderAccessor.getHelper( zParent ) : null;
156 136 }
  @@ -160,8 +140,7 @@
160 140 *
161 141 * @return !null array of the child RenderHelper(s) if any.
162 142 */
163 - public RenderHelper[] restoreForLayout()
164 - {
143 + public RenderHelper[] restoreForLayout() {
165 144 LLrestoreForLayout();
166 145 return EMPTY_ARRAY;
167 146 }
  @@ -169,34 +148,29 @@
169 148 /**
170 149 * Restore the RenderableRect to its pre-Layed-out state.
171 150 */
172 - protected void LLrestoreForLayout()
173 - {
151 + protected void LLrestoreForLayout() {
174 152 mLayoutState = LayoutState.Restored;
175 153 }
176 154
177 155 /**
178 156 * Return if this Helper is current in the Laying Out mode.
179 157 */
180 - public boolean isLayingOut()
181 - {
158 + public boolean isLayingOut() {
182 159 return LayoutState.LayingOut.equals( mLayoutState );
183 160 }
184 161
185 162 /**
186 163 * Set the Helper to indicate that we are in the process of Laying Out.
187 164 */
188 - public void setLayingOut()
189 - {
165 + public void setLayingOut() {
190 166 mLayoutState = LayoutState.LayingOut;
191 167 }
192 168
193 - protected void setLayedOut()
194 - {
169 + protected void setLayedOut() {
195 170 mLayoutState = LayoutState.LayedOut;
196 171 }
197 172
198 - protected boolean isLayedOut()
199 - {
173 + protected boolean isLayedOut() {
200 174 return LayoutState.LayedOut.equals( mLayoutState );
201 175 }
202 176
  @@ -206,34 +180,25 @@
206 180 * Note: RHPs are Instance Equality Managed, so for the same underlying dependency the same RHP must be returned!
207 181 *
208 182 * @return null if no layout process is needed,
209 - * otherwise the returned RHP's callbacks will be notified when it is complete.
183 + * otherwise the returned RHP's callbacks will be notified when it is complete.
210 184 */
211 - public final RenderHelperProcess layout()
212 - {
185 + public final RenderHelperProcess layout() {
213 186 LLsetLayingOut();
214 - if ( isLayoutAncestorHelper() )
215 - {
187 + if ( isLayoutAncestorHelper() ) {
216 188 return layoutFromHereDown();
217 189 }
218 190 return getParentHelper().layout();
219 191 }
220 192
221 - private void LLsetLayingOut()
222 - {
223 - if ( !this.isLayingOut() )
224 - {
193 + private void LLsetLayingOut() {
194 + if ( !this.isLayingOut() ) {
225 195 RenderHelper[] zHelpers = prepForLayout( this );
226 - if ( zHelpers.length != 0 )
227 - {
228 - for ( Queue<RenderHelper[]> zLists = new LinkedList<RenderHelper[]>(); zHelpers != null; zHelpers = zLists.poll() )
229 - {
230 - for ( RenderHelper zHelper : zHelpers )
231 - {
232 - if ( !zHelper.isLayingOut() )
233 - {
196 + if ( zHelpers.length != 0 ) {
197 + for ( Queue<RenderHelper[]> zLists = new LinkedList<RenderHelper[]>(); zHelpers != null; zHelpers = zLists.poll() ) {
198 + for ( RenderHelper zHelper : zHelpers ) {
199 + if ( !zHelper.isLayingOut() ) {
234 200 RenderHelper[] zChildHelpers = prepForLayout( zHelper );
235 - if ( zChildHelpers.length != 0 )
236 - {
201 + if ( zChildHelpers.length != 0 ) {
237 202 zLists.offer( zChildHelpers );
238 203 }
239 204 }
  @@ -243,8 +208,7 @@
243 208 }
244 209 }
245 210
246 - private RenderHelper[] prepForLayout( RenderHelper pHelper )
247 - {
211 + private RenderHelper[] prepForLayout( RenderHelper pHelper ) {
248 212 RenderHelper[] zChildHelpers = pHelper.restoreForLayout();
249 213 pHelper.setLayingOut();
250 214 return zChildHelpers;
  @@ -253,10 +217,10 @@
253 217 /**
254 218 * Determine if this Helper is a Layout Ancestor.
255 219 * <p/>
256 - * When going up the Parentage path, it will obviously return true at the root, but it may also return true at a Clipping Container that has been explicitly sized!
220 + * When going up the Parentage path, it will obviously return true at the root, but it may also return true at a Clipping Container that has been
221 + * explicitly sized!
257 222 */
258 - public boolean isLayoutAncestorHelper()
259 - {
223 + public boolean isLayoutAncestorHelper() {
260 224 return (getParentHelper() == null);
261 225 }
262 226
  @@ -275,8 +239,7 @@
275 239 * @throws UnsupportedOperationException if the SizingApproach is "None"
276 240 */
277 241 public RenderHelperProcess floodSetSize( int pRequestedSize )
278 - throws IllegalArgumentException, UnsupportedOperationException
279 - {
242 + throws IllegalArgumentException, UnsupportedOperationException {
280 243 assertSizableAndAtLeastOne( "Flood Set Size to", pRequestedSize );
281 244 String zRequest = sTraceLogger.traceRequestSet( this, "floodSetSize", pRequestedSize );
282 245 RenderHelperProcess zProcess = requestFloodSetSize( pRequestedSize );
  @@ -295,8 +258,7 @@
295 258 * @throws UnsupportedOperationException if the SizingApproach is "None"
296 259 */
297 260 public RenderHelperProcess floodAdjustSizeBy( int pRequestedSizeChange )
298 - throws UnsupportedOperationException
299 - {
261 + throws UnsupportedOperationException {
300 262 assertSizable();
301 263 String zRequest = sTraceLogger.traceRequestAdjust( this, "floodAdjustSizeBy", pRequestedSizeChange );
302 264 RenderHelperProcess zProcess = requestFloodAdjustSizeBy( pRequestedSizeChange );
  @@ -318,8 +280,7 @@
318 280 * @throws UnsupportedOperationException if the SizingApproach is "None"
319 281 */
320 282 public RenderHelperProcess setSize( int pRequestedSize )
321 - throws IllegalArgumentException, UnsupportedOperationException
322 - {
283 + throws IllegalArgumentException, UnsupportedOperationException {
323 284 assertSizableAndAtLeastOne( "Set Size to", pRequestedSize );
324 285 String zRequest = sTraceLogger.traceRequestSet( this, "setSize", pRequestedSize );
325 286 RenderHelperProcess zProcess = requestSetSize( pRequestedSize );
  @@ -338,62 +299,50 @@
338 299 * @throws UnsupportedOperationException if the SizingApproach is "None"
339 300 */
340 301 public RenderHelperProcess adjustSizeBy( int pRequestedSizeChange )
341 - throws UnsupportedOperationException
342 - {
302 + throws UnsupportedOperationException {
343 303 assertSizable();
344 304 String zRequest = sTraceLogger.traceRequestAdjust( this, "adjustSizeBy", pRequestedSizeChange );
345 305 RenderHelperProcess zProcess = requestAdjustSizeBy( pRequestedSizeChange );
346 306 return sTraceLogger.traceCB( this, zRequest, zProcess );
347 307 }
348 308
349 - protected final Integer getRectSizeNow()
350 - {
351 - if ( isParticipatingInRendering() )
352 - {
353 - if ( mLastReportedSize != null )
354 - {
309 + protected final Integer getRectSizeNow() {
310 + if ( isParticipatingInRendering() ) {
311 + if ( mLastReportedSize != null ) {
355 312 return mLastReportedSize;
356 313 }
357 314 int zSize = mDimensionAdapter.getSize( getRectangularRenderableObject() );
358 - if ( (zSize != mIgnoreInitialNonParticipatingSize) && (zSize != mIgnoreReportedSize) )
359 - {
315 + if ( (zSize != mIgnoreInitialNonParticipatingSize) && (zSize != mIgnoreReportedSize) ) {
360 316 return (mLastReportedSize = zSize);
361 317 }
362 318 }
363 319 return null;
364 320 }
365 321
366 - protected void setSizingChange( int pCurrentSizeToIgnore, Integer pPendingNewSize )
367 - {
322 + protected void setSizingChange( int pCurrentSizeToIgnore, Integer pPendingNewSize ) {
368 323 mIgnoreReportedSize = pCurrentSizeToIgnore;
369 324 mLastReportedSize = null;
370 325 }
371 326
372 - protected static RenderHelperProcess queue( RenderHelperProcess pProcess )
373 - {
327 + protected static RenderHelperProcess queue( RenderHelperProcess pProcess ) {
374 328 return RenderProcessManager.INSTANCE.queue( pProcess );
375 329 }
376 330
377 - protected static void defer( RenderHelperProcess pProcessToDefer, int pForMillisecs )
378 - {
331 + protected static void defer( RenderHelperProcess pProcessToDefer, int pForMillisecs ) {
379 332 RenderProcessManager.INSTANCE.defer( pProcessToDefer, pForMillisecs );
380 333 }
381 334
382 - protected static void deferPending( AbstractRHPwithDependencies pDependentProcess, RenderHelperProcess pDependsOnProcess )
383 - {
384 - if ( pDependentProcess != null )
385 - {
335 + protected static void deferPending( AbstractRHPwithDependencies pDependentProcess, RenderHelperProcess pDependsOnProcess ) {
336 + if ( pDependentProcess != null ) {
386 337 pDependentProcess.deferPending( pDependsOnProcess );
387 338 }
388 339 }
389 340
390 - protected String toString( String pHelperName )
391 - {
341 + protected String toString( String pHelperName ) {
392 342 return pHelperName + getDimensionAdapter().getWhat() + "-" + Objects.justClassName( getRectangularRenderableObject().getClass() );
393 343 }
394 344
395 - private interface TraceLogger
396 - {
345 + private interface TraceLogger {
397 346 public String traceRequestSet( RenderHelper pRenderHelper, String pMethod, int pParam );
398 347
399 348 public String traceRequestAdjust( RenderHelper pRenderHelper, String pMethod, int pParam );
  @@ -401,79 +350,64 @@
401 350 public RenderHelperProcess traceCB( RenderHelper pRenderHelper, String pRequest, RenderHelperProcess pHelperProcess );
402 351 }
403 352
404 - private static class NullTraceLogger implements TraceLogger
405 - {
353 + private static class NullTraceLogger implements TraceLogger {
406 354 public static final TraceLogger INSTANCE = new NullTraceLogger();
407 355
408 - public String traceRequestSet( RenderHelper pRenderHelper, String pMethod, int pParam )
409 - {
356 + public String traceRequestSet( RenderHelper pRenderHelper, String pMethod, int pParam ) {
410 357 return null;
411 358 }
412 359
413 - public String traceRequestAdjust( RenderHelper pRenderHelper, String pMethod, int pParam )
414 - {
360 + public String traceRequestAdjust( RenderHelper pRenderHelper, String pMethod, int pParam ) {
415 361 return null;
416 362 }
417 363
418 - public RenderHelperProcess traceCB( RenderHelper pRenderHelper, String pRequest, RenderHelperProcess pHelperProcess )
419 - {
364 + public RenderHelperProcess traceCB( RenderHelper pRenderHelper, String pRequest, RenderHelperProcess pHelperProcess ) {
420 365 return pHelperProcess;
421 366 }
422 367 }
423 368
424 - private static class RealTraceLogger implements TraceLogger
425 - {
369 + private static class RealTraceLogger implements TraceLogger {
426 370 public static final TraceLogger INSTANCE = new RealTraceLogger();
427 371
428 372 private static int sTraceInstance = 0;
429 373
430 - public String traceRequestSet( RenderHelper pRenderHelper, String pMethod, int pParam )
431 - {
374 + public String traceRequestSet( RenderHelper pRenderHelper, String pMethod, int pParam ) {
432 375 return LLtraceRequest( pRenderHelper, pMethod, Integer.toString( pParam ) );
433 376 }
434 377
435 - public String traceRequestAdjust( RenderHelper pRenderHelper, String pMethod, int pParam )
436 - {
378 + public String traceRequestAdjust( RenderHelper pRenderHelper, String pMethod, int pParam ) {
437 379 Integer zCurrentSize = pRenderHelper.getCurrentSize();
438 380 Integer zExpectedSize = (zCurrentSize != null) ? (zCurrentSize + pParam) : null;
439 381 return LLtraceRequest( pRenderHelper, pMethod, "" + pParam + " + " + zCurrentSize + " = " + zExpectedSize );
440 382 }
441 383
442 - private String LLtraceRequest( RenderHelper pRenderHelper, String pMethod, String pParam )
443 - {
384 + private String LLtraceRequest( RenderHelper pRenderHelper, String pMethod, String pParam ) {
444 385 String zRequest = "" + (++sTraceInstance) + "|" + pRenderHelper + ": " + //
445 386 pMethod + "( " + pParam + " )";
446 387 LOGGER.trace.log( zRequest, "..." );
447 388 return zRequest;
448 389 }
449 390
450 - public RenderHelperProcess traceCB( RenderHelper pRenderHelper, String pRequest, RenderHelperProcess pHelperProcess )
451 - {
452 - if ( pHelperProcess == null )
453 - {
391 + public RenderHelperProcess traceCB( RenderHelper pRenderHelper, String pRequest, RenderHelperProcess pHelperProcess ) {
392 + if ( pHelperProcess == null ) {
454 393 LOGGER.trace.log( pRequest, "!" );
455 - }
456 - else
457 - {
394 + } else {
458 395 pHelperProcess.addCallback( new TraceCallBack( pRenderHelper, pRequest ) );
459 396 }
460 397 return pHelperProcess;
461 398 }
462 399 }
463 400
464 - private static class TraceCallBack implements RenderHelperCallback
465 - {
401 + private static class TraceCallBack implements RenderHelperCallback {
466 402 private RenderHelper mRenderHelper;
467 403 private String mRequest;
468 404
469 - public TraceCallBack( RenderHelper pRenderHelper, String pRequest )
470 - {
405 + public TraceCallBack( RenderHelper pRenderHelper, String pRequest ) {
471 406 mRenderHelper = pRenderHelper;
472 407 mRequest = pRequest;
473 408 }
474 409
475 - public void processCompleted( RenderHelperProcess pCompletedProcess, RenderProcessResult pCompletedProcessResult )
476 - {
410 + public void processCompleted( RenderHelperProcess pCompletedProcess, RenderProcessResult pCompletedProcessResult ) {
477 411 LOGGER.trace.log( mRequest, //
478 412 " -> ", mRenderHelper.getCurrentSize(), //
479 413 " (min:", mRenderHelper.getMinimumSize(), //