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