Subversion Repository Public Repository

litesoft

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
// This Source Code is in the Public Domain per: http://unlicense.org
package org.litesoft.GWT.client.widgets.nonpublic;

import org.litesoft.GWT.client.*;
import org.litesoft.commonfoundation.typeutils.*;
import org.litesoft.ui.*;

import com.google.gwt.user.client.*;
import com.google.gwt.user.client.ui.*;

public class AbstractCssBackgroundButtonHelper implements OnBrowserEventListener {
    private static final State sREGULAR = new State( "Regular" );
    private static final State sMOUSEOVER = new State( "Mouseover" );
    private static final State sMOUSEDOWN = new State( "Mousedown" );
    private static final State sDISABLED = new State( "Disabled" );

    public static final State[] ALL_STATES = new State[]{sREGULAR, sMOUSEOVER, sMOUSEDOWN, sDISABLED};

    private boolean mMouseOver = false;
    private boolean mMouseDown = false;
    private boolean mDisabled = false;
    protected Widget mWidget;
    private String mEnabledToolTip;
    private String mDisabledToolTip = null;
    protected State mCurrentState = null;
    private Element mSavedCaptureElement = null;

    public AbstractCssBackgroundButtonHelper( OnBrowserEventListenable pListenable, String pEnabledToolTip, String pDisabledToolTip ) {
        mWidget = pListenable.getOnBrowserEventListenableWidget();

        if ( null != (mEnabledToolTip = Strings.noEmpty( pEnabledToolTip )) ) {
            mWidget.setTitle( mEnabledToolTip );
            mDisabledToolTip = pDisabledToolTip == null ? pDisabledToolTip : pDisabledToolTip.trim();
        }
        pListenable.setOnBrowserEventListener( Event.MOUSEEVENTS, this );
    }

    public String getEnabledToolTip() {
        return mEnabledToolTip;
    }

    public void setEnabledToolTip( String pEnabledToolTip ) {
        String zEnabledToolTip = Strings.noEmpty( pEnabledToolTip );
        if ( zEnabledToolTip != null ) {
            mEnabledToolTip = pEnabledToolTip;
            if ( isEnabled() ) {
                mWidget.setTitle( mEnabledToolTip );
            }
        }
    }

    private State determineNewForm() {
        if ( mDisabled ) {
            return sDISABLED;
        }
        if ( mMouseDown ) {
            return sMOUSEDOWN;
        }
        if ( mMouseOver ) {
            return sMOUSEOVER;
        }
        return sREGULAR;
    }

    public AbstractCssBackgroundButtonHelper updateForm() {
        State zNewForm = determineNewForm();
        if ( mCurrentState != zNewForm ) {
            if ( mCurrentState != null ) {
                removeCurrentState();

                if ( mCurrentState == sMOUSEDOWN ) {
                    DOM.releaseCapture( mWidget.getElement() );
                    if ( mSavedCaptureElement != null ) {
                        DOM.setCapture( mSavedCaptureElement );
                        mSavedCaptureElement = null;
                    }
                }
            }
            String zNewToolTip = mDisabledToolTip;
            if ( zNewForm != sDISABLED ) {
                zNewToolTip = mEnabledToolTip;
                if ( zNewForm == sMOUSEDOWN ) {
                    mSavedCaptureElement = DOM.getCaptureElement();
                    if ( mSavedCaptureElement != null ) {
                        DOM.releaseCapture( mSavedCaptureElement );
                    }
                    DOM.setCapture( mWidget.getElement() );
                }
            }
            mCurrentState = zNewForm;
            applyCurrentState();
            if ( zNewToolTip != null ) {
                mWidget.setTitle( zNewToolTip );
            }
        }
        return this;
    }

    protected void applyCurrentState() {
        mWidget.addStyleName( "" + mCurrentState );
    }

    protected void removeCurrentState() {
        mWidget.removeStyleName( "" + mCurrentState );
    }

    public boolean isEnabled() {
        return !mDisabled;
    }

    public void setEnabled( boolean pEnabled ) {
        mDisabled = !pEnabled;
        updateForm();
    }

    @Override
    public boolean onBrowserEvent( Event pEvent ) {
        switch ( DOM.eventGetType( pEvent ) ) {
            case Event.ONMOUSEDOWN:
                UtilsGwt.eventPreventDefaultAndCancelBubble( pEvent );
                onMouseDown( pEvent );
                break;
            case Event.ONMOUSEUP:
                onMouseUp( pEvent );
                break;
            case Event.ONMOUSEOVER:
                onMouseEnter( pEvent );
                break;
            case Event.ONMOUSEOUT:
                onMouseLeave( pEvent );
                break;
            case Event.ONMOUSEMOVE:
                UtilsGwt.eventPreventDefaultAndCancelBubble( pEvent );
            default:
                break;
        }
        return !isEnabled();
    }

    protected void onMouseDown( Event pEvent ) {
        mouseDown();
    }

    protected void onMouseUp( Event pEvent ) {
        mouseUp();
    }

    protected void onMouseEnter( Event pEvent ) {
        mouseEnter();
    }

    protected void onMouseLeave( Event pEvent ) {
        mouseLeave();
    }

    protected void mouseDown() {
        mMouseDown = true;
        updateForm();
    }

    protected void mouseUp() {
        mMouseDown = false;
        updateForm();
    }

    protected void mouseEnter() {
        mMouseOver = true;
        updateForm();
    }

    protected void mouseLeave() {
        mMouseOver = false;
        updateForm();
    }

    public static class State {
        private String mText;

        public State( String pText ) {
            mText = pText;
        }

        @Override
        public String toString() {
            return mText;
        }

        public String getURL( String pURLBaseGifExtentionAssumed ) {
            return pURLBaseGifExtentionAssumed + "-" + mText + ".gif";
        }

        public String[] getURLsFor9cell( String pURLBaseGifExtentionAssumed ) {
            return generateURLs( pURLBaseGifExtentionAssumed + "/" + mText + "/", CompassPoint.values() );
        }

        private String[] generateURLs( String pLeader, CompassPoint[] pCells ) {
            String[] rv = new String[pCells.length];
            for ( int i = 0; i < pCells.length; i++ ) {
                rv[i] = pLeader + pCells[i] + ".gif";
            }
            return rv;
        }
    }
}

Commits for litesoft/trunk/Java/GWT/Client/src/org/litesoft/GWT/client/widgets/nonpublic/AbstractCssBackgroundButtonHelper.java

Diff revisions: vs.
Revision Author Commited Message
948 Diff Diff GeorgeS picture GeorgeS Sat 07 Jun, 2014 23:42:39 +0000

Jusefuls Formatter Updated to New Code Format

947 Diff Diff GeorgeS picture GeorgeS Fri 06 Jun, 2014 23:36:56 +0000

Correct Spelling of package!

939 Diff Diff GeorgeS picture GeorgeS Mon 02 Jun, 2014 21:30:31 +0000

Extracting commonfoundation

801 Diff Diff GeorgeS picture GeorgeS Wed 15 Aug, 2012 03:59:02 +0000
390 Diff Diff GeorgeS picture GeorgeS Sun 14 Aug, 2011 19:33:48 +0000
49 Diff Diff GeorgeS picture GeorgeS Mon 12 Apr, 2010 02:59:10 +0000

License Text

23 Diff Diff GeorgeS picture GeorgeS Wed 24 Feb, 2010 00:34:32 +0000
2 GeorgeS picture GeorgeS Sun 07 Feb, 2010 12:50:58 +0000