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