Version 3.6.0.4, tag libreoffice-3.6.0.4
[LibreOffice.git] / qadevOOo / runner / util / DrawTools.java
blobd5f862cb49a7d264effa86aacad72591d82f33be
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 package util;
30 // access the implementations via names
31 import com.sun.star.lang.XMultiServiceFactory;
32 import com.sun.star.uno.UnoRuntime;
34 import com.sun.star.beans.PropertyValue;
35 import com.sun.star.lang.XComponent;
36 import com.sun.star.drawing.XDrawPages;
37 import com.sun.star.drawing.XDrawPagesSupplier;
38 import com.sun.star.drawing.XDrawPage;
39 import com.sun.star.drawing.XShapes;
40 import com.sun.star.drawing.XShape;
43 import util.DesktopTools;
44 import util.InstCreator;
45 import util.ShapeDsc;
47 import com.sun.star.uno.AnyConverter;
48 import com.sun.star.uno.Type;
50 /**
51 * contains helper methods for draw documents
55 public class DrawTools {
57 /**
58 * Opens a new draw document
59 * with arguments
60 * @param xMSF the MultiServiceFactory
61 * @return the XComponent Interface of the document
64 public static XComponent createDrawDoc( XMultiServiceFactory xMSF ) {
65 PropertyValue[] Args = new PropertyValue [0];
66 XComponent DrawDoc = DesktopTools.openNewDoc( xMSF, "sdraw", Args );
67 return DrawDoc;
68 } // finish createDrawDoc
70 /**
71 * gets the XDrawPages container of a draw document
73 * @param aDoc the draw document
74 * @return the XDrawpages container of the document
77 public static XDrawPages getDrawPages ( XComponent aDoc ) {
78 XDrawPages oDPn = null;
79 try {
80 XDrawPagesSupplier oDPS = (XDrawPagesSupplier)
81 UnoRuntime.queryInterface(XDrawPagesSupplier.class,aDoc);
83 oDPn = oDPS.getDrawPages();
84 } catch ( Exception e ) {
85 throw new IllegalArgumentException( "Couldn't get drawpages" );
87 return oDPn;
88 } // finish getDrawPages
90 /**
91 * gets the specified XDrawPage of a draw document
93 * @param aDoc the draw document
94 * @param nr the index of the DrawPage
95 * @return the XDrawpage with index nr of the document
98 public static XDrawPage getDrawPage ( XComponent aDoc, int nr ) {
99 XDrawPage oDP = null;
100 try {
101 oDP = (XDrawPage) AnyConverter.toObject(
102 new Type(XDrawPage.class),getDrawPages( aDoc ).getByIndex( nr ));
103 } catch ( Exception e ) {
104 throw new IllegalArgumentException( "Couldn't get drawpage" );
106 return oDP;
110 * gets the XShapes container of a draw page
112 * @param oDP the draw page
113 * @return the XDrawShape container of the drawpage
116 public static XShapes getShapes ( XDrawPage oDP ) {
117 return (XShapes) UnoRuntime.queryInterface(XShapes.class,oDP);
121 * creates a XShape
123 * @param oDoc the document
124 * @param height the height of the shape
125 * @param width the width of the shape
126 * @param x the x-position of the shape
127 * @param y the y-position of the shape
128 * @param kind the kind of the shape ('Ellipse', 'Line' or 'Rectangle')
129 * @return the created XShape
132 public XShape createShape( XComponent oDoc, int height, int width, int x,
133 int y, String kind ) {
134 //possible values for kind are 'Ellipse', 'Line' and 'Rectangle'
136 ShapeDsc sDsc = new ShapeDsc( height, width, x, y, kind );
137 InstCreator instCreate = new InstCreator( oDoc, sDsc );
138 XShape oShape = (XShape)instCreate.getInstance();
140 return oShape;
144 * creates a XShape and adds it to the documents
145 * first drawpage
146 * @param oDoc the document
147 * @param height the height of the shape
148 * @param width the width of the shape
149 * @param x the x-position of the shape
150 * @param y the y-position of the shape
151 * @param kind the kind of the shape ('Ellipse', 'Line' or 'Rectangle')
152 * @return the created XShape
155 public void addShape( XComponent oDoc, int height, int width, int x,
156 int y, String kind ) {
158 getShapes(getDrawPage(oDoc,0)).add(createShape( oDoc, height, width, x,
159 y, kind ) );