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