View | Details | Raw Unified | Return to issue 120782
Collapse All | Expand All

(-)source/testcase/uno/sd/CustomAnimation.java (-280 lines)
Lines 1-280 Link Here
1
package testcase.uno.sd;
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.table.XCell;
34
import com.sun.star.text.ControlCharacter;
35
import com.sun.star.text.XText;
36
import com.sun.star.text.XTextCursor;
37
import com.sun.star.text.XTextRange;
38
import com.sun.star.uno.UnoRuntime;
39
40
public class CustomAnimation {
41
	XPresentationSupplier sdDocument = null;
42
	XPresentation pre = null;
43
	XComponent precomp = null;
44
	XComponent impressDocument = null;
45
	XComponent reLoadFile = null;
46
	XDrawPagesSupplier drawsupplier = null;
47
	XDrawPages drawpages = null;
48
49
	String filePath = null;
50
51
	UnoApp unoApp = new UnoApp();
52
53
	/**
54
	 * @throws java.lang.Exception
55
	 */
56
	@Before
57
	public void setUp() throws Exception {
58
		unoApp.start();
59
		createDocumentAndSlide();
60
	}
61
62
	@After
63
	public void tearDown() throws Exception {
64
		unoApp.closeDocument(impressDocument);
65
		unoApp.closeDocument(reLoadFile);
66
		unoApp.close();
67
	}
68
69
	@Test
70
	public void testShapeAnimation() throws Exception {
71
72
		XShapes xShapes = null;
73
		XPropertySet xShapePropSet[] = new XPropertySet[23];
74
75
		drawpages.insertNewByIndex(0);
76
77
		String aNameArray[] = { "Page 1", "Page 2", "Page 3", "Page 4",
78
				"Page 5", "Page 6", "Page 7", "Page 8", "Page 9", "Page 10",
79
				"Page 11", "Page 12", "Page 13", "Page 14", "Page 15",
80
				"Page 16", "Page 17", "Page 18", "Page 19", "Page 20",
81
				"Page 21", "Page 22", "Page 23", };
82
		AnimationEffect AnimationEffectArray[] = { 
83
				AnimationEffect.NONE,
84
				AnimationEffect.FADE_FROM_LEFT, 
85
				AnimationEffect.FADE_FROM_TOP,
86
				AnimationEffect.FADE_FROM_RIGHT,
87
				AnimationEffect.FADE_FROM_BOTTOM,
88
				AnimationEffect.FADE_TO_CENTER,
89
				AnimationEffect.FADE_FROM_CENTER,
90
				AnimationEffect.MOVE_FROM_LEFT, 
91
				AnimationEffect.MOVE_FROM_TOP,
92
				AnimationEffect.MOVE_FROM_RIGHT,
93
				AnimationEffect.MOVE_FROM_BOTTOM,
94
				AnimationEffect.VERTICAL_STRIPES,
95
				AnimationEffect.HORIZONTAL_STRIPES, 
96
				AnimationEffect.CLOCKWISE,
97
				AnimationEffect.COUNTERCLOCKWISE,
98
				AnimationEffect.FADE_FROM_UPPERLEFT,
99
				AnimationEffect.FADE_FROM_UPPERRIGHT,
100
				AnimationEffect.FADE_FROM_LOWERLEFT,
101
				AnimationEffect.FADE_FROM_LOWERRIGHT,
102
				AnimationEffect.CLOSE_VERTICAL,
103
				AnimationEffect.CLOSE_HORIZONTAL,
104
				AnimationEffect.OPEN_VERTICAL, 
105
				AnimationEffect.OPEN_HORIZONTAL,
106
				AnimationEffect.PATH, 
107
/*				AnimationEffect.MOVE_TO_LEFT,
108
				AnimationEffect.MOVE_TO_TOP, 
109
				AnimationEffect.MOVE_TO_RIGHT,
110
				AnimationEffect.MOVE_TO_BOTTOM, 
111
				AnimationEffect.SPIRALIN_LEFT,
112
				AnimationEffect.SPIRALIN_RIGHT, 
113
				AnimationEffect.SPIRALOUT_LEFT,
114
				AnimationEffect.SPIRALOUT_RIGHT, 
115
				AnimationEffect.DISSOLVE,
116
				AnimationEffect.WAVYLINE_FROM_LEFT, 
117
				AnimationEffect.RANDOM,
118
				AnimationEffect.VERTICAL_LINES,
119
				AnimationEffect.LASER_FROM_LEFT, 
120
				AnimationEffect.APPEAR,
121
				AnimationEffect.HIDE, 
122
				AnimationEffect.MOVE_FROM_UPPERLEFT,
123
				AnimationEffect.VERTICAL_CHECKERBOARD,
124
				AnimationEffect.HORIZONTAL_ROTATE,
125
				AnimationEffect.VERTICAL_STRETCH, 
126
				AnimationEffect.ZOOM_IN,
127
				AnimationEffect.ZOOM_OUT_FROM_LEFT, */
128
				};
129
130
		// insert  pages
131
		while (drawpages.getCount() < aNameArray.length)
132
			drawpages.insertNewByIndex(0);
133
134
		// add text shape to each page
135
		for (int i = 0; i < aNameArray.length; i++) {
136
			XDrawPage xDrawPage = (XDrawPage) UnoRuntime.queryInterface(
137
					XDrawPage.class, drawpages.getByIndex(i));
138
			XNamed xPageName = (XNamed) UnoRuntime.queryInterface(XNamed.class,
139
					xDrawPage);
140
			xPageName.setName(aNameArray[i]);
141
142
			xShapes = (XShapes) UnoRuntime.queryInterface(XShapes.class,
143
					drawpages.getByIndex(i));
144
145
			// create a rectangle that is placed on the top left of the page
146
			xShapePropSet[i] = ShapeUtil.createAndInsertShape(impressDocument,
147
					xShapes, new Point(1000, 1000), new Size(5000, 5000),
148
					"com.sun.star.drawing.RectangleShape");
149
		}
150
151
		for (int i = 0; i < aNameArray.length; i++) {
152
			// set an object animation for each slide
153
			xShapePropSet[i]
154
					.setPropertyValue("Effect", AnimationEffectArray[i]);
155
		}
156
157
		// If this property and the property DimPrevious are both true, the shape is hidden on the next click after the AnimationEffect has finished. 
158
		xShapePropSet[1].setPropertyValue("DimHide", new Boolean(false));
159
		// If true, this shape is painted using DimColor on the next click after finishing the AnimationEffect. 
160
		xShapePropSet[1].setPropertyValue("DimPrevious", new Boolean(true));
161
		// his color is used to paint the shape on the next click after the animation effect has finished
162
		xShapePropSet[1].setPropertyValue("DimColor", new Integer(0xff0000));
163
		// the sound file specified in Sound is played while the animation effect is executed
164
		xShapePropSet[1].setPropertyValue("SoundOn", new Boolean(false));
165
		// the sound specified in the Sound property of this shape is played completely
166
		xShapePropSet[1].setPropertyValue("PlayFull", new Boolean(false));
167
168
		saveAndLoadSlide();
169
170
		for (int i = 0; i < aNameArray.length; i++) {
171
			// assert if Shape Animation is set
172
			Assert.assertEquals(
173
					"Text Animation Effect is AnimationEffectArray[]",
174
					AnimationEffectArray[i],
175
					xShapePropSet[i].getPropertyValue("Effect"));
176
		}
177
		// assert if DimHide is false
178
		Assert.assertEquals("Shape Animation DimHide is false", Boolean.FALSE,
179
				xShapePropSet[1].getPropertyValue("DimHide"));
180
		// assert if DimPrevious is true
181
		Assert.assertEquals("Shape Animation DimPrevious is true",
182
				Boolean.TRUE, xShapePropSet[1].getPropertyValue("DimPrevious"));
183
		// assert if DimColor is red
184
		Assert.assertEquals("Shape Animation DimColor is Red", 0xff0000,
185
				xShapePropSet[1].getPropertyValue("DimColor"));
186
		// assert the sound file specified in Sound don't play while the
187
		// animation effect is executed.
188
		Assert.assertEquals("Shape SoundOn is false", Boolean.FALSE,
189
				xShapePropSet[1].getPropertyValue("SoundOn"));
190
		// assert the sound specified in the Sound property of this shape is
191
		// played completely
192
		Assert.assertEquals("Shape PlayFull is false", Boolean.FALSE,
193
				xShapePropSet[1].getPropertyValue("PlayFull"));
194
195
	}
196
197
	public XPropertySet addPortion(XShape xShape, String sText,
198
			boolean bNewParagraph)
199
			throws com.sun.star.lang.IllegalArgumentException {
200
		XText xText = (XText) UnoRuntime.queryInterface(XText.class, xShape);
201
202
		XTextCursor xTextCursor = xText.createTextCursor();
203
		xTextCursor.gotoEnd(false);
204
		if (bNewParagraph == true) {
205
			xText.insertControlCharacter(xTextCursor,
206
					ControlCharacter.PARAGRAPH_BREAK, false);
207
			xTextCursor.gotoEnd(false);
208
		}
209
		XTextRange xTextRange = (XTextRange) UnoRuntime.queryInterface(
210
				XTextRange.class, xTextCursor);
211
		xTextRange.setString(sText);
212
		xTextCursor.gotoEnd(true);
213
		XPropertySet xPropSet = (XPropertySet) UnoRuntime.queryInterface(
214
				XPropertySet.class, xText);
215
		return xPropSet;
216
	}
217
218
	/**
219
	 * create a new presentation document and insert a new slide.
220
	 * 
221
	 * @throws Exception
222
	 */
223
	public void createDocumentAndSlide() throws Exception {
224
		impressDocument = (XComponent) UnoRuntime.queryInterface(
225
				XComponent.class, unoApp.newDocument("simpress"));
226
		drawsupplier = (XDrawPagesSupplier) UnoRuntime.queryInterface(
227
				XDrawPagesSupplier.class, impressDocument);
228
		drawpages = drawsupplier.getDrawPages();
229
230
		sdDocument = (XPresentationSupplier) UnoRuntime.queryInterface(
231
				XPresentationSupplier.class, impressDocument);
232
		pre = sdDocument.getPresentation();
233
	}
234
235
	/**
236
	 * Save presentation and reLoad the slide.
237
	 * 
238
	 * @param no
239
	 * @return void
240
	 * @throws Exception
241
	 */
242
	public void saveAndLoadSlide() throws Exception {
243
		reLoadFile = saveAndReloadDoc(impressDocument,
244
				"StarOffice XML (Impress)", "odp");
245
		drawsupplier = (XDrawPagesSupplier) UnoRuntime.queryInterface(
246
				XDrawPagesSupplier.class, reLoadFile);
247
		drawpages = drawsupplier.getDrawPages();
248
249
		sdDocument = (XPresentationSupplier) UnoRuntime.queryInterface(
250
				XPresentationSupplier.class, reLoadFile);
251
		pre = sdDocument.getPresentation();
252
	}
253
254
	/**
255
	 * save and reload Presentation document.
256
	 * 
257
	 * @param presentationDocument
258
	 * @param sFilter
259
	 * @param sExtension
260
	 * @return
261
	 * @throws Exception
262
	 */
263
	private XComponent saveAndReloadDoc(XComponent presentationDocument,
264
			String sFilter, String sExtension) throws Exception {
265
		filePath = Testspace.getPath("tmp/shapeanimation." + sExtension);
266
		PropertyValue[] aStoreProperties = new PropertyValue[2];
267
		aStoreProperties[0] = new PropertyValue();
268
		aStoreProperties[1] = new PropertyValue();
269
		aStoreProperties[0].Name = "Override";
270
		aStoreProperties[0].Value = true;
271
		aStoreProperties[1].Name = "FilterName";
272
		aStoreProperties[1].Value = sFilter;
273
		XStorable xStorable = (XStorable) UnoRuntime.queryInterface(
274
				XStorable.class, presentationDocument);
275
		xStorable.storeToURL(FileUtil.getUrl(filePath), aStoreProperties);
276
277
		return UnoRuntime.queryInterface(XComponent.class,
278
				unoApp.loadDocument(filePath));
279
	}
280
}
(-)source/testcase/uno/sd/ParagraphStyle.java (-201 lines)
Lines 1-201 Link Here
1
package testcase.uno.sd;
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.PageUtil;
13
import testlib.uno.ShapeUtil;
14
15
import com.sun.star.awt.Point;
16
import com.sun.star.awt.Size;
17
import com.sun.star.beans.PropertyValue;
18
import com.sun.star.beans.XPropertySet;
19
import com.sun.star.drawing.TextFitToSizeType;
20
import com.sun.star.drawing.XDrawPage;
21
import com.sun.star.drawing.XDrawPages;
22
import com.sun.star.drawing.XDrawPagesSupplier;
23
import com.sun.star.drawing.XShape;
24
import com.sun.star.drawing.XShapes;
25
import com.sun.star.frame.XStorable;
26
import com.sun.star.lang.XComponent;
27
import com.sun.star.lang.XMultiServiceFactory;
28
import com.sun.star.presentation.XPresentation;
29
import com.sun.star.presentation.XPresentationSupplier;
30
import com.sun.star.style.LineSpacing;
31
import com.sun.star.style.LineSpacingMode;
32
import com.sun.star.style.ParagraphAdjust;
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 ParagraphStyle {
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
	XShapes xShapes = null;
48
	XDrawPage xpage = null;
49
	String filePath=null;
50
	
51
    UnoApp unoApp = new UnoApp();
52
	
53
	/**
54
	 * @throws java.lang.Exception
55
	 */
56
	@Before
57
	public void setUp() throws Exception {
58
		unoApp.start();
59
		createDocumentAndSlide();
60
	}
61
62
	@After
63
	public void tearDown() throws Exception {
64
		unoApp.closeDocument(impressDocument);
65
		unoApp.closeDocument(reLoadFile);
66
		unoApp.close();
67
	}
68
69
	@Test
70
	public void ParaStyle() throws Exception {		
71
		Point po = new Point(5000, 5000);
72
		xShapes = (XShapes) UnoRuntime.queryInterface(XShapes.class, xpage);
73
		// create the shape
74
		XShape xRectangle = ShapeUtil.createShape(impressDocument, po, new Size(21000, 12500), "com.sun.star.drawing.RectangleShape");
75
		 xShapes.add(xRectangle);
76
		 XPropertySet xShapePropSet = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xRectangle);
77
		 // TextFitToSize
78
		 xShapePropSet.setPropertyValue("TextFitToSize", TextFitToSizeType.PROPORTIONAL);
79
		 
80
		 XPropertySet xTextPropSet1 = addPortion(xRectangle, "New text paragraph", true);
81
		 xTextPropSet1.setPropertyValue("ParaAdjust", ParagraphAdjust.CENTER);
82
		 
83
		 //Line Spacing
84
		 LineSpacing xLineSpacing = new LineSpacing(LineSpacingMode.LEADING, (short)1);
85
		 xTextPropSet1.setPropertyValue("ParaLineSpacing",  xLineSpacing);
86
		 
87
		 //left, right, top and bottom margin
88
		 xTextPropSet1.setPropertyValue("ParaLeftMargin",  1000);
89
		 xTextPropSet1.setPropertyValue("ParaRightMargin",  1000);
90
		 xTextPropSet1.setPropertyValue("ParaTopMargin",  1000);
91
		 xTextPropSet1.setPropertyValue("ParaBottomMargin",  1000);
92
		 
93
		 XPropertySet xTextPropSet2 = addPortion(xRectangle, "And another text paragraph", true);
94
		 xTextPropSet2.setPropertyValue("CharColor", new Integer(0xff0000));
95
		 
96
		 xRectangle = saveAndLoadShape(1, 0);
97
		
98
99
		 Assert.assertEquals("Paragraph Left Margin is 1000",1000, xTextPropSet1.getPropertyValue("ParaLeftMargin"));
100
		 Assert.assertEquals("Paragraph Right Margin is 1000", 1000,xTextPropSet1.getPropertyValue("ParaRightMargin"));
101
		 Assert.assertEquals("Paragraph Top Margin is 1000",1000, xTextPropSet1.getPropertyValue("ParaTopMargin") );
102
		 Assert.assertEquals("Paragraph Bottom Margin is 1000 ",1000, xTextPropSet1.getPropertyValue("ParaBottomMargin"));
103
		 Assert.assertEquals("Text Color is red",0xff0000,xTextPropSet2.getPropertyValue("CharColor"));
104
	     
105
	}
