001: /*
002: * Jacareto Copyright (c) 2002-2005
003: * Applied Computer Science Research Group, Darmstadt University of
004: * Technology, Institute of Mathematics & Computer Science,
005: * Ludwigsburg University of Education, and Computer Based
006: * Learning Research Group, Aachen University. All rights reserved.
007: *
008: * Jacareto is free software; you can redistribute it and/or
009: * modify it under the terms of the GNU General Public
010: * License as published by the Free Software Foundation; either
011: * version 2 of the License, or (at your option) any later version.
012: *
013: * Jacareto is distributed in the hope that it will be useful,
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
016: * General Public License for more details.
017: *
018: * You should have received a copy of the GNU General Public
019: * License along with Jacareto; if not, write to the Free
020: * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
021: *
022: */
023:
024: package jacareto.toolkit;
025:
026: /**
027: * This event will be delivered to hashtable change listeners when the hashtable has been changed.
028: *
029: * @author <a href="mailto:cspannagel@web.de">Christian Spannagel</a>
030: * @version 0.9
031: */
032: public class HashtableChangeEvent {
033: /** A new (key,value) pair has been added to the hashtable. */
034: public static final int PAIR_ADDED = 0;
035:
036: /** An existent (key,value) pair has been changed. */
037: public static final int PAIR_CHANGED = 1;
038:
039: /** An existent (key,value) has been removed. */
040: public static final int PAIR_REMOVED = 2;
041:
042: /** The hashtable has been cleared. */
043: public static final int HASHTABLE_CLEARED = 3;
044:
045: /** A child has been added to the hashtable. */
046: public static final int CHILD_ADDED = 4;
047:
048: /** A child has been removed. */
049: public static final int CHILD_REMOVED = 5;
050:
051: /** A child has been changed. */
052: public static final int CHILD_CHANGED = 6;
053:
054: /** The event type. */
055: private int id;
056:
057: /** The key of the (key,value) which has caused the change of the hashtable. */
058: private Object key;
059:
060: /** The value before the change. */
061: private Object valueBeforeChange;
062:
063: /** The value after the change. */
064: private Object valueAfterChange;
065:
066: /**
067: * Creates a hashtable change event with the specified values.
068: *
069: * @param id the id
070: * @param key the key of the (key,value) pair which has caused the change of the hashtable
071: * @param valueBeforeChange the value before the change
072: * @param valueAfterChange the value after the change
073: */
074: public HashtableChangeEvent(int id, Object key,
075: Object valueBeforeChange, Object valueAfterChange) {
076: this .id = id;
077: this .key = key;
078: this .valueBeforeChange = valueBeforeChange;
079: this .valueAfterChange = valueAfterChange;
080: }
081:
082: /**
083: * Returns the type of the event.
084: *
085: * @return the type
086: */
087: public int getID() {
088: return id;
089: }
090:
091: /**
092: * Returns the key of the (key,value) pair which has caused the change of the hashtable. If the
093: * event is not a <code>PAIR_...</code> event, the key will be <code>null</code>.
094: *
095: * @return the key
096: */
097: public Object getKey() {
098: return key;
099: }
100:
101: /**
102: * Returns the value before the change. If the event is not a <code>PAIR_CHANGED</code> event
103: * or a <code>PAIR_REMOVED</code> event, the value will be <code>null</code>.
104: *
105: * @return the value before the change
106: */
107: public Object getValueBeforeChange() {
108: if (getID() == PAIR_ADDED) {
109: return null;
110: } else {
111: return valueBeforeChange;
112: }
113: }
114:
115: /**
116: * Returns the value after the change. If the event is not a <code>PAIR_CHANGED</code> event or
117: * a <code>PAIR_REMOVED</code> event, the value will be <code>null</code>.
118: *
119: * @return the value before the change
120: */
121: public Object getValueAfterChange() {
122: if (getID() == PAIR_REMOVED) {
123: return null;
124: } else {
125: return valueAfterChange;
126: }
127: }
128: }
|