2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 import java
.awt
.BorderLayout
;
20 import java
.awt
.Container
;
21 import java
.awt
.Dimension
;
22 import java
.awt
.FlowLayout
;
23 import java
.awt
.event
.ActionEvent
;
24 import java
.awt
.event
.ActionListener
;
25 import java
.util
.Vector
;
27 import javax
.swing
.JButton
;
28 import javax
.swing
.JDialog
;
29 import javax
.swing
.JLabel
;
30 import javax
.swing
.JList
;
31 import javax
.swing
.JOptionPane
;
32 import javax
.swing
.JPanel
;
33 import javax
.swing
.ListSelectionModel
;
35 import com
.sun
.star
.accessibility
.XAccessible
;
36 import com
.sun
.star
.accessibility
.XAccessibleContext
;
37 import com
.sun
.star
.accessibility
.XAccessibleSelection
;
38 import com
.sun
.star
.lang
.IndexOutOfBoundsException
;
41 * Display a dialog with a list-box of children and select/deselect buttons
43 class SelectionDialog
extends JDialog
44 implements ActionListener
46 public SelectionDialog (AccTreeNode aNode
)
48 super (AccessibilityWorkBench
.Instance());
56 private void Layout ()
60 // vertical stacking of the elements
61 Container aContent
= getContentPane();
63 // label with explanation
64 aContent
.add( new JLabel( "Select/Deselect child elements" ),
68 maChildrenSelector
= new JList (GetChildrenList());
69 maChildrenSelector
.setPreferredSize (new Dimension (500,300));
70 aContent
.add (maChildrenSelector
, BorderLayout
.CENTER
);
71 maChildrenSelector
.setSelectionMode (ListSelectionModel
.SINGLE_SELECTION
);
73 JPanel aButtons
= new JPanel();
74 aButtons
.setLayout( new FlowLayout() );
78 aButton
= new JButton( "Select" );
79 aButton
.setActionCommand( "Select" );
80 aButton
.addActionListener( this );
81 aButtons
.add( aButton
);
83 aButton
= new JButton( "Deselect" );
84 aButton
.setActionCommand( "Deselect" );
85 aButton
.addActionListener( this );
86 aButtons
.add( aButton
);
88 aButton
= new JButton( "Select all" );
89 aButton
.setActionCommand( "Select all" );
90 aButton
.addActionListener( this );
91 aButtons
.add( aButton
);
93 aButton
= new JButton( "Clear Selection" );
94 aButton
.setActionCommand( "Clear Selection" );
95 aButton
.addActionListener( this );
96 aButtons
.add( aButton
);
98 aButton
= new JButton( "Close" );
99 aButton
.setActionCommand( "Close" );
100 aButton
.addActionListener( this );
101 aButtons
.add( aButton
);
103 // add Panel with buttons
104 aContent
.add( aButtons
, BorderLayout
.SOUTH
);
106 setSize( getPreferredSize() );
109 /** Get a list of all children
111 private Vector
<String
> GetChildrenList ()
113 mxSelection
= maNode
.getSelection();
115 XAccessibleContext xContext
= maNode
.getContext();
116 int nCount
= xContext
.getAccessibleChildCount();
117 Vector
<String
> aChildVector
= new Vector
<String
>();
118 for(int i
= 0; i
< nCount
; i
++)
122 XAccessible xChild
= xContext
.getAccessibleChild(i
);
123 XAccessibleContext xChildContext
= xChild
.getAccessibleContext();
124 aChildVector
.add( i
+ " " + xChildContext
.getAccessibleName());
126 catch( IndexOutOfBoundsException e
)
128 aChildVector
.add( "ERROR: IndexOutOfBoundsException" );
135 private void close ()
141 private void select()
145 mxSelection
.selectAccessibleChild (maChildrenSelector
.getSelectedIndex());
147 catch( IndexOutOfBoundsException e
)
149 JOptionPane
.showMessageDialog( AccessibilityWorkBench
.Instance(),
150 "Can't select: IndexOutofBounds",
151 "Error in selectAccessibleChild",
152 JOptionPane
.ERROR_MESSAGE
);
156 private void deselect()
160 mxSelection
.deselectAccessibleChild(
161 maChildrenSelector
.getSelectedIndex());
163 catch( IndexOutOfBoundsException e
)
165 JOptionPane
.showMessageDialog( AccessibilityWorkBench
.Instance(),
166 "Can't deselect: IndexOutofBounds",
167 "Error in deselectAccessibleChild",
168 JOptionPane
.ERROR_MESSAGE
);
172 private void selectAll()
174 mxSelection
.selectAllAccessibleChildren();
177 private void clearSelection()
179 mxSelection
.clearAccessibleSelection();
184 public void actionPerformed(ActionEvent e
)
186 String sCommand
= e
.getActionCommand();
188 if( "Close".equals( sCommand
) )
190 else if ( "Select".equals( sCommand
) )
192 else if ( "Deselect".equals( sCommand
) )
194 else if ( "Clear Selection".equals( sCommand
) )
196 else if ( "Select all".equals( sCommand
) )
200 private JList maChildrenSelector
;
201 private XAccessibleSelection mxSelection
;
202 private final AccTreeNode maNode
;