Subversion Repository Public Repository

litesoft

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
292
293
294
295
296
297
298
299
// This Source Code is in the Public Domain per: http://litesoft.org/License.txt
package org.litesoft.render;

import java.util.*;

import org.litesoft.core.typeutils.*;
import org.litesoft.logger.nonpublic.*;
import org.litesoft.uispecification.*;

public abstract class AbstractRenderContainerHelper extends AbstractSizableRenderHelper implements RenderContainerHelper
{
    protected AbstractRenderContainerHelper( Object pRectangularRenderableObject, //
                                             RenderAccessor pRenderAccessor, //
                                             RenderParticipatingAdapter pParticipatingAdapter, //
                                             RenderDimensionAdapter pDimensionAdapter, //
                                             RenderContainmentApproach pContainmentApproach )
    {
        super( pRectangularRenderableObject, pRenderAccessor, pContainmentApproach.getSizingApproach(), pParticipatingAdapter, pDimensionAdapter );

        mContainmentApproach = RenderContainmentApproach.deNull( pContainmentApproach );

        mDetermineNaturalSize = new DetermineNaturalSizeRHP( mRROname, this, //
                                                             mDetermineRectSizeNow, new DetermineContainerNaturalChildSizesRHP( mRROname, this ) );

        mDetermineContainerDecorationSize = new DetermineContainerDecorationSizeRHP( mRROname, this, //
                                                                                     mDetermineRectSizeNow, //
                                                                                     mDetermineNaturalSize );
        mLayoutContainer = new LayoutContainerRHP( mRROname, this, //
                                                   mDetermineRectSizeNow, //
                                                   mDetermineNaturalSize, //
                                                   mDetermineContainerDecorationSize );

        mDetermineCurrentSize = new DetermineCurrentSizeRHP( mRROname, this, //
                                                             mDetermineRectSizeNow, //
                                                             mDetermineNaturalSize, //
                                                             mLayoutContainer );

        DetermineContainerCurrentChildSizesRHP zCurrentChildSizesRHP = new DetermineContainerCurrentChildSizesRHP( mRROname, this );

        if ( Overflow.None.equals( mContainmentApproach.getOverflow() ) )
        {
            mDetermineContainerMinimumSize = new DetermineContainerMinimumSizeRHP( mRROname, this, //
                                                                                   mDetermineCurrentSize );
            mMutateSize = new MutateSizeRHP( mRROname, this, //
                                             mDetermineCurrentSize, //
                                             mDetermineContainerMinimumSize, //
                                             zCurrentChildSizesRHP );
        }
        else
        {
            mDetermineContainerMinimumSize = null;
            mMutateSize = new MutateSizeRHP( mRROname, this, //
                                             mDetermineCurrentSize, //
                                             zCurrentChildSizesRHP );
        }
    }

    private RenderContainmentApproach mContainmentApproach;
    private Integer mDecorationSize = null;

    protected final DetermineContainerDecorationSizeRHP mDetermineContainerDecorationSize;
    protected final LayoutContainerRHP mLayoutContainer;
    protected final DetermineContainerMinimumSizeRHP mDetermineContainerMinimumSize;

    public Integer getDecorationSize()
    {
        if ( getNaturalSize() == null )
        {
            return null;
        }
        if ( mDecorationSize == null )
        {
            Object zRectangularRenderableObject = getRectangularRenderableObject();
            RenderDimensionAdapter zDimensionAdapter = getDimensionAdapter();
            mDecorationSize = zDimensionAdapter.getContainerOverheadSize( zRectangularRenderableObject );
        }
        return mDecorationSize;
    }

    /**
     * Get the "Decoration" Size RHP.
     * <p/>
     * Note: RHPs are Instance Equality Managed, so for the same underlying dependency the same RHP must be returned!
     *
     * @return !null RHP, where its callbacks will be notified when it is complete.
     */
    public final RenderHelperProcess unavailableDecorationSizeRHP()
    {
        return queue( mDetermineContainerDecorationSize );
    }

    /**
     * Get the "Minimum" Size.
     * <p/>
     * Renderable Objects that are not Sizable will return their "Natural" Size.
     *
     * @return null means that is not "yet" available.
     */
    public Integer getMinimumSize()
    {
        Integer zCurrentSize = getCurrentSize(); // Dependency
        Integer zNaturalSize = getNaturalSize(); // Default if No Children &/ No Minimum specified
        Integer zMinimumSize = LLgetMinimumSize();

        if ( zCurrentSize == null )
        {
            return null;
        }
        if ( mDetermineContainerMinimumSize != null )
        {
            RenderHelper[] zChildHelpers = getChildHelpers();
            if ( Objects.isNotNullOrEmpty( zChildHelpers ) )
            {
                Integer zDecorationSize = getDecorationSize();
                if ( zDecorationSize == null )
                {
                    return null;
                }
                Integer zCalculatedMinimumSize = calculateChildrenMinimumSize( zChildHelpers );
                if ( zCalculatedMinimumSize == null )
                {
                    return null;
                }
                zCalculatedMinimumSize += zDecorationSize;
                if ( zMinimumSize == null )
                {
                    zMinimumSize = zCalculatedMinimumSize;
                }
                else
                {
                    zMinimumSize = Math.max( zMinimumSize, zCalculatedMinimumSize );
                }
            }
        }
        return (zMinimumSize != null) ? zMinimumSize : zNaturalSize;
    }

    /**
     * @param pChildHelpers !null / empty
     *
     * @return null means that someone is not ready, otherwise the current Calculated Minimum Size
     */
    abstract protected Integer calculateChildrenMinimumSize( RenderHelper[] pChildHelpers );

