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
7 * Copyright 2000, 2010 Oracle and/or its affiliates.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
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
.XSingleServiceFactory
;
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
;
49 import com
.sun
.star
.container
.XNameContainer
;
50 import com
.sun
.star
.container
.XIndexContainer
;
52 import com
.sun
.star
.drawing
.XShape
;
53 import com
.sun
.star
.drawing
.XShapes
;
54 import com
.sun
.star
.drawing
.XDrawPage
;
55 import com
.sun
.star
.drawing
.XDrawPages
;
56 import com
.sun
.star
.drawing
.XDrawPagesSupplier
;
58 import com
.sun
.star
.presentation
.XPresentation
;
59 import com
.sun
.star
.presentation
.XPresentationSupplier
;
60 import com
.sun
.star
.presentation
.XCustomPresentationSupplier
;
63 // __________ Implementation __________
67 // This demo will demonstrate how to create a CustomShow
69 // The first parameter describes the connection that is to use. If there is no parameter
70 // "uno:socket,host=localhost,port=2083;urp;StarOffice.ServiceManager" is used.
73 public class CustomShowDemo
75 public static void main( String args
[] )
77 XComponent xDrawDoc
= null;
80 // get the remote office context of a running office (a new office
81 // instance is started if necessary)
82 com
.sun
.star
.uno
.XComponentContext xOfficeContext
= Helper
.connect();
84 // suppress Presentation Autopilot when opening the document
85 // properties are the same as described for
86 // com.sun.star.document.MediaDescriptor
87 PropertyValue
[] pPropValues
= new PropertyValue
[ 1 ];
88 pPropValues
[ 0 ] = new PropertyValue();
89 pPropValues
[ 0 ].Name
= "Silent";
90 pPropValues
[ 0 ].Value
= Boolean
.TRUE
;
92 xDrawDoc
= Helper
.createDocument( xOfficeContext
,
93 "private:factory/simpress", "_blank", 0, pPropValues
);
95 XDrawPagesSupplier xDrawPagesSupplier
=
96 UnoRuntime
.queryInterface(
97 XDrawPagesSupplier
.class, xDrawDoc
);
98 XDrawPages xDrawPages
= xDrawPagesSupplier
.getDrawPages();
100 // take care that this document has ten pages
101 while ( xDrawPages
.getCount() < 10 )
102 xDrawPages
.insertNewByIndex( 0 );
104 // assign a name to each page and also insert a text object including the name of the page
105 String aNameArray
[] = { "Introduction", "page one", "page two", "page three", "page four",
106 "page five", "page six", "page seven", "page eight", "page nine" };
108 for ( i
= 0; i
< 10; i
++ )
110 XDrawPage xDrawPage
= UnoRuntime
.queryInterface(
111 XDrawPage
.class, xDrawPages
.getByIndex( i
));
112 XNamed xPageName
= UnoRuntime
.queryInterface(
113 XNamed
.class, xDrawPage
);
114 xPageName
.setName( aNameArray
[ i
] );
116 // now we will create and insert the text object
117 XShape xTextObj
= ShapeHelper
.createShape( xDrawDoc
, new Point( 10000, 9000 ),
118 new Size( 10000, 5000 ),
119 "com.sun.star.drawing.TextShape" );
120 XShapes xShapes
= UnoRuntime
.queryInterface( XShapes
.class, xDrawPage
);
121 xShapes
.add( xTextObj
);
122 ShapeHelper
.addPortion( xTextObj
, aNameArray
[ i
], true );
125 /* create two custom shows, one will play slide 6 to 10 and is named "ShortVersion"
126 the other one will play slide 2 til 10 and is named "LongVersion" */
127 XCustomPresentationSupplier xCustPresSupplier
= UnoRuntime
.queryInterface( XCustomPresentationSupplier
.class, xDrawDoc
);
129 /* the following container is a container for further container
130 which concludes the list of pages that are to play within a custom show */
131 XNameContainer xNameContainer
= xCustPresSupplier
.getCustomPresentations();
132 XSingleServiceFactory xFactory
= UnoRuntime
.queryInterface( XSingleServiceFactory
.class, xNameContainer
);
135 XIndexContainer xContainer
;
137 /* instantiate an IndexContainer that will take
138 a list of draw pages for the first custom show */
139 xObj
= xFactory
.createInstance();
140 xContainer
= UnoRuntime
.queryInterface( XIndexContainer
.class, xObj
);
141 for ( i
= 5; i
< 10; i
++ )
142 xContainer
.insertByIndex( xContainer
.getCount(), xDrawPages
.getByIndex( i
) );
143 xNameContainer
.insertByName( "ShortVersion", xContainer
);
145 /* instantiate an IndexContainer that will take
146 a list of draw page for the second custom show */
147 xObj
= xFactory
.createInstance();
148 xContainer
= UnoRuntime
.queryInterface( XIndexContainer
.class, xObj
);
149 for ( i
= 1; i
< 10; i
++ )
150 xContainer
.insertByIndex( xContainer
.getCount(), xDrawPages
.getByIndex( i
) );
151 xNameContainer
.insertByName( "LongVersion", xContainer
);
153 /* which custom show is to use
154 can been set in the presentation settings */
156 XPresentationSupplier xPresSupplier
= UnoRuntime
.queryInterface( XPresentationSupplier
.class, xDrawDoc
);
157 XPresentation xPresentation
= xPresSupplier
.getPresentation();
158 XPropertySet xPresPropSet
= UnoRuntime
.queryInterface( XPropertySet
.class, xPresentation
);
159 xPresPropSet
.setPropertyValue( "CustomShow", "ShortVersion" );
161 catch( Exception ex
)
163 System
.out
.println( ex
);
169 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */