1 import com
.sun
.star
.uno
.UnoRuntime
;
2 import com
.sun
.star
.accessibility
.XAccessible
;
3 import com
.sun
.star
.accessibility
.XAccessibleContext
;
4 import com
.sun
.star
.accessibility
.XAccessibleSelection
;
5 import com
.sun
.star
.lang
.IndexOutOfBoundsException
;
9 import java
.util
.Vector
;
10 import java
.awt
.event
.ActionListener
;
11 import java
.awt
.event
.ActionEvent
;
17 * Display a dialog with a list-box of children and select/deselect buttons
19 class SelectionDialog
extends JDialog
20 implements ActionListener
22 public SelectionDialog (AccTreeNode aNode
)
24 super (AccessibilityWorkBench
.Instance());
32 protected void Layout ()
36 // vertical stacking of the elements
37 Container aContent
= getContentPane();
39 // label with explanation
40 aContent
.add( new JLabel( "Select/Deselect child elements" ),
44 maChildrenSelector
= new JList (GetChildrenList());
45 maChildrenSelector
.setPreferredSize (new Dimension (500,300));
46 aContent
.add (maChildrenSelector
, BorderLayout
.CENTER
);
47 maChildrenSelector
.setSelectionMode (ListSelectionModel
.SINGLE_SELECTION
);
49 JPanel aButtons
= new JPanel();
50 aButtons
.setLayout( new FlowLayout() );
54 aButton
= new JButton( "Select" );
55 aButton
.setActionCommand( "Select" );
56 aButton
.addActionListener( this );
57 aButtons
.add( aButton
);
59 aButton
= new JButton( "Deselect" );
60 aButton
.setActionCommand( "Deselect" );
61 aButton
.addActionListener( this );
62 aButtons
.add( aButton
);
64 aButton
= new JButton( "Select all" );
65 aButton
.setActionCommand( "Select all" );
66 aButton
.addActionListener( this );
67 aButtons
.add( aButton
);
69 aButton
= new JButton( "Clear Selection" );
70 aButton
.setActionCommand( "Clear Selection" );
71 aButton
.addActionListener( this );
72 aButtons
.add( aButton
);
74 aButton
= new JButton( "Close" );
75 aButton
.setActionCommand( "Close" );
76 aButton
.addActionListener( this );
77 aButtons
.add( aButton
);
79 // add Panel with buttons
80 aContent
.add( aButtons
, BorderLayout
.SOUTH
);
82 setSize( getPreferredSize() );
85 /** Get a list of all children
87 private Vector
GetChildrenList ()
89 mxSelection
= maNode
.getSelection();
91 XAccessibleContext xContext
= maNode
.getContext();
92 int nCount
= xContext
.getAccessibleChildCount();
93 Vector aChildVector
= new Vector();
94 for(int i
= 0; i
< nCount
; i
++)
98 XAccessible xChild
= xContext
.getAccessibleChild(i
);
99 XAccessibleContext xChildContext
= xChild
.getAccessibleContext();
100 aChildVector
.add( i
+ " " + xChildContext
.getAccessibleName());
102 catch( IndexOutOfBoundsException e
)
104 aChildVector
.add( "ERROR: IndexOutOfBoundsException" );
121 mxSelection
.selectAccessibleChild (maChildrenSelector
.getSelectedIndex());
123 catch( IndexOutOfBoundsException e
)
125 JOptionPane
.showMessageDialog( AccessibilityWorkBench
.Instance(),
126 "Can't select: IndexOutofBounds",
127 "Error in selectAccessibleChild",
128 JOptionPane
.ERROR_MESSAGE
);
136 mxSelection
.deselectAccessibleChild(
137 maChildrenSelector
.getSelectedIndex());
139 catch( IndexOutOfBoundsException e
)
141 JOptionPane
.showMessageDialog( AccessibilityWorkBench
.Instance(),
142 "Can't deselect: IndexOutofBounds",
143 "Error in deselectAccessibleChild",
144 JOptionPane
.ERROR_MESSAGE
);
150 mxSelection
.selectAllAccessibleChildren();
153 void clearSelection()
155 mxSelection
.clearAccessibleSelection();
160 public void actionPerformed(ActionEvent e
)
162 String sCommand
= e
.getActionCommand();
164 if( "Close".equals( sCommand
) )
166 else if ( "Select".equals( sCommand
) )
168 else if ( "Deselect".equals( sCommand
) )
170 else if ( "Clear Selection".equals( sCommand
) )
172 else if ( "Select all".equals( sCommand
) )
176 private JList maChildrenSelector
;
177 private XAccessibleSelection mxSelection
;
178 private AccTreeNode maNode
;