1*1b0aaa91SAndrew Rist /**************************************************************
2*1b0aaa91SAndrew Rist  *
3*1b0aaa91SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*1b0aaa91SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*1b0aaa91SAndrew Rist  * distributed with this work for additional information
6*1b0aaa91SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*1b0aaa91SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*1b0aaa91SAndrew Rist  * "License"); you may not use this file except in compliance
9*1b0aaa91SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*1b0aaa91SAndrew Rist  *
11*1b0aaa91SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*1b0aaa91SAndrew Rist  *
13*1b0aaa91SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*1b0aaa91SAndrew Rist  * software distributed under the License is distributed on an
15*1b0aaa91SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*1b0aaa91SAndrew Rist  * KIND, either express or implied.  See the License for the
17*1b0aaa91SAndrew Rist  * specific language governing permissions and limitations
18*1b0aaa91SAndrew Rist  * under the License.
19*1b0aaa91SAndrew Rist  *
20*1b0aaa91SAndrew Rist  *************************************************************/
21*1b0aaa91SAndrew Rist 
22cdf0e10cSrcweir import com.sun.star.awt.XWindow;
23cdf0e10cSrcweir import com.sun.star.beans.XPropertySet;
24cdf0e10cSrcweir import com.sun.star.beans.XPropertyChangeListener;
25cdf0e10cSrcweir import com.sun.star.beans.PropertyChangeEvent;
26cdf0e10cSrcweir import com.sun.star.container.XEnumerationAccess;
27cdf0e10cSrcweir import com.sun.star.container.XEnumeration;
28cdf0e10cSrcweir import com.sun.star.document.XEventListener;
29cdf0e10cSrcweir import com.sun.star.drawing.XDrawPage;
30cdf0e10cSrcweir import com.sun.star.drawing.XDrawView;
31cdf0e10cSrcweir import com.sun.star.frame.XController;
32cdf0e10cSrcweir import com.sun.star.frame.XFrame;
33cdf0e10cSrcweir import com.sun.star.frame.XFrameActionListener;
34cdf0e10cSrcweir import com.sun.star.frame.FrameActionEvent;
35cdf0e10cSrcweir import com.sun.star.frame.FrameAction;
36cdf0e10cSrcweir import com.sun.star.lang.XComponent;
37cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory;
38cdf0e10cSrcweir import com.sun.star.lang.XServiceInfo;
39cdf0e10cSrcweir import com.sun.star.frame.XDesktop;
40cdf0e10cSrcweir import com.sun.star.frame.XModel;
41cdf0e10cSrcweir import com.sun.star.frame.XTerminateListener;
42cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime;
43cdf0e10cSrcweir 
44cdf0e10cSrcweir import com.sun.star.accessibility.XAccessible;
45cdf0e10cSrcweir import com.sun.star.accessibility.XAccessibleContext;
46cdf0e10cSrcweir import com.sun.star.accessibility.XAccessibleComponent;
47cdf0e10cSrcweir import com.sun.star.accessibility.XAccessibleExtendedComponent;
48cdf0e10cSrcweir import com.sun.star.accessibility.XAccessibleRelationSet;
49cdf0e10cSrcweir import com.sun.star.accessibility.XAccessibleStateSet;
50cdf0e10cSrcweir 
51cdf0e10cSrcweir import com.sun.star.awt.XExtendedToolkit;
52cdf0e10cSrcweir 
53cdf0e10cSrcweir import java.util.Vector;
54cdf0e10cSrcweir import java.awt.*;
55cdf0e10cSrcweir import java.awt.event.*;
56cdf0e10cSrcweir import javax.swing.*;
57cdf0e10cSrcweir import javax.swing.tree.*;
58cdf0e10cSrcweir import javax.swing.event.TreeSelectionListener;
59cdf0e10cSrcweir import javax.swing.event.TreeSelectionEvent;
60cdf0e10cSrcweir import java.io.*;
61cdf0e10cSrcweir 
62cdf0e10cSrcweir import ov.ObjectViewContainer;
63cdf0e10cSrcweir 
64cdf0e10cSrcweir /** This class manages the GUI of the work bench.
65cdf0e10cSrcweir     @see AccessibilityTreeModel
66cdf0e10cSrcweir         for the implementation of the tree view on the left side which also
67cdf0e10cSrcweir         manages the registration of accessibility listeners.
68cdf0e10cSrcweir     @see Canvas
69cdf0e10cSrcweir         for the graphical view of the accessible objects.
70cdf0e10cSrcweir */
71cdf0e10cSrcweir public class AccessibilityWorkBench
72cdf0e10cSrcweir     extends JFrame
73cdf0e10cSrcweir     implements ActionListener, XTerminateListener, TreeSelectionListener
74cdf0e10cSrcweir 
75cdf0e10cSrcweir {
76cdf0e10cSrcweir     public static final String msVersion = "v1.7.2";
77cdf0e10cSrcweir     public String msOptionsFileName = ".AWBrc";
78cdf0e10cSrcweir 
79cdf0e10cSrcweir     public static void main (String args[])
80cdf0e10cSrcweir     {
81cdf0e10cSrcweir         int nPortNumber = 5678;
82cdf0e10cSrcweir 
83cdf0e10cSrcweir         for (int i=0; i<args.length; i++)
84cdf0e10cSrcweir         {
85cdf0e10cSrcweir             if (args[i].equals ("-h") || args[i].equals ("--help") || args[i].equals ("-?"))
86cdf0e10cSrcweir             {
87cdf0e10cSrcweir                 System.out.println ("usage: AccessibilityWorkBench <option>*");
88cdf0e10cSrcweir                 System.out.println ("options:");
89cdf0e10cSrcweir                 System.out.println ("   -p <port-number>   Port on which to connect to StarOffice.");
90cdf0e10cSrcweir                 System.out.println ("                      Defaults to 5678.");
91cdf0e10cSrcweir                 System.exit (0);
92cdf0e10cSrcweir             }
93cdf0e10cSrcweir             else if (args[i].equals ("-p"))
94cdf0e10cSrcweir             {
95cdf0e10cSrcweir                 nPortNumber = Integer.parseInt (args[++i]);
96cdf0e10cSrcweir             }
97cdf0e10cSrcweir         }
98cdf0e10cSrcweir 
99cdf0e10cSrcweir         saWorkBench = new AccessibilityWorkBench (nPortNumber);
100cdf0e10cSrcweir     }
101cdf0e10cSrcweir 
102cdf0e10cSrcweir 
103cdf0e10cSrcweir 
104cdf0e10cSrcweir 
105cdf0e10cSrcweir     /** Return the one instance of the AccessibilityWorkBench
106cdf0e10cSrcweir         @return
107cdf0e10cSrcweir             Returns null when the AccessibilityWorkBench could not be
108cdf0e10cSrcweir             created successfully.
109cdf0e10cSrcweir     */
110cdf0e10cSrcweir     public static AccessibilityWorkBench Instance ()
111cdf0e10cSrcweir     {
112cdf0e10cSrcweir         return saWorkBench;
113cdf0e10cSrcweir     }
114cdf0e10cSrcweir 
115cdf0e10cSrcweir 
116cdf0e10cSrcweir 
117cdf0e10cSrcweir     /** Create an accessibility work bench that listens at the specified
118cdf0e10cSrcweir         port to Office applications.
119cdf0e10cSrcweir     */
120cdf0e10cSrcweir     private AccessibilityWorkBench (int nPortNumber)
121cdf0e10cSrcweir     {
122cdf0e10cSrcweir         mbInitialized = false;
123cdf0e10cSrcweir 
124cdf0e10cSrcweir         Layout ();
125cdf0e10cSrcweir 
126cdf0e10cSrcweir         MessageArea.println (System.getProperty ("os.name") + " / "
127cdf0e10cSrcweir             + System.getProperty ("os.arch") + " / "
128cdf0e10cSrcweir             + System.getProperty ("os.version"));
129cdf0e10cSrcweir         MessageArea.println ("Using port " + nPortNumber);
130cdf0e10cSrcweir         office = new SimpleOffice (nPortNumber);
131cdf0e10cSrcweir         info = new InformationWriter ();
132cdf0e10cSrcweir 
133cdf0e10cSrcweir         maAccessibilityTree.getComponent().addTreeSelectionListener (this);
134cdf0e10cSrcweir 
135cdf0e10cSrcweir         addWindowListener (new WindowAdapter ()
136cdf0e10cSrcweir             { public void windowClosing (WindowEvent e)
137cdf0e10cSrcweir                   { System.exit(0); }
138cdf0e10cSrcweir             });
139cdf0e10cSrcweir 
140cdf0e10cSrcweir         initialize ();
141cdf0e10cSrcweir     }
142cdf0e10cSrcweir 
143cdf0e10cSrcweir 
144cdf0e10cSrcweir 
145cdf0e10cSrcweir 
146cdf0e10cSrcweir     /** Create and arrange the widgets of the GUI.
147cdf0e10cSrcweir     */
148cdf0e10cSrcweir     public void Layout  ()
149cdf0e10cSrcweir     {
150cdf0e10cSrcweir         setSize (new Dimension (8000,600));
151cdf0e10cSrcweir 
152cdf0e10cSrcweir         JScrollPane aScrollPane;
153cdf0e10cSrcweir         GridBagConstraints constraints;
154cdf0e10cSrcweir 
155cdf0e10cSrcweir         // Create new layout.
156cdf0e10cSrcweir         GridBagLayout aLayout = new GridBagLayout ();
157cdf0e10cSrcweir         getContentPane().setLayout (aLayout);
158cdf0e10cSrcweir 
159cdf0e10cSrcweir         //  Accessible Tree.
160cdf0e10cSrcweir         maAccessibilityTree = new AccessibilityTree ();
161cdf0e10cSrcweir         //        maAccessibilityTree.getComponent().setMinimumSize (new Dimension (250,300));
162cdf0e10cSrcweir         JScrollPane aTreeScrollPane = new JScrollPane(
163cdf0e10cSrcweir             maAccessibilityTree.getComponent(),
164cdf0e10cSrcweir             JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
165cdf0e10cSrcweir             JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
166cdf0e10cSrcweir         aTreeScrollPane.setPreferredSize (new Dimension (400,300));
167cdf0e10cSrcweir 
168cdf0e10cSrcweir         // Object view shows details about the currently selected accessible
169cdf0e10cSrcweir         // object.
170cdf0e10cSrcweir         maObjectViewContainer = new ObjectViewContainer ();
171cdf0e10cSrcweir         //        maObjectViewContainer.setPreferredSize (new Dimension (300,100));
172cdf0e10cSrcweir         JScrollPane aObjectViewContainerScrollPane = new JScrollPane(
173cdf0e10cSrcweir             maObjectViewContainer,
174cdf0e10cSrcweir             JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
175cdf0e10cSrcweir             JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
176cdf0e10cSrcweir         aObjectViewContainerScrollPane.setPreferredSize (new Dimension (400,300));
177cdf0e10cSrcweir 
178cdf0e10cSrcweir         // Split pane for tree view and object view.
179cdf0e10cSrcweir         JSplitPane aLeftViewSplitPane = new JSplitPane (
180cdf0e10cSrcweir             JSplitPane.VERTICAL_SPLIT,
181cdf0e10cSrcweir             aTreeScrollPane,
182cdf0e10cSrcweir             aObjectViewContainerScrollPane
183cdf0e10cSrcweir             );
184cdf0e10cSrcweir         aLeftViewSplitPane.setDividerLocation (300);
185cdf0e10cSrcweir 
186cdf0e10cSrcweir         //  Canvas.
187cdf0e10cSrcweir         maCanvas = new Canvas ();
188cdf0e10cSrcweir         maCanvas.setTree (maAccessibilityTree.getComponent());
189cdf0e10cSrcweir         maAccessibilityTree.SetCanvas (maCanvas);
190cdf0e10cSrcweir         JScrollPane aScrolledCanvas = new JScrollPane(maCanvas,
191cdf0e10cSrcweir             JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
192cdf0e10cSrcweir             JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
193cdf0e10cSrcweir         aScrolledCanvas.getViewport().setBackground (Color.RED);
194cdf0e10cSrcweir         aScrolledCanvas.setPreferredSize (new Dimension(600,400));
195cdf0e10cSrcweir 
196cdf0e10cSrcweir         // Split pane for tree view and canvas.
197cdf0e10cSrcweir         JSplitPane aViewSplitPane = new JSplitPane (
198cdf0e10cSrcweir             JSplitPane.HORIZONTAL_SPLIT,
199cdf0e10cSrcweir             aLeftViewSplitPane,
200cdf0e10cSrcweir             aScrolledCanvas
201cdf0e10cSrcweir             );
202cdf0e10cSrcweir         aViewSplitPane.setOneTouchExpandable(true);
203cdf0e10cSrcweir         aViewSplitPane.setDividerLocation (400);
204cdf0e10cSrcweir 
205cdf0e10cSrcweir         //  Text output area.
206cdf0e10cSrcweir         maMessageArea = MessageArea.Instance ();
207cdf0e10cSrcweir         //        maMessageArea.setPreferredSize (new Dimension (300,50));
208cdf0e10cSrcweir 
209cdf0e10cSrcweir         // Split pane for the two views and the message area.
210cdf0e10cSrcweir         JSplitPane aSplitPane = new JSplitPane (JSplitPane.VERTICAL_SPLIT,
211cdf0e10cSrcweir             aViewSplitPane, maMessageArea);
212cdf0e10cSrcweir         aSplitPane.setOneTouchExpandable(true);
213cdf0e10cSrcweir         addGridElement (aViewSplitPane, 0,0, 2,1, 3,3,
214cdf0e10cSrcweir             GridBagConstraints.CENTER, GridBagConstraints.BOTH);
215cdf0e10cSrcweir 
216cdf0e10cSrcweir         // Button bar.
217cdf0e10cSrcweir         maButtonBar = new JPanel();
218cdf0e10cSrcweir         GridBagLayout aButtonLayout = new GridBagLayout ();
219cdf0e10cSrcweir         maButtonBar.setLayout (new FlowLayout());
220cdf0e10cSrcweir         addGridElement (maButtonBar, 0,3, 2,1, 1,0,
221cdf0e10cSrcweir             GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL);
222cdf0e10cSrcweir 
223cdf0e10cSrcweir         //  Buttons.
224cdf0e10cSrcweir         aConnectButton = createButton ("Connect", "connect");
225cdf0e10cSrcweir         aUpdateButton = createButton ("Update", "update");
226cdf0e10cSrcweir         aShapesButton = createButton ("Expand Shapes", "shapes");
227cdf0e10cSrcweir         aExpandButton = createButton ("Expand All", "expand");
228cdf0e10cSrcweir         aQuitButton = createButton ("Quit", "quit");
229cdf0e10cSrcweir         UpdateButtonStates ();
230cdf0e10cSrcweir 
231cdf0e10cSrcweir         Options.Instance().Load (msOptionsFileName);
232cdf0e10cSrcweir 
233cdf0e10cSrcweir         setJMenuBar (CreateMenuBar ());
234cdf0e10cSrcweir 
235cdf0e10cSrcweir         setTitle("Accessibility Workbench " + msVersion);
236cdf0e10cSrcweir 
237cdf0e10cSrcweir         pack ();
238cdf0e10cSrcweir         setVisible (true);
239cdf0e10cSrcweir         validate ();
240cdf0e10cSrcweir         repaint();
241cdf0e10cSrcweir     }
242cdf0e10cSrcweir 
243cdf0e10cSrcweir 
244cdf0e10cSrcweir 
245cdf0e10cSrcweir 
246cdf0e10cSrcweir     /** Shortcut method for adding an object to a GridBagLayout.
247cdf0e10cSrcweir     */
248cdf0e10cSrcweir     void addGridElement (JComponent object,
249cdf0e10cSrcweir         int x, int y, int width, int height, int weightx, int weighty,
250cdf0e10cSrcweir         int anchor, int fill)
251cdf0e10cSrcweir     {
252cdf0e10cSrcweir         GridBagConstraints constraints = new GridBagConstraints ();
253cdf0e10cSrcweir         constraints.gridx = x;
254cdf0e10cSrcweir         constraints.gridy = y;
255cdf0e10cSrcweir         constraints.gridwidth = width;
256cdf0e10cSrcweir         constraints.gridheight = height;
257cdf0e10cSrcweir         constraints.weightx = weightx;
258cdf0e10cSrcweir         constraints.weighty = weighty;
259cdf0e10cSrcweir         constraints.anchor = anchor;
260cdf0e10cSrcweir         constraints.fill = fill;
261cdf0e10cSrcweir         getContentPane().add (object, constraints);
262cdf0e10cSrcweir     }
263cdf0e10cSrcweir 
264cdf0e10cSrcweir 
265cdf0e10cSrcweir 
266cdf0e10cSrcweir 
267cdf0e10cSrcweir     /** Create a new button and place at the right most position into the
268cdf0e10cSrcweir         button bar.
269cdf0e10cSrcweir     */
270cdf0e10cSrcweir     public JButton createButton (String title, String command)
271cdf0e10cSrcweir     {
272cdf0e10cSrcweir         JButton aButton = new JButton (title);
273cdf0e10cSrcweir         aButton.setEnabled (false);
274cdf0e10cSrcweir         aButton.setActionCommand (command);
275cdf0e10cSrcweir         aButton.addActionListener (this);
276cdf0e10cSrcweir 
277cdf0e10cSrcweir         maButtonBar.add (aButton);
278cdf0e10cSrcweir         return aButton;
279cdf0e10cSrcweir     }
280cdf0e10cSrcweir 
281cdf0e10cSrcweir 
282cdf0e10cSrcweir 
283cdf0e10cSrcweir 
284cdf0e10cSrcweir     /** Create a menu bar for the application.
285cdf0e10cSrcweir         @return
286cdf0e10cSrcweir             Returns the new menu bar.  The returned reference is also
287cdf0e10cSrcweir             remembered in the data member <member>maMenuBar</member>.
288cdf0e10cSrcweir     */
289cdf0e10cSrcweir     JMenuBar CreateMenuBar ()
290cdf0e10cSrcweir     {
291cdf0e10cSrcweir         // Menu bar.
292cdf0e10cSrcweir         maMenuBar = new JMenuBar ();
293cdf0e10cSrcweir 
294cdf0e10cSrcweir         // File menu.
295cdf0e10cSrcweir         JMenu aFileMenu = new JMenu ("File");
296cdf0e10cSrcweir         maMenuBar.add (aFileMenu);
297cdf0e10cSrcweir         JMenuItem aItem;
298cdf0e10cSrcweir         aItem = new JMenuItem ("Quit");
299cdf0e10cSrcweir         aFileMenu.add (aItem);
300cdf0e10cSrcweir         aItem.addActionListener (this);
301cdf0e10cSrcweir 
302cdf0e10cSrcweir         // View menu.
303cdf0e10cSrcweir         JMenu aViewMenu = new JMenu ("View");
304cdf0e10cSrcweir         maMenuBar.add (aViewMenu);
305cdf0e10cSrcweir         ButtonGroup aGroup = new ButtonGroup ();
306cdf0e10cSrcweir         JRadioButtonMenuItem aRadioButton = new JRadioButtonMenuItem ("Whole Screen");
307cdf0e10cSrcweir         aGroup.add (aRadioButton);
308cdf0e10cSrcweir         aViewMenu.add (aRadioButton);
309cdf0e10cSrcweir         aRadioButton.addActionListener (this);
310cdf0e10cSrcweir         aRadioButton = new JRadioButtonMenuItem ("200%");
311cdf0e10cSrcweir         aGroup.add (aRadioButton);
312cdf0e10cSrcweir         aViewMenu.add (aRadioButton);
313cdf0e10cSrcweir         aRadioButton.addActionListener (this);
314cdf0e10cSrcweir         aRadioButton = new JRadioButtonMenuItem ("100%");
315cdf0e10cSrcweir         aGroup.add (aRadioButton);
316cdf0e10cSrcweir         aViewMenu.add (aRadioButton);
317cdf0e10cSrcweir         aRadioButton.addActionListener (this);
318cdf0e10cSrcweir         aRadioButton = new JRadioButtonMenuItem ("50%");
319cdf0e10cSrcweir         aGroup.add (aRadioButton);
320cdf0e10cSrcweir         aViewMenu.add (aRadioButton);
321cdf0e10cSrcweir         aRadioButton.addActionListener (this);
322cdf0e10cSrcweir         aRadioButton = new JRadioButtonMenuItem ("25%");
323cdf0e10cSrcweir         aGroup.add (aRadioButton);
324cdf0e10cSrcweir         aViewMenu.add (aRadioButton);
325cdf0e10cSrcweir         aRadioButton.addActionListener (this);
326cdf0e10cSrcweir         aRadioButton = new JRadioButtonMenuItem ("10%");
327cdf0e10cSrcweir         aGroup.add (aRadioButton);
328cdf0e10cSrcweir         aViewMenu.add (aRadioButton);
329cdf0e10cSrcweir         aRadioButton.addActionListener (this);
330cdf0e10cSrcweir 
331cdf0e10cSrcweir         // Options menu.
332cdf0e10cSrcweir         JMenu aOptionsMenu = new JMenu ("Options");
333cdf0e10cSrcweir         maMenuBar.add (aOptionsMenu);
334cdf0e10cSrcweir         JCheckBoxMenuItem aCBItem;
335cdf0e10cSrcweir         aCBItem = new JCheckBoxMenuItem ("Show Descriptions", maCanvas.getShowDescriptions());
336cdf0e10cSrcweir         aOptionsMenu.add (aCBItem);
337cdf0e10cSrcweir         aCBItem.addActionListener (this);
338cdf0e10cSrcweir 
339cdf0e10cSrcweir         aCBItem = new JCheckBoxMenuItem ("Show Names", maCanvas.getShowNames());
340cdf0e10cSrcweir         aOptionsMenu.add (aCBItem);
341cdf0e10cSrcweir         aCBItem.addActionListener (this);
342cdf0e10cSrcweir 
343cdf0e10cSrcweir         aCBItem = new JCheckBoxMenuItem ("Show Text", maCanvas.getShowText());
344cdf0e10cSrcweir         aOptionsMenu.add (aCBItem);
345cdf0e10cSrcweir         aCBItem.addActionListener (this);
346cdf0e10cSrcweir 
347cdf0e10cSrcweir         aCBItem = new JCheckBoxMenuItem ("Antialiased Rendering", maCanvas.getAntialiasing());
348cdf0e10cSrcweir         aOptionsMenu.add (aCBItem);
349cdf0e10cSrcweir         aCBItem.addActionListener (this);
350cdf0e10cSrcweir 
351cdf0e10cSrcweir         // Help menu.
352cdf0e10cSrcweir         JMenu aHelpMenu = new JMenu ("Help");
353cdf0e10cSrcweir         maMenuBar.add (aHelpMenu);
354cdf0e10cSrcweir 
355cdf0e10cSrcweir         aItem = new JMenuItem ("Help");
356cdf0e10cSrcweir         aHelpMenu.add (aItem);
357cdf0e10cSrcweir         aItem.addActionListener (this);
358cdf0e10cSrcweir 
359cdf0e10cSrcweir         aItem = new JMenuItem ("News");
360cdf0e10cSrcweir         aHelpMenu.add (aItem);
361cdf0e10cSrcweir         aItem.addActionListener (this);
362cdf0e10cSrcweir 
363cdf0e10cSrcweir         aItem = new JMenuItem ("About");
364cdf0e10cSrcweir         aHelpMenu.add (aItem);
365cdf0e10cSrcweir         aItem.addActionListener (this);
366cdf0e10cSrcweir 
367cdf0e10cSrcweir         return maMenuBar;
368cdf0e10cSrcweir     }
369cdf0e10cSrcweir 
370cdf0e10cSrcweir 
371cdf0e10cSrcweir 
372cdf0e10cSrcweir 
373cdf0e10cSrcweir     /** Initialize the AWB.  This includes clearing the canvas, add
374cdf0e10cSrcweir         listeners, creation of a new tree model for the tree list box and
375cdf0e10cSrcweir         the update of the button states.
376cdf0e10cSrcweir 
377cdf0e10cSrcweir         This method may be called any number of times.  Note that all
378cdf0e10cSrcweir         actions will be carried out every time.  The main purpose of a
379cdf0e10cSrcweir         second call is that of a re-initialization after a reconnect.
380cdf0e10cSrcweir     */
381cdf0e10cSrcweir     protected void initialize ()
382cdf0e10cSrcweir     {
383cdf0e10cSrcweir         maCanvas.clear();
384cdf0e10cSrcweir 
385cdf0e10cSrcweir         AccessibilityTreeModel aModel = null;
386cdf0e10cSrcweir         aModel = new AccessibilityTreeModel (createTreeModelRoot());
387cdf0e10cSrcweir 
388cdf0e10cSrcweir         aModel.setCanvas (maCanvas);
389cdf0e10cSrcweir         maAccessibilityTree.getComponent().setModel (aModel);
390cdf0e10cSrcweir 
391cdf0e10cSrcweir         if (office != null)
392cdf0e10cSrcweir         {
393cdf0e10cSrcweir             // Add terminate listener.
394cdf0e10cSrcweir             if (office.getDesktop() != null)
395cdf0e10cSrcweir                 office.getDesktop().addTerminateListener (this);
396cdf0e10cSrcweir 
397cdf0e10cSrcweir             XExtendedToolkit xToolkit = office.getExtendedToolkit();
398cdf0e10cSrcweir             // Remove old top window listener.
399cdf0e10cSrcweir             if (maTopWindowListener != null)
400cdf0e10cSrcweir                 xToolkit.removeTopWindowListener (maQueuedTopWindowListener);
401cdf0e10cSrcweir             // Add top window listener.
402cdf0e10cSrcweir             if (xToolkit != null)
403cdf0e10cSrcweir             {
404cdf0e10cSrcweir                 MessageArea.println ("registering at extended toolkit");
405cdf0e10cSrcweir                 maTopWindowListener = new TopWindowListener (aModel, office);
406cdf0e10cSrcweir                 maQueuedTopWindowListener = new QueuedTopWindowListener (maTopWindowListener);
407cdf0e10cSrcweir                 xToolkit.addTopWindowListener (maQueuedTopWindowListener);
408cdf0e10cSrcweir                 maTopWindowListener.Initialize ();
409cdf0e10cSrcweir             }
410cdf0e10cSrcweir             else
411cdf0e10cSrcweir                 maTopWindowListener = null;
412cdf0e10cSrcweir         }
413cdf0e10cSrcweir 
414cdf0e10cSrcweir         mbInitialized = true;
415cdf0e10cSrcweir         UpdateButtonStates ();
416cdf0e10cSrcweir     }
417cdf0e10cSrcweir 
418cdf0e10cSrcweir 
419cdf0e10cSrcweir 
420cdf0e10cSrcweir 
421cdf0e10cSrcweir     /** Update the states of the buttons according to the internal state of
422cdf0e10cSrcweir         the AWB.
423cdf0e10cSrcweir     */
424cdf0e10cSrcweir     protected void UpdateButtonStates ()
425cdf0e10cSrcweir     {
426cdf0e10cSrcweir         aConnectButton.setEnabled (mbInitialized);
427cdf0e10cSrcweir         aQuitButton.setEnabled (mbInitialized);
428cdf0e10cSrcweir         aUpdateButton.setEnabled (mbInitialized);
429cdf0e10cSrcweir         aExpandButton.setEnabled (mbInitialized);
430cdf0e10cSrcweir         aShapesButton.setEnabled (mbInitialized);
431cdf0e10cSrcweir     }
432cdf0e10cSrcweir 
433cdf0e10cSrcweir 
434cdf0e10cSrcweir 
435cdf0e10cSrcweir     /** Callback for GUI actions from the buttons.
436cdf0e10cSrcweir     */
437cdf0e10cSrcweir     public void actionPerformed (java.awt.event.ActionEvent e)
438cdf0e10cSrcweir     {
439cdf0e10cSrcweir         if (e.getActionCommand().equals("connect"))
440cdf0e10cSrcweir         {
441cdf0e10cSrcweir             office.connect();
442cdf0e10cSrcweir             initialize ();
443cdf0e10cSrcweir         }
444cdf0e10cSrcweir         else if (e.getActionCommand().equals("quit"))
445cdf0e10cSrcweir         {
446cdf0e10cSrcweir             AccessibilityTreeModel aModel = (AccessibilityTreeModel)maAccessibilityTree.getComponent().getModel();
447cdf0e10cSrcweir             aModel.clear();
448cdf0e10cSrcweir             System.exit (0);
449cdf0e10cSrcweir         }
450cdf0e10cSrcweir         else if (e.getActionCommand().equals("update"))
451cdf0e10cSrcweir         {
452cdf0e10cSrcweir             initialize ();
453cdf0e10cSrcweir         }
454cdf0e10cSrcweir         else if (e.getActionCommand().equals("shapes"))
455cdf0e10cSrcweir         {
456cdf0e10cSrcweir             Cursor aCursor = getCursor();
457cdf0e10cSrcweir             setCursor (new Cursor (Cursor.WAIT_CURSOR));
458cdf0e10cSrcweir             maAccessibilityTree.expandShapes();
459cdf0e10cSrcweir             setCursor (aCursor);
460cdf0e10cSrcweir         }
461cdf0e10cSrcweir         else if (e.getActionCommand().equals("expand"))
462cdf0e10cSrcweir         {
463cdf0e10cSrcweir             Cursor aCursor = getCursor();
464cdf0e10cSrcweir             setCursor (new Cursor (Cursor.WAIT_CURSOR));
465cdf0e10cSrcweir             maAccessibilityTree.expandAll();
466cdf0e10cSrcweir             setCursor (aCursor);
467cdf0e10cSrcweir         }
468cdf0e10cSrcweir         else if (e.getActionCommand().equals ("Quit"))
469cdf0e10cSrcweir         {
470cdf0e10cSrcweir             System.out.println ("exiting");
471cdf0e10cSrcweir             System.exit (0);
472cdf0e10cSrcweir         }
473cdf0e10cSrcweir         else if (e.getActionCommand().equals ("Show Descriptions"))
474cdf0e10cSrcweir         {
475cdf0e10cSrcweir             maCanvas.setShowDescriptions ( ! maCanvas.getShowDescriptions());
476cdf0e10cSrcweir             Options.Instance().Save (msOptionsFileName);
477cdf0e10cSrcweir         }
478cdf0e10cSrcweir         else if (e.getActionCommand().equals ("Show Names"))
479cdf0e10cSrcweir         {
480cdf0e10cSrcweir             maCanvas.setShowNames ( ! maCanvas.getShowNames());
481cdf0e10cSrcweir             Options.Instance().Save (msOptionsFileName);
482cdf0e10cSrcweir         }
483cdf0e10cSrcweir         else if (e.getActionCommand().equals ("Antialiased Rendering"))
484cdf0e10cSrcweir         {
485cdf0e10cSrcweir             maCanvas.setAntialiasing ( ! maCanvas.getAntialiasing());
486cdf0e10cSrcweir             Options.Instance().Save (msOptionsFileName);
487cdf0e10cSrcweir         }
488cdf0e10cSrcweir         else if (e.getActionCommand().equals ("Help"))
489cdf0e10cSrcweir         {
490cdf0e10cSrcweir             HelpWindow.Instance().loadFile ("help.html");
491cdf0e10cSrcweir         }
492cdf0e10cSrcweir         else if (e.getActionCommand().equals ("News"))
493cdf0e10cSrcweir         {
494cdf0e10cSrcweir             try{
495cdf0e10cSrcweir                 HelpWindow.Instance().loadFile ("news.html");
496cdf0e10cSrcweir             } catch (Exception ex) {}
497cdf0e10cSrcweir         }
498cdf0e10cSrcweir         else if (e.getActionCommand().equals ("About"))
499cdf0e10cSrcweir         {
500cdf0e10cSrcweir             HelpWindow.Instance().loadFile ("about.html");
501cdf0e10cSrcweir         }
502cdf0e10cSrcweir         else if (e.getActionCommand().equals ("Whole Screen"))
503cdf0e10cSrcweir         {
504cdf0e10cSrcweir             maCanvas.setZoomMode (Canvas.WHOLE_SCREEN);
505cdf0e10cSrcweir             Options.Instance().Save (msOptionsFileName);
506cdf0e10cSrcweir         }
507cdf0e10cSrcweir         else if (e.getActionCommand().equals ("200%"))
508cdf0e10cSrcweir         {
509cdf0e10cSrcweir             maCanvas.setZoomMode (200);
510cdf0e10cSrcweir             Options.Instance().Save (msOptionsFileName);
511cdf0e10cSrcweir         }
512cdf0e10cSrcweir         else if (e.getActionCommand().equals ("100%"))
513cdf0e10cSrcweir         {
514cdf0e10cSrcweir             maCanvas.setZoomMode (100);
515cdf0e10cSrcweir             Options.Instance().Save (msOptionsFileName);
516cdf0e10cSrcweir         }
517cdf0e10cSrcweir         else if (e.getActionCommand().equals ("50%"))
518cdf0e10cSrcweir         {
519cdf0e10cSrcweir             maCanvas.setZoomMode (50);
520cdf0e10cSrcweir             Options.Instance().Save (msOptionsFileName);
521cdf0e10cSrcweir         }
522cdf0e10cSrcweir         else if (e.getActionCommand().equals ("25%"))
523cdf0e10cSrcweir         {
524cdf0e10cSrcweir             maCanvas.setZoomMode (25);
525cdf0e10cSrcweir             Options.Instance().Save (msOptionsFileName);
526cdf0e10cSrcweir         }
527cdf0e10cSrcweir         else if (e.getActionCommand().equals ("10%"))
528cdf0e10cSrcweir         {
529cdf0e10cSrcweir             maCanvas.setZoomMode (10);
530cdf0e10cSrcweir             Options.Instance().Save (msOptionsFileName);
531cdf0e10cSrcweir         }
532cdf0e10cSrcweir         else
533cdf0e10cSrcweir         {
534cdf0e10cSrcweir             System.err.println("unknown command " + e.getActionCommand());
535cdf0e10cSrcweir         }
536cdf0e10cSrcweir     }
537cdf0e10cSrcweir 
538cdf0e10cSrcweir 
539cdf0e10cSrcweir 
540cdf0e10cSrcweir 
541cdf0e10cSrcweir     /** Create an AccessibilityTreeModel root which contains the documents
542cdf0e10cSrcweir         (top windows) that are present at the moment.
543cdf0e10cSrcweir     */
544cdf0e10cSrcweir     private AccessibleTreeNode createTreeModelRoot()
545cdf0e10cSrcweir     {
546cdf0e10cSrcweir         // create root node
547cdf0e10cSrcweir         VectorNode aRoot = new VectorNode ("Accessibility Tree", null);
548cdf0e10cSrcweir         if (maTopWindowListener != null)
549cdf0e10cSrcweir             maTopWindowListener.Initialize ();
550cdf0e10cSrcweir         return aRoot;
551cdf0e10cSrcweir     }
552cdf0e10cSrcweir 
553cdf0e10cSrcweir 
554cdf0e10cSrcweir     // TreeSelectionListener
555cdf0e10cSrcweir     public void valueChanged (TreeSelectionEvent aEvent)
556cdf0e10cSrcweir     {
557cdf0e10cSrcweir         TreePath aPath = aEvent.getPath();
558cdf0e10cSrcweir         Object aObject = aPath.getLastPathComponent();
559cdf0e10cSrcweir         if (aObject instanceof AccTreeNode)
560cdf0e10cSrcweir         {
561cdf0e10cSrcweir             AccTreeNode aNode = (AccTreeNode) aObject;
562cdf0e10cSrcweir             XAccessibleContext xContext = aNode.getContext();
563cdf0e10cSrcweir             maObjectViewContainer.SetObject (xContext);
564cdf0e10cSrcweir         }
565cdf0e10cSrcweir     }
566cdf0e10cSrcweir 
567cdf0e10cSrcweir 
568cdf0e10cSrcweir 
569cdf0e10cSrcweir 
570cdf0e10cSrcweir     // XEventListener
571cdf0e10cSrcweir     public void disposing( com.sun.star.lang.EventObject aSourceObj )
572cdf0e10cSrcweir     {
573cdf0e10cSrcweir 		XFrame xFrame = (XFrame)UnoRuntime.queryInterface(XFrame.class, aSourceObj.Source);
574cdf0e10cSrcweir 
575cdf0e10cSrcweir 		if( xFrame != null )
576cdf0e10cSrcweir 			System.out.println("frame disposed");
577cdf0e10cSrcweir 		else
578cdf0e10cSrcweir 			System.out.println("controller disposed");
579cdf0e10cSrcweir     }
580cdf0e10cSrcweir 
581cdf0e10cSrcweir 
582cdf0e10cSrcweir 
583cdf0e10cSrcweir 
584cdf0e10cSrcweir 	// XTerminateListener
585cdf0e10cSrcweir 	public void queryTermination (final com.sun.star.lang.EventObject aEvent) throws RuntimeException
586cdf0e10cSrcweir 	{
587cdf0e10cSrcweir 		System.out.println ("Terminate Event : " + aEvent);
588cdf0e10cSrcweir 	}
589cdf0e10cSrcweir 
590cdf0e10cSrcweir 
591cdf0e10cSrcweir 
592cdf0e10cSrcweir 
593cdf0e10cSrcweir 	// XTerminateListener
594cdf0e10cSrcweir 	public void notifyTermination (final com.sun.star.lang.EventObject aEvent) throws RuntimeException
595cdf0e10cSrcweir 	{
596cdf0e10cSrcweir 		System.out.println ("Notifiy Termination Event : " + aEvent);
597cdf0e10cSrcweir 	}
598cdf0e10cSrcweir 
599cdf0e10cSrcweir 
600cdf0e10cSrcweir 
601cdf0e10cSrcweir     /// The Singleton Workbench object.
602cdf0e10cSrcweir     private static AccessibilityWorkBench
603cdf0e10cSrcweir         saWorkBench = null;
604cdf0e10cSrcweir 
605cdf0e10cSrcweir     protected SimpleOffice
606cdf0e10cSrcweir         office;
607cdf0e10cSrcweir     protected InformationWriter
608cdf0e10cSrcweir         info;
609cdf0e10cSrcweir 
610cdf0e10cSrcweir     private XModel
611cdf0e10cSrcweir         mxModel;
612cdf0e10cSrcweir     private JPanel
613cdf0e10cSrcweir         maMainPanel,
614cdf0e10cSrcweir         maButtonBar;
615cdf0e10cSrcweir     private Canvas
616cdf0e10cSrcweir         maCanvas;
617cdf0e10cSrcweir     private AccessibilityTree
618cdf0e10cSrcweir         maAccessibilityTree;
619cdf0e10cSrcweir     private ObjectViewContainer
620cdf0e10cSrcweir         maObjectViewContainer;
621cdf0e10cSrcweir     private JScrollPane
622cdf0e10cSrcweir         maScrollPane;
623cdf0e10cSrcweir     private MessageArea
624cdf0e10cSrcweir         maMessageArea;
625cdf0e10cSrcweir     private JButton
626cdf0e10cSrcweir         aConnectButton,
627cdf0e10cSrcweir         aQuitButton,
628cdf0e10cSrcweir         aUpdateButton,
629cdf0e10cSrcweir         aExpandButton,
630cdf0e10cSrcweir         aShapesButton;
631cdf0e10cSrcweir     private JMenuBar
632cdf0e10cSrcweir         maMenuBar;
633cdf0e10cSrcweir     private String
634cdf0e10cSrcweir         msMessage;
635cdf0e10cSrcweir     private boolean
636cdf0e10cSrcweir         mbInitialized;
637cdf0e10cSrcweir     private TopWindowListener
638cdf0e10cSrcweir         maTopWindowListener;
639cdf0e10cSrcweir     private QueuedTopWindowListener
640cdf0e10cSrcweir         maQueuedTopWindowListener;
641cdf0e10cSrcweir }
642