106
	
107
		
108
	public static XShape createShape(XComponent xComponent, int x, int y,
109
			int width, int height, String sShapeType)
110
			throws java.lang.Exception {
111
		// query the document for the document-internal service factory
112
		XMultiServiceFactory xFactory = (XMultiServiceFactory) UnoRuntime
113
				.queryInterface(XMultiServiceFactory.class, xComponent);
114
115
		// get the given Shape service from the factory
116
		Object xObj = xFactory.createInstance(sShapeType);
117
		Point aPos = new Point(x, y);
118
		Size aSize = new Size(width, height);
119
120
		// use its XShape interface to determine position and size before
121
		// insertion
122
		XShape xShape = (XShape) UnoRuntime.queryInterface(XShape.class, xObj);
123
		xShape.setPosition(aPos);
124
		xShape.setSize(aSize);
125
		return xShape;
126
	}
127
	
128
	public static XPropertySet addPortion(XShape xShape, String sText, boolean bNewParagraph)
129
	         throws com.sun.star.lang.IllegalArgumentException {
130
	     XText xText = (XText)UnoRuntime.queryInterface(XText.class, xShape);
131
	     XTextCursor xTextCursor = xText.createTextCursor();
132
	     xTextCursor.gotoEnd(false);
133
	     if (bNewParagraph) {
134
	         xText.insertControlCharacter(xTextCursor, ControlCharacter.PARAGRAPH_BREAK, false);
135
	         xTextCursor.gotoEnd(false);
136
	     }
137
	     XTextRange xTextRange = (XTextRange)UnoRuntime.queryInterface(XTextRange.class, xTextCursor);
138
	     xTextRange.setString(sText);
139
	     xTextCursor.gotoEnd(true);
140
	     XPropertySet xPropSet = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xTextRange);
