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
.lang
.XMultiServiceFactory
;
41 import com
.sun
.star
.style
.XStyle
;
42 import com
.sun
.star
.uno
.AnyConverter
;
43 import com
.sun
.star
.uno
.Type
;
44 import com
.sun
.star
.uno
.UnoRuntime
;
45 import com
.sun
.star
.uno
.XInterface
;
50 * @see com.sun.star.drawing._XDrawPage
54 public class SvxShapeGroup
extends TestCase
{
56 static XComponent xDrawDoc
;
59 * 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( (XMultiServiceFactory
)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
82 protected void cleanup( TestParameters Param
, PrintWriter log
) {
84 log
.println("disposing xDrawDoc");
85 util
.DesktopTools
.closeDoc(xDrawDoc
);
90 * creating a Testenvironment for the interfaces to be tested
92 public synchronized TestEnvironment createTestEnvironment
93 (TestParameters Param
, PrintWriter log
) {
95 XInterface oObj
= null;
96 XShapes oShapes
= null;
98 // creation of testobject here
99 // first we write what we are intend to do to log file
100 log
.println( "creating a test environment" );
102 SOfficeFactory SOF
= SOfficeFactory
.getFactory( (XMultiServiceFactory
)Param
.getMSF());
104 // get the drawpage of drawing here
106 log
.println( "getting Drawpage" );
107 XDrawPagesSupplier oDPS
= UnoRuntime
.queryInterface(XDrawPagesSupplier
.class,xDrawDoc
);
108 XDrawPages oDPn
= oDPS
.getDrawPages();
109 XIndexAccess oDPi
= UnoRuntime
.queryInterface(XIndexAccess
.class,oDPn
);
110 oObj
= (XDrawPage
) AnyConverter
.toObject(
111 new Type(XDrawPage
.class),oDPi
.getByIndex(0));
112 } catch ( Exception e
) {
113 // Some exception occurs.FAILED
114 e
.printStackTrace( log
);
115 throw new StatusException( "Couldn't get DrawPage", e
);
119 System
.out
.println("**************************");
120 System
.out
.println(" XDrawPage is NULL");
121 System
.out
.println("**************************");
124 //put something on the drawpage
125 log
.println( "inserting some Shapes" );
126 oShapes
= UnoRuntime
.queryInterface(XShapes
.class,oObj
);
127 XShape Shape1
= SOF
.createShape(xDrawDoc
,
128 3000,4500,15000,1000,"Ellipse");
129 oShapes
.add(SOF
.createShape(xDrawDoc
,
130 2000,1500,1000,1000,"Line"));
132 XShape Shape2
= SOF
.createShape(xDrawDoc
,
133 5000,3500,7500,5000,"Rectangle");
136 log
.println( "adding two style as ObjRelation for ShapeDescriptor" );
137 XPropertySet oShapeProps
= UnoRuntime
.queryInterface(XPropertySet
.class,Shape1
);
138 XStyle aStyle1
= null;
140 aStyle1
= (XStyle
) AnyConverter
.toObject(
141 new Type(XStyle
.class),oShapeProps
.getPropertyValue("Style"));
142 } catch (Exception e
) {}
143 oShapeProps
= UnoRuntime
.queryInterface(XPropertySet
.class,Shape2
);
144 XStyle aStyle2
= null;
146 aStyle2
= (XStyle
) AnyConverter
.toObject(
147 new Type(XStyle
.class),oShapeProps
.getPropertyValue("Style"));
148 } catch (Exception e
) {}
151 //get the XShapeGrouper
153 log
.println("get XShapeGroup");
154 XShapeGrouper oSG
= UnoRuntime
.queryInterface
155 (XShapeGrouper
.class, oObj
);
156 oObj
= oSG
.group(oShapes
);
157 } catch ( Exception e
) {
158 e
.printStackTrace( log
);
159 throw new StatusException(" Couldn't get XShapeGroup: ", e
);
162 log
.println( "creating a new environment for drawpage object" );
163 TestEnvironment tEnv
= new TestEnvironment( oObj
);
165 ShapeDsc sDsc
= new ShapeDsc(5000,3500,7500,10000,"Rectangle");
166 log
.println( "adding Shape as mod relation to environment" );
167 tEnv
.addObjRelation("Shape", new InstCreator( xDrawDoc
, sDsc
));
168 //tEnv.addObjRelation("DrawPage", oObj);
169 //tEnv.addObjRelation("MasterPageSupplier",oGroup);
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