bump product version to 7.2.5.1
[LibreOffice.git] / toolkit / test / accessibility / SelectionDialog.java
blob2f0c6d54344641e69fc4c4411f22147d238d7952
1 /*
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;
40 /**
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());
50 maNode = aNode;
52 Layout();
55 /** build dialog */
56 private void Layout ()
58 setTitle( "Select" );
60 // vertical stacking of the elements
61 Container aContent = getContentPane();
63 // label with explanation
64 aContent.add( new JLabel( "Select/Deselect child elements" ),
65 BorderLayout.NORTH );
67 // the JListBox
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() );
76 JButton aButton;
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" );
131 return aChildVector;
135 private void close ()
137 setVisible(false);
138 dispose();
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 ) )
189 close();
190 else if ( "Select".equals( sCommand ) )
191 select();
192 else if ( "Deselect".equals( sCommand ) )
193 deselect();
194 else if ( "Clear Selection".equals( sCommand ) )
195 clearSelection();
196 else if ( "Select all".equals( sCommand ) )
197 selectAll();
200 private JList maChildrenSelector;
201 private XAccessibleSelection mxSelection;
202 private final AccTreeNode maNode;