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

(-)source/testlib/uno/PageUtils.java (+231 lines)
Line 0 Link Here
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 testlib.uno;
22
23
import com.sun.star.uno.UnoRuntime;
24
import com.sun.star.lang.XComponent;
25
import com.sun.star.lang.XServiceInfo;
26
27
import com.sun.star.awt.Size;
28
29
import com.sun.star.beans.XPropertySet;
30
31
import com.sun.star.drawing.XDrawPage;
32
import com.sun.star.drawing.XDrawPages;
33
import com.sun.star.drawing.XDrawPagesSupplier;
34
import com.sun.star.drawing.XMasterPageTarget;
35
import com.sun.star.drawing.XMasterPagesSupplier;
36
37
import com.sun.star.presentation.XPresentationPage;
38
import com.sun.star.presentation.XHandoutMasterSupplier;
39
40
public class PageUtils {
41
	/**
42
	 * Get the page count for standard pages
43
	 * 
44
	 * @param xComponent
45
	 *            : The presentation document
46
	 * @return slide count
47
	 */
48
	static public int getDrawPageCount(XComponent xComponent) {
49
		XDrawPagesSupplier xDrawPagesSupplier = (XDrawPagesSupplier) UnoRuntime
50
				.queryInterface(XDrawPagesSupplier.class, xComponent);
51
		XDrawPages xDrawPages = xDrawPagesSupplier.getDrawPages();
52
		return xDrawPages.getCount();
53
	}
54
55
	/**
56
	 * Get draw page by index
57
	 * 
58
	 * @param xComponent
59
	 *            : The presentation document
60
	 * @param nIndex
61
	 *            : index of slide pages, from 0 or 1?
62
	 * @return Page of corresponding index.
63
	 */
64
	static public XDrawPage getDrawPageByIndex(XComponent xComponent, int nIndex)
65
			throws com.sun.star.lang.IndexOutOfBoundsException,
66
			com.sun.star.lang.WrappedTargetException {
67
		XDrawPagesSupplier xDrawPagesSupplier = (XDrawPagesSupplier) UnoRuntime
68
				.queryInterface(XDrawPagesSupplier.class, xComponent);
69
		XDrawPages xDrawPages = xDrawPagesSupplier.getDrawPages();
70
		return (XDrawPage) UnoRuntime.queryInterface(XDrawPage.class,
71
				xDrawPages.getByIndex(nIndex));
72
	}
73
74
	/**
75
	 * Create and insert a draw page into the giving position,the method returns
76
	 * the new created page
77
	 * 
78
	 * @param xComponent
79
	 *            :The Presentation Document
80
	 * @param nIndex
81
	 *            :The index at which page will be inserted.
82
	 * @return The newly created page.
83
	 */
84
	static public XDrawPage insertNewDrawPageByIndex(XComponent xComponent,
85
			int nIndex) throws Exception {
86
		XDrawPagesSupplier xDrawPagesSupplier = (XDrawPagesSupplier) UnoRuntime
87
				.queryInterface(XDrawPagesSupplier.class, xComponent);
88
		XDrawPages xDrawPages = xDrawPagesSupplier.getDrawPages();
89
		return xDrawPages.insertNewByIndex(nIndex);
90
	}
91
92
	/**
93
	 * Remove the given page
94
	 * 
95
	 * @param xComponent
96
	 *            : The Presentation Document
97
	 * @param xDrawPage
98
	 *            : The page want to be removed.
99
	 */
100
	static public void removeDrawPage(XComponent xComponent, XDrawPage xDrawPage) {
101
		XDrawPagesSupplier xDrawPagesSupplier = (XDrawPagesSupplier) UnoRuntime
102
				.queryInterface(XDrawPagesSupplier.class, xComponent);
103
		XDrawPages xDrawPages = xDrawPagesSupplier.getDrawPages();
104
		xDrawPages.remove(xDrawPage);
105
	}
106
107
	/**
108
	 * Get size of the given page
109
	 * 
110
	 * @param xDrawPage
111
	 *            : The specified target page
112
	 * @return specifies the 2-dimensional size of the page using width and
113
	 *         height.
114
	 */
115
	static public Size getPageSize(XDrawPage xDrawPage)
116
			throws com.sun.star.beans.UnknownPropertyException,
117
			com.sun.star.lang.WrappedTargetException {
118
		XPropertySet xPageProperties = (XPropertySet) UnoRuntime
119
				.queryInterface(XPropertySet.class, xDrawPage);
120
		return new Size(
121
				((Integer) xPageProperties.getPropertyValue("Width"))
122
						.intValue(),
123
				((Integer) xPageProperties.getPropertyValue("Height"))
124
						.intValue());
125
	}
126
127
	/**
128
	 * Get the page count for master pages
129
	 * 
130
	 * @param xComponent
131
	 *            : The presentation document
132
	 * @return Count of master pages.
133
	 */
134
	static public int getMasterPageCount(XComponent xComponent) {
135
		XMasterPagesSupplier xMasterPagesSupplier = (XMasterPagesSupplier) UnoRuntime
136
				.queryInterface(XMasterPagesSupplier.class, xComponent);
137
		XDrawPages xDrawPages = xMasterPagesSupplier.getMasterPages();
138
		return xDrawPages.getCount();
139
	}
140
141
	/**
142
	 * Get master page by index
143
	 * 
144
	 * @param xComponent
145
	 *            : The Presentation document
146
	 * @param nIndex
147
	 *            : Index of target master page.
148
	 * @return Page of
149
	 */
150
	static public XDrawPage getMasterPageByIndex(XComponent xComponent,
151
			int nIndex) throws com.sun.star.lang.IndexOutOfBoundsException,
152
			com.sun.star.lang.WrappedTargetException {
153
		XMasterPagesSupplier xMasterPagesSupplier = (XMasterPagesSupplier) UnoRuntime
154
				.queryInterface(XMasterPagesSupplier.class, xComponent);
155
		XDrawPages xDrawPages = xMasterPagesSupplier.getMasterPages();
156
		return (XDrawPage) UnoRuntime.queryInterface(XDrawPage.class,
157
				xDrawPages.getByIndex(nIndex));
158
	}
159
160
	/**
161
	 * creates and inserts a new master page into the giving position, the
162
	 * method returns the new created page
163
	 */
164
	static public XDrawPage insertNewMasterPageByIndex(XComponent xComponent,
165
			int nIndex) {
166
		XMasterPagesSupplier xMasterPagesSupplier = (XMasterPagesSupplier) UnoRuntime
167
				.queryInterface(XMasterPagesSupplier.class, xComponent);
168
		XDrawPages xDrawPages = xMasterPagesSupplier.getMasterPages();
169
		return xDrawPages.insertNewByIndex(nIndex);
170
	}
171
172
	/**
173
	 * removes the given page
174
	 */
175
	static public void removeMasterPage(XComponent xComponent,
176
			XDrawPage xDrawPage) {
177
		XMasterPagesSupplier xMasterPagesSupplier = (XMasterPagesSupplier) UnoRuntime
178
				.queryInterface(XMasterPagesSupplier.class, xComponent);
179
		XDrawPages xDrawPages = xMasterPagesSupplier.getMasterPages();
180
		xDrawPages.remove(xDrawPage);
181
	}
182
183
	/**
184
	 * return the corresponding masterpage for the giving drawpage
185
	 */
186
	static public XDrawPage getMasterPage(XDrawPage xDrawPage) {
187
		XMasterPageTarget xMasterPageTarget = (XMasterPageTarget) UnoRuntime
188
				.queryInterface(XMasterPageTarget.class, xDrawPage);
189
		return xMasterPageTarget.getMasterPage();
190
	}
191
192
	/**
193
	 * sets given masterpage at the drawpage
194
	 */
195
	static public void setMasterPage(XDrawPage xDrawPage, XDrawPage xMasterPage) {
196
		XMasterPageTarget xMasterPageTarget = (XMasterPageTarget) UnoRuntime
197
				.queryInterface(XMasterPageTarget.class, xDrawPage);
198
		xMasterPageTarget.setMasterPage(xMasterPage);
199
	}
200
201
	// __________ presentation pages __________
202
203
	/**
204
	 * test if a Presentation Document is supported. This is important, because
205
	 * only presentation documents have notes and handout pages
206
	 */
207
	static public boolean isImpressDocument(XComponent xComponent) {
208
		XServiceInfo xInfo = (XServiceInfo) UnoRuntime.queryInterface(
209
				XServiceInfo.class, xComponent);
210
		return xInfo
211
				.supportsService("com.sun.star.presentation.PresentationDocument");
212
	}
213
214
	/**
215
	 * in impress documents each normal draw page has a corresponding notes page
216
	 */
217
	static public XDrawPage getNotesPage(XDrawPage xDrawPage) {
218
		XPresentationPage aPresentationPage = (XPresentationPage) UnoRuntime
219
				.queryInterface(XPresentationPage.class, xDrawPage);
220
		return aPresentationPage.getNotesPage();
221
	}
222
223
	/**
224
	 * in impress each documents has one handout page
225
	 */
226
	static public XDrawPage getHandoutMasterPage(XComponent xComponent) {
227
		XHandoutMasterSupplier aHandoutMasterSupplier = (XHandoutMasterSupplier) UnoRuntime
228
				.queryInterface(XHandoutMasterSupplier.class, xComponent);
229
		return aHandoutMasterSupplier.getHandoutMasterPage();
230
	}
231
}
(-)source/testlib/uno/ShapeUtils.java (+162 lines)
Line 0 Link Here
1
package testlib.uno;
2
3
/**************************************************************
4
 * 
5
 * Licensed to the Apache Software Foundation (ASF) under one
6
 * or more contributor license agreements.  See the NOTICE file
7
 * distributed with this work for additional information
8
 * regarding copyright ownership.  The ASF licenses this file
9
 * to you under the Apache License, Version 2.0 (the
10
 * "License"); you may not use this file except in compliance
11
 * with the License.  You may obtain a copy of the License at
12
 * 
13
 *   http://www.apache.org/licenses/LICENSE-2.0
14
 * 
15
 * Unless required by applicable law or agreed to in writing,
16
 * software distributed under the License is distributed on an
17
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
18
 * KIND, either express or implied.  See the License for the
19
 * specific language governing permissions and limitations
20
 * under the License.
21
 * 
22
 *************************************************************/
