1 2 import com.sun.star.uno.UnoRuntime; 3 import com.sun.star.accessibility.XAccessibleContext; 4 import com.sun.star.accessibility.XAccessibleComponent; 5 6 7 class AccessibleComponentHandler 8 extends NodeHandler 9 { 10 11 public NodeHandler createHandler (XAccessibleContext xContext) 12 { 13 XAccessibleComponent xComponent = 14 (XAccessibleComponent) UnoRuntime.queryInterface ( 15 XAccessibleComponent.class, xContext); 16 if (xComponent != null) 17 return new AccessibleComponentHandler (xComponent); 18 else 19 return null; 20 21 } 22 23 public AccessibleComponentHandler () 24 { 25 } 26 27 public AccessibleComponentHandler (XAccessibleComponent xComponent) 28 { 29 if (xComponent != null) 30 maChildList.setSize (6); 31 } 32 33 public AccessibleTreeNode createChild (AccessibleTreeNode aParent, int nIndex) 34 { 35 AccessibleTreeNode aChild = null; 36 if (aParent instanceof AccTreeNode) 37 { 38 XAccessibleComponent xComponent = 39 ((AccTreeNode)aParent).getComponent(); 40 41 if (xComponent != null) 42 { 43 int nColor; 44 switch (nIndex) 45 { 46 case 0: 47 com.sun.star.awt.Point aLocation = xComponent.getLocation(); 48 aChild = new StringNode ( 49 "Location: " + aLocation.X + ", " + aLocation.Y, 50 aParent); 51 break; 52 case 1: 53 com.sun.star.awt.Point aScreenLocation = xComponent.getLocationOnScreen(); 54 aChild = new StringNode ( 55 "Location on Screen: " + aScreenLocation.X + ", " + aScreenLocation.Y, 56 aParent); 57 break; 58 case 2: 59 com.sun.star.awt.Size aSize = xComponent.getSize(); 60 aChild = new StringNode ( 61 "Size: "+ aSize.Width + ", " + aSize.Height, 62 aParent); 63 break; 64 case 3: 65 com.sun.star.awt.Rectangle aBBox = xComponent.getBounds(); 66 aChild = new StringNode ( 67 "Bounding Box: "+ aBBox.X + ", " + aBBox.Y + "," 68 + aBBox.Width + ", " + aBBox.Height, 69 aParent); 70 break; 71 case 4: 72 nColor = xComponent.getForeground(); 73 aChild = new StringNode ("Foreground color: R" 74 + (nColor>>16&0xff) 75 + "G" + (nColor>>8&0xff) 76 + "B" + (nColor>>0&0xff) 77 + "A" + (nColor>>24&0xff), 78 aParent); 79 break; 80 case 5: 81 nColor = xComponent.getBackground(); 82 aChild = new StringNode ("Background color: R" 83 + (nColor>>16&0xff) 84 + "G" + (nColor>>8&0xff) 85 + "B" + (nColor>>0&0xff) 86 + "A" + (nColor>>24&0xff), 87 aParent); 88 break; 89 } 90 } 91 } 92 return aChild; 93 } 94 95 public void update (AccessibleTreeNode aNode) 96 { 97 maChildList.clear(); 98 if (aNode instanceof AccTreeNode) 99 if (((AccTreeNode)aNode).getComponent() != null) 100 maChildList.setSize (4); 101 } 102 } 103