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