001: // ResourceEventMulticaster.java
002: // $Id: ResourceEventMulticaster.java,v 1.5 2000/08/16 21:37:53 ylafon Exp $
003: // (c) COPYRIGHT MIT and INRIA, 1997.
004: // Please first read the full copyright statement in file COPYRIGHT.html
005:
006: package org.w3c.tools.resources.event;
007:
008: import java.util.EventListener;
009:
010: /**
011: * Event dispatching suport class.
012: */
013:
014: public class ResourceEventMulticaster implements
015: StructureChangedListener, FrameEventListener,
016: AttributeChangedListener {
017: protected EventListener a = null;
018: protected EventListener b = null;
019:
020: protected ResourceEventMulticaster(EventListener a, EventListener b) {
021: this .a = a;
022: this .b = b;
023: }
024:
025: protected EventListener remove(EventListener oldl) {
026: if (oldl == a)
027: return b;
028: if (oldl == b)
029: return a;
030: EventListener a2 = removeInternal(a, oldl);
031: EventListener b2 = removeInternal(b, oldl);
032: if (a2 == a && b2 == b)
033: return this ;
034: return addInternal(a2, b2);
035: }
036:
037: protected static EventListener removeInternal(EventListener l,
038: EventListener oldl) {
039: if (l == oldl || l == null) {
040: return null;
041: } else if (l instanceof ResourceEventMulticaster) {
042: return ((ResourceEventMulticaster) l).remove(oldl);
043: } else {
044: return l;
045: }
046: }
047:
048: protected static EventListener addInternal(EventListener a,
049: EventListener b) {
050: if (a == null)
051: return b;
052: if (b == null)
053: return a;
054: return new ResourceEventMulticaster(a, b);
055: }
056:
057: /**
058: * Add an attribute change listener.
059: */
060:
061: public static AttributeChangedListener add(
062: AttributeChangedListener a, AttributeChangedListener b) {
063: return (AttributeChangedListener) addInternal(a, b);
064: }
065:
066: /**
067: * Remove an attribute change listener.
068: */
069:
070: public static AttributeChangedListener remove(
071: AttributeChangedListener l, AttributeChangedListener ol) {
072: return (AttributeChangedListener) removeInternal(l, ol);
073: }
074:
075: /**
076: * Propagate AttributeChanged events.
077: */
078:
079: public void attributeChanged(AttributeChangedEvent evt) {
080: ((AttributeChangedListener) a).attributeChanged(evt);
081: ((AttributeChangedListener) b).attributeChanged(evt);
082: }
083:
084: /**
085: * Add an Frame event listener.
086: */
087:
088: public static FrameEventListener add(FrameEventListener a,
089: FrameEventListener b) {
090: return (FrameEventListener) addInternal(a, b);
091: }
092:
093: /**
094: * Remove a frame event listener.
095: */
096:
097: public static FrameEventListener remove(FrameEventListener l,
098: FrameEventListener oldl) {
099: return (FrameEventListener) removeInternal(l, oldl);
100: }
101:
102: public void frameAdded(FrameEvent evt) {
103: ((FrameEventListener) a).frameAdded(evt);
104: ((FrameEventListener) b).frameAdded(evt);
105: }
106:
107: public void frameModified(FrameEvent evt) {
108: ((FrameEventListener) a).frameModified(evt);
109: ((FrameEventListener) b).frameModified(evt);
110: }
111:
112: public void frameRemoved(FrameEvent evt) {
113: ((FrameEventListener) a).frameRemoved(evt);
114: ((FrameEventListener) b).frameRemoved(evt);
115: }
116:
117: /**
118: * Add a structure changed listener.
119: */
120:
121: public static StructureChangedListener add(
122: StructureChangedListener a, StructureChangedListener b) {
123: return (StructureChangedListener) addInternal(a, b);
124: }
125:
126: /**
127: * Remove a structure changed listener.
128: */
129:
130: public static StructureChangedListener remove(
131: StructureChangedListener l, StructureChangedListener ol) {
132: return (StructureChangedListener) removeInternal(l, ol);
133: }
134:
135: public void resourceModified(StructureChangedEvent evt) {
136: ((StructureChangedListener) a).resourceModified(evt);
137: ((StructureChangedListener) b).resourceModified(evt);
138: }
139:
140: public void resourceCreated(StructureChangedEvent evt) {
141: ((StructureChangedListener) a).resourceCreated(evt);
142: ((StructureChangedListener) b).resourceCreated(evt);
143: }
144:
145: public void resourceRemoved(StructureChangedEvent evt) {
146: ((StructureChangedListener) a).resourceRemoved(evt);
147: ((StructureChangedListener) b).resourceRemoved(evt);
148: }
149:
150: public void resourceUnloaded(StructureChangedEvent evt) {
151: ((StructureChangedListener) a).resourceUnloaded(evt);
152: ((StructureChangedListener) b).resourceUnloaded(evt);
153: }
154: }
|