xref: /AOO41X/main/qadevOOo/tests/java/mod/_svx/AccessiblePresentationGraphicShape.java (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 package mod._svx;
29 
30 import java.io.PrintWriter;
31 
32 import lib.StatusException;
33 import lib.TestCase;
34 import lib.TestEnvironment;
35 import lib.TestParameters;
36 import util.AccessibilityTools;
37 import util.DrawTools;
38 import util.SOfficeFactory;
39 import util.utils;
40 
41 import com.sun.star.accessibility.AccessibleRole;
42 import com.sun.star.accessibility.XAccessible;
43 import com.sun.star.awt.Size;
44 import com.sun.star.awt.XWindow;
45 import com.sun.star.beans.XPropertySet;
46 import com.sun.star.drawing.XShape;
47 import com.sun.star.frame.XModel;
48 import com.sun.star.lang.XComponent;
49 import com.sun.star.lang.XMultiServiceFactory;
50 import com.sun.star.uno.UnoRuntime;
51 import com.sun.star.uno.XInterface;
52 
53 public class AccessiblePresentationGraphicShape extends TestCase {
54 
55     static XComponent xDoc;
56     static XModel aModel;
57 
58     protected void initialize( TestParameters tParam, PrintWriter log ) {
59 
60         SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() );
61 
62         try {
63             log.println( "creating a drawdoc" );
64             xDoc = SOF.createImpressDoc(null);
65             aModel = (XModel)
66                 UnoRuntime.queryInterface(XModel.class, xDoc);
67 
68         } catch ( com.sun.star.uno.Exception e ) {
69             // Some exception occures.FAILED
70             e.printStackTrace( log );
71             throw new StatusException( "Couldn't create document", e );
72         }
73     }
74 
75     /**
76      * Disposes the Draw document loaded before.
77      */
78     protected void cleanup( TestParameters tParam, PrintWriter log ) {
79         log.println( "    disposing xDrawDoc " );
80         util.DesktopTools.closeDoc(xDoc);
81     }
82 
83     protected TestEnvironment createTestEnvironment
84             (TestParameters tParam, PrintWriter log) {
85 
86         XInterface oObj = null;
87         XShape oShape = null;
88 
89         // creation of testobject here
90         // first we write what we are intend to do to log file
91         log.println( "creating a test environment" );
92 
93         XMultiServiceFactory docMSF = (XMultiServiceFactory)
94             UnoRuntime.queryInterface(XMultiServiceFactory.class, xDoc);
95         try {
96             oShape = (XShape) UnoRuntime.queryInterface(XShape.class,
97                 docMSF.createInstance
98                 ("com.sun.star.presentation.GraphicObjectShape"));
99         } catch (com.sun.star.uno.Exception e) {
100             throw new StatusException("couldn't create component", e);
101         }
102 
103         DrawTools.getShapes(DrawTools.getDrawPage(xDoc,0)).add(oShape);
104 
105         XPropertySet oShapeProps = (XPropertySet)
106                             UnoRuntime.queryInterface(XPropertySet.class,oShape);
107         try {
108             oShapeProps.setPropertyValue(
109                 "GraphicURL",util.utils.getFullTestURL("space-metal.jpg"));
110             oShapeProps.setPropertyValue("IsEmptyPresentationObject", new Boolean(false));
111         } catch (com.sun.star.lang.WrappedTargetException e) {
112         } catch (com.sun.star.lang.IllegalArgumentException e) {
113         } catch (com.sun.star.beans.PropertyVetoException e) {
114         } catch (com.sun.star.beans.UnknownPropertyException e) {
115         }
116 
117         //DrawTools.getShapes(DrawTools.getDrawPage(xDoc,0)).add(oShape);
118 
119         AccessibilityTools at = new AccessibilityTools();
120 
121         XWindow xWindow = at.getCurrentWindow ((XMultiServiceFactory)tParam.getMSF(),aModel);
122         XAccessible xRoot = at.getAccessibleObject(xWindow);
123 
124 //        oObj = at.getAccessibleObjectForRole
125 //            (xRoot, AccessibleRole.SHAPE, "GraphicObject");
126         oObj = at.getAccessibleObjectForRole(xRoot, AccessibleRole.UNKNOWN, "GraphicObject");
127 
128         // create test environment here
129         TestEnvironment tEnv = new TestEnvironment( oObj );
130 
131         final XShape fShape = oShape ;
132         tEnv.addObjRelation("EventProducer",
133             new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() {
134                 public void fireEvent() {
135                     try {
136                         Size size = fShape.getSize();
137                         size.Width += 100;
138                         fShape.setSize(size);
139                     } catch(com.sun.star.beans.PropertyVetoException e) {}
140                 }
141             });
142 
143         log.println("Implementation Name: " + utils.getImplName(oObj));
144 
145         return tEnv;
146     } // finish method getTestEnvironment
147 
148 }
149 
150