23
24
// __________ Imports __________
25
26
import com.sun.star.uno.Exception;
27
import com.sun.star.uno.UnoRuntime;
28
import com.sun.star.lang.XComponent;
29
import com.sun.star.lang.XMultiServiceFactory;
30
31
import com.sun.star.awt.Point;
32
import com.sun.star.awt.Size;
33
34
import com.sun.star.beans.XPropertySet;
35
36
import com.sun.star.container.XEnumeration;
37
import com.sun.star.container.XEnumerationAccess;
38
39
import com.sun.star.drawing.XShape;
40
import com.sun.star.drawing.XShapes;
41
42
import com.sun.star.text.ControlCharacter;
43
import com.sun.star.text.XText;
44
import com.sun.star.text.XTextCursor;
45
import com.sun.star.text.XTextContent;
46
import com.sun.star.text.XTextRange;
47
48
public class ShapeUtils {
49
	// __________ static helper methods __________
50
	//
51
	public static XPropertySet createAndInsertShape(XComponent xDrawDoc,
52
			XShapes xShapes, Point aPos, Size aSize, String sShapeType)
53
			throws java.lang.Exception {
54
		XShape xShape = createShape(xDrawDoc, aPos, aSize, sShapeType);
55
		xShapes.add(xShape);
56
		XPropertySet xPropSet = (XPropertySet) UnoRuntime.queryInterface(
57
				XPropertySet.class, xShape);
58
		return xPropSet;
59
	}
60
61
	/**
62
	 * create a Shape
63
	 */
64
	public static XShape createShape(XComponent xDrawDoc, Point aPos,
65
			Size aSize, String sShapeType) throws java.lang.Exception {
66
		XShape xShape = null;
67
		XMultiServiceFactory xFactory = (XMultiServiceFactory) UnoRuntime
68
				.queryInterface(XMultiServiceFactory.class, xDrawDoc);
69
		Object xObj = xFactory.createInstance(sShapeType);
70
		xShape = (XShape) UnoRuntime.queryInterface(XShape.class, xObj);
71
		xShape.setPosition(aPos);
72
		xShape.setSize(aSize);
73
		return xShape;
74
	}
75
76
	/**
77
	 * try to get shape according position
78
	 * 
79
	 * @param aPos
80
	 * @return
81
	 */
82
	public static XShape getShape(XComponent xDrawDoc, Point aPos,
83
			String sShapeType) {
84
		XShape xShape = null;
85
		try {
86
			XMultiServiceFactory xFactory = (XMultiServiceFactory) UnoRuntime
87
					.queryInterface(XMultiServiceFactory.class, xDrawDoc);
88
			Object xObj = xFactory.createInstance(sShapeType);
89
			xShape = (XShape) UnoRuntime.queryInterface(XShape.class, xObj);
90
		} catch (Exception e) {
91
			// TODO Auto-generated catch block
92
			e.printStackTrace();
93
		}
94
		return xShape;
95
	}
96
97
	/**
98
	 * add text to a shape. the return value is the PropertySet of the text
99
	 * range that has been added
100
	 */
101
	public static XPropertySet addPortion(XShape xShape, String sText,
102
			boolean bNewParagraph)
103
			throws com.sun.star.lang.IllegalArgumentException {
104
		XText xText = (XText) UnoRuntime.queryInterface(XText.class, xShape);
105
106
		XTextCursor xTextCursor = xText.createTextCursor();
107
		xTextCursor.gotoEnd(false);
108
		if (bNewParagraph == true) {
109
			xText.insertControlCharacter(xTextCursor,
110
					ControlCharacter.PARAGRAPH_BREAK, false);
111
			xTextCursor.gotoEnd(false);
112
		}
113
		XTextRange xTextRange = (XTextRange) UnoRuntime.queryInterface(
114
				XTextRange.class, xTextCursor);
115
		xTextRange.setString(sText);
116
		xTextCursor.gotoEnd(true);
117
		XPropertySet xPropSet = (XPropertySet) UnoRuntime.queryInterface(
118
				XPropertySet.class, xTextRange);
119
		return xPropSet;
120
	}
121
122
	/**
123
	 * try to get text of a shape
124
	 * 
125
	 * @return
126
	 */
127
	public static String getPortion(XShape xShape) {
128
		String text = null;
129
		XText xText = (XText) UnoRuntime.queryInterface(XText.class, xShape);
130
131
		XTextCursor xTextCursor = xText.createTextCursor();
132
		XTextRange xTextRange = (XTextRange) UnoRuntime.queryInterface(
133
				XTextRange.class, xTextCursor);
134
		text = xTextRange.getString();
135
		return text;
136
137
	}
138
139
	public static void setPropertyForLastParagraph(XShape xText,
140
			String sPropName, Object aValue)
141
			throws com.sun.star.beans.UnknownPropertyException,
142
			com.sun.star.beans.PropertyVetoException,
143
			com.sun.star.lang.IllegalArgumentException,
144
			com.sun.star.lang.WrappedTargetException,
145
			com.sun.star.container.NoSuchElementException {
146
		XEnumerationAccess xEnumerationAccess = (XEnumerationAccess) UnoRuntime
147
				.queryInterface(XEnumerationAccess.class, xText);
148
		if (xEnumerationAccess.hasElements()) {
149
			XEnumeration xEnumeration = xEnumerationAccess.createEnumeration();
150
			while (xEnumeration.hasMoreElements()) {
151
				Object xObj = xEnumeration.nextElement();
152
				if (xEnumeration.hasMoreElements() == false) {
153
					XTextContent xTextContent = (XTextContent) UnoRuntime
154
							.queryInterface(XTextContent.class, xObj);
155
					XPropertySet xParaPropSet = (XPropertySet) UnoRuntime
156
							.queryInterface(XPropertySet.class, xTextContent);
157
					xParaPropSet.setPropertyValue(sPropName, aValue);
158
				}
159
			}
160
		}
161
	}
162
}
(-)source/testcase/uno/sd/ShapeProperties.java (+280 lines)
Line 0 Link Here
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 testcase.uno.sd;
22
23
import java.io.File;
24
import java.io.IOException;
25
26
import org.junit.After;
27
import static org.junit.Assert.*;
28
29
import org.junit.AfterClass;
30
import org.junit.Before;
31
import org.junit.Test;
32
import org.openoffice.test.uno.UnoApp;
33
import org.openoffice.test.common.FileUtil;
34
import org.openoffice.test.common.Testspace;
35
36
import testlib.uno.PageUtils;
37
import testlib.uno.ShapeUtils;
38
39
import com.sun.star.uno.UnoRuntime;
40
import com.sun.star.presentation.XPresentation;
41
import com.sun.star.presentation.XPresentationSupplier;
42
import com.sun.star.awt.Gradient;
43
import com.sun.star.awt.GradientStyle;
44
import com.sun.star.awt.Size;
45
import com.sun.star.awt.Point;
46
import com.sun.star.beans.PropertyValue;
47
import com.sun.star.beans.XPropertySet;
48
import com.sun.star.drawing.FillStyle;
49
import com.sun.star.drawing.Hatch;
50
import com.sun.star.drawing.HatchStyle;
51
import com.sun.star.drawing.XDrawPage;
52
import com.sun.star.drawing.XDrawPages;
53
import com.sun.star.drawing.XDrawPagesSupplier;
54
import com.sun.star.drawing.XShape;
55
import com.sun.star.drawing.XShapes;
56
import com.sun.star.frame.XComponentLoader;
57
import com.sun.star.frame.XStorable;
58
import com.sun.star.lang.XComponent;
59
import com.sun.star.lang.XMultiServiceFactory;
60
61
public class ShapeProperties {
62
	UnoApp unoApp = new UnoApp();
63
	XPresentationSupplier sdDocument = null;
64
	XPresentation pre = null;
65
	XComponent precomp = null;
66
	XComponent impressDocument = null;
67
	XComponent reLoadFile = null;
68
	XDrawPagesSupplier drawsupplier = null;
69
	XDrawPages drawpages = null;
70
	XShapes xShapes = null;
71
	XDrawPage xpage = null;
72
	String filePath=null;
73
74
	@Before
75
	public void setUp() throws Exception {
76
		unoApp.start();
77
		createDocumentAndSlide();
78
	}
79
80
	@After
81
	public void tearDown() throws Exception {
82
		unoApp.closeDocument(impressDocument);
83
		unoApp.closeDocument(reLoadFile);
84
		unoApp.close();
85
		if(filePath!=null)
86
			FileUtil.deleteFile(filePath);
87
	}
88
89
	/**
90
	 * test Insert a new slide and Insert a new EllipseShape
91
	 * 
92
	 * @throws Exception
93
	 */
94
	@Test
95
	public void testInsertShape() throws Exception {
96
		Point po = new Point(1000, 8000);
97
		xShapes = (XShapes) UnoRuntime.queryInterface(XShapes.class, xpage);
98
		XShape xShape = ShapeUtils.createShape(impressDocument, po, new Size(
99
				5000, 5000), "com.sun.star.drawing.EllipseShape");
100
		xShapes.add(xShape);
101
		XPropertySet xPropSet = (XPropertySet) UnoRuntime.queryInterface(
102
				XPropertySet.class, xShape);
103
		xPropSet.setPropertyValue("Name", "test");
104
		XShape shap = ShapeUtils.getShape(impressDocument, po,
105
				"com.sun.star.drawing.EllipseShape");
106
		XPropertySet xPropSet2 = (XPropertySet) UnoRuntime.queryInterface(
107
				XPropertySet.class, xShape);
108
		assertEquals("Not the same shape","test",xPropSet2.getPropertyValue("Name"));
109
		assertEquals("Not EllopseShape","com.sun.star.drawing.EllipseShape",shap.getShapeType());
110
	}
111
112
	/**
113
	 * test Insert text to an EllopseShape
114
	 * 
115
	 * @throws Exception
116
	 */
117
	@Test
118
	public void testInsertTextToShape() throws Exception {
119
		Point po = new Point(1000, 8000);
120
		xShapes = (XShapes) UnoRuntime.queryInterface(XShapes.class, xpage);
121
		XShape xShape = ShapeUtils.createShape(impressDocument, po, new Size(
122
				5000, 5000), "com.sun.star.drawing.EllipseShape");
123
		xShapes.add(xShape);
124
		ShapeUtils.addPortion(xShape, "test", false);
125
		assertEquals("Not put text correctly","test",ShapeUtils.getPortion(xShape));
126
	}
127
128
	/**
129
	 * test Shape fill with Gradient
130
	 * 
131
	 * @throws Exception
132
	 */
133
	@Test
134
	public void testShapeFillGradient() throws Exception {
135
		Point po = new Point(1000, 8000);
136
		xShapes = (XShapes) UnoRuntime.queryInterface(XShapes.class, xpage);
137
		XShape xShape = ShapeUtils.createShape(impressDocument, po, new Size(
138
				5000, 5000), "com.sun.star.drawing.EllipseShape");
139
		xShapes.add(xShape);
140
		XPropertySet xPropSet = (XPropertySet) UnoRuntime.queryInterface(
141
				XPropertySet.class, xShape);
142
		xPropSet.setPropertyValue("FillStyle", FillStyle.GRADIENT);
143
		Gradient aGradient = new Gradient();
144
		aGradient.Style = GradientStyle.LINEAR;
145
		aGradient.StartColor = 0x00ff00;
146
		aGradient.EndColor = 0xffff00;
147
		aGradient.Angle = 450;
148
		aGradient.Border = 0;
149
		aGradient.XOffset = 0;
150
		aGradient.YOffset = 0;
151
		aGradient.StartIntensity = 100;
152
		aGradient.EndIntensity = 100;
153
		aGradient.StepCount = 10;
154
		xPropSet.setPropertyValue("FillGradient", aGradient);
155
		// --------------------------
156
		xShape = saveAndLoadShape(po, "com.sun.star.drawing.EllipseShape");
157
		// ----------------------------
158
		assertEquals("Not Gradient Fill Style",FillStyle.GRADIENT,xPropSet.getPropertyValue("FillStyle"));
159
		aGradient=(Gradient) xPropSet.getPropertyValue("FillGradient");
160
		assertEquals("Not Linear Gradient",GradientStyle.LINEAR,aGradient.Style);
161
	}
162
163
	/**
164
	 * test Shape fill with yellow color
165
	 * 
166
	 * @throws Exception
167
	 */
168
	@Test
169
	public void testShapeFillColor() throws Exception {
170
		Point po = new Point(1000, 8000);
171
		xShapes = (XShapes) UnoRuntime.queryInterface(XShapes.class, xpage);
172
		XShape xShape = ShapeUtils.createShape(impressDocument, po, new Size(
173
				5000, 5000), "com.sun.star.drawing.EllipseShape");
174
		xShapes.add(xShape);
175
		XPropertySet xPropSet = (XPropertySet) UnoRuntime.queryInterface(
176
				XPropertySet.class, xShape);
177
		xPropSet.setPropertyValue("FillStyle", FillStyle.SOLID);
178
		xPropSet.setPropertyValue("FillColor", 0xffff00);
179
		// --------------------------
180
		xShape = saveAndLoadShape(po, "com.sun.star.drawing.EllipseShape");
181
		// ----------------------------------------------------
182
		assertEquals("Not Color Fill Style",FillStyle.SOLID,xPropSet.getPropertyValue("FillStyle"));
183
		assertEquals("Not Yellow Color Fill",0xffff00,xPropSet.getPropertyValue("FillColor"));
184
	}
185
	
186
	/**
187
	 * test shape fill with Hatch Style(Pattern in MS)
188
	 * @throws Exception
189
	 */
190
	@Test
191
	public void testShapeFillHatch() throws Exception {
192
		Point po = new Point(1000, 8000);
193
		xShapes = (XShapes) UnoRuntime.queryInterface(XShapes.class, xpage);
194
		XShape xShape = ShapeUtils.createShape(impressDocument, po, new Size(
195
				5000, 5000), "com.sun.star.drawing.EllipseShape");
196
		xShapes.add(xShape);
197
		XPropertySet xPropSet = (XPropertySet) UnoRuntime.queryInterface(
198
				XPropertySet.class, xShape);
199
		xPropSet.setPropertyValue("FillStyle", FillStyle.HATCH);
200
		Hatch aHatch=new Hatch();
201
		aHatch.Style=HatchStyle.DOUBLE;
202
		aHatch.Color=0x00ff00;
203
		aHatch.Distance=100;
204
		aHatch.Angle=450;
205
		xPropSet.setPropertyValue("FillHatch", aHatch);
206
		
207
		// --------------------------
208
		xShape = saveAndLoadShape(po, "com.sun.star.drawing.EllipseShape");
209
		// ----------------------------
210
		assertEquals("Not Gradient Fill Style",FillStyle.HATCH,xPropSet.getPropertyValue("FillStyle"));
211
	
212
		aHatch=(Hatch) xPropSet.getPropertyValue("FillHatch");
213
		assertEquals("Not Double Hatch",HatchStyle.DOUBLE,aHatch.Style);
214
	}
215
	
216
	/**
217
	 * create a new presentation document and insert a new slide.
218
	 * 
219
	 * @throws Exception
220
	 */
221
	public void createDocumentAndSlide() throws Exception {
222
		impressDocument = (XComponent) UnoRuntime.queryInterface(
223
				XComponent.class, unoApp.newDocument("simpress"));
224
		drawsupplier = (XDrawPagesSupplier) UnoRuntime.queryInterface(
225
				XDrawPagesSupplier.class, impressDocument);
226
		drawpages = drawsupplier.getDrawPages();
227
		drawpages.insertNewByIndex(1);
228
		xpage = PageUtils.getDrawPageByIndex(impressDocument, 1);
229
	}
230
231
	/**
232
	 * Save presentation and reLoad the presentation and shape in it.
233
	 * 
234
	 * @param po
235
	 * @param shapeType
236
	 * @return
237
	 * @throws Exception
238
	 */
239
	public XShape saveAndLoadShape(Point po, String shapeType) throws Exception {
240
		reLoadFile = saveAndReloadDoc(impressDocument,
241
				"StarOffice XML (Impress)", "odp");
242
		drawsupplier = (XDrawPagesSupplier) UnoRuntime.queryInterface(
243
				XDrawPagesSupplier.class, reLoadFile);
244
		drawpages = drawsupplier.getDrawPages();
245
		xpage = PageUtils.getDrawPageByIndex(impressDocument, 1);
246
		xShapes = (XShapes) UnoRuntime.queryInterface(XShapes.class, xpage);
247
		XShape shap = ShapeUtils.getShape(impressDocument, po,
248
				"com.sun.star.drawing.EllipseShape");
249
		return shap;
250
	}
251
252
	/**
253
	 * save and reload Presentation document.
254
	 * 
255
	 * @param presentationDocument
256
	 * @param sFilter
257
	 * @param sExtension
258
	 * @return
259
	 * @throws Exception
260
	 */
261
	private XComponent saveAndReloadDoc(XComponent presentationDocument,
262
			String sFilter, String sExtension) throws Exception {
263
		filePath = Testspace.getPath("tmp/presentationtest."
264
				+ sExtension);
265
		PropertyValue[] aStoreProperties = new PropertyValue[2];
266
		aStoreProperties[0] = new PropertyValue();
267
		aStoreProperties[1] = new PropertyValue();
268
		aStoreProperties[0].Name = "Override";
269
		aStoreProperties[0].Value = true;
270
		aStoreProperties[1].Name = "FilterName";
271
		aStoreProperties[1].Value = sFilter;
272
		XStorable xStorable = (XStorable) UnoRuntime.queryInterface(
273
				XStorable.class, presentationDocument);
274
		xStorable.storeToURL(FileUtil.getUrl(filePath), aStoreProperties);
275
276
		return UnoRuntime.queryInterface(XComponent.class,
277
				unoApp.loadDocument(filePath));
278
	}
279
280
}

Return to issue 120527