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. 99cdf0e10cSrcweir * @param tParam test parameters 100cdf0e10cSrcweir * @param tEnv the environment to cleanup 101cdf0e10cSrcweir * @param log writer to log information while testing 102cdf0e10cSrcweir */ 103cdf0e10cSrcweir protected void cleanup(TestParameters Param, PrintWriter log) { 104cdf0e10cSrcweir log.println("disposing xImpressDoc"); 105*170fb961SPedro Giffuni util.DesktopTools.closeDoc(xImpressDoc); 106*170fb961SPedro Giffuni util.DesktopTools.closeDoc(xImpressDoc2); 107cdf0e10cSrcweir } 108cdf0e10cSrcweir 109cdf0e10cSrcweir /** 110cdf0e10cSrcweir * Creating a Testenvironment for the interfaces to be tested. 111cdf0e10cSrcweir * Creates new impress document that is the instance of the service 112cdf0e10cSrcweir * <code>com.sun.star.presentation.PresentationDocument</code>. 113cdf0e10cSrcweir * @see com.sun.star.presentation.PresentationDocument 114cdf0e10cSrcweir */ 115cdf0e10cSrcweir public synchronized TestEnvironment createTestEnvironment(TestParameters Param, 116cdf0e10cSrcweir PrintWriter log) 117cdf0e10cSrcweir throws StatusException { 118cdf0e10cSrcweir log.println("creating a test environment"); 119cdf0e10cSrcweir 120cdf0e10cSrcweir // get a soffice factory object 121cdf0e10cSrcweir SOfficeFactory SOF = SOfficeFactory.getFactory( 122cdf0e10cSrcweir (XMultiServiceFactory) Param.getMSF()); 123cdf0e10cSrcweir 124cdf0e10cSrcweir try { 125cdf0e10cSrcweir log.println("creating two impress documents"); 126cdf0e10cSrcweir xImpressDoc2 = SOF.createImpressDoc(null); 127cdf0e10cSrcweir xImpressDoc = SOF.createImpressDoc(null); 128cdf0e10cSrcweir } catch (com.sun.star.uno.Exception e) { 129cdf0e10cSrcweir e.printStackTrace(log); 130cdf0e10cSrcweir throw new StatusException("Couldn't create documents", e); 131cdf0e10cSrcweir } 132cdf0e10cSrcweir 133cdf0e10cSrcweir XModel xModel1 = (XModel) UnoRuntime.queryInterface(XModel.class, 134cdf0e10cSrcweir xImpressDoc); 135cdf0e10cSrcweir XModel xModel2 = (XModel) UnoRuntime.queryInterface(XModel.class, 136cdf0e10cSrcweir xImpressDoc2); 137cdf0e10cSrcweir 138cdf0e10cSrcweir XController cont1 = xModel1.getCurrentController(); 139cdf0e10cSrcweir XController cont2 = xModel2.getCurrentController(); 140cdf0e10cSrcweir 141cdf0e10cSrcweir cont1.getFrame().setName("cont1"); 142cdf0e10cSrcweir cont2.getFrame().setName("cont2"); 143cdf0e10cSrcweir 144cdf0e10cSrcweir XSelectionSupplier sel = (XSelectionSupplier) UnoRuntime.queryInterface( 145cdf0e10cSrcweir XSelectionSupplier.class, cont1); 146cdf0e10cSrcweir 147cdf0e10cSrcweir XShape aShape = SOF.createShape(xImpressDoc, 5000, 3500, 7500, 5000, 148cdf0e10cSrcweir "Rectangle"); 149cdf0e10cSrcweir 150cdf0e10cSrcweir 151cdf0e10cSrcweir XPropertySet xShapeProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, aShape); 152cdf0e10cSrcweir 153cdf0e10cSrcweir try { 154cdf0e10cSrcweir xShapeProps.setPropertyValue("FillStyle", com.sun.star.drawing.FillStyle.SOLID); 155cdf0e10cSrcweir xShapeProps.setPropertyValue("FillTransparence", new Integer(50)); 156cdf0e10cSrcweir } catch (UnknownPropertyException ex) { 157cdf0e10cSrcweir ex.printStackTrace(log); 158cdf0e10cSrcweir throw new StatusException("Couldn't make shape transparent", ex); 159cdf0e10cSrcweir } catch (PropertyVetoException ex) { 160cdf0e10cSrcweir ex.printStackTrace(log); 161cdf0e10cSrcweir throw new StatusException("Couldn't make shape transparent", ex); 162cdf0e10cSrcweir } catch (com.sun.star.lang.IllegalArgumentException ex) { 163cdf0e10cSrcweir ex.printStackTrace(log); 164cdf0e10cSrcweir throw new StatusException("Couldn't make shape transparent", ex); 165cdf0e10cSrcweir } catch (WrappedTargetException ex) { 166cdf0e10cSrcweir ex.printStackTrace(log); 167cdf0e10cSrcweir throw new StatusException("Couldn't make shape transparent", ex); 168cdf0e10cSrcweir } 169cdf0e10cSrcweir 170cdf0e10cSrcweir DrawTools.getDrawPage(xImpressDoc, 0).add(aShape); 171cdf0e10cSrcweir 172cdf0e10cSrcweir log.println("creating a new environment for drawpage object"); 173cdf0e10cSrcweir 174cdf0e10cSrcweir TestEnvironment tEnv = new TestEnvironment(xImpressDoc); 175cdf0e10cSrcweir 176cdf0e10cSrcweir log.println("adding Controller as ObjRelation for XModel"); 177cdf0e10cSrcweir tEnv.addObjRelation("CONT2", cont2); 178cdf0e10cSrcweir 179cdf0e10cSrcweir log.println("Adding SelectionSupplier and Shape to select for XModel"); 180cdf0e10cSrcweir tEnv.addObjRelation("SELSUPP", sel); 181cdf0e10cSrcweir tEnv.addObjRelation("TOSELECT", aShape); 182cdf0e10cSrcweir 183cdf0e10cSrcweir // create object relation for XPrintJobBroadcaster 184cdf0e10cSrcweir String fileName = utils.getOfficeTempDirSys((XMultiServiceFactory) Param.getMSF())+"printfile.prt" ; 185cdf0e10cSrcweir File f = new File(fileName); 186cdf0e10cSrcweir if (f.exists()) { 187cdf0e10cSrcweir f.delete(); 188cdf0e10cSrcweir } 189cdf0e10cSrcweir _XPrintJobBroadcaster.MyPrintJobListener listener = new _XPrintJobBroadcaster.MyPrintJobListener(xImpressDoc, fileName); 190cdf0e10cSrcweir tEnv.addObjRelation("XPrintJobBroadcaster.XPrintJobListener", listener); 191cdf0e10cSrcweir 192cdf0e10cSrcweir return tEnv; 193cdf0e10cSrcweir } // finish method getTestEnvironment 194cdf0e10cSrcweir 195cdf0e10cSrcweir } // finish class SdDrawPage 196