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