litesoft
@ 939
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 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 |
// This Source Code is in the Public Domain per: http://litesoft.org/License.txt package org.litesoft.GWT.client.widgets.nonpublic; import org.litesoft.commonfoundation.typeutils.*; import java.util.*; import org.litesoft.GWT.client.widgets.*; import org.litesoft.commonfoundation.typeutils.Objects; import org.litesoft.ui.*; import com.google.gwt.dom.client.Element; import com.google.gwt.event.shared.*; import com.google.gwt.user.client.*; import com.google.gwt.user.client.ui.*; public abstract class AbstractCellButton extends AbstractCssBackedButton { private static final String IMAGES_PATH = "common/images/"; private static final String CACHED_GIF = ".gif"; private static final String IMAGE_BUTTONS_FOLDER = "ImageButton/"; private static final String IMAGE_BUTTON_ENABLED_GIF = "/Enabled" + CACHED_GIF; private static final String IMAGE_BUTTON_DISABLED_GIF = "/Disabled" + CACHED_GIF; private static final Set<String> sImageButtons = new HashSet<String>(); private static final Set<String> sBackImages = new HashSet<String>(); private static final Set<String> sForwardImages = new HashSet<String>(); private static final Set<String> sBGCellImages = new HashSet<String>(); protected static void prefetchImageButtonImages( String pButtonImageRef ) { if ( needsFetching( sImageButtons, pButtonImageRef ) ) { prefetchImage( buildImageButtonImageURL( pButtonImageRef, true ) ); prefetchImage( buildImageButtonImageURL( pButtonImageRef, false ) ); } } private static void prefetchBackImages( String pType ) { if ( needsFetching( sBackImages, pType ) ) { prefetchTypedImage( pType, "BackArrow" ); } } private static void prefetchForwardImages( String pType ) { if ( needsFetching( sForwardImages, pType ) ) { prefetchTypedImage( pType, "ForwardArrowRegular" ); prefetchTypedImage( pType, "ForwardArrowOver" ); } } private static void prefetchBackgroupCellImages( String pType ) { if ( needsFetching( sBGCellImages, pType ) ) { for ( CompassPoint zPoint : CompassPoint.values() ) { if ( CompassPoint.center != zPoint ) { for ( State zState : ALL_STATES ) { prefetchTypedImage( pType, zState + "/" + zPoint.name() ); } } } } } private static void prefetchTypedImage( String pType, String pWhat ) { prefetchImage( IMAGES_PATH + pType + "/" + pWhat + CACHED_GIF ); } private static void prefetchImage( String pImagePath ) { Image.prefetch( pImagePath ); } private static boolean needsFetching( Set<String> pFetched, String pKey ) { if ( pFetched.contains( pKey ) ) { return false; } pFetched.add( pKey ); return true; } protected static String buildImageButtonImageURL( String pButtonImageRef, boolean pEnabled ) { return IMAGES_PATH + IMAGE_BUTTONS_FOLDER + pButtonImageRef + (pEnabled ? IMAGE_BUTTON_ENABLED_GIF : IMAGE_BUTTON_DISABLED_GIF); } private int mMinimumCellSize; protected String mTbodyClass; protected Element mInnerElement, mTD; public AbstractCellButton( int pPreImageWidth, DefButtonNamedTypedFactory pDefButtonFactory, int pPostImageWidth, String pSizeSuffix, // int pMinimumCellSize, Element pInnerElement ) { super( pDefButtonFactory.getName(), // createTableWrapper( pPreImageWidth, pInnerElement, pPostImageWidth, pMinimumCellSize, // pDefButtonFactory.getType(), // pTbodyClass pDefButtonFactory.getName(), // pTbodyClass pDefButtonFactory.getCustomStyle() ), // pTbodyClass pDefButtonFactory.getEnabledToolTip(), pDefButtonFactory.getDisabledToolTip() ); mMinimumCellSize = pMinimumCellSize; String zType = mTbodyClass = pDefButtonFactory.getType(); mInnerElement = pInnerElement; mTD = mInnerElement.getParentElement(); mTD.setPropertyString( "align", HasHorizontalAlignment.ALIGN_CENTER.getTextAlignString() ); mTD.setPropertyString( "verticalAlign", HasVerticalAlignment.ALIGN_MIDDLE.getVerticalAlignString() ); addStyleName( "CellButton" ); addStyleName( pDefButtonFactory.getSize() + pSizeSuffix + "CellButton" + pMinimumCellSize ); if ( pPreImageWidth != 0 ) { prefetchBackImages( zType ); } if ( pPostImageWidth != 0 ) { prefetchForwardImages( zType ); } prefetchBackgroupCellImages( zType ); } @Override public void fireEvent( GwtEvent<?> event ) { if ( isEnabled() ) { super.fireEvent( event ); } } private static Element createTable() { return CommonElementHelper.createTable(); } private static Element createTBody( String... pTbodyClasses ) { Element zTBody = DOM.createTBody(); if ( Objects.isNotNullOrEmpty( pTbodyClasses ) ) { String zClasses = ""; for ( String zClass : pTbodyClasses ) { zClasses = (zClasses + " " + Strings.deNull( zClass )).trim(); } if ( zClasses.length() != 0 ) { zTBody.setClassName( zClasses ); } } return zTBody; } private static Element createTR() { return DOM.createTR(); } private static Element createTD( CompassPoint pPoint ) { Element zTD = DOM.createTD(); zTD.setClassName( "CP_" + pPoint ); return zTD; } private static CtrlElements createTableWrapper( int pPreImageWidth, Element pInnerElement, int pPostImageWidth, int pMinimumCellSize, String... pTbodyClasses ) { Element zWidthImg = null; Element zHeightImg = null; Element[][] zTDs = new Element[3][3]; for ( CompassPoint zPoint : CompassPoint.values() ) { int zRow = zPoint.getRow(); int zCol = zPoint.getCol(); Element zInnerElement; if ( (zRow == 1) && (zCol == 1) ) { zInnerElement = pInnerElement; } else { Element zElement = createBorder( pMinimumCellSize ); if ( (zRow == 0) && (zCol == 1) ) { zWidthImg = zElement; } else if ( (zRow == 1) && (zCol == 0) ) { zHeightImg = zElement; } zInnerElement = zElement; } zTDs[zRow][zCol] = appendChild( createTD( zPoint ), zInnerElement ); } Element zTBody = createTBody( pTbodyClasses ); appendChild( zTBody, createRow0( createTR(), zTDs ) ); appendChild( zTBody, createRow1( createTR(), zTDs, pPreImageWidth, pPostImageWidth ) ); appendChild( zTBody, createRow2( createTR(), zTDs ) ); return new CtrlElements( appendChild( createTable(), zTBody ), zTBody, zWidthImg, zHeightImg ); } private static Element createRow0( Element pTR, Element[][] pTDs ) { appendChild( pTR, pTDs[0][0] ); appendChild( pTR, addColSpan( pTDs[0][1] ) ); appendChild( pTR, pTDs[0][2] ); return pTR; } private static Element createRow1( Element pTR, Element[][] pTDs, int pPreImageWidth, int pPostImageWidth ) { appendChild( pTR, pTDs[1][0] ); appendChild( pTR, createTD( "CP_PreCenter", pPreImageWidth ) ); appendChild( pTR, pTDs[1][1] ); appendChild( pTR, createTD( "CP_PostCenter", pPostImageWidth ) ); appendChild( pTR, pTDs[1][2] ); return pTR; } private static Element createRow2( Element pTR, Element[][] pTDs ) { appendChild( pTR, pTDs[2][0] ); appendChild( pTR, addColSpan( pTDs[2][1] ) ); appendChild( pTR, pTDs[2][2] ); return pTR; } private static Element addColSpan( Element pElement ) { pElement.setPropertyInt( "colSpan", 3 ); return pElement; } private static Element createTD( String pClass, int pImageWidth ) { Element zTD = DOM.createTD(); zTD.setClassName( pClass ); Element zImg = createImg(); if ( pImageWidth > 0 ) { zImg.setAttribute( "width", "" + pImageWidth ); } return appendChild( zTD, zImg ); } private static Element appendChild( Element pParent, Element pNewChild ) { pParent.appendChild( pNewChild ); return pParent; } private static Element createBorder( int pMinimumCellSize ) { Element zElement = createImg(); zElement.getStyle().setPropertyPx( "width", pMinimumCellSize ); zElement.getStyle().setPropertyPx( "height", pMinimumCellSize ); return zElement; } private static Element createImg() { Element zElement = DOM.createImg(); zElement.setPropertyString( "src", TransparentImage.URL ); return zElement; } @Override public void setWidth( String width ) { int zSize = parseSize( width ); if ( zSize > 0 ) { mCtrlElements.getWidth().getStyle().setPropertyPx( "width", zSize ); } } @Override public void setHeight( String height ) { int zSize = parseSize( height ); if ( zSize > 0 ) { mCtrlElements.getHeight().getStyle().setPropertyPx( "height", zSize ); } } private int parseSize( String pSize ) { if ( pSize != null ) { pSize = pSize.trim().toUpperCase(); if ( pSize.endsWith( "PX" ) ) { pSize = pSize.substring( 0, pSize.length() - 2 ).trim(); } try { return Integer.parseInt( pSize ) - (mMinimumCellSize + mMinimumCellSize); } catch ( NumberFormatException e ) { // Whatever! } } return 0; } } |
Commits for litesoft/trunk/Java/GWT/Client/src/org/litesoft/GWT/client/widgets/nonpublic/AbstractCellButton.java
Revision | Author | Commited | Message |
---|---|---|---|
939 Diff | GeorgeS | Mon 02 Jun, 2014 21:30:31 +0000 | Extracting commonfoundation |
922 Diff | GeorgeS | Tue 18 Feb, 2014 16:18:01 +0000 | Mini App ready for packaging... |
809 Diff | GeorgeS | Thu 16 Aug, 2012 04:10:46 +0000 | |
802 Diff | GeorgeS | Wed 15 Aug, 2012 04:04:47 +0000 | |
500 Diff | GeorgeS | Sun 11 Sep, 2011 21:24:47 +0000 | |
390 Diff | GeorgeS | Sun 14 Aug, 2011 19:33:48 +0000 | |
144 Diff | GeorgeS | Mon 14 Mar, 2011 03:42:34 +0000 | |
49 Diff | GeorgeS | Mon 12 Apr, 2010 02:59:10 +0000 | License Text |
2 | GeorgeS | Sun 07 Feb, 2010 12:50:58 +0000 |