1ef39d40dSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3ef39d40dSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4ef39d40dSAndrew Rist * or more contributor license agreements. See the NOTICE file 5ef39d40dSAndrew Rist * distributed with this work for additional information 6ef39d40dSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7ef39d40dSAndrew Rist * to you under the Apache License, Version 2.0 (the 8ef39d40dSAndrew Rist * "License"); you may not use this file except in compliance 9ef39d40dSAndrew Rist * with the License. You may obtain a copy of the License at 10ef39d40dSAndrew Rist * 11ef39d40dSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12ef39d40dSAndrew Rist * 13ef39d40dSAndrew Rist * Unless required by applicable law or agreed to in writing, 14ef39d40dSAndrew Rist * software distributed under the License is distributed on an 15ef39d40dSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16ef39d40dSAndrew Rist * KIND, either express or implied. See the License for the 17ef39d40dSAndrew Rist * specific language governing permissions and limitations 18ef39d40dSAndrew Rist * under the License. 19ef39d40dSAndrew Rist * 20ef39d40dSAndrew Rist *************************************************************/ 21ef39d40dSAndrew Rist 22ef39d40dSAndrew Rist 23cdf0e10cSrcweir package mod._sd; 24cdf0e10cSrcweir 25cdf0e10cSrcweir import com.sun.star.beans.PropertyVetoException; 26cdf0e10cSrcweir import com.sun.star.beans.UnknownPropertyException; 27cdf0e10cSrcweir import com.sun.star.beans.XPropertySet; 28cdf0e10cSrcweir import com.sun.star.drawing.XShape; 29cdf0e10cSrcweir import com.sun.star.frame.XController; 30cdf0e10cSrcweir import com.sun.star.frame.XModel; 31cdf0e10cSrcweir import com.sun.star.lang.WrappedTargetException; 32cdf0e10cSrcweir import com.sun.star.lang.XComponent; 33cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory; 34cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime; 35cdf0e10cSrcweir import com.sun.star.view.XSelectionSupplier; 36cdf0e10cSrcweir import ifc.view._XPrintJobBroadcaster; 37cdf0e10cSrcweir import java.io.File; 38cdf0e10cSrcweir 39cdf0e10cSrcweir import java.io.PrintWriter; 40cdf0e10cSrcweir 41cdf0e10cSrcweir import lib.StatusException; 42cdf0e10cSrcweir import lib.TestCase; 43cdf0e10cSrcweir import lib.TestEnvironment; 44cdf0e10cSrcweir import lib.TestParameters; 45cdf0e10cSrcweir 46cdf0e10cSrcweir import util.DrawTools; 47cdf0e10cSrcweir import util.SOfficeFactory; 48cdf0e10cSrcweir import util.utils; 49cdf0e10cSrcweir 50cdf0e10cSrcweir 51cdf0e10cSrcweir /** 52cdf0e10cSrcweir * Test for object which is represented by service 53cdf0e10cSrcweir * <code>com.sun.star.presentation.PresentationDocument</code>. <p> 54cdf0e10cSrcweir * Object implements the following interfaces : 55cdf0e10cSrcweir * <ul> 56cdf0e10cSrcweir * <li> <code>com::sun::star::lang::XMultiServiceFactory</code></li> 57cdf0e10cSrcweir * <li> <code>com::sun::star::drawing::XMasterPagesSupplier</code></li> 58cdf0e10cSrcweir * <li> <code>com::sun::star::presentation::XCustomPresentationSupplier</code></li> 59cdf0e10cSrcweir * <li> <code>com::sun::star::document::XLinkTargetSupplier</code></li> 60cdf0e10cSrcweir * <li> <code>com::sun::star::beans::XPropertySet</code></li> 61cdf0e10cSrcweir * <li> <code>com::sun::star::drawing::XLayerSupplier</code></li> 62cdf0e10cSrcweir * <li> <code>com::sun::star::presentation::XPresentationSupplier</code></li> 63cdf0e10cSrcweir * <li> <code>com::sun::star::style::XStyleFamiliesSupplier</code></li> 64cdf0e10cSrcweir * <li> <code>com::sun::star::drawing::DrawingDocument</code></li> 65cdf0e10cSrcweir * <li> <code>com::sun::star::drawing::XDrawPageDuplicator</code></li> 66cdf0e10cSrcweir * <li> <code>com::sun::star::drawing::XDrawPagesSupplier</code></li> 67cdf0e10cSrcweir * </ul> 68cdf0e10cSrcweir * @see com.sun.star.presentation.PresentationDocument 69cdf0e10cSrcweir * @see com.sun.star.lang.XMultiServiceFactory 70cdf0e10cSrcweir * @see com.sun.star.drawing.XMasterPagesSupplier 71cdf0e10cSrcweir * @see com.sun.star.presentation.XCustomPresentationSupplier 72cdf0e10cSrcweir * @see com.sun.star.document.XLinkTargetSupplier 73cdf0e10cSrcweir * @see com.sun.star.beans.XPropertySet 74cdf0e10cSrcweir * @see com.sun.star.drawing.XLayerSupplier 75cdf0e10cSrcweir * @see com.sun.star.presentation.XPresentationSupplier 76cdf0e10cSrcweir * @see com.sun.star.style.XStyleFamiliesSupplier 77cdf0e10cSrcweir * @see com.sun.star.drawing.DrawingDocument 78cdf0e10cSrcweir * @see com.sun.star.drawing.XDrawPageDuplicator 79cdf0e10cSrcweir * @see com.sun.star.drawing.XDrawPagesSupplier 80cdf0e10cSrcweir * @see ifc.lang._XMultiServiceFactory 81cdf0e10cSrcweir * @see ifc.drawing._XMasterPagesSupplier 82cdf0e10cSrcweir * @see ifc.presentation._XCustomPresentationSupplier 83cdf0e10cSrcweir * @see ifc.document._XLinkTargetSupplier 84cdf0e10cSrcweir * @see ifc.beans._XPropertySet 85cdf0e10cSrcweir * @see ifc.drawing._XLayerSupplier 86cdf0e10cSrcweir * @see ifc.presentation._XPresentationSupplier 87cdf0e10cSrcweir * @see ifc.style._XStyleFamiliesSupplier 88cdf0e10cSrcweir * @see ifc.drawing._DrawingDocument 89cdf0e10cSrcweir * @see ifc.drawing._XDrawPageDuplicator 90cdf0e10cSrcweir * @see ifc.drawing._XDrawPagesSupplier 91cdf0e10cSrcweir */ 92cdf0e10cSrcweir public class SdXImpressDocument extends TestCase { 93cdf0e10cSrcweir XComponent xImpressDoc; 94cdf0e10cSrcweir XComponent xImpressDoc2; 95cdf0e10cSrcweir 96cdf0e10cSrcweir /** 97cdf0e10cSrcweir * Called while disposing a <code>TestEnvironment</code>. 98cdf0e10cSrcweir * Disposes Impress document. 99*e6b649b5SPedro Giffuni * @param Param test parameters 100cdf0e10cSrcweir * @param log writer to log information while testing 101cdf0e10cSrcweir */ cleanup(TestParameters Param, PrintWriter log)102cdf0e10cSrcweir protected void cleanup(TestParameters Param, PrintWriter log) { 103cdf0e10cSrcweir log.println("disposing xImpressDoc"); 104170fb961SPedro Giffuni util.DesktopTools.closeDoc(xImpressDoc); 105170fb961SPedro Giffuni util.DesktopTools.closeDoc(xImpressDoc2); 106cdf0e10cSrcweir } 107cdf0e10cSrcweir 108cdf0e10cSrcweir /** 109cdf0e10cSrcweir * Creating a Testenvironment for the interfaces to be tested. 110cdf0e10cSrcweir * Creates new impress document that is the instance of the service 111cdf0e10cSrcweir * <code>com.sun.star.presentation.PresentationDocument</code>. 112cdf0e10cSrcweir * @see com.sun.star.presentation.PresentationDocument 113cdf0e10cSrcweir */ createTestEnvironment(TestParameters Param, PrintWriter log)114cdf0e10cSrcweir public synchronized TestEnvironment createTestEnvironment(TestParameters Param, 115cdf0e10cSrcweir PrintWriter log) 116cdf0e10cSrcweir throws StatusException { 117cdf0e10cSrcweir log.println("creating a test environment"); 118cdf0e10cSrcweir 119cdf0e10cSrcweir // get a soffice factory object 120cdf0e10cSrcweir SOfficeFactory SOF = SOfficeFactory.getFactory( 121cdf0e10cSrcweir (XMultiServiceFactory) Param.getMSF()); 122cdf0e10cSrcweir 123cdf0e10cSrcweir try { 124cdf0e10cSrcweir log.println("creating two impress documents"); 125cdf0e10cSrcweir xImpressDoc2 = SOF.createImpressDoc(null); 126cdf0e10cSrcweir xImpressDoc = SOF.createImpressDoc(null); 127cdf0e10cSrcweir } catch (com.sun.star.uno.Exception e) { 128cdf0e10cSrcweir e.printStackTrace(log); 129cdf0e10cSrcweir throw new StatusException("Couldn't create documents", e); 130cdf0e10cSrcweir } 131cdf0e10cSrcweir 132cdf0e10cSrcweir XModel xModel1 = (XModel) UnoRuntime.queryInterface(XModel.class, 133cdf0e10cSrcweir xImpressDoc); 134cdf0e10cSrcweir XModel xModel2 = (XModel) UnoRuntime.queryInterface(XModel.class, 135cdf0e10cSrcweir xImpressDoc2); 136cdf0e10cSrcweir 137cdf0e10cSrcweir XController cont1 = xModel1.getCurrentController(); 138cdf0e10cSrcweir XController cont2 = xModel2.getCurrentController(); 139cdf0e10cSrcweir 140cdf0e10cSrcweir cont1.getFrame().setName("cont1"); 141cdf0e10cSrcweir cont2.getFrame().setName("cont2"); 142cdf0e10cSrcweir 143cdf0e10cSrcweir XSelectionSupplier sel = (XSelectionSupplier) UnoRuntime.queryInterface( 144cdf0e10cSrcweir XSelectionSupplier.class, cont1); 145cdf0e10cSrcweir 146cdf0e10cSrcweir XShape aShape = SOF.createShape(xImpressDoc, 5000, 3500, 7500, 5000, 147cdf0e10cSrcweir "Rectangle"); 148cdf0e10cSrcweir 149cdf0e10cSrcweir 150cdf0e10cSrcweir XPropertySet xShapeProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, aShape); 151cdf0e10cSrcweir 152cdf0e10cSrcweir try { 153cdf0e10cSrcweir xShapeProps.setPropertyValue("FillStyle", com.sun.star.drawing.FillStyle.SOLID); 154cdf0e10cSrcweir xShapeProps.setPropertyValue("FillTransparence", new Integer(50)); 155cdf0e10cSrcweir } catch (UnknownPropertyException ex) { 156cdf0e10cSrcweir ex.printStackTrace(log); 157cdf0e10cSrcweir throw new StatusException("Couldn't make shape transparent", ex); 158cdf0e10cSrcweir } catch (PropertyVetoException ex) { 159cdf0e10cSrcweir ex.printStackTrace(log); 160cdf0e10cSrcweir throw new StatusException("Couldn't make shape transparent", ex); 161cdf0e10cSrcweir } catch (com.sun.star.lang.IllegalArgumentException ex) { 162cdf0e10cSrcweir ex.printStackTrace(log); 163cdf0e10cSrcweir throw new StatusException("Couldn't make shape transparent", ex); 164cdf0e10cSrcweir } catch (WrappedTargetException ex) { 165cdf0e10cSrcweir ex.printStackTrace(log); 166cdf0e10cSrcweir throw new StatusException("Couldn't make shape transparent", ex); 167cdf0e10cSrcweir } 168cdf0e10cSrcweir 169cdf0e10cSrcweir DrawTools.getDrawPage(xImpressDoc, 0).add(aShape); 170cdf0e10cSrcweir 171cdf0e10cSrcweir log.println("creating a new environment for drawpage object"); 172cdf0e10cSrcweir 173cdf0e10cSrcweir TestEnvironment tEnv = new TestEnvironment(xImpressDoc); 174cdf0e10cSrcweir 175cdf0e10cSrcweir log.println("adding Controller as ObjRelation for XModel"); 176cdf0e10cSrcweir tEnv.addObjRelation("CONT2", cont2); 177cdf0e10cSrcweir 178cdf0e10cSrcweir log.println("Adding SelectionSupplier and Shape to select for XModel"); 179cdf0e10cSrcweir tEnv.addObjRelation("SELSUPP", sel); 180cdf0e10cSrcweir tEnv.addObjRelation("TOSELECT", aShape); 181cdf0e10cSrcweir 182cdf0e10cSrcweir // create object relation for XPrintJobBroadcaster 183cdf0e10cSrcweir String fileName = utils.getOfficeTempDirSys((XMultiServiceFactory) Param.getMSF())+"printfile.prt" ; 184cdf0e10cSrcweir File f = new File(fileName); 185cdf0e10cSrcweir if (f.exists()) { 186cdf0e10cSrcweir f.delete(); 187cdf0e10cSrcweir } 188cdf0e10cSrcweir _XPrintJobBroadcaster.MyPrintJobListener listener = new _XPrintJobBroadcaster.MyPrintJobListener(xImpressDoc, fileName); 189cdf0e10cSrcweir tEnv.addObjRelation("XPrintJobBroadcaster.XPrintJobListener", listener); 190cdf0e10cSrcweir 191cdf0e10cSrcweir return tEnv; 192cdf0e10cSrcweir } // finish method getTestEnvironment 193cdf0e10cSrcweir 194cdf0e10cSrcweir } // finish class SdDrawPage 195