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.event;
029:
030: import java.util.EventObject;
031:
032: import thinwire.ui.GridBox;
033: import thinwire.ui.ItemChangeEventComponent;
034:
035: /**
036: * Sends a trigger to a listener when something changes in an item.
037: * @author Joshua J. Gertzen
038: */
039: public final class ItemChangeEvent extends EventObject {
040: private String stringValue;
041: private ItemChangeEventComponent sourceComponent;
042: private Type type;
043: private Object position;
044: private Object oldValue;
045: private Object newValue;
046:
047: public static enum Type {
048: ADD, REMOVE, SET;
049: }
050:
051: public ItemChangeEvent(ItemChangeEventComponent sourceComponent,
052: Type type, Object position, Object oldValue, Object newValue) {
053: this (sourceComponent, null, type, position, oldValue, newValue);
054: }
055:
056: public ItemChangeEvent(ItemChangeEventComponent sourceComponent,
057: Object source, Type type, Object position, Object oldValue,
058: Object newValue) {
059: super (source == null ? sourceComponent : source);
060: if (sourceComponent == null)
061: throw new IllegalArgumentException(
062: "sourceComponent == null");
063: if (type == null)
064: throw new IllegalArgumentException("type == null");
065: if (position == null)
066: throw new IllegalArgumentException("position == null");
067: if (!(position instanceof Integer || position instanceof GridBox.Range))
068: throw new IllegalArgumentException(
069: "!(position instanceof Integer || position instanceof GridBox.Range)");
070: this .sourceComponent = sourceComponent;
071: this .type = type;
072: this .position = position;
073: this .oldValue = oldValue;
074: this .newValue = newValue;
075: }
076:
077: public ItemChangeEventComponent getSourceComponent() {
078: return sourceComponent;
079: }
080:
081: public Type getType() {
082: return type;
083: }
084:
085: public Object getPosition() {
086: return position;
087: }
088:
089: public Object getNewValue() {
090: return newValue;
091: }
092:
093: public Object getOldValue() {
094: return oldValue;
095: }
096:
097: public boolean equals(Object o) {
098: return o instanceof PropertyChangeEvent
099: && toString().equals(o.toString());
100: }
101:
102: public int hashCode() {
103: return toString().hashCode();
104: }
105:
106: public String toString() {
107: if (stringValue == null)
108: stringValue = "ItemChangeEvent{sourceComponent:"
109: + sourceComponent.getClass().getName() + "@"
110: + System.identityHashCode(sourceComponent)
111: + ",source:" + source + ",type:" + type
112: + ",position:" + position + ",newValue:" + newValue
113: + ",oldValue:" + oldValue + "}";
114: return stringValue;
115: }
116: }
|