001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.cocoon.forms.event;
018:
019: import java.awt.AWTEventMulticaster;
020: import java.util.EventListener;
021:
022: import org.apache.cocoon.forms.formmodel.tree.TreeSelectionEvent;
023: import org.apache.cocoon.forms.formmodel.tree.TreeSelectionListener;
024:
025: /**
026: * Convenience class to handle all widget event listeners. See
027: * <code>java.awt.AWTEventMulticaster</code> for more information on its use.
028: *
029: * @version $Id: WidgetEventMulticaster.java 506703 2007-02-12 22:22:48Z simoneg $
030: */
031: public class WidgetEventMulticaster extends AWTEventMulticaster
032: implements ActionListener, ValueChangedListener,
033: ProcessingPhaseListener, RepeaterListener {
034:
035: protected WidgetEventMulticaster(EventListener a, EventListener b) {
036: super (a, b);
037: }
038:
039: //-- Create ---------------------------------------------------------------
040:
041: public static CreateListener add(CreateListener a, CreateListener b) {
042: return (CreateListener) addInternal(a, b);
043: }
044:
045: public static CreateListener remove(CreateListener l,
046: CreateListener oldl) {
047: return (CreateListener) removeInternal(l, oldl);
048: }
049:
050: public void widgetCreated(CreateEvent e) {
051: ((CreateListener) a).widgetCreated(e);
052: ((CreateListener) b).widgetCreated(e);
053: }
054:
055: //-- Action ---------------------------------------------------------------
056:
057: public static ActionListener add(ActionListener a, ActionListener b) {
058: return (ActionListener) addInternal(a, b);
059: }
060:
061: public static ActionListener remove(ActionListener l,
062: ActionListener oldl) {
063: return (ActionListener) removeInternal(l, oldl);
064: }
065:
066: public void actionPerformed(ActionEvent e) {
067: ((ActionListener) a).actionPerformed(e);
068: ((ActionListener) b).actionPerformed(e);
069: }
070:
071: //-- ValueChanged ---------------------------------------------------------
072:
073: public static ValueChangedListener add(ValueChangedListener a,
074: ValueChangedListener b) {
075: return (ValueChangedListener) addInternal(a, b);
076: }
077:
078: public static ValueChangedListener remove(ValueChangedListener l,
079: ValueChangedListener oldl) {
080: return (ValueChangedListener) removeInternal(l, oldl);
081: }
082:
083: public void valueChanged(ValueChangedEvent e) {
084: ((ValueChangedListener) a).valueChanged(e);
085: ((ValueChangedListener) b).valueChanged(e);
086: }
087:
088: //-- ProcessingPhase ------------------------------------------------------
089:
090: public void phaseEnded(ProcessingPhaseEvent e) {
091: ((ProcessingPhaseListener) a).phaseEnded(e);
092: ((ProcessingPhaseListener) b).phaseEnded(e);
093: }
094:
095: public static ProcessingPhaseListener add(
096: ProcessingPhaseListener a, ProcessingPhaseListener b) {
097: return (ProcessingPhaseListener) addInternal(a, b);
098: }
099:
100: public static ProcessingPhaseListener remove(
101: ProcessingPhaseListener l, ProcessingPhaseListener oldl) {
102: return (ProcessingPhaseListener) removeInternal(l, oldl);
103: }
104:
105: //-- TreeSelectionChanged ---------------------------------------------------------
106:
107: public static TreeSelectionListener add(TreeSelectionListener a,
108: TreeSelectionListener b) {
109: return (TreeSelectionListener) addInternal(a, b);
110: }
111:
112: public static TreeSelectionListener remove(TreeSelectionListener l,
113: TreeSelectionListener oldl) {
114: return (TreeSelectionListener) removeInternal(l, oldl);
115: }
116:
117: public void selectionChanged(TreeSelectionEvent e) {
118: ((TreeSelectionListener) a).selectionChanged(e);
119: ((TreeSelectionListener) b).selectionChanged(e);
120: }
121:
122: /**
123: * Can't use the superclass method since it creates an AWTEventMulticaster
124: */
125: protected static EventListener addInternal(EventListener a,
126: EventListener b) {
127: if (a == null)
128: return b;
129: if (b == null)
130: return a;
131: return new WidgetEventMulticaster(a, b);
132: }
133:
134: // -- RepeaterListener --------------------------------------
135:
136: public void repeaterModified(RepeaterEvent e) {
137: ((RepeaterListener) a).repeaterModified(e);
138: ((RepeaterListener) b).repeaterModified(e);
139: }
140:
141: public static RepeaterListener add(RepeaterListener a,
142: RepeaterListener b) {
143: return (RepeaterListener) addInternal(a, b);
144: }
145:
146: public static RepeaterListener remove(RepeaterListener l,
147: RepeaterListener oldl) {
148: return (RepeaterListener) removeInternal(l, oldl);
149: }
150:
151: protected EventListener remove(EventListener oldl) {
152: if (oldl == a)
153: return b;
154: if (oldl == b)
155: return a;
156: EventListener a2 = removeInternal(a, oldl);
157: EventListener b2 = removeInternal(b, oldl);
158: if (a2 == a && b2 == b) {
159: return this ; // it's not here
160: }
161: return addInternal(a2, b2);
162: }
163:
164: }
|