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.InstCreator; 37 import util.SOfficeFactory; 38 import util.ShapeDsc; 39 40 import com.sun.star.beans.XPropertySet; 41 import com.sun.star.container.XIndexAccess; 42 import com.sun.star.drawing.XDrawPage; 43 import com.sun.star.drawing.XDrawPages; 44 import com.sun.star.drawing.XDrawPagesSupplier; 45 import com.sun.star.drawing.XShape; 46 import com.sun.star.drawing.XShapeGrouper; 47 import com.sun.star.drawing.XShapes; 48 import com.sun.star.lang.XComponent; 49 import com.sun.star.lang.XMultiServiceFactory; 50 import com.sun.star.style.XStyle; 51 import com.sun.star.uno.AnyConverter; 52 import com.sun.star.uno.Type; 53 import com.sun.star.uno.UnoRuntime; 54 import com.sun.star.uno.XInterface; 55 56 /** 57 * 58 * initial description 59 * @see com.sun.star.drawing._XDrawPage 60 * 61 */ 62 63 public class SvxShapeGroup extends TestCase { 64 65 static XComponent xDrawDoc; 66 67 /** 68 * in general this method initializes the document 69 */ 70 71 protected void initialize(TestParameters Param, PrintWriter log) { 72 73 // get a soffice factory object 74 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)Param.getMSF()); 75 76 try { 77 log.println( "creating a draw document" ); 78 xDrawDoc = SOF.createDrawDoc(null);; 79 } catch ( Exception e ) { 80 // Some exception occures.FAILED 81 e.printStackTrace( log ); 82 throw new StatusException( "Couldn't create document", e ); 83 } 84 85 } 86 87 /** 88 * in general this method disposes the document 89 */ 90 91 protected void cleanup( TestParameters Param, PrintWriter log) { 92 93 log.println("disposing xDrawDoc"); 94 util.DesktopTools.closeDoc(xDrawDoc); 95 96 } 97 98 /** 99 * creating a Testenvironment for the interfaces to be tested 100 */ 101 public synchronized TestEnvironment createTestEnvironment 102 (TestParameters Param, PrintWriter log ) { 103 104 XInterface oObj = null; 105 XShapes oShapes = null; 106 107 // creation of testobject here 108 // first we write what we are intend to do to log file 109 log.println( "creating a test environment" ); 110 111 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)Param.getMSF()); 112 113 // get the drawpage of drawing here 114 try { 115 log.println( "getting Drawpage" ); 116 XDrawPagesSupplier oDPS = (XDrawPagesSupplier) 117 UnoRuntime.queryInterface(XDrawPagesSupplier.class,xDrawDoc); 118 XDrawPages oDPn = oDPS.getDrawPages(); 119 XIndexAccess oDPi = (XIndexAccess) 120 UnoRuntime.queryInterface(XIndexAccess.class,oDPn); 121 oObj = (XDrawPage) AnyConverter.toObject( 122 new Type(XDrawPage.class),oDPi.getByIndex(0)); 123 } catch ( Exception e ) { 124 // Some exception occures.FAILED 125 e.printStackTrace( log ); 126 throw new StatusException( "Couldn't get DrawPage", e ); 127 } 128 129 if (oObj == null) { 130 System.out.println("**************************"); 131 System.out.println(" XDrawPage is NULL"); 132 System.out.println("**************************"); 133 } 134 135 //put something on the drawpage 136 log.println( "inserting some Shapes" ); 137 oShapes = (XShapes) UnoRuntime.queryInterface(XShapes.class,oObj); 138 XShape Shape1 = SOF.createShape(xDrawDoc, 139 3000,4500,15000,1000,"Ellipse"); 140 oShapes.add(SOF.createShape(xDrawDoc, 141 2000,1500,1000,1000,"Line")); 142 oShapes.add(Shape1); 143 XShape Shape2 = SOF.createShape(xDrawDoc, 144 5000,3500,7500,5000,"Rectangle"); 145 oShapes.add(Shape2); 146 147 log.println( "adding two style as ObjRelation for ShapeDescriptor" ); 148 XPropertySet oShapeProps = (XPropertySet) 149 UnoRuntime.queryInterface(XPropertySet.class,Shape1); 150 XStyle aStyle1 = null; 151 try { 152 aStyle1 = (XStyle) AnyConverter.toObject( 153 new Type(XStyle.class),oShapeProps.getPropertyValue("Style")); 154 } catch (Exception e) {} 155 oShapeProps = (XPropertySet) 156 UnoRuntime.queryInterface(XPropertySet.class,Shape2); 157 XStyle aStyle2 = null; 158 try { 159 aStyle2 = (XStyle) AnyConverter.toObject( 160 new Type(XStyle.class),oShapeProps.getPropertyValue("Style")); 161 } catch (Exception e) {} 162 163 164 //get the XShapeGrouper 165 try{ 166 log.println("get XShapeGroup"); 167 XShapeGrouper oSG = (XShapeGrouper)UnoRuntime.queryInterface 168 (XShapeGrouper.class, oObj); 169 oObj = oSG.group(oShapes); 170 } catch ( Exception e) { 171 e.printStackTrace( log ); 172 throw new StatusException(" Couldn't get XShapeGroup: ", e); 173 } 174 175 log.println( "creating a new environment for drawpage object" ); 176 TestEnvironment tEnv = new TestEnvironment( oObj ); 177 178 ShapeDsc sDsc = new ShapeDsc(5000,3500,7500,10000,"Rectangle"); 179 log.println( "adding Shape as mod relation to environment" ); 180 tEnv.addObjRelation("Shape", new InstCreator( xDrawDoc, sDsc)); 181 //tEnv.addObjRelation("DrawPage", oObj); 182 //tEnv.addObjRelation("MasterPageSupplier",oGroup); 183 184 tEnv.addObjRelation("Style1",aStyle1); 185 tEnv.addObjRelation("Style2",aStyle2); 186 for (int i=0;i<6;i++) { 187 Shape2 = SOF.createShape(xDrawDoc, 188 5000+100*i,3500+100*i,7500+100*i,5000+100*i,"Rectangle"); 189 oShapes.add(Shape2); 190 } 191 return tEnv; 192 } // finish method createTestEnvironment 193 194 } // finish class SvxShapeGroup 195 196