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
300
301
302
303
// This Source Code is in the Public Domain per: http://litesoft.org/License.txt
package org.litesoft.render;

import org.litesoft.core.typeutils.*;

import java.util.concurrent.atomic.*;

public class MockNativeRect
{
    public static final MockNativeRect[] EMPTY_ARRAY = new MockNativeRect[0];

    private String mName;
    protected int mNaturalSizeX = 0;
    protected int mNaturalSizeY = 0;
    protected int mRequestedSizeX = 0;
    protected int mRequestedSizeY = 0;
    protected int mRequestedRelativePosX = 0;
    protected int mRequestedRelativePosY = 0;
    private int mLastSizeX = 0;
    private int mLastSizeY = 0;
    private int mLastRelativePosX = 0;
    private int mLastRelativePosY = 0;
    private MockContainer mParent = null;
    protected boolean mParticipating = true;

    protected MockNativeRect( String pName )
    {
        mName = insureName( pName, "NativeRect_" );
    }

    public MockNativeRect( String pName, int pNaturalSizeX, int pNaturalSizeY )
    {
        this( pName );
        mNaturalSizeX = Integers.assertNonNegative( "NaturalSizeX", pNaturalSizeX );
        mNaturalSizeY = Integers.assertNonNegative( "NaturalSizeY", pNaturalSizeY );
    }

    public String getName()
    {
        return mName;
    }

    public final int getSizeX()
    {
        return reportingCorrectly() ? mLastSizeX = LLgetCorrectSizeX() : mLastSizeX;
    }

    protected int LLgetCorrectSizeX()
    {
        return LLgetExpectedSizeX();
    }

    private int LLgetExpectedSizeX()
    {
        return (mRequestedSizeX != 0) ? mRequestedSizeX : mNaturalSizeX;
    }

    public final int getSizeY()
    {
        return reportingCorrectly() ? mLastSizeY = LLgetCorrectSizeY() : mLastSizeY;
    }

    protected int LLgetCorrectSizeY()
    {
        return LLgetExpectedSizeY();
    }

    private int LLgetExpectedSizeY()
    {
        return (mRequestedSizeY != 0) ? mRequestedSizeY : mNaturalSizeY;
    }

    public final int getRelativePosX()
    {
        return reportingCorrectly() ? mLastRelativePosX = LLgetCorrectRelativePosX() : mLastRelativePosX;
    }

    protected int LLgetCorrectRelativePosX()
    {
        return mRequestedRelativePosX;
    }

    public final int getRelativePosY()
    {
        return reportingCorrectly() ? mLastRelativePosY = LLgetCorrectRelativePosY() : mLastRelativePosY;
    }

    protected int LLgetCorrectRelativePosY()
    {
        return mRequestedRelativePosY;
    }

    public RenderHelperProcess setSizeX( int pRequestedSizeX )
    {
        throw new UnsupportedOperationException( "setSizeX( " + pRequestedSizeX + ") on: " + getName() );
    }

    public RenderHelperProcess setSizeY( int pRequestedSizeY )
    {
        throw new UnsupportedOperationException( "setSizeY( " + pRequestedSizeY + ") on: " + getName() );
    }

    public void setRelativePosX( int pRequestedRelativePosX )
    {
        throw new UnsupportedOperationException( "setRelativePosX( " + pRequestedRelativePosX + ") on: " + getName() );
    }

    public void setRelativePosY( int pRequestedRelativePosY )
    {
        throw new UnsupportedOperationException( "setRelativePosY( " + pRequestedRelativePosY + ") on: " + getName() );
    }

    protected void LLsetSizeX( int pRequestedSizeX )
    {
        mRequestedSizeX = Integers.assertPositive( "SizeX", pRequestedSizeX );
        changedPosOrSize();
    }

    public void LLremoveSetSizeX()
    {
        mRequestedSizeX = 0;
        changedPosOrSize();
    }

    protected void LLsetSizeY( int pRequestedSizeY )
    {
        mRequestedSizeY = Integers.assertPositive( "SizeY", pRequestedSizeY );
        changedPosOrSize();
    }

    public void LLremoveSetSizeY()
    {
        mRequestedSizeY = 0;
        changedPosOrSize();
    }

    protected void LLsetRelativePosX( int pRequestedRelativePosX )
    {
        mRequestedRelativePosX = pRequestedRelativePosX;
        changedPosOrSize();
    }

