xref: /trunk/main/odk/examples/DevelopersGuide/Drawing/PresentationDemo.java (revision 34dd1e2512dbacb6a9a7e4c7f17b9296daa8eff3)
1*34dd1e25SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*34dd1e25SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*34dd1e25SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*34dd1e25SAndrew Rist  * distributed with this work for additional information
6*34dd1e25SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*34dd1e25SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*34dd1e25SAndrew Rist  * "License"); you may not use this file except in compliance
9*34dd1e25SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*34dd1e25SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*34dd1e25SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*34dd1e25SAndrew Rist  * software distributed under the License is distributed on an
15*34dd1e25SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*34dd1e25SAndrew Rist  * KIND, either express or implied.  See the License for the
17*34dd1e25SAndrew Rist  * specific language governing permissions and limitations
18*34dd1e25SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*34dd1e25SAndrew Rist  *************************************************************/
21*34dd1e25SAndrew Rist 
22*34dd1e25SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // __________ Imports __________
25cdf0e10cSrcweir 
26cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime;
27cdf0e10cSrcweir import com.sun.star.lang.XComponent;
28cdf0e10cSrcweir import com.sun.star.lang.XServiceInfo;
29cdf0e10cSrcweir 
30cdf0e10cSrcweir import com.sun.star.awt.Point;
31cdf0e10cSrcweir import com.sun.star.awt.Size;
32cdf0e10cSrcweir 
33cdf0e10cSrcweir import com.sun.star.beans.PropertyValue;
34cdf0e10cSrcweir import com.sun.star.beans.XPropertySet;
35cdf0e10cSrcweir 
36cdf0e10cSrcweir import com.sun.star.container.XNamed;
37cdf0e10cSrcweir 
38cdf0e10cSrcweir import com.sun.star.drawing.XShape;
39cdf0e10cSrcweir import com.sun.star.drawing.XShapes;
40cdf0e10cSrcweir import com.sun.star.drawing.XDrawPage;
41cdf0e10cSrcweir 
42cdf0e10cSrcweir import com.sun.star.presentation.XPresentation;
43cdf0e10cSrcweir import com.sun.star.presentation.XPresentationSupplier;
44cdf0e10cSrcweir 
45cdf0e10cSrcweir 
46cdf0e10cSrcweir 
47cdf0e10cSrcweir // __________ Implementation __________
48cdf0e10cSrcweir 
49cdf0e10cSrcweir /** presentation demo
50cdf0e10cSrcweir     @author Sven Jacobi
51cdf0e10cSrcweir  */
52cdf0e10cSrcweir 
53cdf0e10cSrcweir // This demo will demonstrate how to create a presentation using the Office API
54cdf0e10cSrcweir 
55cdf0e10cSrcweir // The first parameter describes the connection that is to use. If there is no parameter
56cdf0e10cSrcweir // "uno:socket,host=localhost,port=2083;urp;StarOffice.ServiceManager" is used.
57cdf0e10cSrcweir 
58cdf0e10cSrcweir 
59cdf0e10cSrcweir public class PresentationDemo
60cdf0e10cSrcweir {
61cdf0e10cSrcweir     public static void main( String args[] )
62cdf0e10cSrcweir     {
63cdf0e10cSrcweir         XComponent xDrawDoc = null;
64cdf0e10cSrcweir         try
65cdf0e10cSrcweir         {
66cdf0e10cSrcweir             // get the remote office context of a running office (a new office
67cdf0e10cSrcweir             // instance is started if necessary)
68cdf0e10cSrcweir             com.sun.star.uno.XComponentContext xOfficeContext = Helper.connect();
69cdf0e10cSrcweir 
70cdf0e10cSrcweir             // suppress Presentation Autopilot when opening the document
71cdf0e10cSrcweir             // properties are the same as described for
72cdf0e10cSrcweir             // com.sun.star.document.MediaDescriptor
73cdf0e10cSrcweir             PropertyValue[] pPropValues = new PropertyValue[ 1 ];
74cdf0e10cSrcweir             pPropValues[ 0 ] = new PropertyValue();
75cdf0e10cSrcweir             pPropValues[ 0 ].Name = "Silent";
76cdf0e10cSrcweir             pPropValues[ 0 ].Value = new Boolean( true );
77cdf0e10cSrcweir 
78cdf0e10cSrcweir             xDrawDoc = Helper.createDocument( xOfficeContext,
79cdf0e10cSrcweir                 "private:factory/simpress", "_blank", 0, pPropValues );
80cdf0e10cSrcweir 
81cdf0e10cSrcweir 
82cdf0e10cSrcweir             XDrawPage    xPage;
83cdf0e10cSrcweir             XShapes      xShapes;
84cdf0e10cSrcweir             XPropertySet xShapePropSet;
85cdf0e10cSrcweir 
86cdf0e10cSrcweir             // create pages, so that three are available
87cdf0e10cSrcweir             while ( PageHelper.getDrawPageCount( xDrawDoc ) < 3 )
88cdf0e10cSrcweir                 PageHelper.insertNewDrawPageByIndex( xDrawDoc, 0 );
89cdf0e10cSrcweir 
90cdf0e10cSrcweir 
91cdf0e10cSrcweir             // set the slide transition for the first page
92cdf0e10cSrcweir             xPage = PageHelper.getDrawPageByIndex( xDrawDoc, 0 );
93cdf0e10cSrcweir             xShapes = (XShapes)
94cdf0e10cSrcweir                 UnoRuntime.queryInterface( XShapes.class, xPage );
95cdf0e10cSrcweir             // set slide transition effect
96cdf0e10cSrcweir             setSlideTransition( xPage,
97cdf0e10cSrcweir                 com.sun.star.presentation.FadeEffect.FADE_FROM_RIGHT,
98cdf0e10cSrcweir                     com.sun.star.presentation.AnimationSpeed.FAST,
99cdf0e10cSrcweir                         1, 0 ); // automatic object and slide transition
100cdf0e10cSrcweir 
101cdf0e10cSrcweir             // create a rectangle that is placed on the top left of the page
102cdf0e10cSrcweir             xShapePropSet = ShapeHelper.createAndInsertShape( xDrawDoc,
103cdf0e10cSrcweir                 xShapes,new Point( 1000, 1000 ), new Size( 5000, 5000 ),
104cdf0e10cSrcweir                     "com.sun.star.drawing.RectangleShape" );
105cdf0e10cSrcweir             xShapePropSet.setPropertyValue("Effect",
106cdf0e10cSrcweir                 com.sun.star.presentation.AnimationEffect.WAVYLINE_FROM_BOTTOM );
107cdf0e10cSrcweir 
108cdf0e10cSrcweir             /* the following three properties provokes that the shape is dimmed
109cdf0e10cSrcweir                to red
110cdf0e10cSrcweir                after the animation has been finished */
111cdf0e10cSrcweir             xShapePropSet.setPropertyValue( "DimHide", new Boolean( false ) );
112cdf0e10cSrcweir             xShapePropSet.setPropertyValue( "DimPrevious", new Boolean( true ) );
113cdf0e10cSrcweir             xShapePropSet.setPropertyValue( "DimColor", new Integer( 0xff0000 ) );
114cdf0e10cSrcweir 
115cdf0e10cSrcweir 
116cdf0e10cSrcweir             // set the slide transition for the second page
117cdf0e10cSrcweir             xPage = PageHelper.getDrawPageByIndex( xDrawDoc, 1 );
118cdf0e10cSrcweir             xShapes = (XShapes)
119cdf0e10cSrcweir                 UnoRuntime.queryInterface( XShapes.class, xPage );
120cdf0e10cSrcweir             setSlideTransition( xPage,
121cdf0e10cSrcweir                 com.sun.star.presentation.FadeEffect.FADE_FROM_RIGHT,
122cdf0e10cSrcweir                     com.sun.star.presentation.AnimationSpeed.SLOW,
123cdf0e10cSrcweir                         1, 0 ); // automatic object and slide transition
124cdf0e10cSrcweir 
125cdf0e10cSrcweir             // create an ellipse that is placed on the bottom right of second page
126cdf0e10cSrcweir             xShapePropSet = ShapeHelper.createAndInsertShape( xDrawDoc,
127cdf0e10cSrcweir                 xShapes, new Point( 21000, 15000 ), new Size( 5000, 5000 ),
128cdf0e10cSrcweir                     "com.sun.star.drawing.EllipseShape" );
129cdf0e10cSrcweir             xShapePropSet.setPropertyValue(
130cdf0e10cSrcweir                 "Effect", com.sun.star.presentation.AnimationEffect.HIDE );
131cdf0e10cSrcweir 
132cdf0e10cSrcweir 
133cdf0e10cSrcweir             // create two objects for the third page
134cdf0e10cSrcweir             // clicking the first object lets the presentation jump
135cdf0e10cSrcweir             // to page one by using ClickAction.FIRSTPAGE,
136cdf0e10cSrcweir             // the second object lets the presentation jump to page two
137cdf0e10cSrcweir             // by using a ClickAction.BOOKMARK;
138cdf0e10cSrcweir             xPage = PageHelper.getDrawPageByIndex( xDrawDoc, 2 );
139cdf0e10cSrcweir             xShapes = (XShapes)
140cdf0e10cSrcweir                 UnoRuntime.queryInterface( XShapes.class, xPage );
141cdf0e10cSrcweir             setSlideTransition( xPage,
142cdf0e10cSrcweir                 com.sun.star.presentation.FadeEffect.ROLL_FROM_LEFT,
143cdf0e10cSrcweir                     com.sun.star.presentation.AnimationSpeed.MEDIUM,
144cdf0e10cSrcweir                         2, 0 );
145cdf0e10cSrcweir             XShape xShape = ShapeHelper.createShape( xDrawDoc,
146cdf0e10cSrcweir                     new Point( 1000, 8000 ), new Size( 5000, 5000 ),
147cdf0e10cSrcweir                     "com.sun.star.drawing.EllipseShape" );
148cdf0e10cSrcweir             xShapes.add( xShape );
149cdf0e10cSrcweir             ShapeHelper.addPortion( xShape, "click to go", false );
150cdf0e10cSrcweir             ShapeHelper.addPortion( xShape, "to first page", true );
151cdf0e10cSrcweir             xShapePropSet = (XPropertySet)
152cdf0e10cSrcweir                 UnoRuntime.queryInterface( XPropertySet.class, xShape );
153cdf0e10cSrcweir             xShapePropSet.setPropertyValue("Effect",
154cdf0e10cSrcweir                 com.sun.star.presentation.AnimationEffect.FADE_FROM_BOTTOM );
155cdf0e10cSrcweir             xShapePropSet.setPropertyValue(
156cdf0e10cSrcweir                 "OnClick", com.sun.star.presentation.ClickAction.FIRSTPAGE );
157cdf0e10cSrcweir 
158cdf0e10cSrcweir 
159cdf0e10cSrcweir             xShape = ShapeHelper.createShape( xDrawDoc,
160cdf0e10cSrcweir                 new Point( 22000, 8000 ), new Size( 5000, 5000 ),
161cdf0e10cSrcweir                     "com.sun.star.drawing.RectangleShape" );
162cdf0e10cSrcweir             xShapes.add( xShape );
163cdf0e10cSrcweir             ShapeHelper.addPortion( xShape, "click to go", false );
164cdf0e10cSrcweir             ShapeHelper.addPortion( xShape, "to the second page", true );
165cdf0e10cSrcweir             xShapePropSet = (XPropertySet)
166cdf0e10cSrcweir                 UnoRuntime.queryInterface( XPropertySet.class, xShape );
167cdf0e10cSrcweir             xShapePropSet.setPropertyValue("Effect",
168cdf0e10cSrcweir                 com.sun.star.presentation.AnimationEffect.FADE_FROM_BOTTOM );
169cdf0e10cSrcweir 
170cdf0e10cSrcweir             xShapePropSet.setPropertyValue(
171cdf0e10cSrcweir                 "OnClick", com.sun.star.presentation.ClickAction.BOOKMARK );
172cdf0e10cSrcweir             // set the name of page two, and use it with the bookmark action
173cdf0e10cSrcweir             XNamed xPageName = (XNamed)UnoRuntime.queryInterface(
174cdf0e10cSrcweir                 XNamed.class, PageHelper.getDrawPageByIndex( xDrawDoc, 1 ) );
175cdf0e10cSrcweir             xPageName.setName( "page two" );
176cdf0e10cSrcweir             xShapePropSet.setPropertyValue(
177cdf0e10cSrcweir                 "Bookmark", xPageName.getName() );
178cdf0e10cSrcweir 
179cdf0e10cSrcweir 
180cdf0e10cSrcweir             /* start an endless presentation which is displayed in
181cdf0e10cSrcweir                full-screen mode and placed on top */
182cdf0e10cSrcweir 
183cdf0e10cSrcweir             XPresentationSupplier xPresSupplier = (XPresentationSupplier)
184cdf0e10cSrcweir                 UnoRuntime.queryInterface( XPresentationSupplier.class, xDrawDoc );
185cdf0e10cSrcweir             XPresentation xPresentation = xPresSupplier.getPresentation();
186cdf0e10cSrcweir             XPropertySet xPresPropSet = (XPropertySet)
187cdf0e10cSrcweir                 UnoRuntime.queryInterface( XPropertySet.class, xPresentation );
188cdf0e10cSrcweir             xPresPropSet.setPropertyValue( "IsEndless", new Boolean( true ) );
189cdf0e10cSrcweir             xPresPropSet.setPropertyValue( "IsAlwaysOnTop", new Boolean( true ) );
190cdf0e10cSrcweir             xPresPropSet.setPropertyValue( "Pause", new Integer( 0 ) );
191cdf0e10cSrcweir             xPresentation.start();
192cdf0e10cSrcweir         }
193cdf0e10cSrcweir         catch( Exception ex )
194cdf0e10cSrcweir         {
195cdf0e10cSrcweir             System.out.println( ex );
196cdf0e10cSrcweir         }
197cdf0e10cSrcweir         System.exit( 0 );
198cdf0e10cSrcweir     }
199cdf0e10cSrcweir 
200cdf0e10cSrcweir     // this simple method applies the slide transition to a page
201cdf0e10cSrcweir     public static void setSlideTransition( XDrawPage xPage,
202cdf0e10cSrcweir         com.sun.star.presentation.FadeEffect eEffect,
203cdf0e10cSrcweir             com.sun.star.presentation.AnimationSpeed eSpeed,
204cdf0e10cSrcweir             int nChange,
205cdf0e10cSrcweir                 int nDuration )
206cdf0e10cSrcweir     {
207cdf0e10cSrcweir         // the following test is only sensible if you do not exactly know
208cdf0e10cSrcweir         // what type of page xPage is, for this purpose it can been tested
209cdf0e10cSrcweir         // if the com.sun.star.presentation.DrawPage service is supported
210cdf0e10cSrcweir         XServiceInfo xInfo = (XServiceInfo)UnoRuntime.queryInterface(
211cdf0e10cSrcweir                 XServiceInfo.class, xPage );
212cdf0e10cSrcweir         if ( xInfo.supportsService( "com.sun.star.presentation.DrawPage" ) == true )
213cdf0e10cSrcweir         {
214cdf0e10cSrcweir             try
215cdf0e10cSrcweir             {
216cdf0e10cSrcweir                 XPropertySet xPropSet = (XPropertySet)
217cdf0e10cSrcweir                     UnoRuntime.queryInterface( XPropertySet.class, xPage );
218cdf0e10cSrcweir                 xPropSet.setPropertyValue( "Effect",   eEffect );
219cdf0e10cSrcweir                 xPropSet.setPropertyValue( "Speed",    eSpeed );
220cdf0e10cSrcweir                 xPropSet.setPropertyValue( "Change",   new Integer( nChange ) );
221cdf0e10cSrcweir                 xPropSet.setPropertyValue( "Duration", new Integer( nDuration ) );
222cdf0e10cSrcweir             }
223cdf0e10cSrcweir             catch( Exception ex )
224cdf0e10cSrcweir             {
225cdf0e10cSrcweir             }
226cdf0e10cSrcweir         }
227cdf0e10cSrcweir     }
228cdf0e10cSrcweir }
229