|
@@ -1,38 +1,130 @@ |
1 |
1 |
|
// This Source Code is in the Public Domain per: http://litesoft.org/License.txt |
2 |
2 |
|
package org.litesoft.GWT.client.widgets.nonpublic; |
3 |
3 |
|
|
|
4 |
+ |
import java.util.*; |
|
5 |
+ |
|
4 |
6 |
|
import org.litesoft.GWT.client.widgets.*; |
5 |
7 |
|
import org.litesoft.core.util.*; |
6 |
8 |
|
import org.litesoft.ui.*; |
7 |
9 |
|
|
8 |
10 |
|
import com.google.gwt.dom.client.Element; |
9 |
|
- |
import com.google.gwt.event.dom.client.*; |
10 |
11 |
|
import com.google.gwt.event.shared.*; |
11 |
12 |
|
import com.google.gwt.user.client.*; |
12 |
13 |
|
import com.google.gwt.user.client.ui.*; |
13 |
14 |
|
|
14 |
15 |
|
public abstract class AbstractCellButton extends AbstractCssBackedButton |
15 |
16 |
|
{ |
|
17 |
+ |
private static final String IMAGES_PATH = "common/images/"; |
|
18 |
+ |
|
|
19 |
+ |
private static final String CACHED_GIF = ".cache.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 |
+ |
{ |
|
32 |
+ |
if ( needsFetching( sImageButtons, pButtonImageRef ) ) |
|
33 |
+ |
{ |
|
34 |
+ |
prefetchImage( buildImageButtonImageURL( pButtonImageRef, true ) ); |
|
35 |
+ |
prefetchImage( buildImageButtonImageURL( pButtonImageRef, false ) ); |
|
36 |
+ |
} |
|
37 |
+ |
} |
|
38 |
+ |
|
|
39 |
+ |
private static void prefetchBackImages( String pType ) |
|
40 |
+ |
{ |
|
41 |
+ |
if ( needsFetching( sBackImages, pType ) ) |
|
42 |
+ |
{ |
|
43 |
+ |
prefetchTypedImage( pType, "BackArrow" ); |
|
44 |
+ |
} |
|
45 |
+ |
} |
|
46 |
+ |
|
|
47 |
+ |
private static void prefetchForwardImages( String pType ) |
|
48 |
+ |
{ |
|
49 |
+ |
if ( needsFetching( sForwardImages, pType ) ) |
|
50 |
+ |
{ |
|
51 |
+ |
prefetchTypedImage( pType, "ForwardArrowRegular" ); |
|
52 |
+ |
prefetchTypedImage( pType, "ForwardArrowOver" ); |
|
53 |
+ |
} |
|
54 |
+ |
} |
|
55 |
+ |
|
|
56 |
+ |
private static void prefetchBackgroupCellImages( String pType ) |
|
57 |
+ |
{ |
|
58 |
+ |
if ( needsFetching( sBGCellImages, pType ) ) |
|
59 |
+ |
{ |
|
60 |
+ |
for ( CompassPoint zPoint : CompassPoint.values() ) |
|
61 |
+ |
{ |
|
62 |
+ |
if ( CompassPoint.center != zPoint ) |
|
63 |
+ |
{ |
|
64 |
+ |
for ( State zState : ALL_STATES ) |
|
65 |
+ |
{ |
|
66 |
+ |
prefetchTypedImage( pType, zState + "/" + zPoint.name() ); |
|
67 |
+ |
} |
|
68 |
+ |
} |
|
69 |
+ |
} |
|
70 |
+ |
} |
|
71 |
+ |
} |
|
72 |
+ |
|
|
73 |
+ |
private static void prefetchTypedImage( String pType, String pWhat ) |
|
74 |
+ |
{ |
|
75 |
+ |
prefetchImage( IMAGES_PATH + pType + "/" + pWhat + CACHED_GIF ); |
|
76 |
+ |
} |
|
77 |
+ |
|
|
78 |
+ |
private static void prefetchImage( String pImagePath ) |
|
79 |
+ |
{ |
|
80 |
+ |
Image.prefetch( pImagePath ); |
|
81 |
+ |
} |
|
82 |
+ |
|
|
83 |
+ |
private static boolean needsFetching( Set<String> pFetched, String pKey ) |
|
84 |
+ |
{ |
|
85 |
+ |
if ( pFetched.contains( pKey ) ) |
|
86 |
+ |
{ |
|
87 |
+ |
return false; |
|
88 |
+ |
} |
|
89 |
+ |
pFetched.add( pKey ); |
|
90 |
+ |
return true; |
|
91 |
+ |
} |
|
92 |
+ |
|
|
93 |
+ |
protected static String buildImageButtonImageURL( String pButtonImageRef, boolean pEnabled ) |
|
94 |
+ |
{ |
|
95 |
+ |
return IMAGES_PATH + IMAGE_BUTTONS_FOLDER + pButtonImageRef + (pEnabled ? IMAGE_BUTTON_ENABLED_GIF : IMAGE_BUTTON_DISABLED_GIF); |
|
96 |
+ |
} |
|
97 |
+ |
|
16 |
98 |
|
private int mMinimumCellSize; |
17 |
99 |
|
protected String mTbodyClass; |
18 |
100 |
|
protected Element mInnerElement, mTD; |
19 |
101 |
|
|
20 |
|
- |
public AbstractCellButton( int pPreImageWidth, String pName, String pType, int pMinimumCellSize, String pTbodyClass, String pTbodyClass2, int pPostImageWidth, Element pInnerElement, String pEnabledToolTip, String pDisabledToolTip, ClickHandler pHandler ) |
|
102 |
+ |
public AbstractCellButton( int pPreImageWidth, DefButtonNamedTypedFactory pDefButtonFactory, int pPostImageWidth, String pSizeSuffix, // |
|
103 |
+ |
int pMinimumCellSize, Element pInnerElement ) |
21 |
104 |
|
{ |
22 |
|
- |
super( pName, createTableWrapper( pPreImageWidth, pMinimumCellSize, pTbodyClass, pTbodyClass2, pPostImageWidth, pInnerElement ), pEnabledToolTip, pDisabledToolTip ); |
|
105 |
+ |
super( pDefButtonFactory.getName(), // |
|
106 |
+ |
createTableWrapper( pPreImageWidth, pInnerElement, pPostImageWidth, pMinimumCellSize, // |
|
107 |
+ |
pDefButtonFactory.getType(), // pTbodyClass |
|
108 |
+ |
pDefButtonFactory.getCustomStyle() ), // pTbodyClass2 |
|
109 |
+ |
pDefButtonFactory.getEnabledToolTip(), pDefButtonFactory.getDisabledToolTip() ); |
23 |
110 |
|
mMinimumCellSize = pMinimumCellSize; |
24 |
|
- |
mTbodyClass = pTbodyClass; |
|
111 |
+ |
String zType = mTbodyClass = pDefButtonFactory.getType(); |
25 |
112 |
|
mInnerElement = pInnerElement; |
26 |
113 |
|
mTD = mInnerElement.getParentElement(); |
27 |
114 |
|
mTD.setPropertyString( "align", HasHorizontalAlignment.ALIGN_CENTER.getTextAlignString() ); |
28 |
115 |
|
mTD.setPropertyString( "verticalAlign", HasVerticalAlignment.ALIGN_MIDDLE.getVerticalAlignString() ); |
29 |
116 |
|
addStyleName( "CellButton" ); |
30 |
|
- |
addStyleName( pType + "CellButton" + pMinimumCellSize ); |
|
117 |
+ |
addStyleName( pDefButtonFactory.getSize() + pSizeSuffix + "CellButton" + pMinimumCellSize ); |
31 |
118 |
|
|
32 |
|
- |
if ( pHandler != null ) |
|
119 |
+ |
if ( pPreImageWidth != 0 ) |
|
120 |
+ |
{ |
|
121 |
+ |
prefetchBackImages( zType ); |
|
122 |
+ |
} |
|
123 |
+ |
if ( pPostImageWidth != 0 ) |
33 |
124 |
|
{ |
34 |
|
- |
addClickHandler( pHandler ); |
|
125 |
+ |
prefetchForwardImages( zType ); |
35 |
126 |
|
} |
|
127 |
+ |
prefetchBackgroupCellImages( zType ); |
36 |
128 |
|
} |
37 |
129 |
|
|
38 |
130 |
|
@Override |
|
@@ -72,7 +164,7 @@ |
72 |
164 |
|
return zTD; |
73 |
165 |
|
} |
74 |
166 |
|
|
75 |
|
- |
private static CtrlElements createTableWrapper( int pPreImageWidth, int pMinimumCellSize, String pTbodyClass, String pTbodyClass2, int pPostImageWidth, Element pInnerElement ) |
|
167 |
+ |
private static CtrlElements createTableWrapper( int pPreImageWidth, Element pInnerElement, int pPostImageWidth, int pMinimumCellSize, String pTbodyClass, String pTbodyClass2 ) |
76 |
168 |
|
{ |
77 |
169 |
|
Element zWidthImg = null; |
78 |
170 |
|
Element zHeightImg = null; |