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.eventmask;
025:
026: import jacareto.record.AWTEventRecordable;
027: import jacareto.system.Environment;
028: import jacareto.system.EnvironmentMember;
029: import jacareto.toolkit.HashtableChangeEvent;
030: import jacareto.toolkit.HashtableChangeListener;
031:
032: import java.awt.AWTEvent;
033:
034: import java.util.Iterator;
035: import java.util.Vector;
036:
037: /**
038: * An event mask with additional features.
039: *
040: * @author <a href="mailto:cspannagel@web.de">Christian Spannagel</a>
041: * @version 1.0
042: */
043: public abstract class AWTEventMask extends EnvironmentMember implements
044: HashtableChangeListener {
045: /** The listeners. */
046: private Vector listeners;
047:
048: /** Whether or not this event mask listens to hashtable changes. */
049: private boolean isListeningToHashtableChanges;
050:
051: /**
052: * Creates an AWTEventMask. The event mask does not listen to customization changes by default.
053: *
054: * @param env the environment
055: */
056: public AWTEventMask(Environment env) {
057: super (env);
058: listeners = new Vector(5);
059: isListeningToHashtableChanges = false;
060: }
061:
062: /**
063: * Adds an eventmask listener to the list of listeners.
064: *
065: * @param listener the listener
066: */
067: public void addEventMaskListener(EventMaskListener listener) {
068: if (listener != null) {
069: listeners.add(listener);
070: }
071: }
072:
073: /**
074: * Removes an eventmask listener from the list of listeners.
075: *
076: * @param listener the listener
077: */
078: public void removeEventMaskListener(EventMaskListener listener) {
079: if (listener != null) {
080: listeners.remove(listener);
081: }
082: }
083:
084: /**
085: * Fires an eventmask event when the event mask has changed to all listeners.
086: *
087: * @param event the hashtable change event
088: */
089: protected void fireEventMaskChange(EventMaskEvent event) {
090: Iterator i = listeners.iterator();
091:
092: while (i.hasNext()) {
093: ((EventMaskListener) i.next()).eventMaskChanged(event);
094: }
095: }
096:
097: /**
098: * Returns the event mask as long value.
099: *
100: * @return the event mask, as long
101: */
102: public abstract long getLongValue();
103:
104: /**
105: * Returns <code>true</code> if the specified event is included in this event mask.
106: *
107: * @param event the event
108: *
109: * @return Whether this event mask includes the event or not
110: */
111: public abstract boolean isIncluded(AWTEvent event);
112:
113: /**
114: * Returns <code>true</code> if the specified {@link AWTEventRecordable} is included in this
115: * event mask.
116: *
117: * @param AWTEventRecordable the event recordable
118: *
119: * @return Whether this event mask includes the event recordable or not
120: */
121: public boolean isIncluded(AWTEventRecordable AWTEventRecordable) {
122: return isIncluded(AWTEventRecordable.getEvent());
123: }
124:
125: /**
126: * Invoked when the hashtable has changed. This method calls the {@link
127: * AWTEventMask#applyCustomization()} method to get the new values.
128: *
129: * @param event the hashtable change event
130: */
131: public void hashtableChanged(HashtableChangeEvent event) {
132: if (isListeningToHashtableChanges) {
133: applyCustomization();
134: }
135: }
136:
137: /**
138: * Specifies whether or not this instance is listening to changes of the customization.
139: *
140: * @param isListening if instance is listening to customization
141: */
142: public void setListeningToHashtableChanges(boolean isListening) {
143: this .isListeningToHashtableChanges = isListening;
144: }
145:
146: /**
147: * Returns whether or not this instance is listening to changes of the customization.
148: *
149: * @return true, if mask is listening to changes in the customization
150: */
151: public boolean isListeningToHashtableChanges() {
152: return isListeningToHashtableChanges;
153: }
154:
155: /**
156: * Load the values from the customization. In this method a subclass should read out the
157: * customization values it is interested in.
158: */
159: protected abstract void applyCustomization();
160: }
|