141
	     return xPropSet;
142
	 }
143
	
144
	/**
145
	 * create a new presentation document and insert a new slide.
146
	 * 
147
	 * @throws Exception
148
	 */
149
	public void createDocumentAndSlide() throws Exception {
150
		impressDocument = (XComponent) UnoRuntime.queryInterface(
151
				XComponent.class, unoApp.newDocument("simpress"));
152
		drawsupplier = (XDrawPagesSupplier) UnoRuntime.queryInterface(
153
				XDrawPagesSupplier.class, impressDocument);
154
		drawpages = drawsupplier.getDrawPages();
155
		drawpages.insertNewByIndex(1);
156
		xpage = PageUtil.getDrawPageByIndex(impressDocument, 1);
157
	}
158
	
159
	/**
160
	 * Save presentation and reLoad the presentation and shape in it.
161
	 * 
162
	 * @param po
163
	 * @param shapeType
164
	 * @return
165
	 * @throws Exception
166
	 */
167
	public XShape saveAndLoadShape(int pageIndex, int shapeIndex) throws Exception {
168
		reLoadFile = saveAndReloadDoc(impressDocument,
169
				"impress8", "odp");
170
		xShapes=ShapeUtil.getShapes(reLoadFile, pageIndex);
171
		return  (XShape) UnoRuntime.queryInterface(XShape.class, xShapes.getByIndex(shapeIndex));
172
	}
