1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  *  The Contents of this file are made available subject to the terms of
4*cdf0e10cSrcweir  *  the BSD license.
5*cdf0e10cSrcweir  *
6*cdf0e10cSrcweir  *  Copyright 2000, 2010 Oracle and/or its affiliates.
7*cdf0e10cSrcweir  *  All rights reserved.
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  *  Redistribution and use in source and binary forms, with or without
10*cdf0e10cSrcweir  *  modification, are permitted provided that the following conditions
11*cdf0e10cSrcweir  *  are met:
12*cdf0e10cSrcweir  *  1. Redistributions of source code must retain the above copyright
13*cdf0e10cSrcweir  *     notice, this list of conditions and the following disclaimer.
14*cdf0e10cSrcweir  *  2. Redistributions in binary form must reproduce the above copyright
15*cdf0e10cSrcweir  *     notice, this list of conditions and the following disclaimer in the
16*cdf0e10cSrcweir  *     documentation and/or other materials provided with the distribution.
17*cdf0e10cSrcweir  *  3. Neither the name of Sun Microsystems, Inc. nor the names of its
18*cdf0e10cSrcweir  *     contributors may be used to endorse or promote products derived
19*cdf0e10cSrcweir  *     from this software without specific prior written permission.
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22*cdf0e10cSrcweir  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23*cdf0e10cSrcweir  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24*cdf0e10cSrcweir  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25*cdf0e10cSrcweir  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26*cdf0e10cSrcweir  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27*cdf0e10cSrcweir  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
28*cdf0e10cSrcweir  *  OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
29*cdf0e10cSrcweir  *  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
30*cdf0e10cSrcweir  *  TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
31*cdf0e10cSrcweir  *  USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32*cdf0e10cSrcweir  *
33*cdf0e10cSrcweir  *************************************************************************/
34*cdf0e10cSrcweir 
35*cdf0e10cSrcweir // __________ Imports __________
36*cdf0e10cSrcweir 
37*cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime;
38*cdf0e10cSrcweir import com.sun.star.lang.XComponent;
39*cdf0e10cSrcweir import com.sun.star.lang.XServiceInfo;
40*cdf0e10cSrcweir 
41*cdf0e10cSrcweir import com.sun.star.awt.Point;
42*cdf0e10cSrcweir import com.sun.star.awt.Size;
43*cdf0e10cSrcweir 
44*cdf0e10cSrcweir import com.sun.star.beans.PropertyValue;
45*cdf0e10cSrcweir import com.sun.star.beans.XPropertySet;
46*cdf0e10cSrcweir 
47*cdf0e10cSrcweir import com.sun.star.container.XNamed;
48*cdf0e10cSrcweir 
49*cdf0e10cSrcweir import com.sun.star.drawing.XShape;
50*cdf0e10cSrcweir import com.sun.star.drawing.XShapes;
51*cdf0e10cSrcweir import com.sun.star.drawing.XDrawPage;
52*cdf0e10cSrcweir 
53*cdf0e10cSrcweir import com.sun.star.presentation.XPresentation;
54*cdf0e10cSrcweir import com.sun.star.presentation.XPresentationSupplier;
55*cdf0e10cSrcweir 
56*cdf0e10cSrcweir 
57*cdf0e10cSrcweir 
58*cdf0e10cSrcweir // __________ Implementation __________
59*cdf0e10cSrcweir 
60*cdf0e10cSrcweir /** presentation demo
61*cdf0e10cSrcweir     @author Sven Jacobi
62*cdf0e10cSrcweir  */
63*cdf0e10cSrcweir 
64*cdf0e10cSrcweir // This demo will demonstrate how to create a presentation using the Office API
65*cdf0e10cSrcweir 
66*cdf0e10cSrcweir // The first parameter describes the connection that is to use. If there is no parameter
67*cdf0e10cSrcweir // "uno:socket,host=localhost,port=2083;urp;StarOffice.ServiceManager" is used.
68*cdf0e10cSrcweir 
69*cdf0e10cSrcweir 
70*cdf0e10cSrcweir public class PresentationDemo
71*cdf0e10cSrcweir {
72*cdf0e10cSrcweir     public static void main( String args[] )
73*cdf0e10cSrcweir     {
74*cdf0e10cSrcweir 		XComponent xDrawDoc = null;
75*cdf0e10cSrcweir 		try
76*cdf0e10cSrcweir 		{
77*cdf0e10cSrcweir             // get the remote office context of a running office (a new office
78*cdf0e10cSrcweir             // instance is started if necessary)
79*cdf0e10cSrcweir 			com.sun.star.uno.XComponentContext xOfficeContext = Helper.connect();
80*cdf0e10cSrcweir 
81*cdf0e10cSrcweir 			// suppress Presentation Autopilot when opening the document
82*cdf0e10cSrcweir 			// properties are the same as described for
83*cdf0e10cSrcweir 			// com.sun.star.document.MediaDescriptor
84*cdf0e10cSrcweir 			PropertyValue[] pPropValues = new PropertyValue[ 1 ];
85*cdf0e10cSrcweir 			pPropValues[ 0 ] = new PropertyValue();
86*cdf0e10cSrcweir 			pPropValues[ 0 ].Name = "Silent";
87*cdf0e10cSrcweir 			pPropValues[ 0 ].Value = new Boolean( true );
88*cdf0e10cSrcweir 
89*cdf0e10cSrcweir 			xDrawDoc = Helper.createDocument( xOfficeContext,
90*cdf0e10cSrcweir 				"private:factory/simpress", "_blank", 0, pPropValues );
91*cdf0e10cSrcweir 
92*cdf0e10cSrcweir 
93*cdf0e10cSrcweir 			XDrawPage	 xPage;
94*cdf0e10cSrcweir 			XShapes		 xShapes;
95*cdf0e10cSrcweir 			XPropertySet xShapePropSet;
96*cdf0e10cSrcweir 
97*cdf0e10cSrcweir 			// create pages, so that three are available
98*cdf0e10cSrcweir 		    while ( PageHelper.getDrawPageCount( xDrawDoc ) < 3 )
99*cdf0e10cSrcweir 				PageHelper.insertNewDrawPageByIndex( xDrawDoc, 0 );
100*cdf0e10cSrcweir 
101*cdf0e10cSrcweir 
102*cdf0e10cSrcweir 			// set the slide transition for the first page
103*cdf0e10cSrcweir 			xPage = PageHelper.getDrawPageByIndex( xDrawDoc, 0 );
104*cdf0e10cSrcweir 			xShapes = (XShapes)
105*cdf0e10cSrcweir 				UnoRuntime.queryInterface( XShapes.class, xPage );
106*cdf0e10cSrcweir 			// set slide transition effect
107*cdf0e10cSrcweir 			setSlideTransition( xPage,
108*cdf0e10cSrcweir 				com.sun.star.presentation.FadeEffect.FADE_FROM_RIGHT,
109*cdf0e10cSrcweir 					com.sun.star.presentation.AnimationSpeed.FAST,
110*cdf0e10cSrcweir 						1, 0 ); // automatic object and slide transition
111*cdf0e10cSrcweir 
112*cdf0e10cSrcweir 			// create a rectangle that is placed on the top left of the page
113*cdf0e10cSrcweir 			xShapePropSet = ShapeHelper.createAndInsertShape( xDrawDoc,
114*cdf0e10cSrcweir 				xShapes,new Point( 1000, 1000 ), new Size( 5000, 5000 ),
115*cdf0e10cSrcweir 					"com.sun.star.drawing.RectangleShape" );
116*cdf0e10cSrcweir 			xShapePropSet.setPropertyValue("Effect",
117*cdf0e10cSrcweir                 com.sun.star.presentation.AnimationEffect.WAVYLINE_FROM_BOTTOM );
118*cdf0e10cSrcweir 
119*cdf0e10cSrcweir 			/* the following three properties provokes that the shape is dimmed
120*cdf0e10cSrcweir 			   to red
121*cdf0e10cSrcweir 			   after the animation has been finished */
122*cdf0e10cSrcweir 			xShapePropSet.setPropertyValue( "DimHide", new Boolean( false ) );
123*cdf0e10cSrcweir 			xShapePropSet.setPropertyValue( "DimPrevious", new Boolean( true ) );
124*cdf0e10cSrcweir 			xShapePropSet.setPropertyValue( "DimColor", new Integer( 0xff0000 ) );
125*cdf0e10cSrcweir 
126*cdf0e10cSrcweir 
127*cdf0e10cSrcweir 			// set the slide transition for the second page
128*cdf0e10cSrcweir 			xPage = PageHelper.getDrawPageByIndex( xDrawDoc, 1 );
129*cdf0e10cSrcweir 			xShapes = (XShapes)
130*cdf0e10cSrcweir 				UnoRuntime.queryInterface( XShapes.class, xPage );
131*cdf0e10cSrcweir 			setSlideTransition( xPage,
132*cdf0e10cSrcweir 				com.sun.star.presentation.FadeEffect.FADE_FROM_RIGHT,
133*cdf0e10cSrcweir 					com.sun.star.presentation.AnimationSpeed.SLOW,
134*cdf0e10cSrcweir 						1, 0 ); // automatic object and slide transition
135*cdf0e10cSrcweir 
136*cdf0e10cSrcweir 			// create an ellipse that is placed on the bottom right of second page
137*cdf0e10cSrcweir 			xShapePropSet = ShapeHelper.createAndInsertShape( xDrawDoc,
138*cdf0e10cSrcweir 				xShapes, new Point( 21000, 15000 ), new Size( 5000, 5000 ),
139*cdf0e10cSrcweir 					"com.sun.star.drawing.EllipseShape" );
140*cdf0e10cSrcweir 			xShapePropSet.setPropertyValue(
141*cdf0e10cSrcweir 				"Effect", com.sun.star.presentation.AnimationEffect.HIDE );
142*cdf0e10cSrcweir 
143*cdf0e10cSrcweir 
144*cdf0e10cSrcweir 			// create two objects for the third page
145*cdf0e10cSrcweir 			// clicking the first object lets the presentation jump
146*cdf0e10cSrcweir 			// to page one by using ClickAction.FIRSTPAGE,
147*cdf0e10cSrcweir 			// the second object lets the presentation jump to page two
148*cdf0e10cSrcweir 			// by using a ClickAction.BOOKMARK;
149*cdf0e10cSrcweir 			xPage = PageHelper.getDrawPageByIndex( xDrawDoc, 2 );
150*cdf0e10cSrcweir 			xShapes = (XShapes)
151*cdf0e10cSrcweir 				UnoRuntime.queryInterface( XShapes.class, xPage );
152*cdf0e10cSrcweir 			setSlideTransition( xPage,
153*cdf0e10cSrcweir 				com.sun.star.presentation.FadeEffect.ROLL_FROM_LEFT,
154*cdf0e10cSrcweir 					com.sun.star.presentation.AnimationSpeed.MEDIUM,
155*cdf0e10cSrcweir 						2, 0 );
156*cdf0e10cSrcweir 			XShape xShape = ShapeHelper.createShape( xDrawDoc,
157*cdf0e10cSrcweir 					new Point( 1000, 8000 ), new Size( 5000, 5000 ),
158*cdf0e10cSrcweir 					"com.sun.star.drawing.EllipseShape" );
159*cdf0e10cSrcweir 			xShapes.add( xShape );
160*cdf0e10cSrcweir 			ShapeHelper.addPortion( xShape, "click to go", false );
161*cdf0e10cSrcweir 			ShapeHelper.addPortion( xShape, "to first page", true );
162*cdf0e10cSrcweir 			xShapePropSet = (XPropertySet)
163*cdf0e10cSrcweir 				UnoRuntime.queryInterface( XPropertySet.class, xShape );
164*cdf0e10cSrcweir 			xShapePropSet.setPropertyValue("Effect",
165*cdf0e10cSrcweir                 com.sun.star.presentation.AnimationEffect.FADE_FROM_BOTTOM );
166*cdf0e10cSrcweir 			xShapePropSet.setPropertyValue(
167*cdf0e10cSrcweir 				"OnClick", com.sun.star.presentation.ClickAction.FIRSTPAGE );
168*cdf0e10cSrcweir 
169*cdf0e10cSrcweir 
170*cdf0e10cSrcweir 			xShape = ShapeHelper.createShape( xDrawDoc,
171*cdf0e10cSrcweir 				new Point( 22000, 8000 ), new Size( 5000, 5000 ),
172*cdf0e10cSrcweir 					"com.sun.star.drawing.RectangleShape" );
173*cdf0e10cSrcweir 			xShapes.add( xShape );
174*cdf0e10cSrcweir 			ShapeHelper.addPortion( xShape, "click to go", false );
175*cdf0e10cSrcweir 			ShapeHelper.addPortion( xShape, "to the second page", true );
176*cdf0e10cSrcweir 			xShapePropSet = (XPropertySet)
177*cdf0e10cSrcweir 				UnoRuntime.queryInterface( XPropertySet.class, xShape );
178*cdf0e10cSrcweir 			xShapePropSet.setPropertyValue("Effect",
179*cdf0e10cSrcweir                 com.sun.star.presentation.AnimationEffect.FADE_FROM_BOTTOM );
180*cdf0e10cSrcweir 
181*cdf0e10cSrcweir 			xShapePropSet.setPropertyValue(
182*cdf0e10cSrcweir 				"OnClick", com.sun.star.presentation.ClickAction.BOOKMARK );
183*cdf0e10cSrcweir 			// set the name of page two, and use it with the bookmark action
184*cdf0e10cSrcweir 			XNamed xPageName = (XNamed)UnoRuntime.queryInterface(
185*cdf0e10cSrcweir 				XNamed.class, PageHelper.getDrawPageByIndex( xDrawDoc, 1 ) );
186*cdf0e10cSrcweir 			xPageName.setName( "page two" );
187*cdf0e10cSrcweir 			xShapePropSet.setPropertyValue(
188*cdf0e10cSrcweir 				"Bookmark", xPageName.getName() );
189*cdf0e10cSrcweir 
190*cdf0e10cSrcweir 
191*cdf0e10cSrcweir 			/* start an endless presentation which is displayed in
192*cdf0e10cSrcweir 			   full-screen mode and placed on top */
193*cdf0e10cSrcweir 
194*cdf0e10cSrcweir 			XPresentationSupplier xPresSupplier = (XPresentationSupplier)
195*cdf0e10cSrcweir 				UnoRuntime.queryInterface( XPresentationSupplier.class, xDrawDoc );
196*cdf0e10cSrcweir 			XPresentation xPresentation = xPresSupplier.getPresentation();
197*cdf0e10cSrcweir 			XPropertySet xPresPropSet = (XPropertySet)
198*cdf0e10cSrcweir 				UnoRuntime.queryInterface( XPropertySet.class, xPresentation );
199*cdf0e10cSrcweir 			xPresPropSet.setPropertyValue( "IsEndless", new Boolean( true ) );
200*cdf0e10cSrcweir 			xPresPropSet.setPropertyValue( "IsAlwaysOnTop", new Boolean( true ) );
201*cdf0e10cSrcweir 			xPresPropSet.setPropertyValue( "Pause", new Integer( 0 ) );
202*cdf0e10cSrcweir 			xPresentation.start();
203*cdf0e10cSrcweir 		}
204*cdf0e10cSrcweir 		catch( Exception ex )
205*cdf0e10cSrcweir 		{
206*cdf0e10cSrcweir             System.out.println( ex );
207*cdf0e10cSrcweir 		}
208*cdf0e10cSrcweir 		System.exit( 0 );
209*cdf0e10cSrcweir     }
210*cdf0e10cSrcweir 
211*cdf0e10cSrcweir 	// this simple method applies the slide transition to a page
212*cdf0e10cSrcweir 	public static void setSlideTransition( XDrawPage xPage,
213*cdf0e10cSrcweir 		com.sun.star.presentation.FadeEffect eEffect,
214*cdf0e10cSrcweir 			com.sun.star.presentation.AnimationSpeed eSpeed,
215*cdf0e10cSrcweir 			int nChange,
216*cdf0e10cSrcweir 				int nDuration )
217*cdf0e10cSrcweir 	{
218*cdf0e10cSrcweir 		// the following test is only sensible if you do not exactly know
219*cdf0e10cSrcweir 		// what type of page xPage is, for this purpose it can been tested
220*cdf0e10cSrcweir 		// if the com.sun.star.presentation.DrawPage service is supported
221*cdf0e10cSrcweir 		XServiceInfo xInfo = (XServiceInfo)UnoRuntime.queryInterface(
222*cdf0e10cSrcweir 				XServiceInfo.class, xPage );
223*cdf0e10cSrcweir 		if ( xInfo.supportsService( "com.sun.star.presentation.DrawPage" ) == true )
224*cdf0e10cSrcweir 		{
225*cdf0e10cSrcweir 			try
226*cdf0e10cSrcweir 			{
227*cdf0e10cSrcweir 				XPropertySet xPropSet = (XPropertySet)
228*cdf0e10cSrcweir 					UnoRuntime.queryInterface( XPropertySet.class, xPage );
229*cdf0e10cSrcweir 				xPropSet.setPropertyValue( "Effect",   eEffect );
230*cdf0e10cSrcweir 				xPropSet.setPropertyValue( "Speed",    eSpeed );
231*cdf0e10cSrcweir 				xPropSet.setPropertyValue( "Change",   new Integer( nChange ) );
232*cdf0e10cSrcweir 				xPropSet.setPropertyValue( "Duration", new Integer( nDuration ) );
233*cdf0e10cSrcweir 			}
234*cdf0e10cSrcweir 			catch( Exception ex )
235*cdf0e10cSrcweir 			{
236*cdf0e10cSrcweir 			}
237*cdf0e10cSrcweir 		}
238*cdf0e10cSrcweir 	}
239*cdf0e10cSrcweir }
240