|
@@ -1,263 +1,262 @@ |
1 |
|
- |
// This Source Code is in the Public Domain per: http://unlicense.org |
2 |
|
- |
package org.litesoft.GWT.client.widgets.nonpublic; |
3 |
|
- |
|
4 |
|
- |
import org.litesoft.GWT.client.widgets.*; |
5 |
|
- |
import org.litesoft.commonfoundation.typeutils.Objects; |
6 |
|
- |
import org.litesoft.commonfoundation.typeutils.*; |
7 |
|
- |
import org.litesoft.ui.*; |
8 |
|
- |
|
9 |
|
- |
import com.google.gwt.dom.client.Element; |
10 |
|
- |
import com.google.gwt.event.shared.*; |
11 |
|
- |
import com.google.gwt.user.client.*; |
12 |
|
- |
import com.google.gwt.user.client.ui.*; |
13 |
|
- |
|
14 |
|
- |
import java.util.*; |
15 |
|
- |
|
16 |
|
- |
public abstract class AbstractCellButton extends AbstractCssBackedButton { |
17 |
|
- |
private static final String IMAGES_PATH = "common/images/"; |
18 |
|
- |
|
19 |
|
- |
private static final String CACHED_GIF = ".gif"; |
20 |
|
- |
|
21 |
|
- |
private static final String IMAGE_BUTTONS_FOLDER = "ImageButton/"; |
22 |
|
- |
private static final String IMAGE_BUTTON_ENABLED_GIF = "/Enabled" + CACHED_GIF; |
23 |
|
- |
private static final String IMAGE_BUTTON_DISABLED_GIF = "/Disabled" + CACHED_GIF; |
24 |
|
- |
|
25 |
|
- |
private static final Set<String> sImageButtons = new HashSet<String>(); |
26 |
|
- |
private static final Set<String> sBackImages = new HashSet<String>(); |
27 |
|
- |
private static final Set<String> sForwardImages = new HashSet<String>(); |
28 |
|
- |
private static final Set<String> sBGCellImages = new HashSet<String>(); |
29 |
|
- |
|
30 |
|
- |
protected static void prefetchImageButtonImages( String pButtonImageRef ) { |
31 |
|
- |
if ( needsFetching( sImageButtons, pButtonImageRef ) ) { |
32 |
|
- |
prefetchImage( buildImageButtonImageURL( pButtonImageRef, true ) ); |
33 |
|
- |
prefetchImage( buildImageButtonImageURL( pButtonImageRef, false ) ); |
34 |
|
- |
} |
35 |
|
- |
} |
36 |
|
- |
|
37 |
|
- |
private static void prefetchBackImages( String pType ) { |
38 |
|
- |
if ( needsFetching( sBackImages, pType ) ) { |
39 |
|
- |
prefetchTypedImage( pType, "BackArrow" ); |
40 |
|
- |
} |
41 |
|
- |
} |
42 |
|
- |
|
43 |
|
- |
private static void prefetchForwardImages( String pType ) { |
44 |
|
- |
if ( needsFetching( sForwardImages, pType ) ) { |
45 |
|
- |
prefetchTypedImage( pType, "ForwardArrowRegular" ); |
46 |
|
- |
prefetchTypedImage( pType, "ForwardArrowOver" ); |
47 |
|
- |
} |
48 |
|
- |
} |
49 |
|
- |
|
50 |
|
- |
private static void prefetchBackgroupCellImages( String pType ) { |
51 |
|
- |
if ( needsFetching( sBGCellImages, pType ) ) { |
52 |
|
- |
for ( CompassPoint zPoint : CompassPoint.values() ) { |
53 |
|
- |
if ( CompassPoint.center != zPoint ) { |
54 |
|
- |
for ( State zState : ALL_STATES ) { |
55 |
|
- |
prefetchTypedImage( pType, zState + "/" + zPoint.name() ); |
56 |
|
- |
} |
57 |
|
- |
} |
58 |
|
- |
} |
59 |
|
- |
} |
60 |
|
- |
} |
61 |
|
- |
|
62 |
|
- |
private static void prefetchTypedImage( String pType, String pWhat ) { |
63 |
|
- |
prefetchImage( IMAGES_PATH + pType + "/" + pWhat + CACHED_GIF ); |
64 |
|
- |
} |
65 |
|
- |
|
66 |
|
- |
private static void prefetchImage( String pImagePath ) { |
67 |
|
- |
Image.prefetch( pImagePath ); |
68 |
|
- |
} |
69 |
|
- |
|
70 |
|
- |
private static boolean needsFetching( Set<String> pFetched, String pKey ) { |
71 |
|
- |
if ( pFetched.contains( pKey ) ) { |
72 |
|
- |
return false; |
73 |
|
- |
} |
74 |
|
- |
pFetched.add( pKey ); |
75 |
|
- |
return true; |
76 |
|
- |
} |
77 |
|
- |
|
78 |
|
- |
protected static String buildImageButtonImageURL( String pButtonImageRef, boolean pEnabled ) { |
79 |
|
- |
return IMAGES_PATH + IMAGE_BUTTONS_FOLDER + pButtonImageRef + (pEnabled ? IMAGE_BUTTON_ENABLED_GIF : IMAGE_BUTTON_DISABLED_GIF); |
80 |
|
- |
} |
81 |
|
- |
|
82 |
|
- |
private int mMinimumCellSize; |
83 |
|
- |
protected String mTbodyClass; |
84 |
|
- |
protected Element mInnerElement, mTD; |
85 |
|
- |
|
86 |
|
- |
public AbstractCellButton( int pPreImageWidth, DefButtonNamedTypedFactory pDefButtonFactory, int pPostImageWidth, String pSizeSuffix, // |
87 |
|
- |
int pMinimumCellSize, Element pInnerElement ) { |
88 |
|
- |
super( pDefButtonFactory.getName(), // |
89 |
|
- |
createTableWrapper( pPreImageWidth, pInnerElement, pPostImageWidth, pMinimumCellSize, // |
90 |
|
- |
pDefButtonFactory.getType(), // pTbodyClass |
91 |
|
- |
pDefButtonFactory.getName(), // pTbodyClass |
92 |
|
- |
pDefButtonFactory.getCustomStyle() ), // pTbodyClass |
93 |
|
- |
pDefButtonFactory.getEnabledToolTip(), pDefButtonFactory.getDisabledToolTip() ); |
94 |
|
- |
mMinimumCellSize = pMinimumCellSize; |
95 |
|
- |
String zType = mTbodyClass = pDefButtonFactory.getType(); |
96 |
|
- |
mInnerElement = pInnerElement; |
97 |
|
- |
mTD = mInnerElement.getParentElement(); |
98 |
|
- |
mTD.setPropertyString( "align", HasHorizontalAlignment.ALIGN_CENTER.getTextAlignString() ); |
99 |
|
- |
mTD.setPropertyString( "verticalAlign", HasVerticalAlignment.ALIGN_MIDDLE.getVerticalAlignString() ); |
100 |
|
- |
addStyleName( "CellButton" ); |
101 |
|
- |
addStyleName( pDefButtonFactory.getSize() + pSizeSuffix + "CellButton" + pMinimumCellSize ); |
102 |
|
- |
|
103 |
|
- |
if ( pPreImageWidth != 0 ) { |
104 |
|
- |
prefetchBackImages( zType ); |
105 |
|
- |
} |
106 |
|
- |
if ( pPostImageWidth != 0 ) { |
107 |
|
- |
prefetchForwardImages( zType ); |
108 |
|
- |
} |
109 |
|
- |
prefetchBackgroupCellImages( zType ); |
110 |
|
- |
} |
111 |
|
- |
|
112 |
|
- |
@Override |
113 |
|
- |
public void fireEvent( GwtEvent<?> event ) { |
114 |
|
- |
if ( isEnabled() ) { |
115 |
|
- |
super.fireEvent( event ); |
116 |
|
- |
} |
117 |
|
- |
} |
118 |
|
- |
|
119 |
|
- |
private static Element createTable() { |
120 |
|
- |
return CommonElementHelper.createTable(); |
121 |
|
- |
} |
122 |
|
- |
|
123 |
|
- |
private static Element createTBody( String... pTbodyClasses ) { |
124 |
|
- |
Element zTBody = DOM.createTBody(); |
125 |
|
- |
if ( Objects.isNotNullOrEmpty( pTbodyClasses ) ) { |
126 |
|
- |
String zClasses = ""; |
127 |
|
- |
for ( String zClass : pTbodyClasses ) { |
128 |
|
- |
zClasses = (zClasses + " " + Strings.deNull( zClass )).trim(); |
129 |
|
- |
} |
130 |
|
- |
if ( zClasses.length() != 0 ) { |
131 |
|
- |
zTBody.setClassName( zClasses ); |
132 |
|
- |
} |
133 |
|
- |
} |
134 |
|
- |
return zTBody; |
135 |
|
- |
} |
136 |
|
- |
|
137 |
|
- |
private static Element createTR() { |
138 |
|
- |
return DOM.createTR(); |
139 |
|
- |
} |
140 |
|
- |
|
141 |
|
- |
private static Element createTD( CompassPoint pPoint ) { |
142 |
|
- |
Element zTD = DOM.createTD(); |
143 |
|
- |
zTD.setClassName( "CP_" + pPoint ); |
144 |
|
- |
return zTD; |
145 |
|
- |
} |
146 |
|
- |
|
147 |
|
- |
private static CtrlElements createTableWrapper( int pPreImageWidth, Element pInnerElement, int pPostImageWidth, int pMinimumCellSize, |
148 |
|
- |
String... pTbodyClasses ) { |
149 |
|
- |
Element zWidthImg = null; |
150 |
|
- |
Element zHeightImg = null; |
151 |
|
- |
Element[][] zTDs = new Element[3][3]; |
152 |
|
- |
for ( CompassPoint zPoint : CompassPoint.values() ) { |
153 |
|
- |
int zRow = zPoint.getRow(); |
154 |
|
- |
int zCol = zPoint.getCol(); |
155 |
|
- |
Element zInnerElement; |
156 |
|
- |
if ( (zRow == 1) && (zCol == 1) ) { |
157 |
|
- |
zInnerElement = pInnerElement; |
158 |
|
- |
} else { |
159 |
|
- |
Element zElement = createBorder( pMinimumCellSize ); |
160 |
|
- |
if ( (zRow == 0) && (zCol == 1) ) { |
161 |
|
- |
zWidthImg = zElement; |
162 |
|
- |
} else if ( (zRow == 1) && (zCol == 0) ) { |
163 |
|
- |
zHeightImg = zElement; |
164 |
|
- |
} |
165 |
|
- |
zInnerElement = zElement; |
166 |
|
- |
} |
167 |
|
- |
zTDs[zRow][zCol] = appendChild( createTD( zPoint ), zInnerElement ); |
168 |
|
- |
} |
169 |
|
- |
Element zTBody = createTBody( pTbodyClasses ); |
170 |
|
- |
appendChild( zTBody, createRow0( createTR(), zTDs ) ); |
171 |
|
- |
appendChild( zTBody, createRow1( createTR(), zTDs, pPreImageWidth, pPostImageWidth ) ); |
172 |
|
- |
appendChild( zTBody, createRow2( createTR(), zTDs ) ); |
173 |
|
- |
return new CtrlElements( appendChild( createTable(), zTBody ), zTBody, zWidthImg, zHeightImg ); |
174 |
|
- |
} |
175 |
|
- |
|
176 |
|
- |
private static Element createRow0( Element pTR, Element[][] pTDs ) { |
177 |
|
- |
appendChild( pTR, pTDs[0][0] ); |
178 |
|
- |
appendChild( pTR, addColSpan( pTDs[0][1] ) ); |
179 |
|
- |
appendChild( pTR, pTDs[0][2] ); |
180 |
|
- |
return pTR; |
181 |
|
- |
} |
182 |
|
- |
|
183 |
|
- |
private static Element createRow1( Element pTR, Element[][] pTDs, int pPreImageWidth, int pPostImageWidth ) { |
184 |
|
- |
appendChild( pTR, pTDs[1][0] ); |
185 |
|
- |
appendChild( pTR, createTD( "CP_PreCenter", pPreImageWidth ) ); |
186 |
|
- |
appendChild( pTR, pTDs[1][1] ); |
187 |
|
- |
appendChild( pTR, createTD( "CP_PostCenter", pPostImageWidth ) ); |
188 |
|
- |
appendChild( pTR, pTDs[1][2] ); |
189 |
|
- |
return pTR; |
190 |
|
- |
} |
191 |
|
- |
|
192 |
|
- |
private static Element createRow2( Element pTR, Element[][] pTDs ) { |
193 |
|
- |
appendChild( pTR, pTDs[2][0] ); |
194 |
|
- |
appendChild( pTR, addColSpan( pTDs[2][1] ) ); |
195 |
|
- |
appendChild( pTR, pTDs[2][2] ); |
196 |
|
- |
return pTR; |
197 |
|
- |
} |
198 |
|
- |
|
199 |
|
- |
private static Element addColSpan( Element pElement ) { |
200 |
|
- |
pElement.setPropertyInt( "colSpan", 3 ); |
201 |
|
- |
return pElement; |
202 |
|
- |
} |
203 |
|
- |
|
204 |
|
- |
private static Element createTD( String pClass, int pImageWidth ) { |
205 |
|
- |
Element zTD = DOM.createTD(); |
206 |
|
- |
zTD.setClassName( pClass ); |
207 |
|
- |
Element zImg = createImg(); |
208 |
|
- |
if ( pImageWidth > 0 ) { |
209 |
|
- |
zImg.setAttribute( "width", "" + pImageWidth ); |
210 |
|
- |
} |
211 |
|
- |
return appendChild( zTD, zImg ); |
212 |
|
- |
} |
213 |
|
- |
|
214 |
|
- |
private static Element appendChild( Element pParent, Element pNewChild ) { |
215 |
|
- |
pParent.appendChild( pNewChild ); |
216 |
|
- |
return pParent; |
217 |
|
- |
} |
218 |
|
- |
|
219 |
|
- |
private static Element createBorder( int pMinimumCellSize ) { |
220 |
|
- |
Element zElement = createImg(); |
221 |
|
- |
zElement.getStyle().setPropertyPx( "width", pMinimumCellSize ); |
222 |
|
- |
zElement.getStyle().setPropertyPx( "height", pMinimumCellSize ); |
223 |
|
- |
return zElement; |
224 |
|
- |
} |
225 |
|
- |
|
226 |
|
- |
private static Element createImg() { |
227 |
|
- |
Element zElement = DOM.createImg(); |
228 |
|
- |
zElement.setPropertyString( "src", TransparentImage.URL ); |
229 |
|
- |
return zElement; |
230 |
|
- |
} |
231 |
|
- |
|
232 |
|
- |
@Override |
233 |
|
- |
public void setWidth( String width ) { |
234 |
|
- |
int zSize = parseSize( width ); |
235 |
|
- |
if ( zSize > 0 ) { |
236 |
|
- |
mCtrlElements.getWidth().getStyle().setPropertyPx( "width", zSize ); |
237 |
|
- |
} |
238 |
|
- |
} |
239 |
|
- |
|
240 |
|
- |
@Override |
241 |
|
- |
public void setHeight( String height ) { |
242 |
|
- |
int zSize = parseSize( height ); |
243 |
|
- |
if ( zSize > 0 ) { |
244 |
|
- |
mCtrlElements.getHeight().getStyle().setPropertyPx( "height", zSize ); |
245 |
|
- |
} |
246 |
|
- |
} |
247 |
|
- |
|
248 |
|
- |
private int parseSize( String pSize ) { |
249 |
|
- |
if ( pSize != null ) { |
250 |
|
- |
pSize = pSize.trim().toUpperCase(); |
251 |
|
- |
if ( pSize.endsWith( "PX" ) ) { |
252 |
|
- |
pSize = pSize.substring( 0, pSize.length() - 2 ).trim(); |
253 |
|
- |
} |
254 |
|
- |
try { |
255 |
|
- |
return Integer.parseInt( pSize ) - (mMinimumCellSize + mMinimumCellSize); |
256 |
|
- |
} |
257 |
|
- |
catch ( NumberFormatException e ) { |
258 |
|
- |
// Whatever! |
259 |
|
- |
} |
260 |
|
- |
} |
261 |
|
- |
return 0; |
262 |
|
- |
} |
263 |
|
- |
} |
|
1 |
+ |
// This Source Code is in the Public Domain per: http://unlicense.org |
|
2 |
+ |
package org.litesoft.GWT.client.widgets.nonpublic; |
|
3 |
+ |
|
|
4 |
+ |
import org.litesoft.GWT.client.widgets.*; |
|
5 |
+ |
import org.litesoft.commonfoundation.base.*; |
|
6 |
+ |
import org.litesoft.ui.*; |
|
7 |
+ |
|
|
8 |
+ |
import com.google.gwt.dom.client.Element; |
|
9 |
+ |
import com.google.gwt.event.shared.*; |
|
10 |
+ |
import com.google.gwt.user.client.*; |
|
11 |
+ |
import com.google.gwt.user.client.ui.*; |
|
12 |
+ |
|
|
13 |
+ |
import java.util.*; |
|
14 |
+ |
|
|
15 |
+ |
public abstract class AbstractCellButton extends AbstractCssBackedButton { |
|
16 |
+ |
private static final String IMAGES_PATH = "common/images/"; |
|
17 |
+ |
|
|
18 |
+ |
private static final String CACHED_GIF = ".gif"; |
|
19 |
+ |
|
|
20 |
+ |
private static final String IMAGE_BUTTONS_FOLDER = "ImageButton/"; |
|
21 |
+ |
private static final String IMAGE_BUTTON_ENABLED_GIF = "/Enabled" + CACHED_GIF; |
|
22 |
+ |
private static final String IMAGE_BUTTON_DISABLED_GIF = "/Disabled" + CACHED_GIF; |
|
23 |
+ |
|
|
24 |
+ |
private static final Set<String> sImageButtons = new HashSet<String>(); |
|
25 |
+ |
private static final Set<String> sBackImages = new HashSet<String>(); |
|
26 |
+ |
private static final Set<String> sForwardImages = new HashSet<String>(); |
|
27 |
+ |
private static final Set<String> sBGCellImages = new HashSet<String>(); |
|
28 |
+ |
|
|
29 |
+ |
protected static void prefetchImageButtonImages( String pButtonImageRef ) { |
|
30 |
+ |
if ( needsFetching( sImageButtons, pButtonImageRef ) ) { |
|
31 |
+ |
prefetchImage( buildImageButtonImageURL( pButtonImageRef, true ) ); |
|
32 |
+ |
prefetchImage( buildImageButtonImageURL( pButtonImageRef, false ) ); |
|
33 |
+ |
} |
|
34 |
+ |
} |
|
35 |
+ |
|
|
36 |
+ |
private static void prefetchBackImages( String pType ) { |
|
37 |
+ |
if ( needsFetching( sBackImages, pType ) ) { |
|
38 |
+ |
prefetchTypedImage( pType, "BackArrow" ); |
|
39 |
+ |
} |
|
40 |
+ |
} |
|
41 |
+ |
|
|
42 |
+ |
private static void prefetchForwardImages( String pType ) { |
|
43 |
+ |
if ( needsFetching( sForwardImages, pType ) ) { |
|
44 |
+ |
prefetchTypedImage( pType, "ForwardArrowRegular" ); |
|
45 |
+ |
prefetchTypedImage( pType, "ForwardArrowOver" ); |
|
46 |
+ |
} |
|
47 |
+ |
} |
|
48 |
+ |
|
|
49 |
+ |
private static void prefetchBackgroupCellImages( String pType ) { |
|
50 |
+ |
if ( needsFetching( sBGCellImages, pType ) ) { |
|
51 |
+ |
for ( CompassPoint zPoint : CompassPoint.values() ) { |
|
52 |
+ |
if ( CompassPoint.center != zPoint ) { |
|
53 |
+ |
for ( State zState : ALL_STATES ) { |
|
54 |
+ |
prefetchTypedImage( pType, zState + "/" + zPoint.name() ); |
|
55 |
+ |
} |
|
56 |
+ |
} |
|
57 |
+ |
} |
|
58 |
+ |
} |
|
59 |
+ |
} |
|
60 |
+ |
|
|
61 |
+ |
private static void prefetchTypedImage( String pType, String pWhat ) { |
|
62 |
+ |
prefetchImage( IMAGES_PATH + pType + "/" + pWhat + CACHED_GIF ); |
|
63 |
+ |
} |
|
64 |
+ |
|
|
65 |
+ |
private static void prefetchImage( String pImagePath ) { |
|
66 |
+ |
Image.prefetch( pImagePath ); |
|
67 |
+ |
} |
|
68 |
+ |
|
|
69 |
+ |
private static boolean needsFetching( Set<String> pFetched, String pKey ) { |
|
70 |
+ |
if ( pFetched.contains( pKey ) ) { |
|
71 |
+ |
return false; |
|
72 |
+ |
} |
|
73 |
+ |
pFetched.add( pKey ); |
|
74 |
+ |
return true; |
|
75 |
+ |
} |
|
76 |
+ |
|
|
77 |
+ |
protected static String buildImageButtonImageURL( String pButtonImageRef, boolean pEnabled ) { |
|
78 |
+ |
return IMAGES_PATH + IMAGE_BUTTONS_FOLDER + pButtonImageRef + (pEnabled ? IMAGE_BUTTON_ENABLED_GIF : IMAGE_BUTTON_DISABLED_GIF); |
|
79 |
+ |
} |
|
80 |
+ |
|
|
81 |
+ |
private int mMinimumCellSize; |
|
82 |
+ |
protected String mTbodyClass; |
|
83 |
+ |
protected Element mInnerElement, mTD; |
|
84 |
+ |
|
|
85 |
+ |
public AbstractCellButton( int pPreImageWidth, DefButtonNamedTypedFactory pDefButtonFactory, int pPostImageWidth, String pSizeSuffix, // |
|
86 |
+ |
int pMinimumCellSize, Element pInnerElement ) { |
|
87 |
+ |
super( pDefButtonFactory.getName(), // |
|
88 |
+ |
createTableWrapper( pPreImageWidth, pInnerElement, pPostImageWidth, pMinimumCellSize, // |
|
89 |
+ |
pDefButtonFactory.getType(), // pTbodyClass |
|
90 |
+ |
pDefButtonFactory.getName(), // pTbodyClass |
|
91 |
+ |
pDefButtonFactory.getCustomStyle() ), // pTbodyClass |
|
92 |
+ |
pDefButtonFactory.getEnabledToolTip(), pDefButtonFactory.getDisabledToolTip() ); |
|
93 |
+ |
mMinimumCellSize = pMinimumCellSize; |
|
94 |
+ |
String zType = mTbodyClass = pDefButtonFactory.getType(); |
|
95 |
+ |
mInnerElement = pInnerElement; |
|
96 |
+ |
mTD = mInnerElement.getParentElement(); |
|
97 |
+ |
mTD.setPropertyString( "align", HasHorizontalAlignment.ALIGN_CENTER.getTextAlignString() ); |
|
98 |
+ |
mTD.setPropertyString( "verticalAlign", HasVerticalAlignment.ALIGN_MIDDLE.getVerticalAlignString() ); |
|
99 |
+ |
addStyleName( "CellButton" ); |
|
100 |
+ |
addStyleName( pDefButtonFactory.getSize() + pSizeSuffix + "CellButton" + pMinimumCellSize ); |
|
101 |
+ |
|
|
102 |
+ |
if ( pPreImageWidth != 0 ) { |
|
103 |
+ |
prefetchBackImages( zType ); |
|
104 |
+ |
} |
|
105 |
+ |
if ( pPostImageWidth != 0 ) { |
|
106 |
+ |
prefetchForwardImages( zType ); |
|
107 |
+ |
} |
|
108 |
+ |
prefetchBackgroupCellImages( zType ); |
|
109 |
+ |
} |
|
110 |
+ |
|
|
111 |
+ |
@Override |
|
112 |
+ |
public void fireEvent( GwtEvent<?> event ) { |
|
113 |
+ |
if ( isEnabled() ) { |
|
114 |
+ |
super.fireEvent( event ); |
|
115 |
+ |
} |
|
116 |
+ |
} |
|
117 |
+ |
|
|
118 |
+ |
private static Element createTable() { |
|
119 |
+ |
return CommonElementHelper.createTable(); |
|
120 |
+ |
} |
|
121 |
+ |
|
|
122 |
+ |
private static Element createTBody( String... pTbodyClasses ) { |
|
123 |
+ |
Element zTBody = DOM.createTBody(); |
|
124 |
+ |
if ( Currently.isNotNullOrEmpty( pTbodyClasses ) ) { |
|
125 |
+ |
String zClasses = ""; |
|
126 |
+ |
for ( String zClass : pTbodyClasses ) { |
|
127 |
+ |
zClasses = (zClasses + " " + ConstrainTo.notNull( zClass )).trim(); |
|
128 |
+ |
} |
|
129 |
+ |
if ( zClasses.length() != 0 ) { |
|
130 |
+ |
zTBody.setClassName( zClasses ); |
|
131 |
+ |
} |
|
132 |
+ |
} |
|
133 |
+ |
return zTBody; |
|
134 |
+ |
} |
|
135 |
+ |
|
|
136 |
+ |
private static Element createTR() { |
|
137 |
+ |
return DOM.createTR(); |
|
138 |
+ |
} |
|
139 |
+ |
|
|
140 |
+ |
private static Element createTD( CompassPoint pPoint ) { |
|
141 |
+ |
Element zTD = DOM.createTD(); |
|
142 |
+ |
zTD.setClassName( "CP_" + pPoint ); |
|
143 |
+ |
return zTD; |
|
144 |
+ |
} |
|
145 |
+ |
|
|
146 |
+ |
private static CtrlElements createTableWrapper( int pPreImageWidth, Element pInnerElement, int pPostImageWidth, int pMinimumCellSize, |
|
147 |
+ |
String... pTbodyClasses ) { |
|
148 |
+ |
Element zWidthImg = null; |
|
149 |
+ |
Element zHeightImg = null; |
|
150 |
+ |
Element[][] zTDs = new Element[3][3]; |
|
151 |
+ |
for ( CompassPoint zPoint : CompassPoint.values() ) { |
|
152 |
+ |
int zRow = zPoint.getRow(); |
|
153 |
+ |
int zCol = zPoint.getCol(); |
|
154 |
+ |
Element zInnerElement; |
|
155 |
+ |
if ( (zRow == 1) && (zCol == 1) ) { |
|
156 |
+ |
zInnerElement = pInnerElement; |
|
157 |
+ |
} else { |
|
158 |
+ |
Element zElement = createBorder( pMinimumCellSize ); |
|
159 |
+ |
if ( (zRow == 0) && (zCol == 1) ) { |
|
160 |
+ |
zWidthImg = zElement; |
|
161 |
+ |
} else if ( (zRow == 1) && (zCol == 0) ) { |
|
162 |
+ |
zHeightImg = zElement; |
|
163 |
+ |
} |
|
164 |
+ |
zInnerElement = zElement; |
|
165 |
+ |
} |
|
166 |
+ |
zTDs[zRow][zCol] = appendChild( createTD( zPoint ), zInnerElement ); |
|
167 |
+ |
} |
|
168 |
+ |
Element zTBody = createTBody( pTbodyClasses ); |
|
169 |
+ |
appendChild( zTBody, createRow0( createTR(), zTDs ) ); |
|
170 |
+ |
appendChild( zTBody, createRow1( createTR(), zTDs, pPreImageWidth, pPostImageWidth ) ); |
|
171 |
+ |
appendChild( zTBody, createRow2( createTR(), zTDs ) ); |
|
172 |
+ |
return new CtrlElements( appendChild( createTable(), zTBody ), zTBody, zWidthImg, zHeightImg ); |
|
173 |
+ |
} |
|
174 |
+ |
|
|
175 |
+ |
private static Element createRow0( Element pTR, Element[][] pTDs ) { |
|
176 |
+ |
appendChild( pTR, pTDs[0][0] ); |
|
177 |
+ |
appendChild( pTR, addColSpan( pTDs[0][1] ) ); |
|
178 |
+ |
appendChild( pTR, pTDs[0][2] ); |
|
179 |
+ |
return pTR; |
|
180 |
+ |
} |
|
181 |
+ |
|
|
182 |
+ |
private static Element createRow1( Element pTR, Element[][] pTDs, int pPreImageWidth, int pPostImageWidth ) { |
|
183 |
+ |
appendChild( pTR, pTDs[1][0] ); |
|
184 |
+ |
appendChild( pTR, createTD( "CP_PreCenter", pPreImageWidth ) ); |
|
185 |
+ |
appendChild( pTR, pTDs[1][1] ); |
|
186 |
+ |
appendChild( pTR, createTD( "CP_PostCenter", pPostImageWidth ) ); |
|
187 |
+ |
appendChild( pTR, pTDs[1][2] ); |
|
188 |
+ |
return pTR; |
|
189 |
+ |
} |
|
190 |
+ |
|
|
191 |
+ |
private static Element createRow2( Element pTR, Element[][] pTDs ) { |
|
192 |
+ |
appendChild( pTR, pTDs[2][0] ); |
|
193 |
+ |
appendChild( pTR, addColSpan( pTDs[2][1] ) ); |
|
194 |
+ |
appendChild( pTR, pTDs[2][2] ); |
|
195 |
+ |
return pTR; |
|
196 |
+ |
} |
|
197 |
+ |
|
|
198 |
+ |
private static Element addColSpan( Element pElement ) { |
|
199 |
+ |
pElement.setPropertyInt( "colSpan", 3 ); |
|
200 |
+ |
return pElement; |
|
201 |
+ |
} |
|
202 |
+ |
|
|
203 |
+ |
private static Element createTD( String pClass, int pImageWidth ) { |
|
204 |
+ |
Element zTD = DOM.createTD(); |
|
205 |
+ |
zTD.setClassName( pClass ); |
|
206 |
+ |
Element zImg = createImg(); |
|
207 |
+ |
if ( pImageWidth > 0 ) { |
|
208 |
+ |
zImg.setAttribute( "width", "" + pImageWidth ); |
|
209 |
+ |
} |
|
210 |
+ |
return appendChild( zTD, zImg ); |
|
211 |
+ |
} |
|
212 |
+ |
|
|
213 |
+ |
private static Element appendChild( Element pParent, Element pNewChild ) { |
|
214 |
+ |
pParent.appendChild( pNewChild ); |
|
215 |
+ |
return pParent; |
|
216 |
+ |
} |
|
217 |
+ |
|
|
218 |
+ |
private static Element createBorder( int pMinimumCellSize ) { |
|
219 |
+ |
Element zElement = createImg(); |
|
220 |
+ |
zElement.getStyle().setPropertyPx( "width", pMinimumCellSize ); |
|
221 |
+ |
zElement.getStyle().setPropertyPx( "height", pMinimumCellSize ); |
|
222 |
+ |
return zElement; |
|
223 |
+ |
} |
|
224 |
+ |
|
|
225 |
+ |
private static Element createImg() { |
|
226 |
+ |
Element zElement = DOM.createImg(); |
|
227 |
+ |
zElement.setPropertyString( "src", TransparentImage.URL ); |
|
228 |
+ |
return zElement; |
|
229 |
+ |
} |
|
230 |
+ |
|
|
231 |
+ |
@Override |
|
232 |
+ |
public void setWidth( String width ) { |
|
233 |
+ |
int zSize = parseSize( width ); |
|
234 |
+ |
if ( zSize > 0 ) { |
|
235 |
+ |
mCtrlElements.getWidth().getStyle().setPropertyPx( "width", zSize ); |
|
236 |
+ |
} |
|
237 |
+ |
} |
|
238 |
+ |
|
|
239 |
+ |
@Override |
|
240 |
+ |
public void setHeight( String height ) { |
|
241 |
+ |
int zSize = parseSize( height ); |
|
242 |
+ |
if ( zSize > 0 ) { |
|
243 |
+ |
mCtrlElements.getHeight().getStyle().setPropertyPx( "height", zSize ); |
|
244 |
+ |
} |
|
245 |
+ |
} |
|
246 |
+ |
|
|
247 |
+ |
private int parseSize( String pSize ) { |
|
248 |
+ |
if ( pSize != null ) { |
|
249 |
+ |
pSize = pSize.trim().toUpperCase(); |
|
250 |
+ |
if ( pSize.endsWith( "PX" ) ) { |
|
251 |
+ |
pSize = pSize.substring( 0, pSize.length() - 2 ).trim(); |
|
252 |
+ |
} |
|
253 |
+ |
try { |
|
254 |
+ |
return Integer.parseInt( pSize ) - (mMinimumCellSize + mMinimumCellSize); |
|
255 |
+ |
} |
|
256 |
+ |
catch ( NumberFormatException e ) { |
|
257 |
+ |
// Whatever! |
|
258 |
+ |
} |
|
259 |
+ |
} |
|
260 |
+ |
return 0; |
|
261 |
+ |
} |
|
262 |
+ |
} |