173
174
	/**
175
	 * save and reload Presentation document.
176
	 * 
177
	 * @param presentationDocument
178
	 * @param sFilter
179
	 * @param sExtension
180
	 * @return
181
	 * @throws Exception
182
	 */
183
	private XComponent saveAndReloadDoc(XComponent presentationDocument,
184
			String sFilter, String sExtension) throws Exception {
185
		filePath = Testspace.getPath("tmp/paragraphstyle."
186
				+ sExtension);
187
		PropertyValue[] aStoreProperties = new PropertyValue[2];
188
		aStoreProperties[0] = new PropertyValue();
189
		aStoreProperties[1] = new PropertyValue();
190
		aStoreProperties[0].Name = "Override";
191
		aStoreProperties[0].Value = true;
192
		aStoreProperties[1].Name = "FilterName";
193
		aStoreProperties[1].Value = sFilter;
194
		XStorable xStorable = (XStorable) UnoRuntime.queryInterface(
195
				XStorable.class, presentationDocument);
196
		xStorable.storeToURL(FileUtil.getUrl(filePath), aStoreProperties);
197
198
		return UnoRuntime.queryInterface(XComponent.class,
199
				unoApp.loadDocument(filePath));
200
	}
201
}
(-)source/testcase/uno/sd/paragraph/ParagraphStyle.java (-1 / +1 lines)
Lines 1-4 Link Here
1
package testcase.uno.sd;
1
package testcase.uno.sd.paragraph;
2
2
3
import junit.framework.Assert;
3
import junit.framework.Assert;
4
4
(-)source/testcase/uno/sd/slidesshow/CustomShow.java (-1 / +1 lines)
Lines 1-4 Link Here
1
package testcase.uno.sd;
1
package testcase.uno.sd.slidesshow;
2
2
3
import junit.framework.Assert;
3
import junit.framework.Assert;
4
4
(-)source/testcase/uno/sd/CustomShow.java (-205 lines)
Lines 1-205 Link Here
1
package testcase.uno.sd;
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 com.sun.star.awt.Point;
13
import com.sun.star.awt.Size;
14
import com.sun.star.beans.PropertyValue;
15
import com.sun.star.beans.XPropertySet;
16
import com.sun.star.container.XIndexContainer;
17
import com.sun.star.container.XNameContainer;
18
import com.sun.star.container.XNamed;
19
import com.sun.star.drawing.XDrawPage;
20
import com.sun.star.drawing.XDrawPages;
21
import com.sun.star.drawing.XDrawPagesSupplier;
22
import com.sun.star.drawing.XShape;
23
import com.sun.star.drawing.XShapes;
24
import com.sun.star.frame.XStorable;
25
import com.sun.star.lang.XComponent;
26
import com.sun.star.lang.XSingleServiceFactory;
27
import com.sun.star.presentation.XCustomPresentationSupplier;
28
import com.sun.star.presentation.XPresentation;
29
import com.sun.star.presentation.XPresentationSupplier;
30
import com.sun.star.uno.UnoRuntime;
31
32
import testlib.uno.ShapeUtil;
33
34
public class CustomShow {
35
	XPresentationSupplier sdDocument = null;
36
	XPresentation pre = null;
37
	XComponent precomp = null;
38
	XComponent impressDocument = null;
39
	XComponent reLoadFile = null;
40
	XDrawPagesSupplier drawsupplier = null;
41
	XDrawPages drawpages = null;
42
43
	String filePath = null;
44
45
	UnoApp unoApp = new UnoApp();
46
47
	/**
48
	 * @throws java.lang.Exception
49
	 */
50
	@Before
51
	public void setUp() throws Exception {
52
		unoApp.start();
53
		createDocumentAndSlide();
54
	}
55
56
	@After
57
	public void tearDown() throws Exception {
58
		unoApp.closeDocument(impressDocument);
59
		unoApp.closeDocument(reLoadFile);
60
		unoApp.close();
61
	}
62
63
	@Test
64
	public void testCustomShow() throws Exception {
65
66
		String aNameArray[] = { "Page 1", "Page 2",  "Page 3", "Page 4", "Page 5"};
67
		
68
		//insert five  pages
69
	    while (drawpages.getCount() < aNameArray.length)
70
		    drawpages.insertNewByIndex(0);
71
	    
72
	    //add text shape to each page
73
		for (int i = 0; i < aNameArray.length; i++) {
74
			XDrawPage xDrawPage = (XDrawPage) UnoRuntime.queryInterface(
75
					XDrawPage.class, drawpages.getByIndex(i));
76
			XNamed xPageName = (XNamed) UnoRuntime.queryInterface(XNamed.class,
77
					xDrawPage);
78
			xPageName.setName(aNameArray[i]);
79
80
			XShape xTextObj = ShapeUtil.createShape(impressDocument, new Point(
81
					10000, 9000), new Size(10000, 5000),
82
					"com.sun.star.drawing.TextShape");
83
			XShapes xShapes = (XShapes) UnoRuntime.queryInterface(
84
					XShapes.class, xDrawPage);
85
			xShapes.add(xTextObj);
86
			ShapeUtil.addPortion(xTextObj, aNameArray[i], true);
87
		}
88
89
		
90
		//create two custom shows 
91
		//one will play slide 3 to 5 and is named "Part" 
92
		//the other one will play slide 1 t0 5 and is named "All"		
93
		XCustomPresentationSupplier xCustPresSupplier = (XCustomPresentationSupplier) UnoRuntime
94
				.queryInterface(XCustomPresentationSupplier.class, impressDocument);
95
96
		
97
		// the following container is a container for further container which
98
		// includes the list of pages that are to play within a custom show
99
		XNameContainer xNameContainer = xCustPresSupplier
100
				.getCustomPresentations();
101
		XSingleServiceFactory xFactory = (XSingleServiceFactory) UnoRuntime
102
				.queryInterface(XSingleServiceFactory.class, xNameContainer);
103
104
		Object xObj;
105
		XIndexContainer xContainer;
106
		
107
		//instantiate an IndexContainer that will take a list of draw pages for
108
		//the first custom show
109
		xObj = xFactory.createInstance();
110
		xContainer = (XIndexContainer) UnoRuntime.queryInterface(
111
				XIndexContainer.class, xObj);
112
		for (int i = 3; i < 5; i++)
113
			xContainer.insertByIndex(xContainer.getCount(),
114
					drawpages.getByIndex(i));
115
		xNameContainer.insertByName("Part", xContainer);
116
117
		
118
		//instantiate an IndexContainer that will take a list of draw page for
119
		//the second custom show
120
		xObj = xFactory.createInstance();
121
		xContainer = (XIndexContainer) UnoRuntime.queryInterface(
122
				XIndexContainer.class, xObj);
123
		for (int i = 1; i < 5; i++)
124
			xContainer.insertByIndex(xContainer.getCount(),
125
					drawpages.getByIndex(i));
126
		xNameContainer.insertByName("All", xContainer);
127
128
		
129
		//set which custom show is to used
130
		XPresentationSupplier xPresSupplier = (XPresentationSupplier) UnoRuntime
131
				.queryInterface(XPresentationSupplier.class, impressDocument);
132
		XPresentation xPresentation = xPresSupplier.getPresentation();
133
		XPropertySet xPresPropSet = (XPropertySet) UnoRuntime.queryInterface(
134
				XPropertySet.class, xPresentation);
135
		xPresPropSet.setPropertyValue("CustomShow", "Part");
136
		
137
		saveAndLoadSlide();
138
		
139
		//assert if custom show is set
140
		Assert.assertEquals("Set Part as CustomSHow", xPresPropSet.getPropertyValue("CustomShow"), "Part");
141
	}
142
143
	/**
144
	 * create a new presentation document and insert a new slide.
145
	 * 
146
	 * @throws Exception
147
	 */
148
	public void createDocumentAndSlide() throws Exception {
149
		impressDocument = (XComponent) UnoRuntime.queryInterface(
150
				XComponent.class, unoApp.newDocument("simpress"));
151
		drawsupplier = (XDrawPagesSupplier) UnoRuntime.queryInterface(
152
				XDrawPagesSupplier.class, impressDocument);
153
		drawpages = drawsupplier.getDrawPages();
154
		
155
		sdDocument = (XPresentationSupplier) UnoRuntime.queryInterface(
156
				XPresentationSupplier.class, impressDocument);
157
		pre = sdDocument.getPresentation();
158
	}
159
	
160
	/**
161
	 * Save presentation and reLoad the slide.
162
	 * 
163
	 * @param no
164
	 * @return void
165
	 * @throws Exception
166
	 */
167
	public void saveAndLoadSlide() throws Exception {
168
		reLoadFile = saveAndReloadDoc(impressDocument,
169
				"StarOffice XML (Impress)", "odp");
170
		drawsupplier = (XDrawPagesSupplier) UnoRuntime.queryInterface(
171
				XDrawPagesSupplier.class, reLoadFile);
172
		drawpages = drawsupplier.getDrawPages();
173
174
		sdDocument = (XPresentationSupplier) UnoRuntime.queryInterface(
175
				XPresentationSupplier.class, reLoadFile);
176
		pre = sdDocument.getPresentation();
177
	}
178
179
	/**
180
	 * save and reload Presentation document.
181
	 * 
182
	 * @param presentationDocument
183
	 * @param sFilter
184
	 * @param sExtension
185
	 * @return
186
	 * @throws Exception
187
	 */
188
	private XComponent saveAndReloadDoc(XComponent presentationDocument,
189
			String sFilter, String sExtension) throws Exception {
190
		filePath = Testspace.getPath("tmp/customshow." + sExtension);
191
		PropertyValue[] aStoreProperties = new PropertyValue[2];
192
		aStoreProperties[0] = new PropertyValue();
193
		aStoreProperties[1] = new PropertyValue();
194
		aStoreProperties[0].Name = "Override";
195
		aStoreProperties[0].Value = true;
196
		aStoreProperties[1].Name = "FilterName";
197
		aStoreProperties[1].Value = sFilter;
198
		XStorable xStorable = (XStorable) UnoRuntime.queryInterface(
199
				XStorable.class, presentationDocument);
200
		xStorable.storeToURL(FileUtil.getUrl(filePath), aStoreProperties);
201
202
		return UnoRuntime.queryInterface(XComponent.class,
203
				unoApp.loadDocument(filePath));
204
	}
205
}
(-)source/testcase/uno/sd/slidesshow/SlideShow.java (-1 / +1 lines)
Lines 1-4 Link Here
1
package testcase.uno.sd;
1
package testcase.uno.sd.slidesshow;
2
2
3
import junit.framework.Assert;
3
import junit.framework.Assert;
4
4
(-)source/testcase/uno/sd/SlideShow.java (-170 lines)
Lines 1-170 Link Here
1
package testcase.uno.sd;
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.PageUtil;
13
import testlib.uno.ShapeUtil;
14
15
import com.sun.star.awt.Point;
16
import com.sun.star.awt.Size;
17
import com.sun.star.beans.PropertyValue;
18
import com.sun.star.beans.XPropertySet;
19
import com.sun.star.drawing.XDrawPage;
20
import com.sun.star.drawing.XDrawPages;
21
import com.sun.star.drawing.XDrawPagesSupplier;
22
import com.sun.star.drawing.XShape;
23
import com.sun.star.drawing.XShapes;
24
import com.sun.star.frame.XStorable;
25
import com.sun.star.lang.XComponent;
26
import com.sun.star.presentation.XPresentation;
27
import com.sun.star.presentation.XPresentationSupplier;
28
import com.sun.star.uno.UnoRuntime;
29
30
public class SlideShow {
31
	XPresentationSupplier sdDocument = null;
32
	XPresentation pre = null;
33
	XComponent precomp = null;
34
	XComponent impressDocument = null;
35
	XComponent reLoadFile = null;
36
	XDrawPagesSupplier drawsupplier = null;
37
	XDrawPages drawpages = null;
38
39
	String filePath = null;
40
41
	UnoApp unoApp = new UnoApp();
42
43
	/**
44
	 * @throws java.lang.Exception
45
	 */
46
	@Before
47
	public void setUp() throws Exception {
48
		unoApp.start();
49
		createDocumentAndSlide();
50
	}
51
52
	@After
53
	public void tearDown() throws Exception {
54
		unoApp.closeDocument(impressDocument);
55
		unoApp.closeDocument(reLoadFile);
56
		unoApp.close();
57
	}
58
59
	@Test
60
	public void testSlideShow() throws Exception {
61
		Point po = new Point(5000, 5000);
62
63
		XDrawPage xPage1 = createSlide(0);
64
		XShapes xShapes1 = (XShapes) UnoRuntime.queryInterface(XShapes.class,
65
				xPage1);
66
		XShape xRectangle1 = ShapeUtil.createShape(impressDocument, po,
67
				new Size(21000, 12500), "com.sun.star.drawing.RectangleShape");
68
		xShapes1.add(xRectangle1);
69
		ShapeUtil.addPortion(xRectangle1, "Page1", false);
70
71
		XDrawPage xPage2 = createSlide(1);
72
		XShapes xShapes2 = (XShapes) UnoRuntime.queryInterface(XShapes.class,
73
				xPage2);
74
		XShape xRectangle2 = ShapeUtil.createShape(impressDocument, po,
75
				new Size(21000, 12500), "com.sun.star.drawing.RectangleShape");
76
		xShapes2.add(xRectangle2);
77
		ShapeUtil.addPortion(xRectangle2, "Page2", false);
78
79
		XDrawPage xPage3 = createSlide(2);
80
		XShapes xShapes3 = (XShapes) UnoRuntime.queryInterface(XShapes.class,
81
				xPage3);
82
		XShape xRectangle3 = ShapeUtil.createShape(impressDocument, po,
83
				new Size(21000, 12500), "com.sun.star.drawing.RectangleShape");
84
		xShapes3.add(xRectangle3);
85
		ShapeUtil.addPortion(xRectangle3, "Page3", false);
86
		
87
		XPropertySet xPresPropSet = (XPropertySet) UnoRuntime.queryInterface(
88
				XPropertySet.class, pre);
89
		xPresPropSet.setPropertyValue("IsEndless", Boolean.FALSE);
90
		xPresPropSet.setPropertyValue("IsFullScreen", Boolean.TRUE);
91
		xPresPropSet.setPropertyValue("Pause", new Integer(0));
92
		
93
		saveAndLoadSlide();
94
		
95
		Assert.assertEquals("IsEndless set to false",
96
				xPresPropSet.getPropertyValue("IsEndless"), Boolean.FALSE);
97
		Assert.assertEquals("IsFullScreen set to true",
98
				xPresPropSet.getPropertyValue("IsFullScreen"), Boolean.TRUE);
99
		Assert.assertEquals("Pause set to 0",
100
				xPresPropSet.getPropertyValue("Pause"), 0);
101
	}
102
103
	public XDrawPage createSlide(int index) throws Exception {
104
		drawpages.insertNewByIndex(index);
105
		XDrawPage xPage = PageUtil.getDrawPageByIndex(impressDocument, index);
106
		return xPage;
107
	}
108
109
	/**
110
	 * create a new presentation document and insert a new slide.
111
	 * 
112
	 * @throws Exception
113
	 */
114
	public void createDocumentAndSlide() throws Exception {
115
		impressDocument = (XComponent) UnoRuntime.queryInterface(
116
				XComponent.class, unoApp.newDocument("simpress"));
117
		drawsupplier = (XDrawPagesSupplier) UnoRuntime.queryInterface(
118
				XDrawPagesSupplier.class, impressDocument);
119
		drawpages = drawsupplier.getDrawPages();
120
		sdDocument = (XPresentationSupplier) UnoRuntime.queryInterface(
121
				XPresentationSupplier.class, impressDocument);
122
		pre = sdDocument.getPresentation();
123
	}
124
	
125
	/**
126
	 * Save presentation and reLoad the slide.
127
	 * 
128
	 * @param no
129
	 * @return void
130
	 * @throws Exception
131
	 */
132
	public void saveAndLoadSlide() throws Exception {
133
		reLoadFile = saveAndReloadDoc(impressDocument,
134
				"StarOffice XML (Impress)", "odp");
135
		drawsupplier = (XDrawPagesSupplier) UnoRuntime.queryInterface(
136
				XDrawPagesSupplier.class, reLoadFile);
137
		drawpages = drawsupplier.getDrawPages();
138
139
		sdDocument = (XPresentationSupplier) UnoRuntime.queryInterface(
140
				XPresentationSupplier.class, reLoadFile);
141
		pre = sdDocument.getPresentation();
142
	}
143
144
	/**
145
	 * save and reload Presentation document.
146
	 * 
147
	 * @param presentationDocument
148
	 * @param sFilter
149
	 * @param sExtension
150
	 * @return
151
	 * @throws Exception
152
	 */
153
	private XComponent saveAndReloadDoc(XComponent presentationDocument,
154
			String sFilter, String sExtension) throws Exception {
155
		filePath = Testspace.getPath("tmp/slideshow." + sExtension);
156
		PropertyValue[] aStoreProperties = new PropertyValue[2];
157
		aStoreProperties[0] = new PropertyValue();
158
		aStoreProperties[1] = new PropertyValue();
159
		aStoreProperties[0].Name = "Override";
160
		aStoreProperties[0].Value = true;
161
		aStoreProperties[1].Name = "FilterName";
162
		aStoreProperties[1].Value = sFilter;
163
		XStorable xStorable = (XStorable) UnoRuntime.queryInterface(
164
				XStorable.class, presentationDocument);
165
		xStorable.storeToURL(FileUtil.getUrl(filePath), aStoreProperties);
166
167
		return UnoRuntime.queryInterface(XComponent.class,
168
				unoApp.loadDocument(filePath));
169
	}
170
}
(-)source/testcase/uno/sd/ParagraphTextProperty.java (-168 lines)
Lines 1-168 Link Here
1
package testcase.uno.sd;
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.PageUtil;
13
import testlib.uno.ShapeUtil;
14
15
import com.sun.star.awt.Point;
16
import com.sun.star.awt.Size;
17
import com.sun.star.beans.PropertyValue;
18
import com.sun.star.beans.XPropertySet;
19
import com.sun.star.drawing.TextFitToSizeType;
20
import com.sun.star.drawing.XDrawPage;
21
import com.sun.star.drawing.XDrawPages;
22
import com.sun.star.drawing.XDrawPagesSupplier;
23
import com.sun.star.drawing.XShape;
24
import com.sun.star.drawing.XShapes;
25
import com.sun.star.frame.XStorable;
26
import com.sun.star.lang.XComponent;
27
28
import com.sun.star.presentation.XPresentation;
29
import com.sun.star.presentation.XPresentationSupplier;
30
31
import com.sun.star.text.ControlCharacter;
32
import com.sun.star.text.XText;
33
import com.sun.star.text.XTextCursor;
34
import com.sun.star.text.XTextRange;
35
import com.sun.star.uno.UnoRuntime;
36
37
public class ParagraphTextProperty {
38
	XPresentationSupplier sdDocument = null;
39
	XPresentation pre = null;
40
	XComponent precomp = null;
41
	XComponent impressDocument = null;
42
	XComponent reLoadFile = null;
43
	XDrawPagesSupplier drawsupplier = null;
44
	XDrawPages drawpages = null;
45
	XShapes xShapes = null;
46
	XDrawPage xpage = null;
47
	String filePath=null;
48
    
49
	UnoApp unoApp = new UnoApp();
50
	
51
	/**
52
	 * @throws java.lang.Exception
53
	 */
54
	@Before
55
	public void setUp() throws Exception {
56
		unoApp.start();
57
		createDocumentAndSlide();
58
	}
59
60
	@After
61
	public void tearDown() throws Exception {
62
		unoApp.closeDocument(impressDocument);
63
		unoApp.closeDocument(reLoadFile);
64
		unoApp.close();
65
	}
66
67
	@Test
68
	public void testParagraphPropertyShape() throws Exception {
69
		 Point po = new Point(5000, 5000);
70
		 xShapes = (XShapes) UnoRuntime.queryInterface(XShapes.class, xpage);
71
		 // create the shape
72
		 XShape xRectangle = ShapeUtil.createShape(impressDocument, po, new Size(21000, 12500), "com.sun.star.drawing.RectangleShape");
73
		 xShapes.add(xRectangle);
74
		 
75
		 XPropertySet xShapePropSet = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xRectangle);
76
		 // TextFitToSize
77
		 xShapePropSet.setPropertyValue("TextFitToSize", TextFitToSizeType.PROPORTIONAL);
78
		 // border size
79
		 xShapePropSet.setPropertyValue("TextLeftDistance", new Integer(2500));
80
		 xShapePropSet.setPropertyValue("TextRightDistance", new Integer(2500));
81
		 xShapePropSet.setPropertyValue("TextUpperDistance", new Integer(2500));
82
		 xShapePropSet.setPropertyValue("TextLowerDistance", new Integer(2500));
83
		 XPropertySet xTextPropSet = addPortion(xRectangle, "using TextFitToSize", false);
84
		 xTextPropSet = addPortion(xRectangle, "and a Border distance of 2,5 cm", true);
85
		 
86
		 xRectangle = saveAndLoadShape(1,0);
87
		 
88
		 Assert.assertEquals("TextLeftDistance is 2500", 2500, xShapePropSet.getPropertyValue("TextLeftDistance"));
89
		 Assert.assertEquals("TextRightDistance is 2500", 2500, xShapePropSet.getPropertyValue("TextRightDistance"));
90
		 Assert.assertEquals("TextUpperDistance is 2500", 2500, xShapePropSet.getPropertyValue("TextUpperDistance"));
91
		 Assert.assertEquals("TextLowerDistance is 2500", 2500, xShapePropSet.getPropertyValue("TextLowerDistance"));
92
		 
93
	}
