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