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