xref: /AOO41X/test/testuno/source/fvt/uno/sd/animation/CustomAnimation.java (revision 22a547fed620e5dd448260a4daaf9d9a82141760)
1*22a547feSLi Feng Wang package fvt.uno.sd.animation;
2*22a547feSLi Feng Wang 
3*22a547feSLi Feng Wang import junit.framework.Assert;
4*22a547feSLi Feng Wang 
5*22a547feSLi Feng Wang import org.junit.After;
6*22a547feSLi Feng Wang import org.junit.Before;
7*22a547feSLi Feng Wang import org.junit.Test;
8*22a547feSLi Feng Wang import org.openoffice.test.common.FileUtil;
9*22a547feSLi Feng Wang import org.openoffice.test.common.Testspace;
10*22a547feSLi Feng Wang import org.openoffice.test.uno.UnoApp;
11*22a547feSLi Feng Wang 
12*22a547feSLi Feng Wang import testlib.uno.ShapeUtil;
13*22a547feSLi Feng Wang 
14*22a547feSLi Feng Wang import com.sun.star.awt.Point;
15*22a547feSLi Feng Wang import com.sun.star.awt.Size;
16*22a547feSLi Feng Wang import com.sun.star.beans.PropertyValue;
17*22a547feSLi Feng Wang import com.sun.star.beans.XPropertySet;
18*22a547feSLi Feng Wang import com.sun.star.container.XIndexContainer;
19*22a547feSLi Feng Wang import com.sun.star.container.XNameContainer;
20*22a547feSLi Feng Wang import com.sun.star.container.XNamed;
21*22a547feSLi Feng Wang import com.sun.star.drawing.XDrawPage;
22*22a547feSLi Feng Wang import com.sun.star.drawing.XDrawPages;
23*22a547feSLi Feng Wang import com.sun.star.drawing.XDrawPagesSupplier;
24*22a547feSLi Feng Wang import com.sun.star.drawing.XShape;
25*22a547feSLi Feng Wang import com.sun.star.drawing.XShapes;
26*22a547feSLi Feng Wang import com.sun.star.frame.XStorable;
27*22a547feSLi Feng Wang import com.sun.star.lang.XComponent;
28*22a547feSLi Feng Wang import com.sun.star.lang.XSingleServiceFactory;
29*22a547feSLi Feng Wang import com.sun.star.presentation.AnimationEffect;
30*22a547feSLi Feng Wang import com.sun.star.presentation.XCustomPresentationSupplier;
31*22a547feSLi Feng Wang import com.sun.star.presentation.XPresentation;
32*22a547feSLi Feng Wang import com.sun.star.presentation.XPresentationSupplier;
33*22a547feSLi Feng Wang import com.sun.star.table.XCell;
34*22a547feSLi Feng Wang import com.sun.star.text.ControlCharacter;
35*22a547feSLi Feng Wang import com.sun.star.text.XText;
36*22a547feSLi Feng Wang import com.sun.star.text.XTextCursor;
37*22a547feSLi Feng Wang import com.sun.star.text.XTextRange;
38*22a547feSLi Feng Wang import com.sun.star.uno.UnoRuntime;
39*22a547feSLi Feng Wang 
40*22a547feSLi Feng Wang public class CustomAnimation {
41*22a547feSLi Feng Wang 	XPresentationSupplier sdDocument = null;
42*22a547feSLi Feng Wang 	XPresentation pre = null;
43*22a547feSLi Feng Wang 	XComponent precomp = null;
44*22a547feSLi Feng Wang 	XComponent impressDocument = null;
45*22a547feSLi Feng Wang 	XComponent reLoadFile = null;
46*22a547feSLi Feng Wang 	XDrawPagesSupplier drawsupplier = null;
47*22a547feSLi Feng Wang 	XDrawPages drawpages = null;
48*22a547feSLi Feng Wang 
49*22a547feSLi Feng Wang 	String filePath = null;
50*22a547feSLi Feng Wang 
51*22a547feSLi Feng Wang 	UnoApp unoApp = new UnoApp();
52*22a547feSLi Feng Wang 
53*22a547feSLi Feng Wang 	/**
54*22a547feSLi Feng Wang 	 * @throws java.lang.Exception
55*22a547feSLi Feng Wang 	 */
56*22a547feSLi Feng Wang 	@Before
57*22a547feSLi Feng Wang 	public void setUp() throws Exception {
58*22a547feSLi Feng Wang 		unoApp.start();
59*22a547feSLi Feng Wang 		createDocumentAndSlide();
60*22a547feSLi Feng Wang 	}
61*22a547feSLi Feng Wang 
62*22a547feSLi Feng Wang 	@After
63*22a547feSLi Feng Wang 	public void tearDown() throws Exception {
64*22a547feSLi Feng Wang 		unoApp.closeDocument(impressDocument);
65*22a547feSLi Feng Wang 		unoApp.closeDocument(reLoadFile);
66*22a547feSLi Feng Wang 		unoApp.close();
67*22a547feSLi Feng Wang 	}
68*22a547feSLi Feng Wang 
69*22a547feSLi Feng Wang 	@Test
70*22a547feSLi Feng Wang 	public void testShapeAnimation() throws Exception {
71*22a547feSLi Feng Wang 
72*22a547feSLi Feng Wang 		XShapes xShapes = null;
73*22a547feSLi Feng Wang 		XPropertySet xShapePropSet[] = new XPropertySet[23];
74*22a547feSLi Feng Wang 
75*22a547feSLi Feng Wang 		drawpages.insertNewByIndex(0);
76*22a547feSLi Feng Wang 
77*22a547feSLi Feng Wang 		String aNameArray[] = { "Page 1", "Page 2", "Page 3", "Page 4",
78*22a547feSLi Feng Wang 				"Page 5", "Page 6", "Page 7", "Page 8", "Page 9", "Page 10",
79*22a547feSLi Feng Wang 				"Page 11", "Page 12", "Page 13", "Page 14", "Page 15",
80*22a547feSLi Feng Wang 				"Page 16", "Page 17", "Page 18", "Page 19", "Page 20",
81*22a547feSLi Feng Wang 				"Page 21", "Page 22", "Page 23", };
82*22a547feSLi Feng Wang 		AnimationEffect AnimationEffectArray[] = {
83*22a547feSLi Feng Wang 				AnimationEffect.NONE,
84*22a547feSLi Feng Wang 				AnimationEffect.FADE_FROM_LEFT,
85*22a547feSLi Feng Wang 				AnimationEffect.FADE_FROM_TOP,
86*22a547feSLi Feng Wang 				AnimationEffect.FADE_FROM_RIGHT,
87*22a547feSLi Feng Wang 				AnimationEffect.FADE_FROM_BOTTOM,
88*22a547feSLi Feng Wang 				AnimationEffect.FADE_TO_CENTER,
89*22a547feSLi Feng Wang 				AnimationEffect.FADE_FROM_CENTER,
90*22a547feSLi Feng Wang 				AnimationEffect.MOVE_FROM_LEFT,
91*22a547feSLi Feng Wang 				AnimationEffect.MOVE_FROM_TOP,
92*22a547feSLi Feng Wang 				AnimationEffect.MOVE_FROM_RIGHT,
93*22a547feSLi Feng Wang 				AnimationEffect.MOVE_FROM_BOTTOM,
94*22a547feSLi Feng Wang 				AnimationEffect.VERTICAL_STRIPES,
95*22a547feSLi Feng Wang 				AnimationEffect.HORIZONTAL_STRIPES,
96*22a547feSLi Feng Wang 				AnimationEffect.CLOCKWISE,
97*22a547feSLi Feng Wang 				AnimationEffect.COUNTERCLOCKWISE,
98*22a547feSLi Feng Wang 				AnimationEffect.FADE_FROM_UPPERLEFT,
99*22a547feSLi Feng Wang 				AnimationEffect.FADE_FROM_UPPERRIGHT,
100*22a547feSLi Feng Wang 				AnimationEffect.FADE_FROM_LOWERLEFT,
101*22a547feSLi Feng Wang 				AnimationEffect.FADE_FROM_LOWERRIGHT,
102*22a547feSLi Feng Wang 				AnimationEffect.CLOSE_VERTICAL,
103*22a547feSLi Feng Wang 				AnimationEffect.CLOSE_HORIZONTAL,
104*22a547feSLi Feng Wang 				AnimationEffect.OPEN_VERTICAL,
105*22a547feSLi Feng Wang 				AnimationEffect.OPEN_HORIZONTAL,
106*22a547feSLi Feng Wang 				AnimationEffect.PATH,
107*22a547feSLi Feng Wang /*				AnimationEffect.MOVE_TO_LEFT,
108*22a547feSLi Feng Wang 				AnimationEffect.MOVE_TO_TOP,
109*22a547feSLi Feng Wang 				AnimationEffect.MOVE_TO_RIGHT,
110*22a547feSLi Feng Wang 				AnimationEffect.MOVE_TO_BOTTOM,
111*22a547feSLi Feng Wang 				AnimationEffect.SPIRALIN_LEFT,
112*22a547feSLi Feng Wang 				AnimationEffect.SPIRALIN_RIGHT,
113*22a547feSLi Feng Wang 				AnimationEffect.SPIRALOUT_LEFT,
114*22a547feSLi Feng Wang 				AnimationEffect.SPIRALOUT_RIGHT,
115*22a547feSLi Feng Wang 				AnimationEffect.DISSOLVE,
116*22a547feSLi Feng Wang 				AnimationEffect.WAVYLINE_FROM_LEFT,
117*22a547feSLi Feng Wang 				AnimationEffect.RANDOM,
118*22a547feSLi Feng Wang 				AnimationEffect.VERTICAL_LINES,
119*22a547feSLi Feng Wang 				AnimationEffect.LASER_FROM_LEFT,
120*22a547feSLi Feng Wang 				AnimationEffect.APPEAR,
121*22a547feSLi Feng Wang 				AnimationEffect.HIDE,
122*22a547feSLi Feng Wang 				AnimationEffect.MOVE_FROM_UPPERLEFT,
123*22a547feSLi Feng Wang 				AnimationEffect.VERTICAL_CHECKERBOARD,
124*22a547feSLi Feng Wang 				AnimationEffect.HORIZONTAL_ROTATE,
125*22a547feSLi Feng Wang 				AnimationEffect.VERTICAL_STRETCH,
126*22a547feSLi Feng Wang 				AnimationEffect.ZOOM_IN,
127*22a547feSLi Feng Wang 				AnimationEffect.ZOOM_OUT_FROM_LEFT, */
128*22a547feSLi Feng Wang 				};
129*22a547feSLi Feng Wang 
130*22a547feSLi Feng Wang 		// insert  pages
131*22a547feSLi Feng Wang 		while (drawpages.getCount() < aNameArray.length)
132*22a547feSLi Feng Wang 			drawpages.insertNewByIndex(0);
133*22a547feSLi Feng Wang 
134*22a547feSLi Feng Wang 		// add text shape to each page
135*22a547feSLi Feng Wang 		for (int i = 0; i < aNameArray.length; i++) {
136*22a547feSLi Feng Wang 			XDrawPage xDrawPage = (XDrawPage) UnoRuntime.queryInterface(
137*22a547feSLi Feng Wang 					XDrawPage.class, drawpages.getByIndex(i));
138*22a547feSLi Feng Wang 			XNamed xPageName = (XNamed) UnoRuntime.queryInterface(XNamed.class,
139*22a547feSLi Feng Wang 					xDrawPage);
140*22a547feSLi Feng Wang 			xPageName.setName(aNameArray[i]);
141*22a547feSLi Feng Wang 
142*22a547feSLi Feng Wang 			xShapes = (XShapes) UnoRuntime.queryInterface(XShapes.class,
143*22a547feSLi Feng Wang 					drawpages.getByIndex(i));
144*22a547feSLi Feng Wang 
145*22a547feSLi Feng Wang 			// create a rectangle that is placed on the top left of the page
146*22a547feSLi Feng Wang 			xShapePropSet[i] = ShapeUtil.createAndInsertShape(impressDocument,
147*22a547feSLi Feng Wang 					xShapes, new Point(1000, 1000), new Size(5000, 5000),
148*22a547feSLi Feng Wang 					"com.sun.star.drawing.RectangleShape");
149*22a547feSLi Feng Wang 		}
150*22a547feSLi Feng Wang 
151*22a547feSLi Feng Wang 		for (int i = 0; i < aNameArray.length; i++) {
152*22a547feSLi Feng Wang 			// set an object animation for each slide
153*22a547feSLi Feng Wang 			xShapePropSet[i]
154*22a547feSLi Feng Wang 					.setPropertyValue("Effect", AnimationEffectArray[i]);
155*22a547feSLi Feng Wang 		}
156*22a547feSLi Feng Wang 
157*22a547feSLi Feng Wang 		// If this property and the property DimPrevious are both true, the shape is hidden on the next click after the AnimationEffect has finished.
158*22a547feSLi Feng Wang 		xShapePropSet[1].setPropertyValue("DimHide", new Boolean(false));
159*22a547feSLi Feng Wang 		// If true, this shape is painted using DimColor on the next click after finishing the AnimationEffect.
160*22a547feSLi Feng Wang 		xShapePropSet[1].setPropertyValue("DimPrevious", new Boolean(true));
161*22a547feSLi Feng Wang 		// his color is used to paint the shape on the next click after the animation effect has finished
162*22a547feSLi Feng Wang 		xShapePropSet[1].setPropertyValue("DimColor", new Integer(0xff0000));
163*22a547feSLi Feng Wang 		// the sound file specified in Sound is played while the animation effect is executed
164*22a547feSLi Feng Wang 		xShapePropSet[1].setPropertyValue("SoundOn", new Boolean(false));
165*22a547feSLi Feng Wang 		// the sound specified in the Sound property of this shape is played completely
166*22a547feSLi Feng Wang 		xShapePropSet[1].setPropertyValue("PlayFull", new Boolean(false));
167*22a547feSLi Feng Wang 
168*22a547feSLi Feng Wang 		saveAndLoadSlide();
169*22a547feSLi Feng Wang 
170*22a547feSLi Feng Wang 		for (int i = 0; i < aNameArray.length; i++) {
171*22a547feSLi Feng Wang 			// assert if Shape Animation is set
172*22a547feSLi Feng Wang 			Assert.assertEquals(
173*22a547feSLi Feng Wang 					"Text Animation Effect is AnimationEffectArray[]",
174*22a547feSLi Feng Wang 					AnimationEffectArray[i],
175*22a547feSLi Feng Wang 					xShapePropSet[i].getPropertyValue("Effect"));
176*22a547feSLi Feng Wang 		}
177*22a547feSLi Feng Wang 		// assert if DimHide is false
178*22a547feSLi Feng Wang 		Assert.assertEquals("Shape Animation DimHide is false", Boolean.FALSE,
179*22a547feSLi Feng Wang 				xShapePropSet[1].getPropertyValue("DimHide"));
180*22a547feSLi Feng Wang 		// assert if DimPrevious is true
181*22a547feSLi Feng Wang 		Assert.assertEquals("Shape Animation DimPrevious is true",
182*22a547feSLi Feng Wang 				Boolean.TRUE, xShapePropSet[1].getPropertyValue("DimPrevious"));
183*22a547feSLi Feng Wang 		// assert if DimColor is red
184*22a547feSLi Feng Wang 		Assert.assertEquals("Shape Animation DimColor is Red", 0xff0000,
185*22a547feSLi Feng Wang 				xShapePropSet[1].getPropertyValue("DimColor"));
186*22a547feSLi Feng Wang 		// assert the sound file specified in Sound don't play while the
187*22a547feSLi Feng Wang 		// animation effect is executed.
188*22a547feSLi Feng Wang 		Assert.assertEquals("Shape SoundOn is false", Boolean.FALSE,
189*22a547feSLi Feng Wang 				xShapePropSet[1].getPropertyValue("SoundOn"));
190*22a547feSLi Feng Wang 		// assert the sound specified in the Sound property of this shape is
191*22a547feSLi Feng Wang 		// played completely
192*22a547feSLi Feng Wang 		Assert.assertEquals("Shape PlayFull is false", Boolean.FALSE,
193*22a547feSLi Feng Wang 				xShapePropSet[1].getPropertyValue("PlayFull"));
194*22a547feSLi Feng Wang 
195*22a547feSLi Feng Wang 	}
196*22a547feSLi Feng Wang 
197*22a547feSLi Feng Wang 	public XPropertySet addPortion(XShape xShape, String sText,
198*22a547feSLi Feng Wang 			boolean bNewParagraph)
199*22a547feSLi Feng Wang 			throws com.sun.star.lang.IllegalArgumentException {
200*22a547feSLi Feng Wang 		XText xText = (XText) UnoRuntime.queryInterface(XText.class, xShape);
201*22a547feSLi Feng Wang 
202*22a547feSLi Feng Wang 		XTextCursor xTextCursor = xText.createTextCursor();
203*22a547feSLi Feng Wang 		xTextCursor.gotoEnd(false);
204*22a547feSLi Feng Wang 		if (bNewParagraph == true) {
205*22a547feSLi Feng Wang 			xText.insertControlCharacter(xTextCursor,
206*22a547feSLi Feng Wang 					ControlCharacter.PARAGRAPH_BREAK, false);
207*22a547feSLi Feng Wang 			xTextCursor.gotoEnd(false);
208*22a547feSLi Feng Wang 		}
209*22a547feSLi Feng Wang 		XTextRange xTextRange = (XTextRange) UnoRuntime.queryInterface(
210*22a547feSLi Feng Wang 				XTextRange.class, xTextCursor);
211*22a547feSLi Feng Wang 		xTextRange.setString(sText);
212*22a547feSLi Feng Wang 		xTextCursor.gotoEnd(true);
213*22a547feSLi Feng Wang 		XPropertySet xPropSet = (XPropertySet) UnoRuntime.queryInterface(
214*22a547feSLi Feng Wang 				XPropertySet.class, xText);
215*22a547feSLi Feng Wang 		return xPropSet;
216*22a547feSLi Feng Wang 	}
217*22a547feSLi Feng Wang 
218*22a547feSLi Feng Wang 	/**
219*22a547feSLi Feng Wang 	 * create a new presentation document and insert a new slide.
220*22a547feSLi Feng Wang 	 *
221*22a547feSLi Feng Wang 	 * @throws Exception
222*22a547feSLi Feng Wang 	 */
223*22a547feSLi Feng Wang 	public void createDocumentAndSlide() throws Exception {
224*22a547feSLi Feng Wang 		impressDocument = (XComponent) UnoRuntime.queryInterface(
225*22a547feSLi Feng Wang 				XComponent.class, unoApp.newDocument("simpress"));
226*22a547feSLi Feng Wang 		drawsupplier = (XDrawPagesSupplier) UnoRuntime.queryInterface(
227*22a547feSLi Feng Wang 				XDrawPagesSupplier.class, impressDocument);
228*22a547feSLi Feng Wang 		drawpages = drawsupplier.getDrawPages();
229*22a547feSLi Feng Wang 
230*22a547feSLi Feng Wang 		sdDocument = (XPresentationSupplier) UnoRuntime.queryInterface(
231*22a547feSLi Feng Wang 				XPresentationSupplier.class, impressDocument);
232*22a547feSLi Feng Wang 		pre = sdDocument.getPresentation();
233*22a547feSLi Feng Wang 	}
234*22a547feSLi Feng Wang 
235*22a547feSLi Feng Wang 	/**
236*22a547feSLi Feng Wang 	 * Save presentation and reLoad the slide.
237*22a547feSLi Feng Wang 	 *
238*22a547feSLi Feng Wang 	 * @param no
239*22a547feSLi Feng Wang 	 * @return void
240*22a547feSLi Feng Wang 	 * @throws Exception
241*22a547feSLi Feng Wang 	 */
242*22a547feSLi Feng Wang 	public void saveAndLoadSlide() throws Exception {
243*22a547feSLi Feng Wang 		reLoadFile = saveAndReloadDoc(impressDocument,
244*22a547feSLi Feng Wang 				"StarOffice XML (Impress)", "odp");
245*22a547feSLi Feng Wang 		drawsupplier = (XDrawPagesSupplier) UnoRuntime.queryInterface(
246*22a547feSLi Feng Wang 				XDrawPagesSupplier.class, reLoadFile);
247*22a547feSLi Feng Wang 		drawpages = drawsupplier.getDrawPages();
248*22a547feSLi Feng Wang 
249*22a547feSLi Feng Wang 		sdDocument = (XPresentationSupplier) UnoRuntime.queryInterface(
250*22a547feSLi Feng Wang 				XPresentationSupplier.class, reLoadFile);
251*22a547feSLi Feng Wang 		pre = sdDocument.getPresentation();
252*22a547feSLi Feng Wang 	}
253*22a547feSLi Feng Wang 
254*22a547feSLi Feng Wang 	/**
255*22a547feSLi Feng Wang 	 * save and reload Presentation document.
256*22a547feSLi Feng Wang 	 *
257*22a547feSLi Feng Wang 	 * @param presentationDocument
258*22a547feSLi Feng Wang 	 * @param sFilter
259*22a547feSLi Feng Wang 	 * @param sExtension
260*22a547feSLi Feng Wang 	 * @return
261*22a547feSLi Feng Wang 	 * @throws Exception
262*22a547feSLi Feng Wang 	 */
263*22a547feSLi Feng Wang 	private XComponent saveAndReloadDoc(XComponent presentationDocument,
264*22a547feSLi Feng Wang 			String sFilter, String sExtension) throws Exception {
265*22a547feSLi Feng Wang 		filePath = Testspace.getPath("tmp/shapeanimation." + sExtension);
266*22a547feSLi Feng Wang 		PropertyValue[] aStoreProperties = new PropertyValue[2];
267*22a547feSLi Feng Wang 		aStoreProperties[0] = new PropertyValue();
268*22a547feSLi Feng Wang 		aStoreProperties[1] = new PropertyValue();
269*22a547feSLi Feng Wang 		aStoreProperties[0].Name = "Override";
270*22a547feSLi Feng Wang 		aStoreProperties[0].Value = true;
271*22a547feSLi Feng Wang 		aStoreProperties[1].Name = "FilterName";
272*22a547feSLi Feng Wang 		aStoreProperties[1].Value = sFilter;
273*22a547feSLi Feng Wang 		XStorable xStorable = (XStorable) UnoRuntime.queryInterface(
274*22a547feSLi Feng Wang 				XStorable.class, presentationDocument);
275*22a547feSLi Feng Wang 		xStorable.storeToURL(FileUtil.getUrl(filePath), aStoreProperties);
276*22a547feSLi Feng Wang 
277*22a547feSLi Feng Wang 		return (XComponent) UnoRuntime.queryInterface(XComponent.class,
278*22a547feSLi Feng Wang 				unoApp.loadDocument(filePath));
279*22a547feSLi Feng Wang 	}
280*22a547feSLi Feng Wang }
281