merge the formfield patch from ooo-build
[ooovba.git] / odk / examples / DevelopersGuide / Accessibility / SSR.java
blobb3b8d812c53f7cd6b2470a9abbed1852e71344df
1 /*************************************************************************
3 * $RCSfile: SSR.java,v $
5 * $Revision: 1.3 $
7 * last change: $Author: hr $ $Date: 2003-06-30 15:07:37 $
9 * The Contents of this file are made available subject to the terms of
10 * the BSD license.
12 * Copyright (c) 2003 by Sun Microsystems, Inc.
13 * All rights reserved.
15 * Redistribution and use in source and binary forms, with or without
16 * modification, are permitted provided that the following conditions
17 * are met:
18 * 1. Redistributions of source code must retain the above copyright
19 * notice, this list of conditions and the following disclaimer.
20 * 2. Redistributions in binary form must reproduce the above copyright
21 * notice, this list of conditions and the following disclaimer in the
22 * documentation and/or other materials provided with the distribution.
23 * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
24 * contributors may be used to endorse or promote products derived
25 * from this software without specific prior written permission.
27 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
30 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
31 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
32 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
33 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
34 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
35 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
36 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
37 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 *************************************************************************/
41 import java.awt.event.ActionListener;
42 import java.awt.GridBagLayout;
43 import java.awt.GridBagConstraints;
44 import javax.swing.*;
47 /** The simple screen reader (SSR) registers at the toolkit as focus listener
48 and displays information about the currently focused object.
50 public class SSR
51 implements ActionListener
53 /** Just pass the control to the SSR class.
55 public static void main (String args[])
57 new SSR ();
63 /** Create a new instance of the simple screen reader.
65 public SSR ()
67 Layout ();
69 // Create the event handler and tell it where to display information
70 // about the currently focused accessible object.
71 maEventHandler = new EventHandler ();
72 maEventHandler.addObjectDisplay (maTextualDisplay);
73 maEventHandler.addObjectDisplay (maGraphicalDisplay);
79 /** Setup the GUI. It is divided into three areas. The lower half is
80 ocupied by a message area that logs all the events received from
81 accessibility objects. The upper half is shared by two different
82 displays of the currently focused object. On left there is a textual
83 representation. On the right there is a graphical view of the
84 objects's outline.
86 private void Layout ()
88 GridBagConstraints constraints;
90 JPanel aPanel = new JPanel (true);
91 aPanel.setLayout (new GridBagLayout());
92 aPanel.setOpaque (true);
94 mFrame = new JFrame ("Simple Screen Reader 0.3");
95 mFrame.setContentPane(aPanel);
96 mFrame.setSize (600,400);
99 addComponent (new JLabel ("Focused Object:"),
100 0,0, 1,1, 0,0, GridBagConstraints.WEST, GridBagConstraints.NONE);
103 maTextualDisplay = new TextualDisplay ();
104 addComponent (maTextualDisplay,
105 0,1, 1,1, 1,1, GridBagConstraints.CENTER, GridBagConstraints.BOTH);
107 maGraphicalDisplay = new GraphicalDisplay ();
108 addComponent (maGraphicalDisplay,
109 1,0, 1,2, 1,1, GridBagConstraints.CENTER, GridBagConstraints.BOTH);
111 addComponent (new JLabel ("Messages:"),
112 0,2, 1,1, 0,0, GridBagConstraints.WEST, GridBagConstraints.NONE);
114 addComponent (MessageArea.Instance(),
115 0,3, 2,1, 1,1, GridBagConstraints.CENTER, GridBagConstraints.BOTH);
118 JButton aButton = new JButton ("Quit SSR");
119 addComponent (aButton,
120 0,4, 1,1, 0,0, GridBagConstraints.WEST,GridBagConstraints.NONE);
121 aButton.addActionListener (this);
123 mFrame.show();
129 /** Add a GUI element with the given constraints to the main window.
131 private JComponent addComponent (JComponent aComponent,
132 int x, int y, int width, int height, double weightx, double weighty,
133 int anchor, int fill)
135 aComponent.setDoubleBuffered (false);
136 GridBagConstraints aConstraints = new GridBagConstraints();
137 aConstraints.gridx = x;
138 aConstraints.gridy = y;
139 aConstraints.gridwidth = width;
140 aConstraints.gridheight = height;
141 aConstraints.weightx = weightx;
142 aConstraints.weighty = weighty;
143 aConstraints.anchor = anchor;
144 aConstraints.fill = fill;
146 mFrame.getContentPane().add (aComponent, aConstraints);
148 return aComponent;
154 /** This call-back handles button presses.
156 public void actionPerformed (java.awt.event.ActionEvent e)
158 if (e.getActionCommand().equals ("Quit SSR"))
160 maEventHandler.finalize ();
161 System.exit(0);
166 /// The main frame that contains all other GUI elements.
167 private JFrame mFrame;
169 /// A textutal representation of the currently focused object.
170 private TextualDisplay maTextualDisplay;
172 /// A graphical representation of the currently focused object.
173 private GraphicalDisplay maGraphicalDisplay;
175 /// The event handler that reacts to all the accessibility events.
176 private EventHandler maEventHandler;