1 /*************************************************************************
2  *
3  *  The Contents of this file are made available subject to the terms of
4  *  the BSD license.
5  *
6  *  Copyright 2000, 2010 Oracle and/or its affiliates.
7  *  All rights reserved.
8  *
9  *  Redistribution and use in source and binary forms, with or without
10  *  modification, are permitted provided that the following conditions
11  *  are met:
12  *  1. Redistributions of source code must retain the above copyright
13  *     notice, this list of conditions and the following disclaimer.
14  *  2. Redistributions in binary form must reproduce the above copyright
15  *     notice, this list of conditions and the following disclaimer in the
16  *     documentation and/or other materials provided with the distribution.
17  *  3. Neither the name of Sun Microsystems, Inc. nor the names of its
18  *     contributors may be used to endorse or promote products derived
19  *     from this software without specific prior written permission.
20  *
21  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
28  *  OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
29  *  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
30  *  TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
31  *  USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  *
33  *************************************************************************/
34 
35 // __________ Imports __________
36 
37 import com.sun.star.uno.UnoRuntime;
38 import com.sun.star.lang.XComponent;
39 import com.sun.star.lang.XSingleServiceFactory;
40 
41 import com.sun.star.awt.Point;
42 import com.sun.star.awt.Size;
43 
44 import com.sun.star.beans.PropertyValue;
45 import com.sun.star.beans.XPropertySet;
46 
47 import com.sun.star.container.XNamed;
48 import com.sun.star.container.XNameContainer;
49 import com.sun.star.container.XIndexContainer;
50 
51 import com.sun.star.drawing.XShape;
52 import com.sun.star.drawing.XShapes;
53 import com.sun.star.drawing.XDrawPage;
54 import com.sun.star.drawing.XDrawPages;
55 import com.sun.star.drawing.XDrawPagesSupplier;
56 
57 import com.sun.star.presentation.XPresentation;
58 import com.sun.star.presentation.XPresentationSupplier;
59 import com.sun.star.presentation.XCustomPresentationSupplier;
60 
61 
62 // __________ Implementation __________
63 
64 /** presentation demo
65     @author Sven Jacobi
66  */
67 
68 // This demo will demonstrate how to create a CustomShow
69 
70 // The first parameter describes the connection that is to use. If there is no parameter
71 // "uno:socket,host=localhost,port=2083;urp;StarOffice.ServiceManager" is used.
72 
73 
74 public class CustomShowDemo
75 {
76     public static void main( String args[] )
77     {
78 		XComponent xDrawDoc = null;
79 		try
80 		{
81             // get the remote office context of a running office (a new office
82             // instance is started if necessary)
83 			com.sun.star.uno.XComponentContext xOfficeContext = Helper.connect();
84 
85 			// suppress Presentation Autopilot when opening the document
86 			// properties are the same as described for
87 			// com.sun.star.document.MediaDescriptor
88 			PropertyValue[] pPropValues = new PropertyValue[ 1 ];
89 			pPropValues[ 0 ] = new PropertyValue();
90 			pPropValues[ 0 ].Name = "Silent";
91 			pPropValues[ 0 ].Value = new Boolean( true );
92 
93 			xDrawDoc = Helper.createDocument( xOfficeContext,
94 				"private:factory/simpress", "_blank", 0, pPropValues );
95 
96 			XDrawPagesSupplier xDrawPagesSupplier =
97 				(XDrawPagesSupplier)UnoRuntime.queryInterface(
98 					XDrawPagesSupplier.class, xDrawDoc );
99 			XDrawPages xDrawPages = xDrawPagesSupplier.getDrawPages();
100 
101 			// take care that this document has ten pages
102 		    while ( xDrawPages.getCount() < 10 )
103 				xDrawPages.insertNewByIndex( 0 );
104 
105 			// assign a name to each page and also insert a text object including the name of the page
106 			String aNameArray[] = { "Introduction", "page one", "page two", "page three", "page four",
107 									"page five", "page six", "page seven", "page eight", "page nine" };
108 			int i;
109 			for ( i = 0; i < 10; i++ )
110 			{
111 				XDrawPage xDrawPage = (XDrawPage)UnoRuntime.queryInterface(
112 					XDrawPage.class, xDrawPages.getByIndex( i ));
113 				XNamed xPageName = (XNamed)UnoRuntime.queryInterface(
114 					XNamed.class, xDrawPage );
115 				xPageName.setName( aNameArray[ i ] );
116 
117 				// now we will create and insert the text object
118 				XShape xTextObj = ShapeHelper.createShape( xDrawDoc, new Point( 10000, 9000 ),
119 					new Size( 10000, 5000 ),
120 						"com.sun.star.drawing.TextShape" );
121 				XShapes xShapes = (XShapes)
122 						UnoRuntime.queryInterface( XShapes.class, xDrawPage );
123 				xShapes.add( xTextObj );
124 				ShapeHelper.addPortion( xTextObj, aNameArray[ i ], true );
125 			}
126 
127 			/* create two custom shows, one will play slide 6 to 10 and is named "ShortVersion"
128 			   the other one will play slide 2 til 10 and is named "LongVersion" */
129 			XCustomPresentationSupplier xCustPresSupplier = (XCustomPresentationSupplier)
130 				UnoRuntime.queryInterface( XCustomPresentationSupplier.class, xDrawDoc );
131 
132 			/* the following container is a container for further container
133 			   which concludes the list of pages that are to play within a custom show */
134 			XNameContainer xNameContainer = xCustPresSupplier.getCustomPresentations();
135 			XSingleServiceFactory xFactory = (XSingleServiceFactory)
136 				UnoRuntime.queryInterface( XSingleServiceFactory.class, xNameContainer );
137 
138 			Object			xObj;
139 			XIndexContainer xContainer;
140 
141 			/* instanciate an IndexContainer that will take
142 			   a list of draw pages for the first custom show */
143 			xObj = xFactory.createInstance();
144 		    xContainer = (XIndexContainer)UnoRuntime.queryInterface( XIndexContainer.class, xObj );
145 			for ( i = 5; i < 10; i++ )
146 				xContainer.insertByIndex( xContainer.getCount(), xDrawPages.getByIndex( i ) );
147 			xNameContainer.insertByName( "ShortVersion", xContainer );
148 
149 			/* instanciate an IndexContainer that will take
150 			   a list of draw page for the second custom show */
151 			xObj = xFactory.createInstance();
152 		    xContainer = (XIndexContainer)UnoRuntime.queryInterface( XIndexContainer.class, xObj );
153 			for ( i = 1; i < 10; i++ )
154 				xContainer.insertByIndex( xContainer.getCount(), xDrawPages.getByIndex( i ) );
155 			xNameContainer.insertByName( "LongVersion", xContainer );
156 
157 			/* which custom show is to use
158 			   can been set in the presentation settings */
159 
160 			XPresentationSupplier xPresSupplier = (XPresentationSupplier)
161 				UnoRuntime.queryInterface( XPresentationSupplier.class, xDrawDoc );
162 			XPresentation xPresentation = xPresSupplier.getPresentation();
163 			XPropertySet xPresPropSet = (XPropertySet)
164 				UnoRuntime.queryInterface( XPropertySet.class, xPresentation );
165 			xPresPropSet.setPropertyValue( "CustomShow", "ShortVersion" );
166 		}
167 		catch( Exception ex )
168 		{
169             System.out.println( ex );
170 		}
171 		System.exit( 0 );
172     }
173 }
174