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 package ov;
23 
24 import com.sun.star.accessibility.AccessibleEventObject;
25 import com.sun.star.accessibility.XAccessibleContext;
26 import com.sun.star.accessibility.XAccessibleEventBroadcaster;
27 import com.sun.star.accessibility.XAccessibleEventListener;
28 import com.sun.star.lang.EventObject;
29 import com.sun.star.uno.UnoRuntime;
30 
31 /** Base class for object views that regsiters as accessibility event
32     listener.
33 */
34 abstract class ListeningObjectView
35     extends ObjectView
36     implements XAccessibleEventListener
37 {
ListeningObjectView(ObjectViewContainer aContainer)38     public ListeningObjectView (ObjectViewContainer aContainer)
39     {
40         super (aContainer);
41     }
42 
43     /** Add this object as event listener at the broadcasting
44         accessible object.
45     */
SetObject(XAccessibleContext xContext)46     public void SetObject (XAccessibleContext xContext)
47     {
48         super.SetObject (xContext);
49         XAccessibleEventBroadcaster xBroadcaster =
50             (XAccessibleEventBroadcaster)UnoRuntime.queryInterface(
51                 XAccessibleEventBroadcaster.class, xContext);
52         if (xBroadcaster != null)
53             xBroadcaster.addEventListener (this);
54     }
55 
56 
57     /** Remove this object as event listener from the broadcasting
58         accessible object.
59     */
Destroy()60     public void Destroy ()
61     {
62         super.Destroy ();
63         XAccessibleEventBroadcaster xBroadcaster =
64             (XAccessibleEventBroadcaster)UnoRuntime.queryInterface(
65                 XAccessibleEventBroadcaster.class, mxContext);
66         if (xBroadcaster != null)
67             xBroadcaster.removeEventListener (this);
68     }
69 
70     /** Derived classes have to implement this method to handle incoming
71         events.
72     */
notifyEvent(AccessibleEventObject aEvent)73     abstract public void notifyEvent (AccessibleEventObject aEvent);
74 
75     /** The disposing event is ignored per default.  If a derived class is
76         interested it can overwrite this method.
77     */
disposing(EventObject aEvent)78     public void disposing (EventObject aEvent)
79     {
80     }
81 }
82