bump product version to 4.1.6.2
[LibreOffice.git] / qadevOOo / runner / util / DrawTools.java
blob05c5551c117dd26ec671d57e520f50cc68de8224
1 /*
2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 package util;
21 // access the implementations via names
22 import com.sun.star.lang.XMultiServiceFactory;
23 import com.sun.star.uno.UnoRuntime;
25 import com.sun.star.beans.PropertyValue;
26 import com.sun.star.lang.XComponent;
27 import com.sun.star.drawing.XDrawPages;
28 import com.sun.star.drawing.XDrawPagesSupplier;
29 import com.sun.star.drawing.XDrawPage;
30 import com.sun.star.drawing.XShapes;
31 import com.sun.star.drawing.XShape;
34 import util.DesktopTools;
35 import util.InstCreator;
36 import util.ShapeDsc;
38 import com.sun.star.uno.AnyConverter;
39 import com.sun.star.uno.Type;
41 /**
42 * contains helper methods for draw documents
46 public class DrawTools {
48 /**
49 * Opens a new draw document
50 * with arguments
51 * @param xMSF the MultiServiceFactory
52 * @return the XComponent Interface of the document
55 public static XComponent createDrawDoc( XMultiServiceFactory xMSF ) {
56 PropertyValue[] Args = new PropertyValue [0];
57 XComponent DrawDoc = DesktopTools.openNewDoc( xMSF, "sdraw", Args );
58 return DrawDoc;
59 } // finish createDrawDoc
61 /**
62 * gets the XDrawPages container of a draw document
64 * @param aDoc the draw document
65 * @return the XDrawpages container of the document
68 public static XDrawPages getDrawPages ( XComponent aDoc ) {
69 XDrawPages oDPn = null;
70 try {
71 XDrawPagesSupplier oDPS = UnoRuntime.queryInterface(XDrawPagesSupplier.class,aDoc);
73 oDPn = oDPS.getDrawPages();
74 } catch ( Exception e ) {
75 throw new IllegalArgumentException( "Couldn't get drawpages" );
77 return oDPn;
78 } // finish getDrawPages
80 /**
81 * gets the specified XDrawPage of a draw document
83 * @param aDoc the draw document
84 * @param nr the index of the DrawPage
85 * @return the XDrawpage with index nr of the document
88 public static XDrawPage getDrawPage ( XComponent aDoc, int nr ) {
89 XDrawPage oDP = null;
90 try {
91 oDP = (XDrawPage) AnyConverter.toObject(
92 new Type(XDrawPage.class),getDrawPages( aDoc ).getByIndex( nr ));
93 } catch ( Exception e ) {
94 throw new IllegalArgumentException( "Couldn't get drawpage" );
96 return oDP;
99 /**
100 * gets the XShapes container of a draw page
102 * @param oDP the draw page
103 * @return the XDrawShape container of the drawpage
106 public static XShapes getShapes ( XDrawPage oDP ) {
107 return UnoRuntime.queryInterface(XShapes.class,oDP);
111 * creates a XShape
113 * @param oDoc the document
114 * @param height the height of the shape
115 * @param width the width of the shape
116 * @param x the x-position of the shape
117 * @param y the y-position of the shape
118 * @param kind the kind of the shape ('Ellipse', 'Line' or 'Rectangle')
119 * @return the created XShape
122 public XShape createShape( XComponent oDoc, int height, int width, int x,
123 int y, String kind ) {
124 //possible values for kind are 'Ellipse', 'Line' and 'Rectangle'
126 ShapeDsc sDsc = new ShapeDsc( height, width, x, y, kind );
127 InstCreator instCreate = new InstCreator( oDoc, sDsc );
128 XShape oShape = (XShape)instCreate.getInstance();
130 return oShape;
134 * creates a XShape and adds it to the documents
135 * first drawpage
136 * @param oDoc the document
137 * @param height the height of the shape
138 * @param width the width of the shape
139 * @param x the x-position of the shape
140 * @param y the y-position of the shape
141 * @param kind the kind of the shape ('Ellipse', 'Line' or 'Rectangle')
143 public void addShape( XComponent oDoc, int height, int width, int x,
144 int y, String kind ) {
146 getShapes(getDrawPage(oDoc,0)).add(createShape( oDoc, height, width, x,
147 y, kind ) );