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.XServiceInfo; 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 49 import com.sun.star.drawing.XShape; 50 import com.sun.star.drawing.XShapes; 51 import com.sun.star.drawing.XDrawPage; 52 53 import com.sun.star.presentation.XPresentation; 54 import com.sun.star.presentation.XPresentationSupplier; 55 56 57 58 // __________ Implementation __________ 59 60 /** presentation demo 61 @author Sven Jacobi 62 */ 63 64 // This demo will demonstrate how to create a presentation using the Office API 65 66 // The first parameter describes the connection that is to use. If there is no parameter 67 // "uno:socket,host=localhost,port=2083;urp;StarOffice.ServiceManager" is used. 68 69 70 public class PresentationDemo 71 { 72 public static void main( String args[] ) 73 { 74 XComponent xDrawDoc = null; 75 try 76 { 77 // get the remote office context of a running office (a new office 78 // instance is started if necessary) 79 com.sun.star.uno.XComponentContext xOfficeContext = Helper.connect(); 80 81 // suppress Presentation Autopilot when opening the document 82 // properties are the same as described for 83 // com.sun.star.document.MediaDescriptor 84 PropertyValue[] pPropValues = new PropertyValue[ 1 ]; 85 pPropValues[ 0 ] = new PropertyValue(); 86 pPropValues[ 0 ].Name = "Silent"; 87 pPropValues[ 0 ].Value = new Boolean( true ); 88 89 xDrawDoc = Helper.createDocument( xOfficeContext, 90 "private:factory/simpress", "_blank", 0, pPropValues ); 91 92 93 XDrawPage xPage; 94 XShapes xShapes; 95 XPropertySet xShapePropSet; 96 97 // create pages, so that three are available 98 while ( PageHelper.getDrawPageCount( xDrawDoc ) < 3 ) 99 PageHelper.insertNewDrawPageByIndex( xDrawDoc, 0 ); 100 101 102 // set the slide transition for the first page 103 xPage = PageHelper.getDrawPageByIndex( xDrawDoc, 0 ); 104 xShapes = (XShapes) 105 UnoRuntime.queryInterface( XShapes.class, xPage ); 106 // set slide transition effect 107 setSlideTransition( xPage, 108 com.sun.star.presentation.FadeEffect.FADE_FROM_RIGHT, 109 com.sun.star.presentation.AnimationSpeed.FAST, 110 1, 0 ); // automatic object and slide transition 111 112 // create a rectangle that is placed on the top left of the page 113 xShapePropSet = ShapeHelper.createAndInsertShape( xDrawDoc, 114 xShapes,new Point( 1000, 1000 ), new Size( 5000, 5000 ), 115 "com.sun.star.drawing.RectangleShape" ); 116 xShapePropSet.setPropertyValue("Effect", 117 com.sun.star.presentation.AnimationEffect.WAVYLINE_FROM_BOTTOM ); 118 119 /* the following three properties provokes that the shape is dimmed 120 to red 121 after the animation has been finished */ 122 xShapePropSet.setPropertyValue( "DimHide", new Boolean( false ) ); 123 xShapePropSet.setPropertyValue( "DimPrevious", new Boolean( true ) ); 124 xShapePropSet.setPropertyValue( "DimColor", new Integer( 0xff0000 ) ); 125 126 127 // set the slide transition for the second page 128 xPage = PageHelper.getDrawPageByIndex( xDrawDoc, 1 ); 129 xShapes = (XShapes) 130 UnoRuntime.queryInterface( XShapes.class, xPage ); 131 setSlideTransition( xPage, 132 com.sun.star.presentation.FadeEffect.FADE_FROM_RIGHT, 133 com.sun.star.presentation.AnimationSpeed.SLOW, 134 1, 0 ); // automatic object and slide transition 135 136 // create an ellipse that is placed on the bottom right of second page 137 xShapePropSet = ShapeHelper.createAndInsertShape( xDrawDoc, 138 xShapes, new Point( 21000, 15000 ), new Size( 5000, 5000 ), 139 "com.sun.star.drawing.EllipseShape" ); 140 xShapePropSet.setPropertyValue( 141 "Effect", com.sun.star.presentation.AnimationEffect.HIDE ); 142 143 144 // create two objects for the third page 145 // clicking the first object lets the presentation jump 146 // to page one by using ClickAction.FIRSTPAGE, 147 // the second object lets the presentation jump to page two 148 // by using a ClickAction.BOOKMARK; 149 xPage = PageHelper.getDrawPageByIndex( xDrawDoc, 2 ); 150 xShapes = (XShapes) 151 UnoRuntime.queryInterface( XShapes.class, xPage ); 152 setSlideTransition( xPage, 153 com.sun.star.presentation.FadeEffect.ROLL_FROM_LEFT, 154 com.sun.star.presentation.AnimationSpeed.MEDIUM, 155 2, 0 ); 156 XShape xShape = ShapeHelper.createShape( xDrawDoc, 157 new Point( 1000, 8000 ), new Size( 5000, 5000 ), 158 "com.sun.star.drawing.EllipseShape" ); 159 xShapes.add( xShape ); 160 ShapeHelper.addPortion( xShape, "click to go", false ); 161 ShapeHelper.addPortion( xShape, "to first page", true ); 162 xShapePropSet = (XPropertySet) 163 UnoRuntime.queryInterface( XPropertySet.class, xShape ); 164 xShapePropSet.setPropertyValue("Effect", 165 com.sun.star.presentation.AnimationEffect.FADE_FROM_BOTTOM ); 166 xShapePropSet.setPropertyValue( 167 "OnClick", com.sun.star.presentation.ClickAction.FIRSTPAGE ); 168 169 170 xShape = ShapeHelper.createShape( xDrawDoc, 171 new Point( 22000, 8000 ), new Size( 5000, 5000 ), 172 "com.sun.star.drawing.RectangleShape" ); 173 xShapes.add( xShape ); 174 ShapeHelper.addPortion( xShape, "click to go", false ); 175 ShapeHelper.addPortion( xShape, "to the second page", true ); 176 xShapePropSet = (XPropertySet) 177 UnoRuntime.queryInterface( XPropertySet.class, xShape ); 178 xShapePropSet.setPropertyValue("Effect", 179 com.sun.star.presentation.AnimationEffect.FADE_FROM_BOTTOM ); 180 181 xShapePropSet.setPropertyValue( 182 "OnClick", com.sun.star.presentation.ClickAction.BOOKMARK ); 183 // set the name of page two, and use it with the bookmark action 184 XNamed xPageName = (XNamed)UnoRuntime.queryInterface( 185 XNamed.class, PageHelper.getDrawPageByIndex( xDrawDoc, 1 ) ); 186 xPageName.setName( "page two" ); 187 xShapePropSet.setPropertyValue( 188 "Bookmark", xPageName.getName() ); 189 190 191 /* start an endless presentation which is displayed in 192 full-screen mode and placed on top */ 193 194 XPresentationSupplier xPresSupplier = (XPresentationSupplier) 195 UnoRuntime.queryInterface( XPresentationSupplier.class, xDrawDoc ); 196 XPresentation xPresentation = xPresSupplier.getPresentation(); 197 XPropertySet xPresPropSet = (XPropertySet) 198 UnoRuntime.queryInterface( XPropertySet.class, xPresentation ); 199 xPresPropSet.setPropertyValue( "IsEndless", new Boolean( true ) ); 200 xPresPropSet.setPropertyValue( "IsAlwaysOnTop", new Boolean( true ) ); 201 xPresPropSet.setPropertyValue( "Pause", new Integer( 0 ) ); 202 xPresentation.start(); 203 } 204 catch( Exception ex ) 205 { 206 System.out.println( ex ); 207 } 208 System.exit( 0 ); 209 } 210 211 // this simple method applies the slide transition to a page 212 public static void setSlideTransition( XDrawPage xPage, 213 com.sun.star.presentation.FadeEffect eEffect, 214 com.sun.star.presentation.AnimationSpeed eSpeed, 215 int nChange, 216 int nDuration ) 217 { 218 // the following test is only sensible if you do not exactly know 219 // what type of page xPage is, for this purpose it can been tested 220 // if the com.sun.star.presentation.DrawPage service is supported 221 XServiceInfo xInfo = (XServiceInfo)UnoRuntime.queryInterface( 222 XServiceInfo.class, xPage ); 223 if ( xInfo.supportsService( "com.sun.star.presentation.DrawPage" ) == true ) 224 { 225 try 226 { 227 XPropertySet xPropSet = (XPropertySet) 228 UnoRuntime.queryInterface( XPropertySet.class, xPage ); 229 xPropSet.setPropertyValue( "Effect", eEffect ); 230 xPropSet.setPropertyValue( "Speed", eSpeed ); 231 xPropSet.setPropertyValue( "Change", new Integer( nChange ) ); 232 xPropSet.setPropertyValue( "Duration", new Integer( nDuration ) ); 233 } 234 catch( Exception ex ) 235 { 236 } 237 } 238 } 239 } 240