0N/A/*
2362N/A * Copyright (c) 1997, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Apackage sun.applet;
0N/A
0N/Aimport java.util.EventListener;
0N/Aimport java.io.Serializable;
0N/Aimport java.io.ObjectOutputStream;
0N/Aimport java.io.IOException;
0N/A
0N/A/**
0N/A * AppletEventMulticaster class. This class manages an immutable
0N/A * structure consisting of a chain of AppletListeners and is
0N/A * responsible for dispatching events to them.
0N/A *
0N/A * @author Sunita Mani
0N/A */
0N/Apublic class AppletEventMulticaster implements AppletListener {
0N/A
0N/A private final AppletListener a, b;
0N/A
0N/A public AppletEventMulticaster(AppletListener a, AppletListener b) {
0N/A this.a = a; this.b = b;
0N/A }
0N/A
0N/A public void appletStateChanged(AppletEvent e) {
0N/A a.appletStateChanged(e);
0N/A b.appletStateChanged(e);
0N/A }
0N/A
0N/A /**
0N/A * Adds Applet-listener-a with Applet-listener-b and
0N/A * returns the resulting multicast listener.
0N/A * @param a Applet-listener-a
0N/A * @param b Applet-listener-b
0N/A */
0N/A public static AppletListener add(AppletListener a, AppletListener b) {
0N/A return addInternal(a, b);
0N/A }
0N/A
0N/A /**
0N/A * Removes the old Applet-listener from Applet-listener-l and
0N/A * returns the resulting multicast listener.
0N/A * @param l Applet-listener-l
0N/A * @param oldl the Applet-listener being removed
0N/A */
0N/A public static AppletListener remove(AppletListener l, AppletListener oldl) {
0N/A return removeInternal(l, oldl);
0N/A }
0N/A
0N/A /**
0N/A * Returns the resulting multicast listener from adding listener-a
0N/A * and listener-b together.
0N/A * If listener-a is null, it returns listener-b;
0N/A * If listener-b is null, it returns listener-a
0N/A * If neither are null, then it creates and returns
0N/A * a new AppletEventMulticaster instance which chains a with b.
0N/A * @param a event listener-a
0N/A * @param b event listener-b
0N/A */
0N/A private static AppletListener addInternal(AppletListener a, AppletListener b) {
0N/A if (a == null) return b;
0N/A if (b == null) return a;
0N/A return new AppletEventMulticaster(a, b);
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Removes a listener from this multicaster and returns the
0N/A * resulting multicast listener.
0N/A * @param oldl the listener to be removed
0N/A */
0N/A protected AppletListener remove(AppletListener oldl) {
0N/A if (oldl == a) return b;
0N/A if (oldl == b) return a;
0N/A AppletListener a2 = removeInternal(a, oldl);
0N/A AppletListener b2 = removeInternal(b, oldl);
0N/A if (a2 == a && b2 == b) {
0N/A return this; // it's not here
0N/A }
0N/A return addInternal(a2, b2);
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Returns the resulting multicast listener after removing the
0N/A * old listener from listener-l.
0N/A * If listener-l equals the old listener OR listener-l is null,
0N/A * returns null.
0N/A * Else if listener-l is an instance of AppletEventMulticaster
0N/A * then it removes the old listener from it.
0N/A * Else, returns listener l.
0N/A * @param l the listener being removed from
0N/A * @param oldl the listener being removed
0N/A */
0N/A private static AppletListener removeInternal(AppletListener l, AppletListener oldl) {
0N/A if (l == oldl || l == null) {
0N/A return null;
0N/A } else if (l instanceof AppletEventMulticaster) {
0N/A return ((AppletEventMulticaster)l).remove(oldl);
0N/A } else {
0N/A return l; // it's not here
0N/A }
0N/A }
0N/A}