litesoft
@ 629
litesoft / trunk / GWT_Sandbox / FormEngine / src / com / temp / client / foundation / widget / input / fieldsupport / StateInputField.java
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 |
package com.temp.client.foundation.widget.input.fieldsupport; /** * The State of an InputField is the combination of the following boolean states: * <p/> * Changed * Errored * Focused */ public class StateInputField { public static final StateInputField BASE = new StateInputField( false, false, false ); private boolean mChanged, mErrored, mFocused; private StateInputField( boolean pChanged, boolean pErrored, boolean pFocused ) { mChanged = pChanged; mErrored = pErrored; mFocused = pFocused; } public boolean isChanged() { return mChanged; } public boolean isErrored() { return mErrored; } public boolean isFocused() { return mFocused; } public StateInputField changed( boolean pChanged ) { return changeTo( pChanged, mErrored, mFocused ); } public StateInputField errored( boolean pErrored ) { return changeTo( mChanged, pErrored, mFocused ); } public StateInputField focused( boolean pFocused ) { return changeTo( mChanged, mErrored, pFocused ); } private StateInputField changeTo( boolean pChanged, boolean pErrored, boolean pFocused ) { if ( (mChanged == pChanged) && (mErrored == pErrored) && (mFocused == pFocused) ) { return this; } return new StateInputField( pChanged, pErrored, pFocused ); } @Override public boolean equals( Object o ) { return (this == o) || ((o instanceof StateInputField) && equals( (StateInputField) o )); } public boolean equals( StateInputField them ) { return (them != null) // && (this.mChanged == them.mChanged) // && (this.mErrored == them.mErrored) // && (this.mFocused == them.mFocused); } @Override public int hashCode() { int result = (mChanged ? 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, "Errored", mErrored ); add( sb, "Focused", mFocused ); return sb.toString(); } public String toCSS() { return "IF_Box" + this; } private void add( StringBuilder sb, String what, boolean flag ) { if ( flag ) { sb.append( what ); } } } |