1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 package mod._svx;
25 
26 import java.io.PrintWriter;
27 
28 import lib.StatusException;
29 import lib.TestCase;
30 import lib.TestEnvironment;
31 import lib.TestParameters;
32 import util.InstCreator;
33 import util.SOfficeFactory;
34 import util.ShapeDsc;
35 
36 import com.sun.star.beans.XPropertySet;
37 import com.sun.star.container.XIndexAccess;
38 import com.sun.star.drawing.XDrawPage;
39 import com.sun.star.drawing.XDrawPages;
40 import com.sun.star.drawing.XDrawPagesSupplier;
41 import com.sun.star.drawing.XShape;
42 import com.sun.star.drawing.XShapeGrouper;
43 import com.sun.star.drawing.XShapes;
44 import com.sun.star.lang.XComponent;
45 import com.sun.star.lang.XMultiServiceFactory;
46 import com.sun.star.style.XStyle;
47 import com.sun.star.uno.AnyConverter;
48 import com.sun.star.uno.Type;
49 import com.sun.star.uno.UnoRuntime;
50 import com.sun.star.uno.XInterface;
51 
52 /**
53  *
54  * initial description
55  * @see com.sun.star.drawing._XDrawPage
56  *
57  */
58 
59 public class SvxShapeGroup extends TestCase {
60 
61     static XComponent xDrawDoc;
62 
63            /**
64      * in general this method initializes the document
65      */
66 
67        protected void initialize(TestParameters Param, PrintWriter log) {
68 
69        // get a soffice factory object
70     SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)Param.getMSF());
71 
72     try {
73         log.println( "creating a draw document" );
74         xDrawDoc = SOF.createDrawDoc(null);
75      } catch ( Exception e ) {
76         // Some exception occures.FAILED
77         e.printStackTrace( log );
78         throw new StatusException( "Couldn't create document", e );
79      }
80 
81        }
82 
83            /**
84      * in general this method disposes the document
85      */
86 
87        protected void cleanup( TestParameters Param, PrintWriter log) {
88 
89         log.println("disposing xDrawDoc");
90         util.DesktopTools.closeDoc(xDrawDoc);
91 
92        }
93 
94     /**
95      *    creating a Testenvironment for the interfaces to be tested
96      */
97     public synchronized TestEnvironment createTestEnvironment
98             (TestParameters Param, PrintWriter log ) {
99 
100         XInterface oObj = null;
101         XShapes oShapes = null;
102 
103         // creation of testobject here
104         // first we write what we are intend to do to log file
105         log.println( "creating a test environment" );
106 
107         SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)Param.getMSF());
108 
109         // get the drawpage of drawing here
110         try {
111             log.println( "getting Drawpage" );
112             XDrawPagesSupplier oDPS = (XDrawPagesSupplier)
113                 UnoRuntime.queryInterface(XDrawPagesSupplier.class,xDrawDoc);
114             XDrawPages oDPn = oDPS.getDrawPages();
115             XIndexAccess oDPi = (XIndexAccess)
116                 UnoRuntime.queryInterface(XIndexAccess.class,oDPn);
117             oObj = (XDrawPage) AnyConverter.toObject(
118                 new Type(XDrawPage.class),oDPi.getByIndex(0));
119         } catch ( Exception e ) {
120             // Some exception occures.FAILED
121             e.printStackTrace( log );
122             throw new StatusException( "Couldn't get DrawPage", e );
123         }
124 
125         if (oObj == null) {
126             System.out.println("**************************");
127             System.out.println("    XDrawPage is NULL");
128             System.out.println("**************************");
129         }
130 
131         //put something on the drawpage
132         log.println( "inserting some Shapes" );
133         oShapes = (XShapes) UnoRuntime.queryInterface(XShapes.class,oObj);
134         XShape Shape1 = SOF.createShape(xDrawDoc,
135             3000,4500,15000,1000,"Ellipse");
136         oShapes.add(SOF.createShape(xDrawDoc,
137             2000,1500,1000,1000,"Line"));
138         oShapes.add(Shape1);
139         XShape Shape2 = SOF.createShape(xDrawDoc,
140             5000,3500,7500,5000,"Rectangle");
141         oShapes.add(Shape2);
142 
143         log.println( "adding two style as ObjRelation for ShapeDescriptor" );
144         XPropertySet oShapeProps = (XPropertySet)
145             UnoRuntime.queryInterface(XPropertySet.class,Shape1);
146         XStyle aStyle1 = null;
147         try {
148             aStyle1 = (XStyle) AnyConverter.toObject(
149                 new Type(XStyle.class),oShapeProps.getPropertyValue("Style"));
150         } catch (Exception e) {}
151         oShapeProps = (XPropertySet)
152             UnoRuntime.queryInterface(XPropertySet.class,Shape2);
153         XStyle aStyle2 = null;
154         try {
155             aStyle2 = (XStyle) AnyConverter.toObject(
156                 new Type(XStyle.class),oShapeProps.getPropertyValue("Style"));
157         } catch (Exception e) {}
158 
159 
160        //get the XShapeGrouper
161        try{
162             log.println("get XShapeGroup");
163             XShapeGrouper oSG = (XShapeGrouper)UnoRuntime.queryInterface
164                 (XShapeGrouper.class, oObj);
165             oObj = oSG.group(oShapes);
166         } catch ( Exception e) {
167                 e.printStackTrace( log );
168                 throw new StatusException(" Couldn't get XShapeGroup: ", e);
169         }
170 
171         log.println( "creating a new environment for drawpage object" );
172         TestEnvironment tEnv = new TestEnvironment( oObj );
173 
174         ShapeDsc sDsc = new ShapeDsc(5000,3500,7500,10000,"Rectangle");
175           log.println( "adding Shape as mod relation to environment" );
176         tEnv.addObjRelation("Shape", new InstCreator( xDrawDoc, sDsc));
177         //tEnv.addObjRelation("DrawPage", oObj);
178         //tEnv.addObjRelation("MasterPageSupplier",oGroup);
179 
180         tEnv.addObjRelation("Style1",aStyle1);
181         tEnv.addObjRelation("Style2",aStyle2);
182         for (int i=0;i<6;i++) {
183             Shape2 = SOF.createShape(xDrawDoc,
184                 5000+100*i,3500+100*i,7500+100*i,5000+100*i,"Rectangle");
185             oShapes.add(Shape2);
186         }
187         return tEnv;
188     } // finish method createTestEnvironment
189 
190 }    // finish class SvxShapeGroup
191 
192