1 2 import com.sun.star.uno.UnoRuntime; 3 import com.sun.star.accessibility.XAccessible; 4 import com.sun.star.accessibility.XAccessibleContext; 5 import com.sun.star.accessibility.XAccessibleSelection; 6 import com.sun.star.lang.IndexOutOfBoundsException; 7 8 import javax.swing.*; 9 import java.awt.*; 10 import java.util.Vector; 11 import java.awt.event.ActionListener; 12 import java.awt.event.ActionEvent; 13 14 15 16 class AccessibleSelectionHandler 17 extends NodeHandler 18 { 19 public NodeHandler createHandler( XAccessibleContext xContext ) 20 { 21 XAccessibleSelection xSelection = 22 (XAccessibleSelection) UnoRuntime.queryInterface( 23 XAccessibleSelection.class, xContext); 24 return (xSelection == null) ? null : 25 new AccessibleSelectionHandler(xSelection); 26 } 27 28 public AccessibleSelectionHandler() 29 { 30 } 31 32 public AccessibleSelectionHandler( XAccessibleSelection xSelection ) 33 { 34 if (xSelection != null) 35 maChildList.setSize( 2 ); 36 } 37 38 public AccessibleTreeNode createChild( AccessibleTreeNode aParent, 39 int nIndex ) 40 { 41 AccessibleTreeNode aChild = null; 42 43 if( aParent instanceof AccTreeNode ) 44 { 45 XAccessibleSelection xSelection = 46 ((AccTreeNode)aParent).getSelection(); 47 if( xSelection != null ) 48 { 49 switch( nIndex ) 50 { 51 case 0: 52 aChild = new StringNode( 53 "getSelectedAccessibleChildCount: " + 54 xSelection.getSelectedAccessibleChildCount(), 55 aParent ); 56 break; 57 case 1: 58 { 59 VectorNode aVNode = 60 new VectorNode( "Selected Children", aParent); 61 int nSelected = 0; 62 int nCount = ((AccTreeNode)aParent).getContext(). 63 getAccessibleChildCount(); 64 try 65 { 66 for( int i = 0; i < nCount; i++ ) 67 { 68 try 69 { 70 if( xSelection.isAccessibleChildSelected( i ) ) 71 { 72 XAccessible xSelChild = xSelection. 73 getSelectedAccessibleChild(nSelected); 74 XAccessible xNChild = 75 ((AccTreeNode)aParent). 76 getContext().getAccessibleChild( i ); 77 aVNode.addChild( new StringNode( 78 i + ": " + 79 xNChild.getAccessibleContext(). 80 getAccessibleDescription() + " (" + 81 (xSelChild.equals(xNChild) ? "OK" : "XXX") + 82 ")", aParent ) ); 83 } 84 } 85 catch (com.sun.star.lang.DisposedException e) 86 { 87 aVNode.addChild( new StringNode( 88 i + ": caught DisposedException while creating", 89 aParent )); 90 } 91 } 92 aChild = aVNode; 93 } 94 catch( IndexOutOfBoundsException e ) 95 { 96 aChild = new StringNode( "IndexOutOfBounds", 97 aParent ); 98 } 99 } 100 break; 101 default: 102 aChild = new StringNode( "ERROR", aParent ); 103 break; 104 } 105 } 106 } 107 108 return aChild; 109 } 110 111 112 public String[] getActions (AccessibleTreeNode aNode) 113 { 114 if( aNode instanceof AccTreeNode ) 115 { 116 XAccessibleSelection xSelection = 117 ((AccTreeNode)aNode).getSelection(); 118 if( xSelection != null ) 119 { 120 return new String[] { "Select..." }; 121 } 122 } 123 return new String[0]; 124 } 125 126 public void performAction (AccessibleTreeNode aNode, int nIndex) 127 { 128 new SelectionDialog( (AccTreeNode)aNode ).show(); 129 } 130 } 131