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