|
@@ -8,8 +8,7 @@ |
8 |
8 |
|
import com.google.gwt.user.client.*; |
9 |
9 |
|
import com.google.gwt.user.client.ui.*; |
10 |
10 |
|
|
11 |
|
- |
public class AbstractCssBackgroundButtonHelper implements OnBrowserEventListener |
12 |
|
- |
{ |
|
11 |
+ |
public class AbstractCssBackgroundButtonHelper implements OnBrowserEventListener { |
13 |
12 |
|
private static final State sREGULAR = new State( "Regular" ); |
14 |
13 |
|
private static final State sMOUSEOVER = new State( "Mouseover" ); |
15 |
14 |
|
private static final State sMOUSEDOWN = new State( "Mousedown" ); |
|
@@ -26,81 +25,63 @@ |
26 |
25 |
|
protected State mCurrentState = null; |
27 |
26 |
|
private Element mSavedCaptureElement = null; |
28 |
27 |
|
|
29 |
|
- |
public AbstractCssBackgroundButtonHelper( OnBrowserEventListenable pListenable, String pEnabledToolTip, String pDisabledToolTip ) |
30 |
|
- |
{ |
|
28 |
+ |
public AbstractCssBackgroundButtonHelper( OnBrowserEventListenable pListenable, String pEnabledToolTip, String pDisabledToolTip ) { |
31 |
29 |
|
mWidget = pListenable.getOnBrowserEventListenableWidget(); |
32 |
30 |
|
|
33 |
|
- |
if ( null != (mEnabledToolTip = Strings.noEmpty( pEnabledToolTip )) ) |
34 |
|
- |
{ |
|
31 |
+ |
if ( null != (mEnabledToolTip = Strings.noEmpty( pEnabledToolTip )) ) { |
35 |
32 |
|
mWidget.setTitle( mEnabledToolTip ); |
36 |
33 |
|
mDisabledToolTip = pDisabledToolTip == null ? pDisabledToolTip : pDisabledToolTip.trim(); |
37 |
34 |
|
} |
38 |
35 |
|
pListenable.setOnBrowserEventListener( Event.MOUSEEVENTS, this ); |
39 |
36 |
|
} |
40 |
37 |
|
|
41 |
|
- |
public String getEnabledToolTip() |
42 |
|
- |
{ |
|
38 |
+ |
public String getEnabledToolTip() { |
43 |
39 |
|
return mEnabledToolTip; |
44 |
40 |
|
} |
45 |
41 |
|
|
46 |
|
- |
public void setEnabledToolTip( String pEnabledToolTip ) |
47 |
|
- |
{ |
|
42 |
+ |
public void setEnabledToolTip( String pEnabledToolTip ) { |
48 |
43 |
|
String zEnabledToolTip = Strings.noEmpty( pEnabledToolTip ); |
49 |
|
- |
if ( zEnabledToolTip != null ) |
50 |
|
- |
{ |
|
44 |
+ |
if ( zEnabledToolTip != null ) { |
51 |
45 |
|
mEnabledToolTip = pEnabledToolTip; |
52 |
|
- |
if ( isEnabled() ) |
53 |
|
- |
{ |
|
46 |
+ |
if ( isEnabled() ) { |
54 |
47 |
|
mWidget.setTitle( mEnabledToolTip ); |
55 |
48 |
|
} |
56 |
49 |
|
} |
57 |
50 |
|
} |
58 |
51 |
|
|
59 |
|
- |
private State determineNewForm() |
60 |
|
- |
{ |
61 |
|
- |
if ( mDisabled ) |
62 |
|
- |
{ |
|
52 |
+ |
private State determineNewForm() { |
|
53 |
+ |
if ( mDisabled ) { |
63 |
54 |
|
return sDISABLED; |
64 |
55 |
|
} |
65 |
|
- |
if ( mMouseDown ) |
66 |
|
- |
{ |
|
56 |
+ |
if ( mMouseDown ) { |
67 |
57 |
|
return sMOUSEDOWN; |
68 |
58 |
|
} |
69 |
|
- |
if ( mMouseOver ) |
70 |
|
- |
{ |
|
59 |
+ |
if ( mMouseOver ) { |
71 |
60 |
|
return sMOUSEOVER; |
72 |
61 |
|
} |
73 |
62 |
|
return sREGULAR; |
74 |
63 |
|
} |
75 |
64 |
|
|
76 |
|
- |
public AbstractCssBackgroundButtonHelper updateForm() |
77 |
|
- |
{ |
|
65 |
+ |
public AbstractCssBackgroundButtonHelper updateForm() { |
78 |
66 |
|
State zNewForm = determineNewForm(); |
79 |
|
- |
if ( mCurrentState != zNewForm ) |
80 |
|
- |
{ |
81 |
|
- |
if ( mCurrentState != null ) |
82 |
|
- |
{ |
|
67 |
+ |
if ( mCurrentState != zNewForm ) { |
|
68 |
+ |
if ( mCurrentState != null ) { |
83 |
69 |
|
removeCurrentState(); |
84 |
70 |
|
|
85 |
|
- |
if ( mCurrentState == sMOUSEDOWN ) |
86 |
|
- |
{ |
|
71 |
+ |
if ( mCurrentState == sMOUSEDOWN ) { |
87 |
72 |
|
DOM.releaseCapture( mWidget.getElement() ); |
88 |
|
- |
if ( mSavedCaptureElement != null ) |
89 |
|
- |
{ |
|
73 |
+ |
if ( mSavedCaptureElement != null ) { |
90 |
74 |
|
DOM.setCapture( mSavedCaptureElement ); |
91 |
75 |
|
mSavedCaptureElement = null; |
92 |
76 |
|
} |
93 |
77 |
|
} |
94 |
78 |
|
} |
95 |
79 |
|
String zNewToolTip = mDisabledToolTip; |
96 |
|
- |
if ( zNewForm != sDISABLED ) |
97 |
|
- |
{ |
|
80 |
+ |
if ( zNewForm != sDISABLED ) { |
98 |
81 |
|
zNewToolTip = mEnabledToolTip; |
99 |
|
- |
if ( zNewForm == sMOUSEDOWN ) |
100 |
|
- |
{ |
|
82 |
+ |
if ( zNewForm == sMOUSEDOWN ) { |
101 |
83 |
|
mSavedCaptureElement = DOM.getCaptureElement(); |
102 |
|
- |
if ( mSavedCaptureElement != null ) |
103 |
|
- |
{ |
|
84 |
+ |
if ( mSavedCaptureElement != null ) { |
104 |
85 |
|
DOM.releaseCapture( mSavedCaptureElement ); |
105 |
86 |
|
} |
106 |
87 |
|
DOM.setCapture( mWidget.getElement() ); |
|
@@ -108,40 +89,33 @@ |
108 |
89 |
|
} |
109 |
90 |
|
mCurrentState = zNewForm; |
110 |
91 |
|
applyCurrentState(); |
111 |
|
- |
if ( zNewToolTip != null ) |
112 |
|
- |
{ |
|
92 |
+ |
if ( zNewToolTip != null ) { |
113 |
93 |
|
mWidget.setTitle( zNewToolTip ); |
114 |
94 |
|
} |
115 |
95 |
|
} |
116 |
96 |
|
return this; |
117 |
97 |
|
} |
118 |
98 |
|
|
119 |
|
- |
protected void applyCurrentState() |
120 |
|
- |
{ |
|
99 |
+ |
protected void applyCurrentState() { |
121 |
100 |
|
mWidget.addStyleName( "" + mCurrentState ); |
122 |
101 |
|
} |
123 |
102 |
|
|
124 |
|
- |
protected void removeCurrentState() |
125 |
|
- |
{ |
|
103 |
+ |
protected void removeCurrentState() { |
126 |
104 |
|
mWidget.removeStyleName( "" + mCurrentState ); |
127 |
105 |
|
} |
128 |
106 |
|
|
129 |
|
- |
public boolean isEnabled() |
130 |
|
- |
{ |
|
107 |
+ |
public boolean isEnabled() { |
131 |
108 |
|
return !mDisabled; |
132 |
109 |
|
} |
133 |
110 |
|
|
134 |
|
- |
public void setEnabled( boolean pEnabled ) |
135 |
|
- |
{ |
|
111 |
+ |
public void setEnabled( boolean pEnabled ) { |
136 |
112 |
|
mDisabled = !pEnabled; |
137 |
113 |
|
updateForm(); |
138 |
114 |
|
} |
139 |
115 |
|
|
140 |
116 |
|
@Override |
141 |
|
- |
public boolean onBrowserEvent( Event pEvent ) |
142 |
|
- |
{ |
143 |
|
- |
switch ( DOM.eventGetType( pEvent ) ) |
144 |
|
- |
{ |
|
117 |
+ |
public boolean onBrowserEvent( Event pEvent ) { |
|
118 |
+ |
switch ( DOM.eventGetType( pEvent ) ) { |
145 |
119 |
|
case Event.ONMOUSEDOWN: |
146 |
120 |
|
UtilsGwt.eventPreventDefaultAndCancelBubble( pEvent ); |
147 |
121 |
|
onMouseDown( pEvent ); |
|
@@ -163,80 +137,65 @@ |
163 |
137 |
|
return !isEnabled(); |
164 |
138 |
|
} |
165 |
139 |
|
|
166 |
|
- |
protected void onMouseDown( Event pEvent ) |
167 |
|
- |
{ |
|
140 |
+ |
protected void onMouseDown( Event pEvent ) { |
168 |
141 |
|
mouseDown(); |
169 |
142 |
|
} |
170 |
143 |
|
|
171 |
|
- |
protected void onMouseUp( Event pEvent ) |
172 |
|
- |
{ |
|
144 |
+ |
protected void onMouseUp( Event pEvent ) { |
173 |
145 |
|
mouseUp(); |
174 |
146 |
|
} |
175 |
147 |
|
|
176 |
|
- |
protected void onMouseEnter( Event pEvent ) |
177 |
|
- |
{ |
|
148 |
+ |
protected void onMouseEnter( Event pEvent ) { |
178 |
149 |
|
mouseEnter(); |
179 |
150 |
|
} |
180 |
151 |
|
|
181 |
|
- |
protected void onMouseLeave( Event pEvent ) |
182 |
|
- |
{ |
|
152 |
+ |
protected void onMouseLeave( Event pEvent ) { |
183 |
153 |
|
mouseLeave(); |
184 |
154 |
|
} |
185 |
155 |
|
|
186 |
|
- |
protected void mouseDown() |
187 |
|
- |
{ |
|
156 |
+ |
protected void mouseDown() { |
188 |
157 |
|
mMouseDown = true; |
189 |
158 |
|
updateForm(); |
190 |
159 |
|
} |
191 |
160 |
|
|
192 |
|
- |
protected void mouseUp() |
193 |
|
- |
{ |
|
161 |
+ |
protected void mouseUp() { |
194 |
162 |
|
mMouseDown = false; |
195 |
163 |
|
updateForm(); |
196 |
164 |
|
} |
197 |
165 |
|
|
198 |
|
- |
protected void mouseEnter() |
199 |
|
- |
{ |
|
166 |
+ |
protected void mouseEnter() { |
200 |
167 |
|
mMouseOver = true; |
201 |
168 |
|
updateForm(); |
202 |
169 |
|
} |
203 |
170 |
|
|
204 |
|
- |
protected void mouseLeave() |
205 |
|
- |
{ |
|
171 |
+ |
protected void mouseLeave() { |
206 |
172 |
|
mMouseOver = false; |
207 |
173 |
|
updateForm(); |
208 |
174 |
|
} |
209 |
175 |
|
|
210 |
|
- |
public static class State |
211 |
|
- |
{ |
|
176 |
+ |
public static class State { |
212 |
177 |
|
private String mText; |
213 |
178 |
|
|
214 |
|
- |
public State( String pText ) |
215 |
|
- |
{ |
|
179 |
+ |
public State( String pText ) { |
216 |
180 |
|
mText = pText; |
217 |
181 |
|
} |
218 |
182 |
|
|
219 |
183 |
|
@Override |
220 |
|
- |
public String toString() |
221 |
|
- |
{ |
|
184 |
+ |
public String toString() { |
222 |
185 |
|
return mText; |
223 |
186 |
|
} |
224 |
187 |
|
|
225 |
|
- |
public String getURL( String pURLBaseGifExtentionAssumed ) |
226 |
|
- |
{ |
|
188 |
+ |
public String getURL( String pURLBaseGifExtentionAssumed ) { |
227 |
189 |
|
return pURLBaseGifExtentionAssumed + "-" + mText + ".gif"; |
228 |
190 |
|
} |
229 |
191 |
|
|
230 |
|
- |
public String[] getURLsFor9cell( String pURLBaseGifExtentionAssumed ) |
231 |
|
- |
{ |
|
192 |
+ |
public String[] getURLsFor9cell( String pURLBaseGifExtentionAssumed ) { |
232 |
193 |
|
return generateURLs( pURLBaseGifExtentionAssumed + "/" + mText + "/", CompassPoint.values() ); |
233 |
194 |
|
} |
234 |
195 |
|
|
235 |
|
- |
private String[] generateURLs( String pLeader, CompassPoint[] pCells ) |
236 |
|
- |
{ |
|
196 |
+ |
private String[] generateURLs( String pLeader, CompassPoint[] pCells ) { |
237 |
197 |
|
String[] rv = new String[pCells.length]; |
238 |
|
- |
for ( int i = 0; i < pCells.length; i++ ) |
239 |
|
- |
{ |
|
198 |
+ |
for ( int i = 0; i < pCells.length; i++ ) { |
240 |
199 |
|
rv[i] = pLeader + pCells[i] + ".gif"; |
241 |
200 |
|
} |
242 |
201 |
|
return rv; |