xref: /AOO41X/main/odk/examples/DevelopersGuide/Drawing/CustomShowDemo.java (revision 34dd1e2512dbacb6a9a7e4c7f17b9296daa8eff3)
1*34dd1e25SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*34dd1e25SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*34dd1e25SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*34dd1e25SAndrew Rist  * distributed with this work for additional information
6*34dd1e25SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*34dd1e25SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*34dd1e25SAndrew Rist  * "License"); you may not use this file except in compliance
9*34dd1e25SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*34dd1e25SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*34dd1e25SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*34dd1e25SAndrew Rist  * software distributed under the License is distributed on an
15*34dd1e25SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*34dd1e25SAndrew Rist  * KIND, either express or implied.  See the License for the
17*34dd1e25SAndrew Rist  * specific language governing permissions and limitations
18*34dd1e25SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*34dd1e25SAndrew Rist  *************************************************************/
21*34dd1e25SAndrew Rist 
22*34dd1e25SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // __________ Imports __________
25cdf0e10cSrcweir 
26cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime;
27cdf0e10cSrcweir import com.sun.star.lang.XComponent;
28cdf0e10cSrcweir import com.sun.star.lang.XSingleServiceFactory;
29cdf0e10cSrcweir 
30cdf0e10cSrcweir import com.sun.star.awt.Point;
31cdf0e10cSrcweir import com.sun.star.awt.Size;
32cdf0e10cSrcweir 
33cdf0e10cSrcweir import com.sun.star.beans.PropertyValue;
34cdf0e10cSrcweir import com.sun.star.beans.XPropertySet;
35cdf0e10cSrcweir 
36cdf0e10cSrcweir import com.sun.star.container.XNamed;
37cdf0e10cSrcweir import com.sun.star.container.XNameContainer;
38cdf0e10cSrcweir import com.sun.star.container.XIndexContainer;
39cdf0e10cSrcweir 
40cdf0e10cSrcweir import com.sun.star.drawing.XShape;
41cdf0e10cSrcweir import com.sun.star.drawing.XShapes;
42cdf0e10cSrcweir import com.sun.star.drawing.XDrawPage;
43cdf0e10cSrcweir import com.sun.star.drawing.XDrawPages;
44cdf0e10cSrcweir import com.sun.star.drawing.XDrawPagesSupplier;
45cdf0e10cSrcweir 
46cdf0e10cSrcweir import com.sun.star.presentation.XPresentation;
47cdf0e10cSrcweir import com.sun.star.presentation.XPresentationSupplier;
48cdf0e10cSrcweir import com.sun.star.presentation.XCustomPresentationSupplier;
49cdf0e10cSrcweir 
50cdf0e10cSrcweir 
51cdf0e10cSrcweir // __________ Implementation __________
52cdf0e10cSrcweir 
53cdf0e10cSrcweir /** presentation demo
54cdf0e10cSrcweir     @author Sven Jacobi
55cdf0e10cSrcweir  */
56cdf0e10cSrcweir 
57cdf0e10cSrcweir // This demo will demonstrate how to create a CustomShow
58cdf0e10cSrcweir 
59cdf0e10cSrcweir // The first parameter describes the connection that is to use. If there is no parameter
60cdf0e10cSrcweir // "uno:socket,host=localhost,port=2083;urp;StarOffice.ServiceManager" is used.
61cdf0e10cSrcweir 
62cdf0e10cSrcweir 
63cdf0e10cSrcweir public class CustomShowDemo
64cdf0e10cSrcweir {
main( String args[] )65cdf0e10cSrcweir     public static void main( String args[] )
66cdf0e10cSrcweir     {
67cdf0e10cSrcweir 		XComponent xDrawDoc = null;
68cdf0e10cSrcweir 		try
69cdf0e10cSrcweir 		{
70cdf0e10cSrcweir             // get the remote office context of a running office (a new office
71cdf0e10cSrcweir             // instance is started if necessary)
72cdf0e10cSrcweir 			com.sun.star.uno.XComponentContext xOfficeContext = Helper.connect();
73cdf0e10cSrcweir 
74cdf0e10cSrcweir 			// suppress Presentation Autopilot when opening the document
75cdf0e10cSrcweir 			// properties are the same as described for
76cdf0e10cSrcweir 			// com.sun.star.document.MediaDescriptor
77cdf0e10cSrcweir 			PropertyValue[] pPropValues = new PropertyValue[ 1 ];
78cdf0e10cSrcweir 			pPropValues[ 0 ] = new PropertyValue();
79cdf0e10cSrcweir 			pPropValues[ 0 ].Name = "Silent";
80cdf0e10cSrcweir 			pPropValues[ 0 ].Value = new Boolean( true );
81cdf0e10cSrcweir 
82cdf0e10cSrcweir 			xDrawDoc = Helper.createDocument( xOfficeContext,
83cdf0e10cSrcweir 				"private:factory/simpress", "_blank", 0, pPropValues );
84cdf0e10cSrcweir 
85cdf0e10cSrcweir 			XDrawPagesSupplier xDrawPagesSupplier =
86cdf0e10cSrcweir 				(XDrawPagesSupplier)UnoRuntime.queryInterface(
87cdf0e10cSrcweir 					XDrawPagesSupplier.class, xDrawDoc );
88cdf0e10cSrcweir 			XDrawPages xDrawPages = xDrawPagesSupplier.getDrawPages();
89cdf0e10cSrcweir 
90cdf0e10cSrcweir 			// take care that this document has ten pages
91cdf0e10cSrcweir 		    while ( xDrawPages.getCount() < 10 )
92cdf0e10cSrcweir 				xDrawPages.insertNewByIndex( 0 );
93cdf0e10cSrcweir 
94cdf0e10cSrcweir 			// assign a name to each page and also insert a text object including the name of the page
95cdf0e10cSrcweir 			String aNameArray[] = { "Introduction", "page one", "page two", "page three", "page four",
96cdf0e10cSrcweir 									"page five", "page six", "page seven", "page eight", "page nine" };
97cdf0e10cSrcweir 			int i;
98cdf0e10cSrcweir 			for ( i = 0; i < 10; i++ )
99cdf0e10cSrcweir 			{
100cdf0e10cSrcweir 				XDrawPage xDrawPage = (XDrawPage)UnoRuntime.queryInterface(
101cdf0e10cSrcweir 					XDrawPage.class, xDrawPages.getByIndex( i ));
102cdf0e10cSrcweir 				XNamed xPageName = (XNamed)UnoRuntime.queryInterface(
103cdf0e10cSrcweir 					XNamed.class, xDrawPage );
104cdf0e10cSrcweir 				xPageName.setName( aNameArray[ i ] );
105cdf0e10cSrcweir 
106cdf0e10cSrcweir 				// now we will create and insert the text object
107cdf0e10cSrcweir 				XShape xTextObj = ShapeHelper.createShape( xDrawDoc, new Point( 10000, 9000 ),
108cdf0e10cSrcweir 					new Size( 10000, 5000 ),
109cdf0e10cSrcweir 						"com.sun.star.drawing.TextShape" );
110cdf0e10cSrcweir 				XShapes xShapes = (XShapes)
111cdf0e10cSrcweir 						UnoRuntime.queryInterface( XShapes.class, xDrawPage );
112cdf0e10cSrcweir 				xShapes.add( xTextObj );
113cdf0e10cSrcweir 				ShapeHelper.addPortion( xTextObj, aNameArray[ i ], true );
114cdf0e10cSrcweir 			}
115cdf0e10cSrcweir 
116cdf0e10cSrcweir 			/* create two custom shows, one will play slide 6 to 10 and is named "ShortVersion"
117cdf0e10cSrcweir 			   the other one will play slide 2 til 10 and is named "LongVersion" */
118cdf0e10cSrcweir 			XCustomPresentationSupplier xCustPresSupplier = (XCustomPresentationSupplier)
119cdf0e10cSrcweir 				UnoRuntime.queryInterface( XCustomPresentationSupplier.class, xDrawDoc );
120cdf0e10cSrcweir 
121cdf0e10cSrcweir 			/* the following container is a container for further container
122cdf0e10cSrcweir 			   which concludes the list of pages that are to play within a custom show */
123cdf0e10cSrcweir 			XNameContainer xNameContainer = xCustPresSupplier.getCustomPresentations();
124cdf0e10cSrcweir 			XSingleServiceFactory xFactory = (XSingleServiceFactory)
125cdf0e10cSrcweir 				UnoRuntime.queryInterface( XSingleServiceFactory.class, xNameContainer );
126cdf0e10cSrcweir 
127cdf0e10cSrcweir 			Object			xObj;
128cdf0e10cSrcweir 			XIndexContainer xContainer;
129cdf0e10cSrcweir 
130cdf0e10cSrcweir 			/* instanciate an IndexContainer that will take
131cdf0e10cSrcweir 			   a list of draw pages for the first custom show */
132cdf0e10cSrcweir 			xObj = xFactory.createInstance();
133cdf0e10cSrcweir 		    xContainer = (XIndexContainer)UnoRuntime.queryInterface( XIndexContainer.class, xObj );
134cdf0e10cSrcweir 			for ( i = 5; i < 10; i++ )
135cdf0e10cSrcweir 				xContainer.insertByIndex( xContainer.getCount(), xDrawPages.getByIndex( i ) );
136cdf0e10cSrcweir 			xNameContainer.insertByName( "ShortVersion", xContainer );
137cdf0e10cSrcweir 
138cdf0e10cSrcweir 			/* instanciate an IndexContainer that will take
139cdf0e10cSrcweir 			   a list of draw page for the second custom show */
140cdf0e10cSrcweir 			xObj = xFactory.createInstance();
141cdf0e10cSrcweir 		    xContainer = (XIndexContainer)UnoRuntime.queryInterface( XIndexContainer.class, xObj );
142cdf0e10cSrcweir 			for ( i = 1; i < 10; i++ )
143cdf0e10cSrcweir 				xContainer.insertByIndex( xContainer.getCount(), xDrawPages.getByIndex( i ) );
144cdf0e10cSrcweir 			xNameContainer.insertByName( "LongVersion", xContainer );
145cdf0e10cSrcweir 
146cdf0e10cSrcweir 			/* which custom show is to use
147cdf0e10cSrcweir 			   can been set in the presentation settings */
148cdf0e10cSrcweir 
149cdf0e10cSrcweir 			XPresentationSupplier xPresSupplier = (XPresentationSupplier)
150cdf0e10cSrcweir 				UnoRuntime.queryInterface( XPresentationSupplier.class, xDrawDoc );
151cdf0e10cSrcweir 			XPresentation xPresentation = xPresSupplier.getPresentation();
152cdf0e10cSrcweir 			XPropertySet xPresPropSet = (XPropertySet)
153cdf0e10cSrcweir 				UnoRuntime.queryInterface( XPropertySet.class, xPresentation );
154cdf0e10cSrcweir 			xPresPropSet.setPropertyValue( "CustomShow", "ShortVersion" );
155cdf0e10cSrcweir 		}
156cdf0e10cSrcweir 		catch( Exception ex )
157cdf0e10cSrcweir 		{
158cdf0e10cSrcweir             System.out.println( ex );
159cdf0e10cSrcweir 		}
160cdf0e10cSrcweir 		System.exit( 0 );
161cdf0e10cSrcweir     }
162cdf0e10cSrcweir }
163