001: /*
002: #IFNDEF ALT_LICENSE
003: ThinWire(R) RIA Ajax Framework
004: Copyright (C) 2003-2007 Custom Credit Systems
005:
006: This library is free software; you can redistribute it and/or modify it under
007: the terms of the GNU Lesser General Public License as published by the Free
008: Software Foundation; either version 2.1 of the License, or (at your option) any
009: later version.
010:
011: This library is distributed in the hope that it will be useful, but WITHOUT ANY
012: WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
013: PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
014:
015: You should have received a copy of the GNU Lesser General Public License along
016: with this library; if not, write to the Free Software Foundation, Inc., 59
017: Temple Place, Suite 330, Boston, MA 02111-1307 USA
018:
019: Users who would rather have a commercial license, warranty or support should
020: contact the following company who invented, built and supports the technology:
021:
022: Custom Credit Systems, Richardson, TX 75081, USA.
023: email: info@thinwire.com ph: +1 (888) 644-6405
024: http://www.thinwire.com
025: #ENDIF
026: [ v1.2_RC2 ]
027: */
028: package thinwire.ui.style;
029:
030: import static thinwire.ui.style.Effect.*;
031:
032: /**
033: * @author Joshua J. Gertzen
034: */
035: public class FX {
036: public static final String PROPERTY_FX_POSITION_CHANGE = "fXPositionChange";
037: public static final String PROPERTY_FX_SIZE_CHANGE = "fXSizeChange";
038: public static final String PROPERTY_FX_VISIBLE_CHANGE = "fXVisibleChange";
039: public static final String PROPERTY_FX_OPACITY_CHANGE = "fXOpacityChange";
040: public static final String PROPERTY_FX_COLOR_CHANGE = "fXColorChange";
041:
042: private Style parent;
043: private Motion positionChange;
044: private Motion sizeChange;
045: private Motion visibleChange;
046: private Motion opacityChange;
047: private Motion colorChange;
048: private String stringValue;
049:
050: FX(Style parent) {
051: this .parent = parent;
052: if (parent.defaultStyle != null)
053: copy(parent.defaultStyle.getFX());
054: }
055:
056: private void clearStringValue() {
057: this .stringValue = stringValue;
058: if (parent != null)
059: parent.stringValue = null;
060: }
061:
062: public String toString() {
063: if (stringValue == null)
064: stringValue = "FX{colorChange:" + getColorChange()
065: + ",opacityChange:" + getOpacityChange()
066: + ",positionChange:" + getPositionChange()
067: + ",sizeChange:" + getSizeChange()
068: + ",visibleChange:" + getVisibleChange() + "}";
069: return stringValue;
070: }
071:
072: public int hashCode() {
073: return toString().hashCode();
074: }
075:
076: public boolean equals(Object o) {
077: if (!(o instanceof FX))
078: return false;
079: if (this == o)
080: return true;
081: return this .toString().equals(o.toString());
082: }
083:
084: public void copy(FX fx) {
085: copy(fx, false);
086: }
087:
088: public void copy(FX fx, boolean onlyIfDefault) {
089: if (fx == null)
090: throw new IllegalArgumentException("fx == null");
091:
092: if (onlyIfDefault) {
093: FX df = parent.defaultStyle.getFX();
094: if (getPositionChange().equals(df.getPositionChange()))
095: setPositionChange(fx.getPositionChange());
096: if (getSizeChange().equals(df.getSizeChange()))
097: setSizeChange(fx.getSizeChange());
098: if (getVisibleChange().equals(df.getVisibleChange()))
099: setVisibleChange(fx.getVisibleChange());
100: if (getOpacityChange().equals(df.getOpacityChange()))
101: setOpacityChange(fx.getOpacityChange());
102: if (getColorChange().equals(df.getColorChange()))
103: setColorChange(fx.getColorChange());
104: } else {
105: setPositionChange(fx.getPositionChange());
106: setSizeChange(fx.getSizeChange());
107: setVisibleChange(fx.getVisibleChange());
108: setOpacityChange(fx.getOpacityChange());
109: setColorChange(fx.getColorChange());
110: }
111: }
112:
113: public void setProperty(String name, Object value) {
114: if (name.equals(FX.PROPERTY_FX_POSITION_CHANGE)) {
115: setPositionChange((Effect.Motion) value);
116: } else if (name.equals(FX.PROPERTY_FX_SIZE_CHANGE)) {
117: setSizeChange((Effect.Motion) value);
118: } else if (name.equals(FX.PROPERTY_FX_VISIBLE_CHANGE)) {
119: setVisibleChange((Effect.Motion) value);
120: } else if (name.equals(FX.PROPERTY_FX_OPACITY_CHANGE)) {
121: setOpacityChange((Effect.Motion) value);
122: } else if (name.equals(FX.PROPERTY_FX_COLOR_CHANGE)) {
123: setColorChange((Effect.Motion) value);
124: } else {
125: throw new IllegalArgumentException(
126: "unknown style property '" + name + "'");
127: }
128: }
129:
130: public Object getProperty(String name) {
131: Object ret;
132:
133: if (name.equals(FX.PROPERTY_FX_POSITION_CHANGE)) {
134: ret = getPositionChange();
135: } else if (name.equals(FX.PROPERTY_FX_SIZE_CHANGE)) {
136: ret = getSizeChange();
137: } else if (name.equals(FX.PROPERTY_FX_VISIBLE_CHANGE)) {
138: ret = getVisibleChange();
139: } else if (name.equals(FX.PROPERTY_FX_OPACITY_CHANGE)) {
140: ret = getOpacityChange();
141: } else {
142: throw new IllegalArgumentException(
143: "unknown style property '" + name + "'");
144: }
145:
146: return ret;
147: }
148:
149: public Style getParent() {
150: return parent;
151: }
152:
153: public Motion getPositionChange() {
154: if (positionChange == null)
155: throw new IllegalArgumentException("positionChange == null");
156: return positionChange;
157: }
158:
159: public void setPositionChange(Motion positionChange) {
160: if (positionChange == null && parent.defaultStyle != null)
161: positionChange = parent.defaultStyle.getFX()
162: .getPositionChange();
163: if (positionChange == null)
164: throw new IllegalArgumentException("positionChange == null");
165: Motion oldPositionChange = this .positionChange;
166: this .clearStringValue();
167: this .positionChange = positionChange;
168: if (parent != null)
169: parent.firePropertyChange(this ,
170: PROPERTY_FX_POSITION_CHANGE, oldPositionChange,
171: this .positionChange);
172: }
173:
174: public Motion getSizeChange() {
175: if (sizeChange == null)
176: throw new IllegalArgumentException("sizeChange == null");
177: return sizeChange;
178: }
179:
180: public void setSizeChange(Motion sizeChange) {
181: if (sizeChange == null && parent.defaultStyle != null)
182: sizeChange = parent.defaultStyle.getFX().getSizeChange();
183: if (sizeChange == null)
184: throw new IllegalArgumentException("sizeChange == null");
185: Motion oldSizeChange = this .sizeChange;
186: this .clearStringValue();
187: this .sizeChange = sizeChange;
188: if (parent != null)
189: parent.firePropertyChange(this , PROPERTY_FX_SIZE_CHANGE,
190: oldSizeChange, this .sizeChange);
191: }
192:
193: public Motion getVisibleChange() {
194: if (visibleChange == null)
195: throw new IllegalArgumentException("visibleChange == null");
196: return visibleChange;
197: }
198:
199: public void setVisibleChange(Motion visibleChange) {
200: if (visibleChange == null && parent.defaultStyle != null)
201: visibleChange = parent.defaultStyle.getFX()
202: .getVisibleChange();
203: if (visibleChange == null)
204: throw new IllegalArgumentException("visibleChange == null");
205: Motion oldVisibleChange = this .visibleChange;
206: this .clearStringValue();
207: this .visibleChange = visibleChange;
208: if (parent != null)
209: parent.firePropertyChange(this , PROPERTY_FX_VISIBLE_CHANGE,
210: oldVisibleChange, this .visibleChange);
211: }
212:
213: public Motion getOpacityChange() {
214: if (opacityChange == null)
215: throw new IllegalArgumentException("opacityChange == null");
216: return opacityChange;
217: }
218:
219: public void setOpacityChange(Motion opacityChange) {
220: if (opacityChange == null && parent.defaultStyle != null)
221: opacityChange = parent.defaultStyle.getFX()
222: .getOpacityChange();
223: if (opacityChange == null)
224: throw new IllegalArgumentException("opacityChange == null");
225: Motion oldOpacityChange = this .opacityChange;
226: this .clearStringValue();
227: this .opacityChange = opacityChange;
228: if (parent != null)
229: parent.firePropertyChange(this , PROPERTY_FX_OPACITY_CHANGE,
230: oldOpacityChange, this .opacityChange);
231: }
232:
233: public Motion getColorChange() {
234: if (colorChange == null)
235: throw new IllegalArgumentException("colorChange == null");
236: return colorChange;
237: }
238:
239: public void setColorChange(Motion colorChange) {
240: if (colorChange == null && parent.defaultStyle != null)
241: colorChange = parent.defaultStyle.getFX().getColorChange();
242: if (colorChange == null)
243: throw new IllegalArgumentException("colorChange == null");
244: Motion oldColorChange = this.colorChange;
245: this.clearStringValue();
246: this.colorChange = colorChange;
247: if (parent != null)
248: parent.firePropertyChange(this, PROPERTY_FX_COLOR_CHANGE,
249: oldColorChange, this.colorChange);
250: }
251: }
|