ShapeUtil.java (e6e6073d) ShapeUtil.java (85b88695)
1package 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

--- 23 unchanged lines hidden (view full) ---

32import com.sun.star.awt.Point;
33import com.sun.star.awt.Size;
34
35import com.sun.star.beans.XPropertySet;
36
37import com.sun.star.container.NoSuchElementException;
38import com.sun.star.container.XEnumeration;
39import com.sun.star.container.XEnumerationAccess;
1package 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

--- 23 unchanged lines hidden (view full) ---

32import com.sun.star.awt.Point;
33import com.sun.star.awt.Size;
34
35import com.sun.star.beans.XPropertySet;
36
37import com.sun.star.container.NoSuchElementException;
38import com.sun.star.container.XEnumeration;
39import com.sun.star.container.XEnumerationAccess;
40
40import com.sun.star.drawing.XDrawPage;
41import com.sun.star.drawing.XDrawPages;
42import com.sun.star.drawing.XDrawPagesSupplier;
41import com.sun.star.drawing.XShape;
42import com.sun.star.drawing.XShapes;
43
44import com.sun.star.text.ControlCharacter;
45import com.sun.star.text.XText;
46import com.sun.star.text.XTextCursor;
47import com.sun.star.text.XTextContent;
48import com.sun.star.text.XTextRange;

--- 21 unchanged lines hidden (view full) ---

70 .queryInterface(XMultiServiceFactory.class, xDrawDoc);
71 Object xObj = xFactory.createInstance(sShapeType);
72 xShape = (XShape) UnoRuntime.queryInterface(XShape.class, xObj);
73 xShape.setPosition(aPos);
74 xShape.setSize(aSize);
75 return xShape;
76 }
77
43import com.sun.star.drawing.XShape;
44import com.sun.star.drawing.XShapes;
45
46import com.sun.star.text.ControlCharacter;
47import com.sun.star.text.XText;
48import com.sun.star.text.XTextCursor;
49import com.sun.star.text.XTextContent;
50import com.sun.star.text.XTextRange;

--- 21 unchanged lines hidden (view full) ---

72 .queryInterface(XMultiServiceFactory.class, xDrawDoc);
73 Object xObj = xFactory.createInstance(sShapeType);
74 xShape = (XShape) UnoRuntime.queryInterface(XShape.class, xObj);
75 xShape.setPosition(aPos);
76 xShape.setSize(aSize);
77 return xShape;
78 }
79
78 /**
79 * try to get shape according position
80 *
81 * @param aPos
82 * @return
83 */
84 public static XShape getShape(XComponent xDrawDoc, Point aPos,
85 String sShapeType) {
86 XShape xShape = null;
87 try {
88 XMultiServiceFactory xFactory = (XMultiServiceFactory) UnoRuntime
89 .queryInterface(XMultiServiceFactory.class, xDrawDoc);
90 Object xObj = xFactory.createInstance(sShapeType);
91 xShape = (XShape) UnoRuntime.queryInterface(XShape.class, xObj);
92 } catch (Exception e) {
93 // TODO Auto-generated catch block
94 e.printStackTrace();
95 }
96 return xShape;
97 }
98
99 /**
100 * add text to a shape. the return value is the PropertySet of the text
101 * range that has been added
102 */
103 public static XPropertySet addPortion(XShape xShape, String sText,
104 boolean bNewParagraph)
105 throws com.sun.star.lang.IllegalArgumentException {

--- 76 unchanged lines hidden (view full) ---

182 .queryInterface(XTextContent.class, xObj);
183 XPropertySet xParaPropSet = (XPropertySet) UnoRuntime
184 .queryInterface(XPropertySet.class, xTextContent);
185 xParaPropSet.setPropertyValue(sPropName, aValue);
186 }
187 }
188 }
189 }
80
81 /**
82 * add text to a shape. the return value is the PropertySet of the text
83 * range that has been added
84 */
85 public static XPropertySet addPortion(XShape xShape, String sText,
86 boolean bNewParagraph)
87 throws com.sun.star.lang.IllegalArgumentException {

--- 76 unchanged lines hidden (view full) ---

164 .queryInterface(XTextContent.class, xObj);
165 XPropertySet xParaPropSet = (XPropertySet) UnoRuntime
166 .queryInterface(XPropertySet.class, xTextContent);
167 xParaPropSet.setPropertyValue(sPropName, aValue);
168 }
169 }
170 }
171 }
172 /**
173 * Get shapes in specific page
174 * @param impressDocument
175 * @param pageIndex
176 * @return
177 * @throws Exception
178 */
179 public static XShapes getShapes(XComponent impressDocument, int pageIndex) throws Exception{
180
181 XDrawPagesSupplier drawsupplier = (XDrawPagesSupplier) UnoRuntime.queryInterface(
182 XDrawPagesSupplier.class, impressDocument);
183 XDrawPages drawpages = drawsupplier.getDrawPages();
184 XDrawPage xpage=(XDrawPage)UnoRuntime.queryInterface(XDrawPage.class, drawpages.getByIndex(pageIndex));
185 XShapes xShapes = (XShapes) UnoRuntime.queryInterface(XShapes.class, xpage);
186 return xShapes;
187
188 }
189
190 /**
191 * Remove the specific shape in specific page
192 * @param impressDocument
193 * @param pageIndex
194 * @param shapeIndex
195 * @throws Exception
196 */
197 public static void removeOneShape(XComponent impressDocument, int pageIndex, int shapeIndex) throws Exception{
198 XDrawPagesSupplier drawsupplier = (XDrawPagesSupplier) UnoRuntime.queryInterface(
199 XDrawPagesSupplier.class, impressDocument);
200 XDrawPages drawpages = drawsupplier.getDrawPages();
201 XDrawPage xpage=(XDrawPage)UnoRuntime.queryInterface(XDrawPage.class, drawpages.getByIndex(pageIndex));
202 XShapes xShapes = (XShapes) UnoRuntime.queryInterface(XShapes.class, xpage);
203 XShape xShape = (XShape) UnoRuntime.queryInterface(XShape.class, xShapes.getByIndex(shapeIndex));
204 xShapes.remove(xShape);
205
206 }
190}
207}