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 import com.sun.star.accessibility.XAccessible;
23 import com.sun.star.accessibility.XAccessibleContext;
24 import com.sun.star.accessibility.AccessibleEventObject;
25 import com.sun.star.uno.UnoRuntime;
26 
27 import java.io.PrintStream;
28 
29 import tools.NameProvider;
30 
31 /** Base class for handling of accessibility events.
32 */
33 class EventHandler
34 {
EventHandler(AccessibleEventObject aEvent, AccessibilityTreeModel aTreeModel)35     public EventHandler (AccessibleEventObject aEvent, AccessibilityTreeModel aTreeModel)
36     {
37         maEvent = aEvent;
38         maTreeModel = aTreeModel;
39 
40         mnEventId = aEvent.EventId;
41 
42         mxEventSource = (XAccessibleContext)UnoRuntime.queryInterface(
43             XAccessibleContext.class, aEvent.Source);
44         if (mxEventSource == null)
45         {
46             XAccessible xAccessible = (XAccessible)UnoRuntime.queryInterface(
47                 XAccessible.class, aEvent.Source);
48             if (xAccessible != null)
49                 mxEventSource = xAccessible.getAccessibleContext();
50         }
51     }
52 
Print(PrintStream out)53     public void Print (PrintStream out)
54     {
55         out.println ("Event id is " + mnEventId
56             + " (" + NameProvider.getEventName(mnEventId)+")"
57             + " for " + mxEventSource.getAccessibleName() + " / "
58             + NameProvider.getRoleName (mxEventSource.getAccessibleRole()));
59         PrintOldAndNew (out);
60     }
61 
PrintOldAndNew(PrintStream out)62     public void PrintOldAndNew (PrintStream out)
63     {
64         out.println ("    old value is " + maEvent.OldValue);
65         out.println ("    new value is " + maEvent.NewValue);
66     }
67 
Process()68     public void Process ()
69     {
70         System.out.println ("processing of event " + maEvent + " not implemented");
71     }
72 
73     protected AccessibleEventObject maEvent;
74     protected AccessibilityTreeModel maTreeModel;
75 
76     protected int mnEventId;
77     protected XAccessibleContext mxEventSource;
78 }
79