    protected void LLsetRelativePosY( int pRequestedRelativePosY )
    {
        mRequestedRelativePosY = pRequestedRelativePosY;
        changedPosOrSize();
    }

    protected final void changedPosOrSize()
    {
        if ( isAttachedAndParticipating() )
        {
            setPnAts();
        }
    }

    public MockContainer getParent()
    {
        return mParent;
    }

    public void setParent( MockContainer pParent )
    {
        if ( mParent != null )
        {
            MockContainer zParent = mParent;
            mParent = null;
            zParent.LLchildRemoved( this );
        }
        if ( null != (mParent = pParent) )
        {
            mParent.LLchildAdded( this );
        }
    }

    public boolean isAttached()
    {
        return (mParent != null) && mParent.isAttached();
    }

    /**
     * called by Parent Container when this NativeRect was "justAttached".
     */
    protected void justAttached()
    {
        if ( isParticipating() )
        {
            setPnAts();
        }
    }

    /**
     * called by Parent Container when this NativeRect was "justDetached".
     */
    protected void justDetached()
    {
        clrPnAts();
    }

    public boolean isParticipating()
    {
        return mParticipating && (mParent != null) && mParent.isParticipating();
    }

    public void setParticipating( boolean pParticipating )
    {
        if ( !(mParticipating = pParticipating) )
        {
            clrPnAts();
        }
        else if ( isAttached() )
        {
            setPnAts();
        }
    }

    public boolean isAttachedAndParticipating()
    {
        return isAttached() && isParticipating();
    }

    public String toString()
    {
        StringBuilder zSB = new StringBuilder();
        return toStringBuilder( zSB, 0 ).toString();
    }

    public StringBuilder toStringBuilder( StringBuilder pSB, int pDepth )
    {
        pSB.append( mName );

        int zReportedSizeX = getSizeX();
        int zReportedSizeY = getSizeY();
        int zReportedRelativePosX = getRelativePosX();
        int zReportedRelativePosY = getRelativePosY();

        appendTo( pSB, " (", //
                  zReportedSizeX, LLgetExpectedSizeX(), zReportedSizeY, LLgetExpectedSizeY() );

        appendPostSize( pSB );

        if ( (zReportedRelativePosX != 0) || (mRequestedRelativePosX != 0) ||
             (zReportedRelativePosY != 0) || (mRequestedRelativePosY != 0) )
        {
            appendTo( pSB, " @ (", //
                      zReportedRelativePosX, mRequestedRelativePosX, zReportedRelativePosY, mRequestedRelativePosY );
        }

        return pSB;
    }

    protected void appendPostSize( StringBuilder pSB )
    {
    }

    protected final void appendTo( StringBuilder pSB, String pPrefix, //
                                   int pReportedX, int pRequestedX, int pReportedY, int pRequestedY )
    {
        appendTo( pSB, pPrefix, pReportedX, pRequestedX );
        appendTo( pSB, ",", pReportedY, pRequestedY );
        pSB.append( ")" );
    }

    private void appendTo( StringBuilder pSB, String pPrefix, int pReported, int pRequested )
    {
        pSB.append( pPrefix ).append( pReported );
        if ( (pReported != pRequested) && (pRequested != 0) )
        {
            pSB.append( "!=" ).append( pRequested );
        }
    }

    private static final AtomicInteger sSequenceSource = new AtomicInteger( 0 );

    protected static String insureName( String pName, String pDefaultPrefix )
    {
        return (null != (pName = Strings.noEmpty( pName ))) ? //
               pName : //
               pDefaultPrefix + sSequenceSource.incrementAndGet();
    }

    private Long mPnAts = null;

    private void setPnAts()
    {
        mPnAts = Timestamps.now().getTime();
    }

    private void clrPnAts()
    {
        mPnAts = null;
    }

    protected final boolean reportingCorrectly()
    {
        if ( mPnAts != null )
        {
            long zTime = Timestamps.now().getTime();
            return (zTime >= (mPnAts + 10));
        }
        return false;
    }
}

Commits for litesoft/trunk/Java/core/jvm1.5/src/org/litesoft/render/MockNativeRect.java

Diff revisions: vs.
Revision Author Commited Message
821 Diff Diff GeorgeS picture GeorgeS Sun 19 Aug, 2012 00:08:41 +0000
819 Diff Diff GeorgeS picture GeorgeS Sat 18 Aug, 2012 18:09:40 +0000
801 Diff Diff GeorgeS picture GeorgeS Wed 15 Aug, 2012 03:59:02 +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