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 .
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
;
38 import com
.sun
.star
.uno
.AnyConverter
;
39 import com
.sun
.star
.uno
.Type
;
42 * contains helper methods for draw documents
46 public class DrawTools
{
49 * Opens a new draw document
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
);
59 } // finish createDrawDoc
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;
71 XDrawPagesSupplier oDPS
= UnoRuntime
.queryInterface(XDrawPagesSupplier
.class,aDoc
);
73 oDPn
= oDPS
.getDrawPages();
74 } catch ( Exception e
) {
75 throw new IllegalArgumentException( "Couldn't get drawpages" );
78 } // finish getDrawPages
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
) {
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" );
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
);
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();
134 * creates a XShape and adds it to the documents
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
,