1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 package fvt.uno.sd.animation; 22 23 import junit.framework.Assert; 24 25 import org.junit.After; 26 import org.junit.Before; 27 import org.junit.Test; 28 import org.openoffice.test.common.FileUtil; 29 import org.openoffice.test.common.Testspace; 30 import org.openoffice.test.uno.UnoApp; 31 32 import testlib.uno.ShapeUtil; 33 34 import com.sun.star.awt.Point; 35 import com.sun.star.awt.Size; 36 import com.sun.star.beans.PropertyValue; 37 import com.sun.star.beans.XPropertySet; 38 import com.sun.star.container.XIndexContainer; 39 import com.sun.star.container.XNameContainer; 40 import com.sun.star.container.XNamed; 41 import com.sun.star.drawing.XDrawPage; 42 import com.sun.star.drawing.XDrawPages; 43 import com.sun.star.drawing.XDrawPagesSupplier; 44 import com.sun.star.drawing.XShape; 45 import com.sun.star.drawing.XShapes; 46 import com.sun.star.frame.XStorable; 47 import com.sun.star.lang.XComponent; 48 import com.sun.star.lang.XSingleServiceFactory; 49 import com.sun.star.presentation.AnimationEffect; 50 import com.sun.star.presentation.XCustomPresentationSupplier; 51 import com.sun.star.presentation.XPresentation; 52 import com.sun.star.presentation.XPresentationSupplier; 53 import com.sun.star.text.ControlCharacter; 54 import com.sun.star.text.XText; 55 import com.sun.star.text.XTextCursor; 56 import com.sun.star.text.XTextRange; 57 import com.sun.star.uno.UnoRuntime; 58 59 public class TextAnimation { 60 XPresentationSupplier sdDocument = null; 61 XPresentation pre = null; 62 XComponent precomp = null; 63 XComponent impressDocument = null; 64 XComponent reLoadFile = null; 65 XDrawPagesSupplier drawsupplier = null; 66 XDrawPages drawpages = null; 67 68 String filePath = null; 69 70 UnoApp unoApp = new UnoApp(); 71 72 /** 73 * @throws java.lang.Exception 74 */ 75 @Before setUp()76 public void setUp() throws Exception { 77 unoApp.start(); 78 createDocumentAndSlide(); 79 } 80 81 @After tearDown()82 public void tearDown() throws Exception { 83 unoApp.closeDocument(impressDocument); 84 unoApp.closeDocument(reLoadFile); 85 unoApp.close(); 86 } 87 88 @Test testTextAnimation()89 public void testTextAnimation() throws Exception { 90 91 XShapes xShapes; 92 XPropertySet xShapePropSet; 93 Point po = new Point(5000, 5000); 94 95 // create pages, so that three are available 96 drawpages.insertNewByIndex(0); 97 // get the shape container for page one 98 xShapes = (XShapes) UnoRuntime.queryInterface(XShapes.class, 99 drawpages.getByIndex(0)); 100 // create a rectangle that is placed on the top left of the page 101 XShape xRectangle = ShapeUtil.createShape(impressDocument, po, 102 new Size(21000, 12500), "com.sun.star.drawing.RectangleShape"); 103 xShapes.add(xRectangle); 104 105 XPropertySet xTextPropSet = addPortion(xRectangle, "Text Animation", 106 false); 107 108 xTextPropSet.setPropertyValue("TextEffect", 109 AnimationEffect.MOVE_FROM_RIGHT); 110 111 saveAndLoadSlide(); 112 113 // assert if Text Animation is set 114 Assert.assertEquals("Text Animation Effect is MOVE_FROM_RIGHT", 115 AnimationEffect.MOVE_FROM_RIGHT, 116 xTextPropSet.getPropertyValue("TextEffect")); 117 118 } 119 addPortion(XShape xShape, String sText, boolean bNewParagraph)120 public XPropertySet addPortion(XShape xShape, String sText, 121 boolean bNewParagraph) 122 throws com.sun.star.lang.IllegalArgumentException { 123 XText xText = (XText) UnoRuntime.queryInterface(XText.class, xShape); 124 125 XTextCursor xTextCursor = xText.createTextCursor(); 126 xTextCursor.gotoEnd(false); 127 if (bNewParagraph == true) { 128 xText.insertControlCharacter(xTextCursor, 129 ControlCharacter.PARAGRAPH_BREAK, false); 130 xTextCursor.gotoEnd(false); 131 } 132 XTextRange xTextRange = (XTextRange) UnoRuntime.queryInterface( 133 XTextRange.class, xTextCursor); 134 xTextRange.setString(sText); 135 xTextCursor.gotoEnd(true); 136 XPropertySet xPropSet = (XPropertySet) UnoRuntime.queryInterface( 137 XPropertySet.class, xText); 138 return xPropSet; 139 } 140 141 /** 142 * create a new presentation document and insert a new slide. 143 * 144 * @throws Exception 145 */ createDocumentAndSlide()146 public void createDocumentAndSlide() throws Exception { 147 impressDocument = (XComponent) UnoRuntime.queryInterface( 148 XComponent.class, unoApp.newDocument("simpress")); 149 drawsupplier = (XDrawPagesSupplier) UnoRuntime.queryInterface( 150 XDrawPagesSupplier.class, impressDocument); 151 drawpages = drawsupplier.getDrawPages(); 152 153 sdDocument = (XPresentationSupplier) UnoRuntime.queryInterface( 154 XPresentationSupplier.class, impressDocument); 155 pre = sdDocument.getPresentation(); 156 } 157 158 /** 159 * Save presentation and reLoad the slide. 160 * 161 * @param no 162 * @return void 163 * @throws Exception 164 */ saveAndLoadSlide()165 public void saveAndLoadSlide() throws Exception { 166 reLoadFile = saveAndReloadDoc(impressDocument, 167 "StarOffice XML (Impress)", "odp"); 168 drawsupplier = (XDrawPagesSupplier) UnoRuntime.queryInterface( 169 XDrawPagesSupplier.class, reLoadFile); 170 drawpages = drawsupplier.getDrawPages(); 171 172 sdDocument = (XPresentationSupplier) UnoRuntime.queryInterface( 173 XPresentationSupplier.class, reLoadFile); 174 pre = sdDocument.getPresentation(); 175 } 176 177 /** 178 * save and reload Presentation document. 179 * 180 * @param presentationDocument 181 * @param sFilter 182 * @param sExtension 183 * @return 184 * @throws Exception 185 */ saveAndReloadDoc(XComponent presentationDocument, String sFilter, String sExtension)186 private XComponent saveAndReloadDoc(XComponent presentationDocument, 187 String sFilter, String sExtension) throws Exception { 188 filePath = Testspace.getPath("tmp/customshow." + sExtension); 189 PropertyValue[] aStoreProperties = new PropertyValue[2]; 190 aStoreProperties[0] = new PropertyValue(); 191 aStoreProperties[1] = new PropertyValue(); 192 aStoreProperties[0].Name = "Override"; 193 aStoreProperties[0].Value = true; 194 aStoreProperties[1].Name = "FilterName"; 195 aStoreProperties[1].Value = sFilter; 196 XStorable xStorable = (XStorable) UnoRuntime.queryInterface( 197 XStorable.class, presentationDocument); 198 xStorable.storeToURL(FileUtil.getUrl(filePath), aStoreProperties); 199 200 return (XComponent)UnoRuntime.queryInterface(XComponent.class, 201 unoApp.loadDocument(filePath)); 202 } 203 } 204