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.XAccessibleStateSet;
25 import com.sun.star.uno.UnoRuntime;
26 import com.sun.star.container.XIndexAccess;
27 import java.util.HashMap;
28 
29 import tools.NameProvider;
30 
31 class AccessibleContextHandler
32     extends NodeHandler
33 {
34     protected int nChildrenCount;
35 
createHandler(XAccessibleContext xContext)36     public NodeHandler createHandler (XAccessibleContext xContext)
37     {
38         if (xContext != null)
39             return new AccessibleContextHandler (xContext);
40         else
41             return null;
42     }
43 
AccessibleContextHandler()44     public AccessibleContextHandler ()
45     {
46         super ();
47     }
48 
AccessibleContextHandler(XAccessibleContext xContext)49     public AccessibleContextHandler (XAccessibleContext xContext)
50     {
51         super();
52         if (xContext != null)
53             maChildList.setSize (4);
54     }
55 
createChild(AccessibleTreeNode aParent, int nIndex)56     public AccessibleTreeNode createChild (AccessibleTreeNode aParent, int nIndex)
57     {
58         XAccessibleContext xContext = null;
59         if (aParent instanceof AccTreeNode)
60             xContext = ((AccTreeNode)aParent).getContext();
61 
62         String sChild = new String();
63         if (xContext != null)
64         {
65             switch( nIndex )
66             {
67                 case 0:
68                     sChild = "Description: " +
69                         xContext.getAccessibleDescription();
70                     break;
71                 case 1:
72                     int nRole = xContext.getAccessibleRole();
73                     sChild = "Role: " + nRole + " (" + NameProvider.getRoleName(nRole) + ")";
74                     break;
75                 case 2:
76                     XAccessible xParent = xContext.getAccessibleParent();
77                     sChild = "Has parent: " + (xParent!=null ? "yes" : "no");
78                     /*                    if (xParent != ((AccTreeNode)aParent).getAccessible())
79                     {
80                         sChild += " but that is inconsistent"
81                             + "#" + xParent + " # " + ((AccTreeNode)aParent).getAccessible();
82                     }
83                     */
84                     break;
85                 case 3:
86                     sChild = "";
87                     XAccessibleStateSet xStateSet =
88                         xContext.getAccessibleStateSet();
89                     if (xStateSet != null)
90                     {
91                         for (short i=0; i<=30; i++)
92                         {
93                             if (xStateSet.contains (i))
94                             {
95                                 if (sChild.compareTo ("") != 0)
96                                     sChild += ", ";
97                                 sChild += NameProvider.getStateName(i);
98                             }
99                         }
100                     }
101                     else
102                         sChild += "no state set";
103                     sChild = "State set: " + sChild;
104 
105                     /*                case 3:
106                     sChild = "Child count: " + xContext.getAccessibleChildCount();
107                     break;*/
108             }
109         }
110         return new StringNode (sChild, aParent);
111     }
112 }
113