2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 import java
.io
.PrintWriter
;
23 import lib
.StatusException
;
25 import lib
.TestEnvironment
;
26 import lib
.TestParameters
;
27 import util
.InstCreator
;
28 import util
.SOfficeFactory
;
31 import com
.sun
.star
.beans
.XPropertySet
;
32 import com
.sun
.star
.container
.XIndexAccess
;
33 import com
.sun
.star
.drawing
.XDrawPage
;
34 import com
.sun
.star
.drawing
.XDrawPages
;
35 import com
.sun
.star
.drawing
.XDrawPagesSupplier
;
36 import com
.sun
.star
.drawing
.XShape
;
37 import com
.sun
.star
.drawing
.XShapeGrouper
;
38 import com
.sun
.star
.drawing
.XShapes
;
39 import com
.sun
.star
.lang
.XComponent
;
40 import com
.sun
.star
.style
.XStyle
;
41 import com
.sun
.star
.uno
.AnyConverter
;
42 import com
.sun
.star
.uno
.Type
;
43 import com
.sun
.star
.uno
.UnoRuntime
;
44 import com
.sun
.star
.uno
.XInterface
;
49 * @see com.sun.star.drawing._XDrawPage
53 public class SvxShapeGroup
extends TestCase
{
55 static XComponent xDrawDoc
;
58 * in general this method initializes the document
62 protected void initialize(TestParameters Param
, PrintWriter log
) {
64 // get a soffice factory object
65 SOfficeFactory SOF
= SOfficeFactory
.getFactory( Param
.getMSF());
68 log
.println( "creating a draw document" );
69 xDrawDoc
= SOF
.createDrawDoc(null);
70 } catch ( Exception e
) {
71 // Some exception occurs.FAILED
72 e
.printStackTrace( log
);
73 throw new StatusException( "Couldn't create document", e
);
79 * in general this method disposes the document
83 protected void cleanup( TestParameters Param
, PrintWriter log
) {
85 log
.println("disposing xDrawDoc");
86 util
.DesktopTools
.closeDoc(xDrawDoc
);
91 * creating a Testenvironment for the interfaces to be tested
94 public synchronized TestEnvironment createTestEnvironment
95 (TestParameters Param
, PrintWriter log
) {
97 XInterface oObj
= null;
98 XShapes oShapes
= null;
100 // creation of testobject here
101 // first we write what we are intend to do to log file
102 log
.println( "creating a test environment" );
104 SOfficeFactory SOF
= SOfficeFactory
.getFactory( Param
.getMSF());
106 // get the drawpage of drawing here
108 log
.println( "getting Drawpage" );
109 XDrawPagesSupplier oDPS
= UnoRuntime
.queryInterface(XDrawPagesSupplier
.class,xDrawDoc
);
110 XDrawPages oDPn
= oDPS
.getDrawPages();
111 XIndexAccess oDPi
= UnoRuntime
.queryInterface(XIndexAccess
.class,oDPn
);
112 oObj
= (XDrawPage
) AnyConverter
.toObject(
113 new Type(XDrawPage
.class),oDPi
.getByIndex(0));
114 } catch ( Exception e
) {
115 // Some exception occurs.FAILED
116 e
.printStackTrace( log
);
117 throw new StatusException( "Couldn't get DrawPage", e
);
121 System
.out
.println("**************************");
122 System
.out
.println(" XDrawPage is NULL");
123 System
.out
.println("**************************");
126 //put something on the drawpage
127 log
.println( "inserting some Shapes" );
128 oShapes
= UnoRuntime
.queryInterface(XShapes
.class,oObj
);
129 XShape Shape1
= SOF
.createShape(xDrawDoc
,
130 3000,4500,15000,1000,"Ellipse");
131 oShapes
.add(SOF
.createShape(xDrawDoc
,
132 2000,1500,1000,1000,"Line"));
134 XShape Shape2
= SOF
.createShape(xDrawDoc
,
135 5000,3500,7500,5000,"Rectangle");
138 log
.println( "adding two style as ObjRelation for ShapeDescriptor" );
139 XPropertySet oShapeProps
= UnoRuntime
.queryInterface(XPropertySet
.class,Shape1
);
140 XStyle aStyle1
= null;
142 aStyle1
= (XStyle
) AnyConverter
.toObject(
143 new Type(XStyle
.class),oShapeProps
.getPropertyValue("Style"));
144 } catch (Exception e
) {}
145 oShapeProps
= UnoRuntime
.queryInterface(XPropertySet
.class,Shape2
);
146 XStyle aStyle2
= null;
148 aStyle2
= (XStyle
) AnyConverter
.toObject(
149 new Type(XStyle
.class),oShapeProps
.getPropertyValue("Style"));
150 } catch (Exception e
) {}
153 //get the XShapeGrouper
155 log
.println("get XShapeGroup");
156 XShapeGrouper oSG
= UnoRuntime
.queryInterface
157 (XShapeGrouper
.class, oObj
);
158 oObj
= oSG
.group(oShapes
);
159 } catch ( Exception e
) {
160 e
.printStackTrace( log
);
161 throw new StatusException(" Couldn't get XShapeGroup: ", e
);
164 log
.println( "creating a new environment for drawpage object" );
165 TestEnvironment tEnv
= new TestEnvironment( oObj
);
167 ShapeDsc sDsc
= new ShapeDsc(5000,3500,7500,10000,"Rectangle");
168 log
.println( "adding Shape as mod relation to environment" );
169 tEnv
.addObjRelation("Shape", new InstCreator( xDrawDoc
, sDsc
));
171 tEnv
.addObjRelation("Style1",aStyle1
);
172 tEnv
.addObjRelation("Style2",aStyle2
);
173 for (int i
=0;i
<6;i
++) {
174 Shape2
= SOF
.createShape(xDrawDoc
,
175 5000+100*i
,3500+100*i
,7500+100*i
,5000+100*i
,"Rectangle");
179 } // finish method createTestEnvironment
181 } // finish class SvxShapeGroup