94
		
95
	public static XPropertySet addPortion(XShape xShape, String sText, boolean bNewParagraph)
96
	         throws com.sun.star.lang.IllegalArgumentException {
97
	     XText xText = (XText)UnoRuntime.queryInterface(XText.class, xShape);
98
	     XTextCursor xTextCursor = xText.createTextCursor();
99
	     xTextCursor.gotoEnd(false);
100
	     if (bNewParagraph) {
101
	         xText.insertControlCharacter(xTextCursor, ControlCharacter.PARAGRAPH_BREAK, false);
102
	         xTextCursor.gotoEnd(false);
103
	     }
104
	     XTextRange xTextRange = (XTextRange)UnoRuntime.queryInterface(XTextRange.class, xTextCursor);
105
	     xTextRange.setString(sText);
106
	     xTextCursor.gotoEnd(true);
107
	     XPropertySet xPropSet = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xTextRange);
108
	     return xPropSet;
109
	 }
110
	
111
	/**
112
	 * create a new presentation document and insert a new slide.
113
	 * 
114
	 * @throws Exception
115
	 */
116
	public void createDocumentAndSlide() throws Exception {
117
		impressDocument = (XComponent) UnoRuntime.queryInterface(
118
				XComponent.class, unoApp.newDocument("simpress"));
119
		drawsupplier = (XDrawPagesSupplier) UnoRuntime.queryInterface(
120
				XDrawPagesSupplier.class, impressDocument);
121
		drawpages = drawsupplier.getDrawPages();
122
		drawpages.insertNewByIndex(1);
123
		xpage = PageUtil.getDrawPageByIndex(impressDocument, 1);
124
	}
