1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 package org.openoffice.accessibility.misc; 25 26 import com.sun.star.lang.EventObject; 27 28 import com.sun.star.accessibility.AccessibleEventObject; 29 import com.sun.star.accessibility.XAccessibleEventBroadcaster; 30 import com.sun.star.accessibility.XAccessibleEventListener; 31 32 /** 33 * 34 */ 35 public class AccessibleEventMulticaster implements XAccessibleEventListener { 36 37 private final XAccessibleEventListener a; 38 private final XAccessibleEventListener b; 39 40 /** Creates a new instance of AccessibleEventMulticaster */ AccessibleEventMulticaster(XAccessibleEventListener a, XAccessibleEventListener b)41 protected AccessibleEventMulticaster(XAccessibleEventListener a, 42 XAccessibleEventListener b) { 43 this.a = a; 44 this.b = b; 45 } 46 remove(XAccessibleEventListener l)47 protected XAccessibleEventListener remove(XAccessibleEventListener l) { 48 if (l == a) 49 return b; 50 if (l == b) 51 return a; 52 XAccessibleEventListener a2 = remove(a, l); 53 XAccessibleEventListener b2 = remove(b, l); 54 if (a2 == a && b2 == b) { 55 return this; // not found 56 } 57 return add(a2, b2); 58 } 59 notifyEvent(AccessibleEventObject accessibleEventObject)60 public void notifyEvent(AccessibleEventObject accessibleEventObject) { 61 a.notifyEvent(accessibleEventObject); 62 b.notifyEvent(accessibleEventObject); 63 } 64 disposing(EventObject eventObject)65 public void disposing(EventObject eventObject) { 66 a.disposing(eventObject); 67 b.disposing(eventObject); 68 } 69 add(XAccessibleEventListener a, XAccessibleEventListener b)70 public static XAccessibleEventListener add(XAccessibleEventListener a, XAccessibleEventListener b) { 71 if (a == null) 72 return b; 73 if (b == null) 74 return a; 75 return new AccessibleEventMulticaster(a,b); 76 } 77 remove(XAccessibleEventListener l, XAccessibleEventListener oldl)78 public static XAccessibleEventListener remove(XAccessibleEventListener l, XAccessibleEventListener oldl) { 79 if (l == oldl || l == null) { 80 return null; 81 } else if (l instanceof AccessibleEventMulticaster) { 82 return ((AccessibleEventMulticaster) l).remove(oldl); 83 } else { 84 return l; 85 } 86 } 87 88 } 89