1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: AccessibleButton.java,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
32 import com
.sun
.star
.accessibility
.AccessibleRole
;
33 import com
.sun
.star
.accessibility
.XAccessible
;
34 import com
.sun
.star
.accessibility
.XAccessibleAction
;
35 import com
.sun
.star
.accessibility
.XAccessibleComponent
;
36 import com
.sun
.star
.accessibility
.XAccessibleText
;
37 import com
.sun
.star
.awt
.XExtendedToolkit
;
38 import com
.sun
.star
.awt
.XWindow
;
39 import com
.sun
.star
.frame
.XController
;
40 import com
.sun
.star
.frame
.XDispatch
;
41 import com
.sun
.star
.frame
.XDispatchProvider
;
42 import com
.sun
.star
.frame
.XModel
;
43 import com
.sun
.star
.lang
.XMultiServiceFactory
;
44 import com
.sun
.star
.text
.XTextDocument
;
45 import com
.sun
.star
.uno
.UnoRuntime
;
46 import com
.sun
.star
.uno
.XInterface
;
47 import com
.sun
.star
.util
.URL
;
48 import com
.sun
.star
.util
.XURLTransformer
;
50 import java
.io
.PrintWriter
;
52 import lib
.StatusException
;
53 import lib
.TestEnvironment
;
54 import lib
.TestParameters
;
56 import util
.AccessibilityTools
;
57 import util
.SOfficeFactory
;
62 * Object implements the following interfaces :
64 * <li> <code>::com::sun::star::accessibility::XAccessibleExtendedComponent</code></li>
65 * <li> <code>::com::sun::star::accessibility::XAccessibleEventBroadcaster</code></li>
66 * <li> <code>::com::sun::star::accessibility::XAccessibleComponent</code></li>
67 * <li> <code>::com::sun::star::accessibility::XAccessibleValue</code></li>
68 * <li> <code>::com::sun::star::accessibility::XAccessibleAction</code></li>
69 * <li> <code>::com::sun::star::accessibility::XAccessibleContext</code></li>
70 * <li> <code>::com::sun::star::accessibility::XAccessibleText</code></li>
73 * @see com.sun.star.accessibility.XAccessibleExtendedComponent
74 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
75 * @see com.sun.star.accessibility.XAccessibleComponent
76 * @see com.sun.star.accessibility.XAccessibleValue
77 * @see com.sun.star.accessibility.XAccessibleAction
78 * @see com.sun.star.accessibility.XAccessibleContext
79 * @see com.sun.star.accessibility.XAccessibleText
80 * @see ifc.accessibility._XAccessibleExtendedComponent
81 * @see ifc.accessibility._XAccessibleEventBroadcaster
82 * @see ifc.accessibility._XAccessibleComponent
83 * @see ifc.accessibility._XAccessibleValue
84 * @see ifc.accessibility._XAccessibleAction
85 * @see ifc.accessibility._XAccessibleContext
86 * @see ifc.accessibility._XAccessibleText
88 public class AccessibleButton
extends lib
.TestCase
{
89 private static XTextDocument xTextDoc
= null;
90 private static XAccessibleAction action
= null;
93 * Opens 'Printer Settings' dialog using document dispatch provider
94 * running in a separate thread. Finds active top window (the dialog
95 * window) and finds accessible button 'OK' walking through the
96 * accessible component tree.
98 protected TestEnvironment
createTestEnvironment(TestParameters Param
,
100 XInterface oObj
= null;
101 XMultiServiceFactory msf
= (XMultiServiceFactory
) Param
.getMSF();
104 oObj
= (XInterface
) msf
.createInstance("com.sun.star.awt.Toolkit");
105 } catch (com
.sun
.star
.uno
.Exception e
) {
106 log
.println("Couldn't get toolkit");
107 e
.printStackTrace(log
);
108 throw new StatusException("Couldn't get toolkit", e
);
111 XExtendedToolkit tk
= (XExtendedToolkit
) UnoRuntime
.queryInterface(
112 XExtendedToolkit
.class, oObj
);
114 util
.utils
.shortWait(Param
.getInt("ShortWait"));
116 DiagThread psDiag
= new DiagThread(xTextDoc
, msf
);
119 util
.utils
.shortWait(Param
.getInt("ShortWait"));
121 AccessibilityTools at
= new AccessibilityTools();
123 util
.utils
.shortWait(Param
.getInt("ShortWait"));
125 Object atw
= tk
.getActiveTopWindow();
127 XWindow xWindow
= (XWindow
) UnoRuntime
.queryInterface(XWindow
.class,
130 XAccessible xRoot
= at
.getAccessibleObject(xWindow
);
133 at
.printAccessibleTree(log
, xRoot
, Param
.getBool(util
.PropertyName
.DEBUG_IS_ACTIVE
));
134 oObj
= at
.getAccessibleObjectForRole(xRoot
, AccessibleRole
.PUSH_BUTTON
,
137 log
.println("ImplementationName " + utils
.getImplName(oObj
));
139 TestEnvironment tEnv
= new TestEnvironment(oObj
);
141 action
= (XAccessibleAction
) UnoRuntime
.queryInterface(
142 XAccessibleAction
.class, oObj
);
144 final XAccessibleComponent acomp
= (XAccessibleComponent
) UnoRuntime
.queryInterface(
145 XAccessibleComponent
.class,
148 tEnv
.addObjRelation("EventProducer",
149 new ifc
.accessibility
._XAccessibleEventBroadcaster
.EventProducer() {
150 public void fireEvent() {
151 System
.out
.println("Grabbing focus ... ");
156 XAccessibleText text
= (XAccessibleText
) UnoRuntime
.queryInterface(
157 XAccessibleText
.class, oObj
);
159 tEnv
.addObjRelation("XAccessibleText.Text", text
.getText());
161 tEnv
.addObjRelation("EditOnly",
162 "This method isn't supported in this component");
164 tEnv
.addObjRelation("LimitedBounds", "yes");
170 * Closes the dialog using accessible button 'OK' found in
171 * <code>createTestEnvironment()</code>.
173 protected void cleanup(TestParameters Param
, PrintWriter log
) {
174 log
.println(" disposing xTextDoc ");
177 action
.doAccessibleAction(0);
178 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException ioe
) {
179 log
.println("Couldn't close dialog");
180 } catch (com
.sun
.star
.lang
.DisposedException de
) {
181 log
.println("Dialog already disposed");
184 util
.DesktopTools
.closeDoc(xTextDoc
);
189 * Opens new writer document.
191 protected void initialize(TestParameters Param
, PrintWriter log
) {
193 SOfficeFactory SOF
= SOfficeFactory
.getFactory(
194 (XMultiServiceFactory
) Param
.getMSF());
195 xTextDoc
= SOF
.createTextDoc(null);
196 } catch (com
.sun
.star
.uno
.Exception e
) {
197 throw new StatusException("Can't create document", e
);
203 * Thread for opening modal dialog 'Print Settings'.
205 public class DiagThread
extends Thread
{
206 public XTextDocument xTextDoc
= null;
207 public XMultiServiceFactory msf
= null;
209 public DiagThread(XTextDocument xTextDoc
, XMultiServiceFactory msf
) {
210 this.xTextDoc
= xTextDoc
;
215 XModel aModel
= (XModel
) UnoRuntime
.queryInterface(XModel
.class,
218 XController xController
= aModel
.getCurrentController();
220 //Opening PrinterSetupDialog
222 String aSlotID
= ".uno:Zoom";
223 XDispatchProvider xDispProv
= (XDispatchProvider
) UnoRuntime
.queryInterface(
224 XDispatchProvider
.class,
226 XURLTransformer xParser
= (com
.sun
.star
.util
.XURLTransformer
) UnoRuntime
.queryInterface(
227 XURLTransformer
.class,
229 "com.sun.star.util.URLTransformer"));
231 // Because it's an in/out parameter
232 // we must use an array of URL objects.
233 URL
[] aParseURL
= new URL
[1];
234 aParseURL
[0] = new URL();
235 aParseURL
[0].Complete
= aSlotID
;
236 xParser
.parseStrict(aParseURL
);
238 URL aURL
= aParseURL
[0];
239 XDispatch xDispatcher
= xDispProv
.queryDispatch(aURL
, "", 0);
241 if (xDispatcher
!= null) {
242 xDispatcher
.dispatch(aURL
, null);
244 } catch (com
.sun
.star
.uno
.Exception e
) {
245 log
.println("Couldn't open dialog");