125
	
126
	/**
127
	 * Save presentation and reLoad the presentation and shape in it.
128
	 * 
129
	 * @param po
130
	 * @param shapeType
131
	 * @return
132
	 * @throws Exception
133
	 */
134
	public XShape saveAndLoadShape(int pageIndex, int shapeIndex) throws Exception {
135
		reLoadFile = saveAndReloadDoc(impressDocument,
136
				"impress8", "odp");
137
		xShapes=ShapeUtil.getShapes(reLoadFile, pageIndex);
138
		return  (XShape) UnoRuntime.queryInterface(XShape.class, xShapes.getByIndex(shapeIndex));
139
	}
140
141
	/**
142
	 * save and reload Presentation document.
143
	 * 
144
	 * @param presentationDocument
145
	 * @param sFilter
146
	 * @param sExtension
147
	 * @return
148
	 * @throws Exception
149
	 */
150
	private XComponent saveAndReloadDoc(XComponent presentationDocument,
151
			String sFilter, String sExtension) throws Exception {
152
		filePath = Testspace.getPath("tmp/paragraphtextproperty."
153
				+ sExtension);
154
		PropertyValue[] aStoreProperties = new PropertyValue[2];
155
		aStoreProperties[0] = new PropertyValue();
156
		aStoreProperties[1] = new PropertyValue();
157
		aStoreProperties[0].Name = "Override";
158
		aStoreProperties[0].Value = true;
159
		aStoreProperties[1].Name = "FilterName";
160
		aStoreProperties[1].Value = sFilter;
161
		XStorable xStorable = (XStorable) UnoRuntime.queryInterface(
162
				XStorable.class, presentationDocument);
163
		xStorable.storeToURL(FileUtil.getUrl(filePath), aStoreProperties);
164
165
		return UnoRuntime.queryInterface(XComponent.class,
166
				unoApp.loadDocument(filePath));
167
	}
168
}
(-)source/testcase/uno/sd/paragraph/ParagraphTextProperty.java (-1 / +1 lines)
Lines 1-4 Link Here
1
package testcase.uno.sd;
1
package testcase.uno.sd.paragraph;
2
2
3
import junit.framework.Assert;
3
import junit.framework.Assert;
4
4
(-)source/testcase/uno/sd/animation/CustomAnimation.java (-1 / +1 lines)
Lines 1-4 Link Here
1
package testcase.uno.sd;
1
package testcase.uno.sd.animation;
2
2
3
import junit.framework.Assert;
3
import junit.framework.Assert;
4
4
(-)source/testcase/uno/sd/animation/TextAnimation.java (+183 lines)
Line 0 Link Here
1
package testcase.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
}

Return to issue 120782