1b1aaa6deSLiu Zhe /**************************************************************
2b1aaa6deSLiu Zhe  *
3b1aaa6deSLiu Zhe  * Licensed to the Apache Software Foundation (ASF) under one
4b1aaa6deSLiu Zhe  * or more contributor license agreements.  See the NOTICE file
5b1aaa6deSLiu Zhe  * distributed with this work for additional information
6b1aaa6deSLiu Zhe  * regarding copyright ownership.  The ASF licenses this file
7b1aaa6deSLiu Zhe  * to you under the Apache License, Version 2.0 (the
8b1aaa6deSLiu Zhe  * "License"); you may not use this file except in compliance
9b1aaa6deSLiu Zhe  * with the License.  You may obtain a copy of the License at
10b1aaa6deSLiu Zhe  *
11b1aaa6deSLiu Zhe  *   http://www.apache.org/licenses/LICENSE-2.0
12b1aaa6deSLiu Zhe  *
13b1aaa6deSLiu Zhe  * Unless required by applicable law or agreed to in writing,
14b1aaa6deSLiu Zhe  * software distributed under the License is distributed on an
15b1aaa6deSLiu Zhe  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16b1aaa6deSLiu Zhe  * KIND, either express or implied.  See the License for the
17b1aaa6deSLiu Zhe  * specific language governing permissions and limitations
18b1aaa6deSLiu Zhe  * under the License.
19b1aaa6deSLiu Zhe  *
20b1aaa6deSLiu Zhe  *************************************************************/
21*eba4d44aSLiu Zhe package fvt.uno.sd.textbox;
22b1aaa6deSLiu Zhe 
23b1aaa6deSLiu Zhe import static org.junit.Assert.assertEquals;
24b1aaa6deSLiu Zhe 
25b1aaa6deSLiu Zhe import org.junit.After;
26b1aaa6deSLiu Zhe import org.junit.Before;
27b1aaa6deSLiu Zhe import org.junit.Test;
28b1aaa6deSLiu Zhe import org.openoffice.test.common.FileUtil;
29b1aaa6deSLiu Zhe import org.openoffice.test.common.Testspace;
30b1aaa6deSLiu Zhe import org.openoffice.test.uno.UnoApp;
31b1aaa6deSLiu Zhe 
32b1aaa6deSLiu Zhe import testlib.uno.PageUtil;
33b1aaa6deSLiu Zhe import testlib.uno.ShapeUtil;
34b1aaa6deSLiu Zhe 
35b1aaa6deSLiu Zhe import com.sun.star.awt.Point;
36b1aaa6deSLiu Zhe import com.sun.star.awt.Size;
37b1aaa6deSLiu Zhe import com.sun.star.beans.PropertyValue;
38b1aaa6deSLiu Zhe import com.sun.star.beans.XPropertySet;
39b1aaa6deSLiu Zhe import com.sun.star.drawing.DashStyle;
40b1aaa6deSLiu Zhe import com.sun.star.drawing.LineDash;
41b1aaa6deSLiu Zhe import com.sun.star.drawing.LineStyle;
42b1aaa6deSLiu Zhe import com.sun.star.drawing.XDrawPage;
43b1aaa6deSLiu Zhe import com.sun.star.drawing.XDrawPages;
44b1aaa6deSLiu Zhe import com.sun.star.drawing.XDrawPagesSupplier;
45b1aaa6deSLiu Zhe import com.sun.star.drawing.XShape;
46b1aaa6deSLiu Zhe import com.sun.star.drawing.XShapes;
47b1aaa6deSLiu Zhe import com.sun.star.frame.XStorable;
48b1aaa6deSLiu Zhe import com.sun.star.lang.XComponent;
49b1aaa6deSLiu Zhe import com.sun.star.presentation.XPresentation;
50b1aaa6deSLiu Zhe import com.sun.star.presentation.XPresentationSupplier;
51b1aaa6deSLiu Zhe import com.sun.star.uno.UnoRuntime;
52b1aaa6deSLiu Zhe 
53b1aaa6deSLiu Zhe public class LineProperties {
54b1aaa6deSLiu Zhe 	UnoApp unoApp = new UnoApp();
55b1aaa6deSLiu Zhe 	XPresentationSupplier sdDocument = null;
56b1aaa6deSLiu Zhe 	XPresentation pre = null;
57b1aaa6deSLiu Zhe 	XComponent precomp = null;
58b1aaa6deSLiu Zhe 	XComponent impressDocument = null;
59b1aaa6deSLiu Zhe 	XComponent reLoadFile = null;
60b1aaa6deSLiu Zhe 	XDrawPagesSupplier drawsupplier = null;
61b1aaa6deSLiu Zhe 	XDrawPages drawpages = null;
62b1aaa6deSLiu Zhe 	XShapes xShapes = null;
63b1aaa6deSLiu Zhe 	XDrawPage xpage = null;
64b1aaa6deSLiu Zhe 	String filePath = null;
65b1aaa6deSLiu Zhe 
66b1aaa6deSLiu Zhe 	@Before
setUp()67b1aaa6deSLiu Zhe 	public void setUp() throws Exception {
68b1aaa6deSLiu Zhe 		unoApp.start();
69b1aaa6deSLiu Zhe 		createDocumentAndSlide();
70b1aaa6deSLiu Zhe 	}
71b1aaa6deSLiu Zhe 
72b1aaa6deSLiu Zhe 	@After
tearDown()73b1aaa6deSLiu Zhe 	public void tearDown() throws Exception {
74b1aaa6deSLiu Zhe 		unoApp.closeDocument(impressDocument);
75b1aaa6deSLiu Zhe 		unoApp.closeDocument(reLoadFile);
76b1aaa6deSLiu Zhe 		unoApp.close();
77b1aaa6deSLiu Zhe 		 if (filePath != null)
78b1aaa6deSLiu Zhe 		 FileUtil.deleteFile(filePath);
79b1aaa6deSLiu Zhe 	}
80b1aaa6deSLiu Zhe 
81b1aaa6deSLiu Zhe 
82b1aaa6deSLiu Zhe 	/**
83b1aaa6deSLiu Zhe 	 * test Textbox Line style DASH
84b1aaa6deSLiu Zhe 	 *
85b1aaa6deSLiu Zhe 	 * @throws Exception
86b1aaa6deSLiu Zhe 	 */
87b1aaa6deSLiu Zhe 	 @Test
testShapeLineStyle()88b1aaa6deSLiu Zhe 	 public void testShapeLineStyle() throws Exception {
89b1aaa6deSLiu Zhe 	 Point po = new Point(1000, 8000);
90b1aaa6deSLiu Zhe 	 xShapes = (XShapes) UnoRuntime.queryInterface(XShapes.class, xpage);
91b1aaa6deSLiu Zhe 	 XShape xShape = ShapeUtil.createShape(impressDocument, po, new Size(
92b1aaa6deSLiu Zhe 	 5000, 5000), "com.sun.star.drawing.TextShape");
93b1aaa6deSLiu Zhe 	 xShapes.add(xShape);
94b1aaa6deSLiu Zhe 	 ShapeUtil.addPortion(xShape, "test", false);
95b1aaa6deSLiu Zhe 	 XPropertySet xPropSet = (XPropertySet) UnoRuntime.queryInterface(
96b1aaa6deSLiu Zhe 	 XPropertySet.class, xShape);
97b1aaa6deSLiu Zhe 	 xPropSet.setPropertyValue("LineStyle", LineStyle.DASH);
98b1aaa6deSLiu Zhe 
99b1aaa6deSLiu Zhe 	 LineDash aLineDash=new LineDash();
100b1aaa6deSLiu Zhe 	 aLineDash.Style=DashStyle.ROUND;
101b1aaa6deSLiu Zhe 	 aLineDash.Dots=2;
102b1aaa6deSLiu Zhe 	 aLineDash.DashLen=100;
103b1aaa6deSLiu Zhe 	 aLineDash.Distance=50;
104b1aaa6deSLiu Zhe 	 xPropSet.setPropertyValue("LineDash", aLineDash);
105b1aaa6deSLiu Zhe 
106b1aaa6deSLiu Zhe 	 // --------------------------
107b1aaa6deSLiu Zhe 	 xShape=saveAndLoadShape(1,0);
108b1aaa6deSLiu Zhe 	 xPropSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xShape);
109b1aaa6deSLiu Zhe 	 // ----------------------------
110b1aaa6deSLiu Zhe 	 assertEquals("Not Dash Line Style",LineStyle.DASH,xPropSet.getPropertyValue("LineStyle"));
111b1aaa6deSLiu Zhe 	 aLineDash=(LineDash) xPropSet.getPropertyValue("LineDash");
112b1aaa6deSLiu Zhe 	 assertEquals("Not Round Dash Style", DashStyle.ROUND ,aLineDash.Style);
113b1aaa6deSLiu Zhe 	 }
114b1aaa6deSLiu Zhe 
115b1aaa6deSLiu Zhe 	 /**
116b1aaa6deSLiu Zhe 	 * test Textbox Line Color
117b1aaa6deSLiu Zhe 	 * @throws Exception
118b1aaa6deSLiu Zhe 	 */
119b1aaa6deSLiu Zhe 
120b1aaa6deSLiu Zhe 	 @Test
testShapeLineColor()121b1aaa6deSLiu Zhe 	 public void testShapeLineColor() throws Exception {
122b1aaa6deSLiu Zhe 	 Point po = new Point(1000, 8000);
123b1aaa6deSLiu Zhe 	 xShapes = (XShapes) UnoRuntime.queryInterface(XShapes.class, xpage);
124b1aaa6deSLiu Zhe 	 XShape xShape = ShapeUtil.createShape(impressDocument, po, new Size(
125b1aaa6deSLiu Zhe 	 5000, 5000), "com.sun.star.drawing.TextShape");
126b1aaa6deSLiu Zhe 	 xShapes.add(xShape);
127b1aaa6deSLiu Zhe 	 ShapeUtil.addPortion(xShape, "test", false);
128b1aaa6deSLiu Zhe 	 XPropertySet xPropSet = (XPropertySet) UnoRuntime.queryInterface(
129b1aaa6deSLiu Zhe 	 XPropertySet.class, xShape);
130b1aaa6deSLiu Zhe 	 xPropSet.setPropertyValue("LineStyle", LineStyle.DASH);
131b1aaa6deSLiu Zhe 	 xPropSet.setPropertyValue("LineColor", 0x00ff00);
132b1aaa6deSLiu Zhe 	 xShape=saveAndLoadShape(1,0);
133b1aaa6deSLiu Zhe 	 xPropSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xShape);
134b1aaa6deSLiu Zhe 	 // ----------------------------
135b1aaa6deSLiu Zhe 	 assertEquals("Not Dash Line Style",LineStyle.DASH,xPropSet.getPropertyValue("LineStyle"));
136b1aaa6deSLiu Zhe 	 assertEquals("wrong line color", 0x00ff00,xPropSet.getPropertyValue("LineColor"));
137b1aaa6deSLiu Zhe 	 }
138b1aaa6deSLiu Zhe 
139b1aaa6deSLiu Zhe 	/**
140b1aaa6deSLiu Zhe 	 * create a new presentation document and insert a new slide.
141b1aaa6deSLiu Zhe 	 *
142b1aaa6deSLiu Zhe 	 * @throws Exception
143b1aaa6deSLiu Zhe 	 */
createDocumentAndSlide()144b1aaa6deSLiu Zhe 	public void createDocumentAndSlide() throws Exception {
145b1aaa6deSLiu Zhe 		impressDocument = (XComponent) UnoRuntime.queryInterface(
146b1aaa6deSLiu Zhe 				XComponent.class, unoApp.newDocument("simpress"));
147b1aaa6deSLiu Zhe 		drawsupplier = (XDrawPagesSupplier) UnoRuntime.queryInterface(
148b1aaa6deSLiu Zhe 				XDrawPagesSupplier.class, impressDocument);
149b1aaa6deSLiu Zhe 		drawpages = drawsupplier.getDrawPages();
150b1aaa6deSLiu Zhe 		drawpages.insertNewByIndex(1);
151b1aaa6deSLiu Zhe 		xpage = PageUtil.getDrawPageByIndex(impressDocument, 1);
152b1aaa6deSLiu Zhe 	}
153b1aaa6deSLiu Zhe 
154b1aaa6deSLiu Zhe 	/**
155b1aaa6deSLiu Zhe 	 * Save presentation and reLoad the presentation and shape in it.
156b1aaa6deSLiu Zhe 	 *
157b1aaa6deSLiu Zhe 	 * @param po
158b1aaa6deSLiu Zhe 	 * @param shapeType
159b1aaa6deSLiu Zhe 	 * @return
160b1aaa6deSLiu Zhe 	 * @throws Exception
161b1aaa6deSLiu Zhe 	 */
saveAndLoadShape(int pageIndex, int shapeIndex)162b1aaa6deSLiu Zhe 	public XShape saveAndLoadShape(int pageIndex, int shapeIndex)
163b1aaa6deSLiu Zhe 			throws Exception {
164b1aaa6deSLiu Zhe 		reLoadFile = saveAndReloadDoc(impressDocument, "impress8", "odp");
165b1aaa6deSLiu Zhe 		xShapes = ShapeUtil.getShapes(reLoadFile, pageIndex);
166b1aaa6deSLiu Zhe 		return (XShape) UnoRuntime.queryInterface(XShape.class,
167b1aaa6deSLiu Zhe 				xShapes.getByIndex(shapeIndex));
168b1aaa6deSLiu Zhe 	}
169b1aaa6deSLiu Zhe 
170b1aaa6deSLiu Zhe 	/**
171b1aaa6deSLiu Zhe 	 * save and reload Presentation document.
172b1aaa6deSLiu Zhe 	 *
173b1aaa6deSLiu Zhe 	 * @param presentationDocument
174b1aaa6deSLiu Zhe 	 * @param sFilter
175b1aaa6deSLiu Zhe 	 * @param sExtension
176b1aaa6deSLiu Zhe 	 * @return
177b1aaa6deSLiu Zhe 	 * @throws Exception
178b1aaa6deSLiu Zhe 	 */
saveAndReloadDoc(XComponent presentationDocument, String sFilter, String sExtension)179b1aaa6deSLiu Zhe 	private XComponent saveAndReloadDoc(XComponent presentationDocument,
180b1aaa6deSLiu Zhe 			String sFilter, String sExtension) throws Exception {
181b1aaa6deSLiu Zhe 		filePath = Testspace.getPath("tmp/textboxline." + sExtension);
182b1aaa6deSLiu Zhe 		PropertyValue[] aStoreProperties = new PropertyValue[2];
183b1aaa6deSLiu Zhe 		aStoreProperties[0] = new PropertyValue();
184b1aaa6deSLiu Zhe 		aStoreProperties[1] = new PropertyValue();
185b1aaa6deSLiu Zhe 		aStoreProperties[0].Name = "Override";
186b1aaa6deSLiu Zhe 		aStoreProperties[0].Value = true;
187b1aaa6deSLiu Zhe 		aStoreProperties[1].Name = "FilterName";
188b1aaa6deSLiu Zhe 		aStoreProperties[1].Value = sFilter;
189b1aaa6deSLiu Zhe 		XStorable xStorable = (XStorable) UnoRuntime.queryInterface(
190b1aaa6deSLiu Zhe 				XStorable.class, presentationDocument);
191b1aaa6deSLiu Zhe 		xStorable.storeToURL(FileUtil.getUrl(filePath), aStoreProperties);
192b1aaa6deSLiu Zhe 
1934481f6d8SLinyi Li 		return (XComponent) UnoRuntime.queryInterface(XComponent.class,
194b1aaa6deSLiu Zhe 				unoApp.loadDocument(filePath));
195b1aaa6deSLiu Zhe 	}
196b1aaa6deSLiu Zhe }
197b1aaa6deSLiu Zhe 
198b1aaa6deSLiu Zhe 
199