Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/sun/applet/AppletEventMulticaster.java
38829 views
/*1* Copyright (c) 1997, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package sun.applet;2627import java.util.EventListener;28import java.io.Serializable;29import java.io.ObjectOutputStream;30import java.io.IOException;3132/**33* AppletEventMulticaster class. This class manages an immutable34* structure consisting of a chain of AppletListeners and is35* responsible for dispatching events to them.36*37* @author Sunita Mani38*/39public class AppletEventMulticaster implements AppletListener {4041private final AppletListener a, b;4243public AppletEventMulticaster(AppletListener a, AppletListener b) {44this.a = a; this.b = b;45}4647public void appletStateChanged(AppletEvent e) {48a.appletStateChanged(e);49b.appletStateChanged(e);50}5152/**53* Adds Applet-listener-a with Applet-listener-b and54* returns the resulting multicast listener.55* @param a Applet-listener-a56* @param b Applet-listener-b57*/58public static AppletListener add(AppletListener a, AppletListener b) {59return addInternal(a, b);60}6162/**63* Removes the old Applet-listener from Applet-listener-l and64* returns the resulting multicast listener.65* @param l Applet-listener-l66* @param oldl the Applet-listener being removed67*/68public static AppletListener remove(AppletListener l, AppletListener oldl) {69return removeInternal(l, oldl);70}7172/**73* Returns the resulting multicast listener from adding listener-a74* and listener-b together.75* If listener-a is null, it returns listener-b;76* If listener-b is null, it returns listener-a77* If neither are null, then it creates and returns78* a new AppletEventMulticaster instance which chains a with b.79* @param a event listener-a80* @param b event listener-b81*/82private static AppletListener addInternal(AppletListener a, AppletListener b) {83if (a == null) return b;84if (b == null) return a;85return new AppletEventMulticaster(a, b);86}878889/**90* Removes a listener from this multicaster and returns the91* resulting multicast listener.92* @param oldl the listener to be removed93*/94protected AppletListener remove(AppletListener oldl) {95if (oldl == a) return b;96if (oldl == b) return a;97AppletListener a2 = removeInternal(a, oldl);98AppletListener b2 = removeInternal(b, oldl);99if (a2 == a && b2 == b) {100return this; // it's not here101}102return addInternal(a2, b2);103}104105106/**107* Returns the resulting multicast listener after removing the108* old listener from listener-l.109* If listener-l equals the old listener OR listener-l is null,110* returns null.111* Else if listener-l is an instance of AppletEventMulticaster112* then it removes the old listener from it.113* Else, returns listener l.114* @param l the listener being removed from115* @param oldl the listener being removed116*/117private static AppletListener removeInternal(AppletListener l, AppletListener oldl) {118if (l == oldl || l == null) {119return null;120} else if (l instanceof AppletEventMulticaster) {121return ((AppletEventMulticaster)l).remove(oldl);122} else {123return l; // it's not here124}125}126}127128129