litesoft
@ 939
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 |
// This Source Code is in the Public Domain per: http://litesoft.org/License.txt package org.litesoft.render; import org.litesoft.commonfoundation.typeutils.*; public abstract class AbstractRenderOneDimensionalContainerHelper extends AbstractRenderContainerHelper { private RenderContainerChildrenPolicy mChildrenPolicy; protected AbstractRenderOneDimensionalContainerHelper( Object pRectangularRenderableObject, // RenderAccessor pRenderAccessor, // RenderParticipatingAdapter pParticipatingAdapter, // RenderDimensionAdapter pDimensionAdapter, // RenderContainmentApproach pContainmentApproach, // RenderContainerChildrenPolicy pChildrenPolicy ) { super( pRectangularRenderableObject, pRenderAccessor, pParticipatingAdapter, pDimensionAdapter, pContainmentApproach ); Objects.assertNotNull( "ChildrenPolicy", mChildrenPolicy = pChildrenPolicy ); } /** * @param pChildHelpers !null / * * @return null means that someone is not ready, otherwise the current Calculated Minimum Size */ protected Integer calculateChildrenMinimumSize( RenderHelper[] pChildHelpers ) { int[] zMinimumSizes = new int[pChildHelpers.length]; for ( int i = 0; i < pChildHelpers.length; i++ ) { Integer zMinimumSize = pChildHelpers[i].getMinimumSize(); if ( zMinimumSize == null ) { return null; } zMinimumSizes[i] = zMinimumSize; } return RenderContainerChildrenPolicy.Distribute.equals( mChildrenPolicy ) ? // sum( zMinimumSizes ) : // max( zMinimumSizes ); } protected RenderProcessResult LLadjustChildSizesAfterLayout( LayoutContainerRHP pLayoutContainerRHP, RenderHelper[] pChildHelpers ) { if ( RenderContainerChildrenPolicy.Propogate.equals( mChildrenPolicy ) ) { boolean anySizableKids = false; boolean allChildrenSizing = true; int[] zCurSizes = new int[pChildHelpers.length]; for ( int i = 0; i < pChildHelpers.length; i++ ) { RenderHelper zChildHelper = pChildHelpers[i]; Integer zSize = zChildHelper.getCurrentSize(); if ( zSize == null ) { deferPending( pLayoutContainerRHP, zChildHelper.unavailableCurrentSizeRHP() ); allChildrenSizing = false; } else { zCurSizes[i] = zSize; anySizableKids |= zChildHelper.isSizable(); } } if ( !allChildrenSizing ) { return RenderProcessResult.Requeued; } if ( anySizableKids ) { boolean anyFloodings = false; int zMaxSize = max( zCurSizes ); for ( RenderHelper zChildHelper : pChildHelpers ) { if ( zChildHelper.isSizable() ) { Integer zChildSize = zChildHelper.getCurrentSize(); if ( zChildSize == null ) { deferPending( pLayoutContainerRHP, zChildHelper.unavailableCurrentSizeRHP() ); return RenderProcessResult.Requeued; } if ( zMaxSize > zChildSize ) { RenderHelperProcess zChildHelperProcess = zChildHelper.floodSetSize( zMaxSize ); if ( zChildHelperProcess != null ) { deferPending( pLayoutContainerRHP, zChildHelperProcess ); anyFloodings = true; } } } } if ( anyFloodings ) { return RenderProcessResult.Requeued; } } } return RenderProcessResult.Completed; } public final RenderHelper[] getChildHelpers() { Object[] zChildObjects = getChildObjects(); if ( Objects.isNullOrEmpty( zChildObjects ) ) { return RenderHelper.EMPTY_ARRAY; } RenderHelper[] zHelpers = new RenderHelper[zChildObjects.length]; for ( int i = 0; i < zChildObjects.length; i++ ) { Object zChildObject = zChildObjects[i]; RenderHelper zHelper = getChildHelper( zChildObject ); if ( zHelper == null ) { putChildHelper( zChildObject, zHelper = getRenderHelperForChildObject( zChildObject ) ); } zHelpers[i] = zHelper; } return zHelpers; } abstract protected Object[] getChildObjects(); abstract protected RenderHelper getRenderHelperForChildObject( Object pRectangularRenderableObject ); /** * Set the Size - pCurrentSize != pNewSize */ protected RenderProcessResult LLLsetSize( MutateSizeRHP pMutateSizeRHP, int pCurrentSize, int pNewSize ) { setSizingChange( pCurrentSize, pNewSize ); switch ( getSizingApproach() ) { case Adjustable: return wrapping_adjustSizeTo( pMutateSizeRHP, pNewSize ); default: // Should Never Happen... case Settable: return clipping_setSizeTo( pMutateSizeRHP, pNewSize ); } } /** * Set the Size - pNewSize != The Current Size */ private RenderProcessResult wrapping_adjustSizeTo( MutateSizeRHP pMutateSizeRHP, int pNewSize ) { AbstractRHPwithDependencies zRenderHelperProcess = (AbstractRHPwithDependencies) unavailableCurrentSizeRHP(); deferPending( pMutateSizeRHP, zRenderHelperProcess ); processChildren( zRenderHelperProcess, pNewSize ); // Set our Size so that we might "stretch" getDimensionAdapter().setSize( getRectangularRenderableObject(), pNewSize ); return RenderProcessResult.Requeued; } /** * Set the Size - pNewSize != The Current Size */ private RenderProcessResult clipping_setSizeTo( MutateSizeRHP pMutateSizeRHP, int pNewSize ) { getDimensionAdapter().setSize( getRectangularRenderableObject(), pNewSize ); // Set our Size // Make us wait until we get the size! deferPending( pMutateSizeRHP, unavailableCurrentSizeRHP() ); processChildren( null, pNewSize ); return RenderProcessResult.Requeued; } /** * Set the child Size(s) - pNewSize != The Current Size */ private void processChildren( AbstractRHPwithDependencies pRHPtoDefer, int pNewSize ) { RenderHelper[] zChildHelpers = getChildHelpers(); if ( zChildHelpers.length != 0 ) { Integer zDecorationSize = getDecorationSize(); if ( zDecorationSize == null ) { LOGGER.error.log( "No Decoration Size on ", this, // " w/ Sizes: " + getCurrentSize() + " Current", // ", " + getMinimumSize() + " Minimum", // ", " + getNaturalSize() + " Natural", // ", " + getRectSizeNow() + " Now" ); return; } int zInnerSize = pNewSize - zDecorationSize; if ( LOGGER.trace.isEnabled() ) { LOGGER.trace.log( "Size Children to " + zInnerSize, // " from ( " + pNewSize + " - " + zDecorationSize + " ) ", " on ", this, // " w/ Sizes: " + getCurrentSize() + " Current", // ", " + getMinimumSize() + " Minimum", // ", " + getNaturalSize() + " Natural", // ", " + getRectSizeNow() + " Now" ); } switch ( mChildrenPolicy ) { default: // should never happen! case Propogate: propogateToChildren( pRHPtoDefer, zChildHelpers, zInnerSize ); break; case Distribute: distributeToChildren( pRHPtoDefer, zChildHelpers, zInnerSize ); break; } } } /** * This should work because we should have previously Flooded! * * @param pNewSize !0 */ private void propogateToChildren( AbstractRHPwithDependencies pRHPtoDefer, RenderHelper[] pChildHelpers, int pNewSize ) { for ( RenderHelper zHelper : pChildHelpers ) { if ( zHelper.isSizable() ) { adjustChildTo( pRHPtoDefer, zHelper, pNewSize ); } } } private void adjustChildTo( AbstractRHPwithDependencies pRHPtoDefer, RenderHelper pHelper, int pNewSize ) { RenderHelperProcess zProcess = pHelper.floodSetSize( pNewSize ); if ( (pRHPtoDefer != null) && (zProcess != null) ) { deferPending( pRHPtoDefer, zProcess ); } } /** * @param pNewSize !0 */ private void distributeToChildren( AbstractRHPwithDependencies pRHPtoDefer, RenderHelper[] pChildHelpers, int pNewSize ) { int zSumChildSizes = 0; DistributeToChildren zDC = new DistributeToChildren(); for ( int i = 0; i < pChildHelpers.length; i++ ) { RenderHelper zHelper = pChildHelpers[i]; Integer zCurrentSize = zHelper.getCurrentSize(); Integer zMinimumSize = zHelper.getMinimumSize(); if ( (zCurrentSize == null) || (zMinimumSize == null) ) { LOGGER.error.log( "Child ", zHelper, " of ", this, " w/ Sizes: ", // zCurrentSize, " Current, ", zMinimumSize, " Minimum" ); } zSumChildSizes += zCurrentSize; if ( zHelper.isSizable() ) { int zMaxShrinkAllowed = zCurrentSize - zMinimumSize; zDC.add( new ChildAdjustStruct( i, zMaxShrinkAllowed ) ); } } if ( zDC.hasChildren() ) { int zAdjustSizeBy = pNewSize - zSumChildSizes; mIndexOfLastAdjusted = zDC.distribute( zAdjustSizeBy, mIndexOfLastAdjusted ); for ( ChildAdjustStruct zChild : zDC.getChildren() ) { int zAdjustBy = zChild.getAdjustBy(); if ( zAdjustBy != 0 ) { adjustChildBy( pRHPtoDefer, pChildHelpers[zChild.getIndex()], zAdjustBy ); } } } } private void adjustChildBy( AbstractRHPwithDependencies pRHPtoDefer, RenderHelper pHelper, int pAdjustBy ) { RenderHelperProcess zProcess = pHelper.floodAdjustSizeBy( pAdjustBy ); if ( (pRHPtoDefer != null) && (zProcess != null) ) { deferPending( pRHPtoDefer, zProcess ); } } private int mIndexOfLastAdjusted = -1; public String toString() { return toString( "1dContainer" ); } } |
Commits for litesoft/trunk/Java/core/Anywhere/src/org/litesoft/render/AbstractRenderOneDimensionalContainerHelper.java
Revision | Author | Commited | Message |
---|---|---|---|
939 Diff | GeorgeS | Mon 02 Jun, 2014 21:30:31 +0000 | Extracting commonfoundation |
809 Diff | GeorgeS | Thu 16 Aug, 2012 04:10:46 +0000 | |
804 Diff | GeorgeS | Wed 15 Aug, 2012 12:48:51 +0000 | |
151 Diff | GeorgeS | Thu 17 Mar, 2011 04:16:22 +0000 | |
49 Diff | GeorgeS | Mon 12 Apr, 2010 02:59:10 +0000 | License Text |
2 | GeorgeS | Sun 07 Feb, 2010 12:50:58 +0000 |