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
package org.litesoft.sandbox.infrastructure.client;

import com.google.gwt.user.client.ui.*;

import java.util.*;

public class SameSize extends com.google.gwt.user.client.Timer {
    public static void these( Collection<Widget> pWidgets ) {
        if ( pWidgets != null ) {
            these( pWidgets.toArray( new Widget[pWidgets.size()] ) );
        }
    }

    public static void these( Widget... pWidgets ) {
        if ( pWidgets != null ) {
            List<Widget> zNonNull = new ArrayList<Widget>( pWidgets.length );
            for ( Widget zWidget : pWidgets ) {
                if ( zWidget != null ) {
                    zNonNull.add( zWidget );
                }
            }
            if ( zNonNull.size() > 1 ) {
                new SameSize( zNonNull ).run();
            }
        }
    }

    private static final int MAX_INT = Integer.MAX_VALUE / 2;

    private final List<Widget> mWidgets;

    private SameSize( List<Widget> pWidgets ) {
        mWidgets = pWidgets;
    }

    private int mDelay = 50;
    private int mMaxX, mMaxY;
    private boolean mAnyResizingNeeded;
    private boolean mSizingWorking;

    @Override
    public void run() {
        mAnyResizingNeeded = false;
        mSizingWorking = true;

        Widget zWidget;
        for ( int i = 0; i < mWidgets.size(); i++ ) {
            if ( null == (zWidget = get( i )) ) {
                return;
            }
            mMaxX = checkSize( mMaxX, zWidget.getOffsetWidth() );
            mMaxY = checkSize( mMaxY, zWidget.getOffsetHeight() );
        }
        if ( mSizingWorking ) {
            if ( !mAnyResizingNeeded ) {
                return;
            }
            for ( int i = 0; i < mWidgets.size(); i++ ) {
                if ( null == (zWidget = get( i )) ) {
                    return;
                }
                if ( mMaxX > zWidget.getOffsetWidth() ) {
                    zWidget.setWidth( mMaxX + "px" );
                }
                if ( mMaxY > zWidget.getOffsetHeight() ) {
                    zWidget.setHeight( mMaxY + "px" );
                }
            }
        }
        if ( mDelay < MAX_INT ) {
            schedule( mDelay += mDelay ); // Double each time
        }
    }

    private int checkSize( int pMaxSize, int pOffsetSize ) {
        if ( pOffsetSize < 10 ) {
            mSizingWorking = false;
            return pMaxSize;
        }
        if ( pMaxSize == 0 ) {
            return pOffsetSize;
        }
        mAnyResizingNeeded |= (pOffsetSize != pMaxSize);
        return Math.max( pOffsetSize, pMaxSize );
    }

    private Widget get( int pIndex ) {
        Widget zWidget = mWidgets.get( pIndex );
        if ( zWidget.isAttached() ) {
            return zWidget;
        }
        System.out.println( "Not Attached: " + zWidget );
        return null;
    }
}

Commits for litesoft/trunk/GWT_Sandbox/MultiModule/common/src/org/litesoft/sandbox/infrastructure/client/SameSize.java

Diff revisions: vs.
Revision Author Commited Message
948 Diff Diff GeorgeS picture GeorgeS Sat 07 Jun, 2014 23:42:39 +0000

Jusefuls Formatter Updated to New Code Format

939 Diff Diff GeorgeS picture GeorgeS Mon 02 Jun, 2014 21:30:31 +0000

Extracting commonfoundation

548 GeorgeS picture GeorgeS Mon 10 Oct, 2011 19:08:21 +0000