merge the formfield patch from ooo-build
[ooovba.git] / odk / examples / DevelopersGuide / Drawing / PageHelper.java
blobb9a654a0d7d5b6f5ff8988871edf83ef22ac5769
1 /*************************************************************************
3 * $RCSfile: PageHelper.java,v $
5 * $Revision: 1.4 $
7 * last change: $Author: rt $ $Date: 2005-01-31 16:24:25 $
9 * The Contents of this file are made available subject to the terms of
10 * the BSD license.
12 * Copyright (c) 2003 by Sun Microsystems, Inc.
13 * All rights reserved.
15 * Redistribution and use in source and binary forms, with or without
16 * modification, are permitted provided that the following conditions
17 * are met:
18 * 1. Redistributions of source code must retain the above copyright
19 * notice, this list of conditions and the following disclaimer.
20 * 2. Redistributions in binary form must reproduce the above copyright
21 * notice, this list of conditions and the following disclaimer in the
22 * documentation and/or other materials provided with the distribution.
23 * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
24 * contributors may be used to endorse or promote products derived
25 * from this software without specific prior written permission.
27 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
30 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
31 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
32 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
33 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
34 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
35 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
36 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
37 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 *************************************************************************/
41 // __________ Imports __________
43 import com.sun.star.uno.UnoRuntime;
44 import com.sun.star.lang.XComponent;
45 import com.sun.star.lang.XServiceInfo;
47 import com.sun.star.awt.Size;
49 import com.sun.star.beans.XPropertySet;
51 import com.sun.star.drawing.XDrawPage;
52 import com.sun.star.drawing.XDrawPages;
53 import com.sun.star.drawing.XDrawPagesSupplier;
54 import com.sun.star.drawing.XMasterPageTarget;
55 import com.sun.star.drawing.XMasterPagesSupplier;
57 import com.sun.star.presentation.XPresentationPage;
58 import com.sun.star.presentation.XHandoutMasterSupplier;
61 public class PageHelper
63 // __________ static helper methods __________
65 // __________ draw pages __________
67 /** get the page count for standard pages
69 static public int getDrawPageCount( XComponent xComponent )
71 XDrawPagesSupplier xDrawPagesSupplier =
72 (XDrawPagesSupplier)UnoRuntime.queryInterface(
73 XDrawPagesSupplier.class, xComponent );
74 XDrawPages xDrawPages = xDrawPagesSupplier.getDrawPages();
75 return xDrawPages.getCount();
78 /** get draw page by index
80 static public XDrawPage getDrawPageByIndex( XComponent xComponent, int nIndex )
81 throws com.sun.star.lang.IndexOutOfBoundsException,
82 com.sun.star.lang.WrappedTargetException
84 XDrawPagesSupplier xDrawPagesSupplier =
85 (XDrawPagesSupplier)UnoRuntime.queryInterface(
86 XDrawPagesSupplier.class, xComponent );
87 XDrawPages xDrawPages = xDrawPagesSupplier.getDrawPages();
88 return (XDrawPage)UnoRuntime.queryInterface(XDrawPage.class, xDrawPages.getByIndex( nIndex ));
91 /** creates and inserts a draw page into the giving position,
92 the method returns the new created page
94 static public XDrawPage insertNewDrawPageByIndex( XComponent xComponent, int nIndex )
95 throws Exception
97 XDrawPagesSupplier xDrawPagesSupplier =
98 (XDrawPagesSupplier)UnoRuntime.queryInterface(
99 XDrawPagesSupplier.class, xComponent );
100 XDrawPages xDrawPages = xDrawPagesSupplier.getDrawPages();
101 return xDrawPages.insertNewByIndex( nIndex );
104 /** removes the given page
106 static public void removeDrawPage( XComponent xComponent, XDrawPage xDrawPage )
108 XDrawPagesSupplier xDrawPagesSupplier =
109 (XDrawPagesSupplier)UnoRuntime.queryInterface(
110 XDrawPagesSupplier.class, xComponent );
111 XDrawPages xDrawPages = xDrawPagesSupplier.getDrawPages();
112 xDrawPages.remove( xDrawPage );
115 /** get size of the given page
117 static public Size getPageSize( XDrawPage xDrawPage )
118 throws com.sun.star.beans.UnknownPropertyException,
119 com.sun.star.lang.WrappedTargetException
121 XPropertySet xPageProperties = (XPropertySet)
122 UnoRuntime.queryInterface( XPropertySet.class, xDrawPage );
123 return new Size(
124 ((Integer)xPageProperties.getPropertyValue( "Width" )).intValue(),
125 ((Integer)xPageProperties.getPropertyValue( "Height" )).intValue() );
128 // __________ master pages __________
130 /** get the page count for master pages
132 static public int getMasterPageCount( XComponent xComponent )
134 XMasterPagesSupplier xMasterPagesSupplier =
135 (XMasterPagesSupplier)UnoRuntime.queryInterface(
136 XMasterPagesSupplier.class, xComponent );
137 XDrawPages xDrawPages = xMasterPagesSupplier.getMasterPages();
138 return xDrawPages.getCount();
141 /** get master page by index
143 static public XDrawPage getMasterPageByIndex( XComponent xComponent, int nIndex )
144 throws com.sun.star.lang.IndexOutOfBoundsException,
145 com.sun.star.lang.WrappedTargetException
147 XMasterPagesSupplier xMasterPagesSupplier =
148 (XMasterPagesSupplier)UnoRuntime.queryInterface(
149 XMasterPagesSupplier.class, xComponent );
150 XDrawPages xDrawPages = xMasterPagesSupplier.getMasterPages();
151 return (XDrawPage)UnoRuntime.queryInterface(XDrawPage.class, xDrawPages.getByIndex( nIndex ));
154 /** creates and inserts a new master page into the giving position,
155 the method returns the new created page
157 static public XDrawPage insertNewMasterPageByIndex( XComponent xComponent, int nIndex )
159 XMasterPagesSupplier xMasterPagesSupplier =
160 (XMasterPagesSupplier)UnoRuntime.queryInterface(
161 XMasterPagesSupplier.class, xComponent );
162 XDrawPages xDrawPages = xMasterPagesSupplier.getMasterPages();
163 return xDrawPages.insertNewByIndex( nIndex );
166 /** removes the given page
168 static public void removeMasterPage( XComponent xComponent, XDrawPage xDrawPage )
170 XMasterPagesSupplier xMasterPagesSupplier =
171 (XMasterPagesSupplier)UnoRuntime.queryInterface(
172 XMasterPagesSupplier.class, xComponent );
173 XDrawPages xDrawPages = xMasterPagesSupplier.getMasterPages();
174 xDrawPages.remove( xDrawPage );
177 /** return the corresponding masterpage for the giving drawpage
179 static public XDrawPage getMasterPage( XDrawPage xDrawPage )
181 XMasterPageTarget xMasterPageTarget =
182 (XMasterPageTarget)UnoRuntime.queryInterface(
183 XMasterPageTarget.class, xDrawPage );
184 return xMasterPageTarget.getMasterPage();
187 /** sets given masterpage at the drawpage
189 static public void setMasterPage( XDrawPage xDrawPage, XDrawPage xMasterPage )
191 XMasterPageTarget xMasterPageTarget =
192 (XMasterPageTarget)UnoRuntime.queryInterface(
193 XMasterPageTarget.class, xDrawPage );
194 xMasterPageTarget.setMasterPage( xMasterPage );
197 // __________ presentation pages __________
199 /** test if a Presentation Document is supported.
200 This is important, because only presentation documents
201 have notes and handout pages
203 static public boolean isImpressDocument( XComponent xComponent )
205 XServiceInfo xInfo = (XServiceInfo)UnoRuntime.queryInterface(
206 XServiceInfo.class, xComponent );
207 return xInfo.supportsService( "com.sun.star.presentation.PresentationDocument" );
210 /** in impress documents each normal draw page has a corresponding notes page
212 static public XDrawPage getNotesPage( XDrawPage xDrawPage )
214 XPresentationPage aPresentationPage =
215 (XPresentationPage)UnoRuntime.queryInterface(
216 XPresentationPage.class, xDrawPage );
217 return aPresentationPage.getNotesPage();
220 /** in impress each documents has one handout page
222 static public XDrawPage getHandoutMasterPage( XComponent xComponent )
224 XHandoutMasterSupplier aHandoutMasterSupplier =
225 (XHandoutMasterSupplier)UnoRuntime.queryInterface(
226 XHandoutMasterSupplier.class, xComponent );
227 return aHandoutMasterSupplier.getHandoutMasterPage();