    /**
     * Get the "Minimum" Size RHP.
     * <p/>
     * Note: RHPs are Instance Equality Managed, so for the same underlying dependency the same RHP must be returned!
     *
     * @return !null RHP, where its callbacks will be notified when it is complete.
     */
    public RenderHelperProcess unavailableMinimumSizeRHP()
    {
        return (mDetermineContainerMinimumSize != null) ? //
               queue( mDetermineContainerMinimumSize ) : unavailableCurrentSizeRHP();
    }

    public final RenderContainmentApproach getContainmentApproach()
    {
        return mContainmentApproach;
    }

    protected void LLrenderingParticipationChanged()
    {
        super.LLrenderingParticipationChanged();
        for ( RenderHelper zHelper : mChildHelpers.values() )
        {
            zHelper.renderingParticipationChanged();
        }
    }

    protected RenderProcessResult sizingError( MutateSizeRHP pMutateSizeRHP, int pExpectedSize, int pActualSize )
    {
        if ( mDecorationSize == null ) // Should NOT be possible!!!
        {
            return RenderProcessResult.Terminated;
        }
        if ( ++mDorkedCount < 20 )
        {
            int zNewDecorationSize = getDimensionAdapter().getContainerOverheadSize( getRectangularRenderableObject() );

            int zDecorationDelta = zNewDecorationSize - mDecorationSize;

            if ( zDecorationDelta == 0 )
            {
                logSizingError( LOGGER.error, pExpectedSize, pActualSize, "" );
            }
            else  // Decoration Size Changed!!!
            {
                if ( (pExpectedSize + zDecorationDelta) == pActualSize ) // by just the needed amount
                {
                    logSizingErrorWithDecorationChange( LOGGER.warn, pExpectedSize, pActualSize, zNewDecorationSize );
                    return LLLsetSize( pMutateSizeRHP, pActualSize, pExpectedSize );
                }
                logSizingErrorWithDecorationChange( LOGGER.error, pExpectedSize, pActualSize, zNewDecorationSize );
            }

            defer( pMutateSizeRHP, 50 ); // Will it Settle...?
            return RenderProcessResult.Requeued;
        }
        logSizingError( LOGGER.fatal, pExpectedSize, pActualSize, "" );
        return RenderProcessResult.Terminated;
    }

    protected final void logSizingErrorWithDecorationChange( AbstractLogger pLogger, int pExpectedSize, int pActualSize, int zNewDecorationSize )
    {
        logSizingError( pLogger, pExpectedSize, pActualSize, " Decoration was " + mDecorationSize + " != " + zNewDecorationSize + " now" );
        mDecorationSize = zNewDecorationSize; // Update the Decoration Size
    }

    protected void sizingOK()
    {
        mDorkedCount = 0;
    }

    private int mDorkedCount = 0;

    /**
     * Determine if this Helper is a Layout Ancestor.
     * <p/>
     * 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!
     */
    public boolean isLayoutAncestorHelper()
    {
        return super.isLayoutAncestorHelper() || //
               (isExplicitlySized() && //
                RenderSizingApproach.Settable.equals( getContainmentApproach().getSizingApproach() ));
    }

    /**
     * Restore the RenderableRect to its pre-Layed-out state and return the RenderHelper(s) for its children.
     *
     * @return !null array of the child RenderHelper(s) if any.
     */
    public RenderHelper[] restoreForLayout()
    {
        LLrestoreForLayout();
        return getChildHelpers();
    }

    /**
     * Request "this" RederableRect and its' children be layed out.
     * <p/>
     * Note: RHPs are Instance Equality Managed, so for the same underlying dependency the same RHP must be returned!
     *
     * @return null if no layout process is needed,
     *         otherwise the returned RHP's callbacks will be notified when it is complete.
     */
    public RenderHelperProcess layoutFromHereDown()
    {
        if ( mLayoutContainer.isProcessingNeeded() )
        {
            return RenderProcessManager.INSTANCE.queue( mLayoutContainer );
        }
        setLayedOut();
        return null;
    }

    abstract protected RenderProcessResult LLadjustChildSizesAfterLayout( LayoutContainerRHP pLayoutContainerRHP, RenderHelper[] zChildHelpers );

    public void childRemoved( Object pRectangularRenderableObject )
    {
        mChildHelpers.remove( pRectangularRenderableObject );
        layout();
    }

    private Map<Object, RenderHelper> mChildHelpers = new IdentityHashMap<Object, RenderHelper>();

    protected RenderHelper getChildHelper( Object pRectangularRenderableObject )
    {
        return mChildHelpers.get( pRectangularRenderableObject );
    }

    protected void putChildHelper( Object pRectangularRenderableObject, RenderHelper pHelper )
    {
        mChildHelpers.put( pRectangularRenderableObject, pHelper );
        layout();
    }

    protected static int sum( int[] pInts )
    {
        int rv = 0;
        for ( int zInt : pInts )
        {
            rv += zInt;
        }
        return rv;
    }

    protected static int max( int[] pInts )
    {
        int rv = pInts[0];
        for ( int i = 1; i < pInts.length; i++ )
        {
            rv = Math.max( rv, pInts[i] );
        }
        return rv;
    }
}

Commits for litesoft/trunk/Java/core/Anywhere/src/org/litesoft/render/AbstractRenderContainerHelper.java

Diff revisions: vs.
Revision Author Commited Message
809 Diff Diff GeorgeS picture GeorgeS Thu 16 Aug, 2012 04:10:46 +0000
151 Diff Diff GeorgeS picture GeorgeS Thu 17 Mar, 2011 04:16:22 +0000
49 Diff Diff GeorgeS picture GeorgeS Mon 12 Apr, 2010 02:59:10 +0000

License Text

2 GeorgeS picture GeorgeS Sun 07 Feb, 2010 12:50:58 +0000