1 import com.sun.star.accessibility.XAccessible; 2 import com.sun.star.accessibility.XAccessibleContext; 3 import com.sun.star.accessibility.XAccessibleStateSet; 4 import com.sun.star.uno.UnoRuntime; 5 import com.sun.star.container.XIndexAccess; 6 import java.util.HashMap; 7 8 import tools.NameProvider; 9 10 class AccessibleContextHandler 11 extends NodeHandler 12 { 13 protected int nChildrenCount; 14 15 public NodeHandler createHandler (XAccessibleContext xContext) 16 { 17 if (xContext != null) 18 return new AccessibleContextHandler (xContext); 19 else 20 return null; 21 } 22 23 public AccessibleContextHandler () 24 { 25 super (); 26 } 27 28 public AccessibleContextHandler (XAccessibleContext xContext) 29 { 30 super(); 31 if (xContext != null) 32 maChildList.setSize (4); 33 } 34 35 public AccessibleTreeNode createChild (AccessibleTreeNode aParent, int nIndex) 36 { 37 XAccessibleContext xContext = null; 38 if (aParent instanceof AccTreeNode) 39 xContext = ((AccTreeNode)aParent).getContext(); 40 41 String sChild = new String(); 42 if (xContext != null) 43 { 44 switch( nIndex ) 45 { 46 case 0: 47 sChild = "Description: " + 48 xContext.getAccessibleDescription(); 49 break; 50 case 1: 51 int nRole = xContext.getAccessibleRole(); 52 sChild = "Role: " + nRole + " (" + NameProvider.getRoleName(nRole) + ")"; 53 break; 54 case 2: 55 XAccessible xParent = xContext.getAccessibleParent(); 56 sChild = "Has parent: " + (xParent!=null ? "yes" : "no"); 57 /* if (xParent != ((AccTreeNode)aParent).getAccessible()) 58 { 59 sChild += " but that is inconsistent" 60 + "#" + xParent + " # " + ((AccTreeNode)aParent).getAccessible(); 61 } 62 */ 63 break; 64 case 3: 65 sChild = ""; 66 XAccessibleStateSet xStateSet = 67 xContext.getAccessibleStateSet(); 68 if (xStateSet != null) 69 { 70 for (short i=0; i<=30; i++) 71 { 72 if (xStateSet.contains (i)) 73 { 74 if (sChild.compareTo ("") != 0) 75 sChild += ", "; 76 sChild += NameProvider.getStateName(i); 77 } 78 } 79 } 80 else 81 sChild += "no state set"; 82 sChild = "State set: " + sChild; 83 84 /* case 3: 85 sChild = "Child count: " + xContext.getAccessibleChildCount(); 86 break;*/ 87 } 88 } 89 return new StringNode (sChild, aParent); 90 } 91 } 92