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
package com.temp.foundation.widgets.inputfieldsupport;

/**
 * The State of an InputField is the combination of the following boolean states:
 * <p/>
 * Empty
 * Changed
 * Required
 * Errored
 * Focused
 */
public class StateInputField
{
    public static class Flags
    {
        public static final Flags NOTHING = new Flags( false, false, false, false, false );

        private boolean mEmpty, mChanged, mRequired, mErrored, mFocused;

        private Flags( boolean pEmpty, boolean pChanged, boolean pRequired, boolean pErrored, boolean pFocused )
        {
            mEmpty = pEmpty;
            mChanged = pChanged;
            mRequired = pRequired;
            mErrored = pErrored;
            mFocused = pFocused;
        }

        public boolean isEmpty()
        {
            return mEmpty;
        }

        public boolean isChanged()
        {
            return mChanged;
        }

        public boolean isRequired()
        {
            return mRequired;
        }

        public boolean isErrored()
        {
            return mErrored;
        }

        public boolean isFocused()
        {
            return mFocused;
        }

        public Flags empty( boolean pEmpty )
        {
            return changeTo( pEmpty, mChanged, mRequired, mErrored, mFocused );
        }

        public Flags changed( boolean pChanged )
        {
            return changeTo( mEmpty, pChanged, mRequired, mErrored, mFocused );
        }

        public Flags required( boolean pRequired )
        {
            return changeTo( mEmpty, mChanged, pRequired, mErrored, mFocused );
        }

        public Flags errored( boolean pErrored )
        {
            return changeTo( mEmpty, mChanged, mRequired, pErrored, mFocused );
        }

        public Flags focused( boolean pFocused )
        {
            return changeTo( mEmpty, mChanged, mRequired, mErrored, pFocused );
        }

        private Flags changeTo( boolean pEmpty, boolean pChanged, boolean pRequired, boolean pErrored, boolean pFocused )
        {
            if ( (mEmpty == pEmpty) && (mChanged == pChanged) && (mRequired == pRequired) && (mErrored == pErrored) && (mFocused == pFocused) )
            {
                return this;
            }
            return new Flags( pEmpty, pChanged, pRequired, pErrored, pFocused );
        }

        @Override
        public boolean equals( Object o )
        {
            return (this == o) || ((o instanceof Flags) && equals( (Flags) o ));
        }

        public boolean equals( Flags them )
        {
            return (them != null) //
                   && (this.mChanged == them.mChanged) //
                   && (this.mEmpty == them.mEmpty) //
                   && (this.mErrored == them.mErrored) //
                   && (this.mFocused == them.mFocused) //
                   && (this.mRequired == them.mRequired);
        }

        @Override
        public int hashCode()
        {
            int result = (mEmpty ? 1 : 0);
            result = (result << 1) + (mChanged ? 1 : 0);
            result = (result << 1) + (mRequired ? 1 : 0);
            result = (result << 1) + (mErrored ? 1 : 0);
            result = (result << 1) + (mFocused ? 1 : 0);
            return result;
        }

        @Override
        public String toString()
        {
            StringBuilder sb = new StringBuilder();
            add( sb, "Changed", mChanged );
            add( sb, "Empty", mEmpty );
            add( sb, "Errored", mErrored );
            add( sb, "Focused", mFocused );
            add( sb, "Required", mRequired );
            return sb.toString();
        }

        private void add( StringBuilder sb, String what, boolean flag )
        {
            if ( flag )
            {
                if ( sb.length() != 0 )
                {
                    sb.append( ", " );
                }
                sb.append( what );
            }
        }
    }

    public enum RequiredSpacerStyle
    {
        Unsatisfied, //
        Satisfied;

        public String toCSS()
        {
            return "IF_RequiresData" + name();
        }

        public static RequiredSpacerStyle fromFlags( Flags flags )
        {
            return (flags.isRequired() && flags.isEmpty()) ? Unsatisfied : Satisfied;
        }
    }

    public enum BoxStyle
    {
        Focused, //
        Errored, //
        Changed, //
        Normal;

        public String toCSS()
        {
            return "IF_Box" + name();
        }

        public static BoxStyle fromFlags( Flags flags )
        {
            if ( flags.isFocused() )
            {
                return Focused;
            }
            if ( flags.isErrored() )
            {
                return Errored;
            }
            if ( flags.isChanged() )
            {
                return Changed;
            }
            return Normal;
        }
    }
}

Commits for litesoft/trunk/GWT_Sandbox/FormEngine/src/com/temp/foundation/widgets/inputfieldsupport/StateInputField.java

Diff revisions: vs.
Revision Author Commited Message
600 GeorgeS picture GeorgeS Sun 05 Feb, 2012 18:55:58 +0000

Sync-n