Version 5.4.3.2, tag libreoffice-5.4.3.2
[LibreOffice.git] / qadevOOo / runner / util / DrawTools.java
bloba8f416312de3d61a09a59fbe58fe39613632a159
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.uno.AnyConverter;
32 import com.sun.star.uno.Type;
34 /**
35 * contains helper methods for draw documents
39 public class DrawTools {
41 /**
42 * Opens a new draw document
43 * with arguments
44 * @param xMSF the MultiServiceFactory
45 * @return the XComponent Interface of the document
48 public static XComponent createDrawDoc( XMultiServiceFactory xMSF ) {
49 PropertyValue[] Args = new PropertyValue [0];
50 XComponent DrawDoc = DesktopTools.openNewDoc( xMSF, "sdraw", Args );
51 return DrawDoc;
52 } // finish createDrawDoc
54 /**
55 * gets the XDrawPages container of a draw document
57 * @param aDoc the draw document
58 * @return the XDrawpages container of the document
61 public static XDrawPages getDrawPages ( XComponent aDoc ) {
62 XDrawPages oDPn = null;
63 try {
64 XDrawPagesSupplier oDPS = UnoRuntime.queryInterface(XDrawPagesSupplier.class,aDoc);
66 oDPn = oDPS.getDrawPages();
67 } catch ( Exception e ) {
68 throw new IllegalArgumentException( "Couldn't get drawpages", e );
70 return oDPn;
71 } // finish getDrawPages
73 /**
74 * gets the specified XDrawPage of a draw document
76 * @param aDoc the draw document
77 * @param nr the index of the DrawPage
78 * @return the XDrawpage with index nr of the document
81 public static XDrawPage getDrawPage ( XComponent aDoc, int nr ) {
82 XDrawPage oDP = null;
83 try {
84 oDP = (XDrawPage) AnyConverter.toObject(
85 new Type(XDrawPage.class),getDrawPages( aDoc ).getByIndex( nr ));
86 } catch ( Exception e ) {
87 throw new IllegalArgumentException( "Couldn't get drawpage", e );
89 return oDP;
92 /**
93 * gets the XShapes container of a draw page
95 * @param oDP the draw page
96 * @return the XDrawShape container of the drawpage
99 public static XShapes getShapes ( XDrawPage oDP ) {
100 return UnoRuntime.queryInterface(XShapes.class,oDP);