|
@@ -4,8 +4,7 @@ |
4 |
4 |
|
|
5 |
5 |
|
import java.util.*; |
6 |
6 |
|
|
7 |
|
- |
public abstract class AbstractSameSize extends com.google.gwt.user.client.Timer |
8 |
|
- |
{ |
|
7 |
+ |
public abstract class AbstractSameSize extends com.google.gwt.user.client.Timer { |
9 |
8 |
|
private static final int MAX_INT = Integer.MAX_VALUE / 2; |
10 |
9 |
|
|
11 |
10 |
|
private List<Widget> mWidgets; |
|
@@ -17,113 +16,87 @@ |
17 |
16 |
|
private boolean mSizingWorking; |
18 |
17 |
|
private boolean mAnyResizingNeeded; |
19 |
18 |
|
|
20 |
|
- |
protected AbstractSameSize( boolean pProcessX, boolean pProcessY, Widget... pWidgets ) |
21 |
|
- |
{ |
|
19 |
+ |
protected AbstractSameSize( boolean pProcessX, boolean pProcessY, Widget... pWidgets ) { |
22 |
20 |
|
mProcessX = pProcessX; |
23 |
21 |
|
mProcessY = pProcessY; |
24 |
|
- |
if ( pWidgets != null ) |
25 |
|
- |
{ |
|
22 |
+ |
if ( pWidgets != null ) { |
26 |
23 |
|
mWidgets = new ArrayList<Widget>( pWidgets.length ); |
27 |
|
- |
for ( Widget zWidget : pWidgets ) |
28 |
|
- |
{ |
29 |
|
- |
if ( zWidget != null ) |
30 |
|
- |
{ |
|
24 |
+ |
for ( Widget zWidget : pWidgets ) { |
|
25 |
+ |
if ( zWidget != null ) { |
31 |
26 |
|
mWidgets.add( zWidget ); |
32 |
27 |
|
} |
33 |
28 |
|
} |
34 |
|
- |
if ( mWidgets.size() > 1 ) |
35 |
|
- |
{ |
|
29 |
+ |
if ( mWidgets.size() > 1 ) { |
36 |
30 |
|
run(); |
37 |
31 |
|
} |
38 |
32 |
|
} |
39 |
33 |
|
} |
40 |
34 |
|
|
41 |
|
- |
protected static Widget[] toArray( Collection<Widget> pWidgets ) |
42 |
|
- |
{ |
43 |
|
- |
return (pWidgets != null) ? pWidgets.toArray( new Widget[pWidgets.size()] ) : null; |
|
35 |
+ |
protected static Widget[] toArray( Collection<Widget> pWidgets ) { |
|
36 |
+ |
return (pWidgets != null) ? pWidgets.toArray( new Widget[pWidgets.size()] ) : null; |
44 |
37 |
|
} |
45 |
38 |
|
|
46 |
39 |
|
@Override |
47 |
|
- |
public void run() |
48 |
|
- |
{ |
|
40 |
+ |
public void run() { |
49 |
41 |
|
mAnyResizingNeeded = false; |
50 |
42 |
|
mSizingWorking = true; |
51 |
43 |
|
|
52 |
44 |
|
Widget zWidget; |
53 |
|
- |
if ( !mAllAttached ) |
54 |
|
- |
{ |
55 |
|
- |
for ( int i = 0; i < mWidgets.size(); i++ ) |
56 |
|
- |
{ |
57 |
|
- |
if ( null == (zWidget = get( i )) ) |
58 |
|
- |
{ |
|
45 |
+ |
if ( !mAllAttached ) { |
|
46 |
+ |
for ( int i = 0; i < mWidgets.size(); i++ ) { |
|
47 |
+ |
if ( null == (zWidget = get( i )) ) { |
59 |
48 |
|
schedule( mDelay ); |
60 |
49 |
|
return; |
61 |
50 |
|
} |
62 |
51 |
|
} |
63 |
52 |
|
mAllAttached = true; |
64 |
53 |
|
} |
65 |
|
- |
for ( int i = 0; i < mWidgets.size(); i++ ) |
66 |
|
- |
{ |
67 |
|
- |
if ( null == (zWidget = get( i )) ) |
68 |
|
- |
{ |
|
54 |
+ |
for ( int i = 0; i < mWidgets.size(); i++ ) { |
|
55 |
+ |
if ( null == (zWidget = get( i )) ) { |
69 |
56 |
|
return; // Lost Attachment |
70 |
57 |
|
} |
71 |
|
- |
if ( mProcessX ) |
72 |
|
- |
{ |
|
58 |
+ |
if ( mProcessX ) { |
73 |
59 |
|
mMaxX = checkSize( mMaxX, zWidget.getOffsetWidth() ); |
74 |
60 |
|
} |
75 |
|
- |
if ( mProcessY ) |
76 |
|
- |
{ |
|
61 |
+ |
if ( mProcessY ) { |
77 |
62 |
|
mMaxY = checkSize( mMaxY, zWidget.getOffsetHeight() ); |
78 |
63 |
|
} |
79 |
64 |
|
} |
80 |
|
- |
if ( mSizingWorking ) |
81 |
|
- |
{ |
82 |
|
- |
if ( !mAnyResizingNeeded ) |
83 |
|
- |
{ |
|
65 |
+ |
if ( mSizingWorking ) { |
|
66 |
+ |
if ( !mAnyResizingNeeded ) { |
84 |
67 |
|
return; // Done! |
85 |
68 |
|
} |
86 |
|
- |
for ( int i = 0; i < mWidgets.size(); i++ ) |
87 |
|
- |
{ |
88 |
|
- |
if ( null != (zWidget = get( i )) ) |
89 |
|
- |
{ |
90 |
|
- |
if ( mProcessX && (mMaxX > zWidget.getOffsetWidth()) ) |
91 |
|
- |
{ |
|
69 |
+ |
for ( int i = 0; i < mWidgets.size(); i++ ) { |
|
70 |
+ |
if ( null != (zWidget = get( i )) ) { |
|
71 |
+ |
if ( mProcessX && (mMaxX > zWidget.getOffsetWidth()) ) { |
92 |
72 |
|
zWidget.setWidth( mMaxX + "px" ); |
93 |
73 |
|
} |
94 |
|
- |
if ( mProcessY && (mMaxY > zWidget.getOffsetHeight()) ) |
95 |
|
- |
{ |
|
74 |
+ |
if ( mProcessY && (mMaxY > zWidget.getOffsetHeight()) ) { |
96 |
75 |
|
zWidget.setHeight( mMaxY + "px" ); |
97 |
76 |
|
} |
98 |
77 |
|
} |
99 |
78 |
|
} |
100 |
79 |
|
} |
101 |
|
- |
if ( mDelay < MAX_INT ) |
102 |
|
- |
{ |
|
80 |
+ |
if ( mDelay < MAX_INT ) { |
103 |
81 |
|
schedule( mDelay += mDelay ); // Double each time |
104 |
82 |
|
} |
105 |
83 |
|
} |
106 |
84 |
|
|
107 |
|
- |
private int checkSize( int pMaxSize, int pOffsetSize ) |
108 |
|
- |
{ |
109 |
|
- |
if ( pOffsetSize < 10 ) |
110 |
|
- |
{ |
|
85 |
+ |
private int checkSize( int pMaxSize, int pOffsetSize ) { |
|
86 |
+ |
if ( pOffsetSize < 10 ) { |
111 |
87 |
|
mSizingWorking = false; |
112 |
88 |
|
return pMaxSize; |
113 |
89 |
|
} |
114 |
|
- |
if ( pMaxSize == 0 ) |
115 |
|
- |
{ |
|
90 |
+ |
if ( pMaxSize == 0 ) { |
116 |
91 |
|
return pOffsetSize; |
117 |
92 |
|
} |
118 |
93 |
|
mAnyResizingNeeded |= (pOffsetSize != pMaxSize); |
119 |
94 |
|
return Math.max( pOffsetSize, pMaxSize ); |
120 |
95 |
|
} |
121 |
96 |
|
|
122 |
|
- |
private Widget get( int pIndex ) |
123 |
|
- |
{ |
|
97 |
+ |
private Widget get( int pIndex ) { |
124 |
98 |
|
Widget zWidget = mWidgets.get( pIndex ); |
125 |
|
- |
if ( zWidget.isAttached() ) |
126 |
|
- |
{ |
|
99 |
+ |
if ( zWidget.isAttached() ) { |
127 |
100 |
|
return zWidget; |
128 |
101 |
|
} |
129 |
102 |
|
System.out.println( "Not Attached: " + zWidget ); |