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: SwAccessiblePageView.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 java
.io
.PrintWriter
;
35 import lib
.StatusException
;
37 import lib
.TestEnvironment
;
38 import lib
.TestParameters
;
39 import util
.AccessibilityTools
;
40 import util
.WriterTools
;
43 import com
.sun
.star
.accessibility
.AccessibleRole
;
44 import com
.sun
.star
.accessibility
.XAccessible
;
45 import com
.sun
.star
.accessibility
.XAccessibleContext
;
46 import com
.sun
.star
.accessibility
.XAccessibleValue
;
47 import com
.sun
.star
.awt
.XWindow
;
48 import com
.sun
.star
.beans
.XPropertySet
;
49 import com
.sun
.star
.container
.XEnumeration
;
50 import com
.sun
.star
.container
.XEnumerationAccess
;
51 import com
.sun
.star
.frame
.XController
;
52 import com
.sun
.star
.frame
.XDispatch
;
53 import com
.sun
.star
.frame
.XDispatchProvider
;
54 import com
.sun
.star
.frame
.XModel
;
55 import com
.sun
.star
.lang
.XMultiServiceFactory
;
56 import com
.sun
.star
.text
.ControlCharacter
;
57 import com
.sun
.star
.text
.XText
;
58 import com
.sun
.star
.text
.XTextCursor
;
59 import com
.sun
.star
.text
.XTextDocument
;
60 import com
.sun
.star
.uno
.AnyConverter
;
61 import com
.sun
.star
.uno
.Type
;
62 import com
.sun
.star
.uno
.UnoRuntime
;
63 import com
.sun
.star
.uno
.XInterface
;
64 import com
.sun
.star
.util
.URL
;
65 import com
.sun
.star
.util
.XURLTransformer
;
67 public class SwAccessiblePageView
extends TestCase
{
69 XTextDocument xTextDoc
= null;
72 * Called to create an instance of <code>TestEnvironment</code>
73 * with an object to test and related objects.
74 * Switchs the document to Print Preview mode.
75 * Obtains accissible object for the page view.
77 * @param tParam test parameters
78 * @param log writer to log information while testing
80 * @see TestEnvironment
81 * @see #getTestEnvironment()
83 protected TestEnvironment
createTestEnvironment(
84 TestParameters Param
, PrintWriter log
) {
86 XInterface oObj
= null;
87 XInterface port
= null;
88 XInterface para
= null;
89 XPropertySet paraP
= null;
90 XPropertySet portP
= null;
92 XText oText
= xTextDoc
.getText();
93 XTextCursor oCursor
= oText
.createTextCursor();
95 log
.println( "inserting some lines" );
97 for (int i
=0; i
<2; i
++){
98 oText
.insertString( oCursor
,"Paragraph Number: " + i
, false);
99 oText
.insertString( oCursor
,
100 " The quick brown fox jumps over the lazy Dog: SwXParagraph",
102 oText
.insertControlCharacter(
103 oCursor
, ControlCharacter
.PARAGRAPH_BREAK
, false );
104 oText
.insertString( oCursor
,
105 "THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG: SwXParagraph",
107 oText
.insertControlCharacter(oCursor
,
108 ControlCharacter
.PARAGRAPH_BREAK
, false );
109 oText
.insertControlCharacter(
110 oCursor
, ControlCharacter
.LINE_BREAK
, false );
112 } catch ( com
.sun
.star
.lang
.IllegalArgumentException e
){
113 e
.printStackTrace(log
);
114 throw new StatusException( "Couldn't insert lines", e
);
118 XEnumerationAccess oEnumA
= (XEnumerationAccess
)
119 UnoRuntime
.queryInterface(XEnumerationAccess
.class, oText
);
120 XEnumeration oEnum
= oEnumA
.createEnumeration();
123 para
= (XInterface
) AnyConverter
.toObject(
124 new Type(XInterface
.class),oEnum
.nextElement());
125 XEnumerationAccess oEnumB
= (XEnumerationAccess
)
126 UnoRuntime
.queryInterface( XEnumerationAccess
.class, para
);
127 XEnumeration oEnum2
= oEnumB
.createEnumeration();
128 port
= (XInterface
) AnyConverter
.toObject(
129 new Type(XInterface
.class),oEnum2
.nextElement());
130 } catch ( com
.sun
.star
.lang
.WrappedTargetException e
) {
131 e
.printStackTrace(log
);
132 log
.println("Error: exception occured...");
133 } catch ( com
.sun
.star
.container
.NoSuchElementException e
) {
134 e
.printStackTrace(log
);
135 log
.println("Error: exception occured...");
136 } catch ( com
.sun
.star
.lang
.IllegalArgumentException e
) {
137 e
.printStackTrace(log
);
138 log
.println("Error: exception occured...");
142 portP
= (XPropertySet
)
143 UnoRuntime
.queryInterface(XPropertySet
.class, port
);
144 paraP
= (XPropertySet
)
145 UnoRuntime
.queryInterface(XPropertySet
.class, para
);
146 paraP
.setPropertyValue("BreakType",com
.sun
.star
.style
.BreakType
.PAGE_AFTER
);
147 } catch ( com
.sun
.star
.lang
.WrappedTargetException e
) {
148 log
.println("Error, exception occured...");
149 e
.printStackTrace(log
);
150 throw new StatusException( "Couldn't get Paragraph", e
);
151 } catch ( com
.sun
.star
.lang
.IllegalArgumentException e
) {
152 log
.println("Error, exception occured...");
153 e
.printStackTrace(log
);
154 throw new StatusException( "Couldn't get Paragraph", e
);
155 } catch ( com
.sun
.star
.beans
.UnknownPropertyException e
) {
156 log
.println("Error, exception occured...");
157 e
.printStackTrace(log
);
158 throw new StatusException( "Couldn't get Paragraph", e
);
159 } catch ( com
.sun
.star
.beans
.PropertyVetoException e
) {
160 log
.println("Error, exception occured...");
161 e
.printStackTrace(log
);
162 throw new StatusException( "Couldn't get Paragraph", e
);
167 XController xController
= xTextDoc
.getCurrentController();
169 XModel aModel
= (XModel
)
170 UnoRuntime
.queryInterface(XModel
.class, xTextDoc
);
172 //switch to 'Print Preview' mode
174 XDispatchProvider xDispProv
= (XDispatchProvider
)
175 UnoRuntime
.queryInterface(XDispatchProvider
.class, xController
);
176 XURLTransformer xParser
= (com
.sun
.star
.util
.XURLTransformer
)
177 UnoRuntime
.queryInterface(XURLTransformer
.class,
178 ((XMultiServiceFactory
)Param
.getMSF()).createInstance("com.sun.star.util.URLTransformer"));
179 // Because it's an in/out parameter we must use an array of URL objects.
180 URL
[] aParseURL
= new URL
[1];
181 aParseURL
[0] = new URL();
182 aParseURL
[0].Complete
= ".uno:PrintPreview";
183 xParser
.parseStrict(aParseURL
);
184 URL aURL
= aParseURL
[0];
185 XDispatch xDispatcher
= xDispProv
.queryDispatch(aURL
, "", 0);
186 if(xDispatcher
!= null)
187 xDispatcher
.dispatch( aURL
, null );
188 } catch (com
.sun
.star
.uno
.Exception e
) {
189 log
.println("Couldn't change mode");
190 throw new StatusException(Status
.failed("Couldn't change mode"));
195 AccessibilityTools at
= new AccessibilityTools();
197 XWindow xWindow
= at
.getCurrentWindow((XMultiServiceFactory
)Param
.getMSF(), aModel
);
198 XAccessible xRoot
= at
.getAccessibleObject(xWindow
);
200 at
.printAccessibleTree(log
, xRoot
, Param
.getBool(util
.PropertyName
.DEBUG_IS_ACTIVE
));
202 System
.out
.println("Panel: "+AccessibleRole
.PANEL
);
203 System
.out
.println("ScrollPane: "+AccessibleRole
.SCROLL_PANE
);
204 oObj
= at
.getAccessibleObjectForRole(xRoot
, AccessibleRole
.PANEL
,"Page");
206 log
.println("ImplementationName " + utils
.getImplName(oObj
));
209 TestEnvironment tEnv
= new TestEnvironment(oObj
);
211 getAccessibleObjectForRole(xRoot
, AccessibleRole
.SCROLL_BAR
);
212 final XAccessibleValue xAccVal
= (XAccessibleValue
) UnoRuntime
.queryInterface
213 (XAccessibleValue
.class, SearchedContext
) ;
215 tEnv
.addObjRelation("EventProducer",
216 new ifc
.accessibility
._XAccessibleEventBroadcaster
.EventProducer() {
217 public void fireEvent() {
218 Integer old
= (Integer
) xAccVal
.getCurrentValue();
219 Integer newValue
= new Integer(old
.intValue()+10);
220 xAccVal
.setCurrentValue(newValue
);
221 xAccVal
.setCurrentValue(old
);
229 public static boolean first
= false;
230 public static XAccessibleContext SearchedContext
= null;
232 public static void getAccessibleObjectForRole(XAccessible xacc
,short role
) {
233 XAccessibleContext ac
= xacc
.getAccessibleContext();
234 if (ac
.getAccessibleRole()==role
) {
235 if (first
) SearchedContext
= ac
;
238 int k
= ac
.getAccessibleChildCount();
239 for (int i
=0;i
<k
;i
++) {
241 getAccessibleObjectForRole(ac
.getAccessibleChild(i
),role
);
242 if (SearchedContext
!= null) return ;
243 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
244 System
.out
.println("Couldn't get Child");
252 * Called while disposing a <code>TestEnvironment</code>.
253 * Disposes text document.
254 * @param tParam test parameters
255 * @param tEnv the environment to cleanup
256 * @param log writer to log information while testing
258 protected void cleanup( TestParameters Param
, PrintWriter log
) {
259 log
.println("dispose text document");
260 util
.DesktopTools
.closeDoc(xTextDoc
);
264 * Called while the <code>TestCase</code> initialization. In the
265 * implementation does nothing. Subclasses can override to initialize
266 * objects shared among all <code>TestEnvironment</code>s.
268 * @param tParam test parameters
269 * @param log writer to log information while testing
271 * @see #initializeTestCase()
273 protected void initialize(TestParameters Param
, PrintWriter log
) {
274 log
.println( "creating a text document" );
275 xTextDoc
= WriterTools
.createTextDoc((XMultiServiceFactory
)Param
.getMSF());
279 * Sleeps for 0.5 sec. to allow StarOffice to react on <code>
282 private void shortWait() {
285 } catch (InterruptedException e
) {
286 log
.println("While waiting :" + e
) ;