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