Subversion Repository Public Repository

litesoft

Diff Revisions 947 vs 948 for /trunk/Java/GWT/Client/src/org/litesoft/GWT/client/widgets/nonpublic/AbstractCellButton.java

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