merge the formfield patch from ooo-build
[ooovba.git] / odk / examples / DevelopersGuide / Drawing / CustomShowDemo.java
blobde1a7afea8cd525b9e7c34403fc6df20473379e6
1 /*************************************************************************
3 * $RCSfile: CustomShowDemo.java,v $
5 * $Revision: 1.5 $
7 * last change: $Author: rt $ $Date: 2005-01-31 16:21:33 $
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.XSingleServiceFactory;
47 import com.sun.star.awt.Point;
48 import com.sun.star.awt.Size;
50 import com.sun.star.beans.PropertyValue;
51 import com.sun.star.beans.XPropertySet;
53 import com.sun.star.container.XNamed;
54 import com.sun.star.container.XNameContainer;
55 import com.sun.star.container.XIndexContainer;
57 import com.sun.star.drawing.XShape;
58 import com.sun.star.drawing.XShapes;
59 import com.sun.star.drawing.XDrawPage;
60 import com.sun.star.drawing.XDrawPages;
61 import com.sun.star.drawing.XDrawPagesSupplier;
63 import com.sun.star.presentation.XPresentation;
64 import com.sun.star.presentation.XPresentationSupplier;
65 import com.sun.star.presentation.XCustomPresentationSupplier;
68 // __________ Implementation __________
70 /** presentation demo
71 @author Sven Jacobi
74 // This demo will demonstrate how to create a CustomShow
76 // The first parameter describes the connection that is to use. If there is no parameter
77 // "uno:socket,host=localhost,port=2083;urp;StarOffice.ServiceManager" is used.
80 public class CustomShowDemo
82 public static void main( String args[] )
84 XComponent xDrawDoc = null;
85 try
87 // get the remote office context of a running office (a new office
88 // instance is started if necessary)
89 com.sun.star.uno.XComponentContext xOfficeContext = Helper.connect();
91 // suppress Presentation Autopilot when opening the document
92 // properties are the same as described for
93 // com.sun.star.document.MediaDescriptor
94 PropertyValue[] pPropValues = new PropertyValue[ 1 ];
95 pPropValues[ 0 ] = new PropertyValue();
96 pPropValues[ 0 ].Name = "Silent";
97 pPropValues[ 0 ].Value = new Boolean( true );
99 xDrawDoc = Helper.createDocument( xOfficeContext,
100 "private:factory/simpress", "_blank", 0, pPropValues );
102 XDrawPagesSupplier xDrawPagesSupplier =
103 (XDrawPagesSupplier)UnoRuntime.queryInterface(
104 XDrawPagesSupplier.class, xDrawDoc );
105 XDrawPages xDrawPages = xDrawPagesSupplier.getDrawPages();
107 // take care that this document has ten pages
108 while ( xDrawPages.getCount() < 10 )
109 xDrawPages.insertNewByIndex( 0 );
111 // assign a name to each page and also insert a text object including the name of the page
112 String aNameArray[] = { "Introduction", "page one", "page two", "page three", "page four",
113 "page five", "page six", "page seven", "page eight", "page nine" };
114 int i;
115 for ( i = 0; i < 10; i++ )
117 XDrawPage xDrawPage = (XDrawPage)UnoRuntime.queryInterface(
118 XDrawPage.class, xDrawPages.getByIndex( i ));
119 XNamed xPageName = (XNamed)UnoRuntime.queryInterface(
120 XNamed.class, xDrawPage );
121 xPageName.setName( aNameArray[ i ] );
123 // now we will create and insert the text object
124 XShape xTextObj = ShapeHelper.createShape( xDrawDoc, new Point( 10000, 9000 ),
125 new Size( 10000, 5000 ),
126 "com.sun.star.drawing.TextShape" );
127 XShapes xShapes = (XShapes)
128 UnoRuntime.queryInterface( XShapes.class, xDrawPage );
129 xShapes.add( xTextObj );
130 ShapeHelper.addPortion( xTextObj, aNameArray[ i ], true );
133 /* create two custom shows, one will play slide 6 to 10 and is named "ShortVersion"
134 the other one will play slide 2 til 10 and is named "LongVersion" */
135 XCustomPresentationSupplier xCustPresSupplier = (XCustomPresentationSupplier)
136 UnoRuntime.queryInterface( XCustomPresentationSupplier.class, xDrawDoc );
138 /* the following container is a container for further container
139 which concludes the list of pages that are to play within a custom show */
140 XNameContainer xNameContainer = xCustPresSupplier.getCustomPresentations();
141 XSingleServiceFactory xFactory = (XSingleServiceFactory)
142 UnoRuntime.queryInterface( XSingleServiceFactory.class, xNameContainer );
144 Object xObj;
145 XIndexContainer xContainer;
147 /* instanciate an IndexContainer that will take
148 a list of draw pages for the first custom show */
149 xObj = xFactory.createInstance();
150 xContainer = (XIndexContainer)UnoRuntime.queryInterface( XIndexContainer.class, xObj );
151 for ( i = 5; i < 10; i++ )
152 xContainer.insertByIndex( xContainer.getCount(), xDrawPages.getByIndex( i ) );
153 xNameContainer.insertByName( "ShortVersion", xContainer );
155 /* instanciate an IndexContainer that will take
156 a list of draw page for the second custom show */
157 xObj = xFactory.createInstance();
158 xContainer = (XIndexContainer)UnoRuntime.queryInterface( XIndexContainer.class, xObj );
159 for ( i = 1; i < 10; i++ )
160 xContainer.insertByIndex( xContainer.getCount(), xDrawPages.getByIndex( i ) );
161 xNameContainer.insertByName( "LongVersion", xContainer );
163 /* which custom show is to use
164 can been set in the presentation settings */
166 XPresentationSupplier xPresSupplier = (XPresentationSupplier)
167 UnoRuntime.queryInterface( XPresentationSupplier.class, xDrawDoc );
168 XPresentation xPresentation = xPresSupplier.getPresentation();
169 XPropertySet xPresPropSet = (XPropertySet)
170 UnoRuntime.queryInterface( XPropertySet.class, xPresentation );
171 xPresPropSet.setPropertyValue( "CustomShow", "ShortVersion" );
173 catch( Exception ex )
175 System.out.println( ex );
177 System.exit( 0 );