1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: DrawTools.java,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
33 // access the implementations via names
34 import com
.sun
.star
.lang
.XMultiServiceFactory
;
35 import com
.sun
.star
.uno
.UnoRuntime
;
37 import com
.sun
.star
.beans
.PropertyValue
;
38 import com
.sun
.star
.lang
.XComponent
;
39 import com
.sun
.star
.drawing
.XDrawPages
;
40 import com
.sun
.star
.drawing
.XDrawPagesSupplier
;
41 import com
.sun
.star
.drawing
.XDrawPage
;
42 import com
.sun
.star
.drawing
.XShapes
;
43 import com
.sun
.star
.drawing
.XShape
;
46 import util
.DesktopTools
;
47 import util
.InstCreator
;
50 import com
.sun
.star
.uno
.AnyConverter
;
51 import com
.sun
.star
.uno
.Type
;
54 * contains helper methods for draw documents
58 public class DrawTools
{
61 * Opens a new draw document
63 * @param xMSF the MultiServiceFactory
64 * @return the XComponent Interface of the document
67 public static XComponent
createDrawDoc( XMultiServiceFactory xMSF
) {
68 PropertyValue
[] Args
= new PropertyValue
[0];
69 XComponent DrawDoc
= DesktopTools
.openNewDoc( xMSF
, "sdraw", Args
);
71 } // finish createDrawDoc
74 * gets the XDrawPages container of a draw document
76 * @param aDoc the draw document
77 * @return the XDrawpages container of the document
80 public static XDrawPages
getDrawPages ( XComponent aDoc
) {
81 XDrawPages oDPn
= null;
83 XDrawPagesSupplier oDPS
= (XDrawPagesSupplier
)
84 UnoRuntime
.queryInterface(XDrawPagesSupplier
.class,aDoc
);
86 oDPn
= oDPS
.getDrawPages();
87 } catch ( Exception e
) {
88 throw new IllegalArgumentException( "Couldn't get drawpages" );
91 } // finish getDrawPages
94 * gets the specified XDrawPage of a draw document
96 * @param aDoc the draw document
97 * @param nr the index of the DrawPage
98 * @return the XDrawpage with index nr of the document
101 public static XDrawPage
getDrawPage ( XComponent aDoc
, int nr
) {
102 XDrawPage oDP
= null;
104 oDP
= (XDrawPage
) AnyConverter
.toObject(
105 new Type(XDrawPage
.class),getDrawPages( aDoc
).getByIndex( nr
));
106 } catch ( Exception e
) {
107 throw new IllegalArgumentException( "Couldn't get drawpage" );
113 * gets the XShapes container of a draw page
115 * @param oDP the draw page
116 * @return the XDrawShape container of the drawpage
119 public static XShapes
getShapes ( XDrawPage oDP
) {
120 return (XShapes
) UnoRuntime
.queryInterface(XShapes
.class,oDP
);
126 * @param oDoc the document
127 * @param height the height of the shape
128 * @param width the width of the shape
129 * @param x the x-position of the shape
130 * @param y the y-position of the shape
131 * @param kind the kind of the shape ('Ellipse', 'Line' or 'Rectangle')
132 * @return the created XShape
135 public XShape
createShape( XComponent oDoc
, int height
, int width
, int x
,
136 int y
, String kind
) {
137 //possible values for kind are 'Ellipse', 'Line' and 'Rectangle'
139 ShapeDsc sDsc
= new ShapeDsc( height
, width
, x
, y
, kind
);
140 InstCreator instCreate
= new InstCreator( oDoc
, sDsc
);
141 XShape oShape
= (XShape
)instCreate
.getInstance();
147 * creates a XShape and adds it to the documents
149 * @param oDoc the document
150 * @param height the height of the shape
151 * @param width the width of the shape
152 * @param x the x-position of the shape
153 * @param y the y-position of the shape
154 * @param kind the kind of the shape ('Ellipse', 'Line' or 'Rectangle')
155 * @return the created XShape
158 public void addShape( XComponent oDoc
, int height
, int width
, int x
,
159 int y
, String kind
) {
161 getShapes(getDrawPage(oDoc
,0)).add(createShape( oDoc
, height
, width
, x
,