1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  *  The Contents of this file are made available subject to the terms of
4*cdf0e10cSrcweir  *  the BSD license.
5*cdf0e10cSrcweir  *
6*cdf0e10cSrcweir  *  Copyright 2000, 2010 Oracle and/or its affiliates.
7*cdf0e10cSrcweir  *  All rights reserved.
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  *  Redistribution and use in source and binary forms, with or without
10*cdf0e10cSrcweir  *  modification, are permitted provided that the following conditions
11*cdf0e10cSrcweir  *  are met:
12*cdf0e10cSrcweir  *  1. Redistributions of source code must retain the above copyright
13*cdf0e10cSrcweir  *     notice, this list of conditions and the following disclaimer.
14*cdf0e10cSrcweir  *  2. Redistributions in binary form must reproduce the above copyright
15*cdf0e10cSrcweir  *     notice, this list of conditions and the following disclaimer in the
16*cdf0e10cSrcweir  *     documentation and/or other materials provided with the distribution.
17*cdf0e10cSrcweir  *  3. Neither the name of Sun Microsystems, Inc. nor the names of its
18*cdf0e10cSrcweir  *     contributors may be used to endorse or promote products derived
19*cdf0e10cSrcweir  *     from this software without specific prior written permission.
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22*cdf0e10cSrcweir  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23*cdf0e10cSrcweir  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24*cdf0e10cSrcweir  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25*cdf0e10cSrcweir  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26*cdf0e10cSrcweir  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27*cdf0e10cSrcweir  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
28*cdf0e10cSrcweir  *  OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
29*cdf0e10cSrcweir  *  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
30*cdf0e10cSrcweir  *  TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
31*cdf0e10cSrcweir  *  USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32*cdf0e10cSrcweir  *
33*cdf0e10cSrcweir  *************************************************************************/
34*cdf0e10cSrcweir 
35*cdf0e10cSrcweir // __________ Imports __________
36*cdf0e10cSrcweir 
37*cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime;
38*cdf0e10cSrcweir import com.sun.star.lang.XComponent;
39*cdf0e10cSrcweir 
40*cdf0e10cSrcweir import com.sun.star.awt.Point;
41*cdf0e10cSrcweir import com.sun.star.awt.Size;
42*cdf0e10cSrcweir 
43*cdf0e10cSrcweir import com.sun.star.beans.PropertyValue;
44*cdf0e10cSrcweir import com.sun.star.beans.XPropertySet;
45*cdf0e10cSrcweir 
46*cdf0e10cSrcweir import com.sun.star.container.XNamed;
47*cdf0e10cSrcweir 
48*cdf0e10cSrcweir import com.sun.star.drawing.PolygonFlags;
49*cdf0e10cSrcweir import com.sun.star.drawing.PolyPolygonBezierCoords;
50*cdf0e10cSrcweir import com.sun.star.drawing.XShape;
51*cdf0e10cSrcweir import com.sun.star.drawing.XShapes;
52*cdf0e10cSrcweir import com.sun.star.drawing.XShapeGrouper;
53*cdf0e10cSrcweir import com.sun.star.drawing.XDrawPage;
54*cdf0e10cSrcweir 
55*cdf0e10cSrcweir import java.util.Random;
56*cdf0e10cSrcweir 
57*cdf0e10cSrcweir 
58*cdf0e10cSrcweir // __________ Implementation __________
59*cdf0e10cSrcweir 
60*cdf0e10cSrcweir /** drawing demo
61*cdf0e10cSrcweir     @author Sven Jacobi
62*cdf0e10cSrcweir  */
63*cdf0e10cSrcweir 
64*cdf0e10cSrcweir // This drawing demo will create/load a document, and show how to
65*cdf0e10cSrcweir // handle pages and shapes using the Office API,
66*cdf0e10cSrcweir 
67*cdf0e10cSrcweir // Calling this demo two parameter can be used. The first parameter
68*cdf0e10cSrcweir // describes if a document is to create or load: "draw" creates a
69*cdf0e10cSrcweir // draw document, "impress" creates an impress document, any other
70*cdf0e10cSrcweir // parameter is interpreted as URL and loads the corresponding
71*cdf0e10cSrcweir // document. ( example for a URL is: "file:///c:/test.odp" )
72*cdf0e10cSrcweir // The second parameter is the connection that is to use. If no parameter
73*cdf0e10cSrcweir // is given a standard impress document is created by using following
74*cdf0e10cSrcweir // connection: "uno:socket,host=localhost,port=2083;urp;StarOffice.ServiceManager";
75*cdf0e10cSrcweir 
76*cdf0e10cSrcweir public class DrawingDemo
77*cdf0e10cSrcweir {
78*cdf0e10cSrcweir     public static void main( String args[] )
79*cdf0e10cSrcweir     {
80*cdf0e10cSrcweir 		XComponent xDrawDoc = null;
81*cdf0e10cSrcweir 		try
82*cdf0e10cSrcweir 		{
83*cdf0e10cSrcweir             // get the remote office context of a running office (a new office
84*cdf0e10cSrcweir             // instance is started if necessary)
85*cdf0e10cSrcweir 			com.sun.star.uno.XComponentContext xOfficeContext = Helper.connect();
86*cdf0e10cSrcweir 
87*cdf0e10cSrcweir 			String sURL;
88*cdf0e10cSrcweir 			if ( args.length == 0 )
89*cdf0e10cSrcweir 				sURL = "impress";
90*cdf0e10cSrcweir 			else
91*cdf0e10cSrcweir 				sURL = args[ 0 ];
92*cdf0e10cSrcweir 
93*cdf0e10cSrcweir 			if ( sURL.equals( "draw" ) )
94*cdf0e10cSrcweir 				sURL = "private:factory/sdraw";
95*cdf0e10cSrcweir 			else if ( sURL.equals( "impress" ) )
96*cdf0e10cSrcweir 				sURL = "private:factory/simpress";
97*cdf0e10cSrcweir 
98*cdf0e10cSrcweir 			// suppress Presentation Autopilot when opening the document
99*cdf0e10cSrcweir 			// properties are the same as described for
100*cdf0e10cSrcweir 			// com.sun.star.document.MediaDescriptor
101*cdf0e10cSrcweir 			PropertyValue[] pPropValues = new PropertyValue[ 1 ];
102*cdf0e10cSrcweir 			pPropValues[ 0 ] = new PropertyValue();
103*cdf0e10cSrcweir 			pPropValues[ 0 ].Name = "Silent";
104*cdf0e10cSrcweir 			pPropValues[ 0 ].Value = new Boolean( true );
105*cdf0e10cSrcweir 
106*cdf0e10cSrcweir 			xDrawDoc = Helper.createDocument( xOfficeContext,
107*cdf0e10cSrcweir 				sURL, "_blank", 0, pPropValues );
108*cdf0e10cSrcweir 		}
109*cdf0e10cSrcweir 		catch( Exception ex )
110*cdf0e10cSrcweir 		{
111*cdf0e10cSrcweir             System.out.println( ex );
112*cdf0e10cSrcweir 			System.exit( 0 );
113*cdf0e10cSrcweir 		}
114*cdf0e10cSrcweir 
115*cdf0e10cSrcweir 
116*cdf0e10cSrcweir 		Demo_PageCreation( xDrawDoc, 10 );
117*cdf0e10cSrcweir 		Demo_PageNaming( xDrawDoc, "this page is called: LastPage" );
118*cdf0e10cSrcweir 		Demo_ShapeCreation( xDrawDoc );
119*cdf0e10cSrcweir 		Demo_PolyPolygonBezier( xDrawDoc );
120*cdf0e10cSrcweir 		Demo_Group1( xDrawDoc );
121*cdf0e10cSrcweir 		Demo_Group2( xDrawDoc );
122*cdf0e10cSrcweir         System.exit( 0 );
123*cdf0e10cSrcweir     }
124*cdf0e10cSrcweir 
125*cdf0e10cSrcweir 	// This method appends draw pages to the document, so that a
126*cdf0e10cSrcweir 	// minimum of n draw pages will be available.
127*cdf0e10cSrcweir 	// For each second draw page also a new master page is created.
128*cdf0e10cSrcweir 	public static void Demo_PageCreation( XComponent xDrawDoc, int n )
129*cdf0e10cSrcweir 	{
130*cdf0e10cSrcweir 		try
131*cdf0e10cSrcweir 		{
132*cdf0e10cSrcweir 			// If the document has less than n draw pages, append them,
133*cdf0e10cSrcweir 			// a minimum of n draw pages will be available
134*cdf0e10cSrcweir 			int i, nDrawPages;
135*cdf0e10cSrcweir 			for ( nDrawPages = PageHelper.getDrawPageCount( xDrawDoc );
136*cdf0e10cSrcweir 				nDrawPages < n; nDrawPages++ )
137*cdf0e10cSrcweir 				PageHelper.insertNewDrawPageByIndex( xDrawDoc, nDrawPages );
138*cdf0e10cSrcweir 			// Create a master page for each second drawpage
139*cdf0e10cSrcweir 			int nMasterPages;
140*cdf0e10cSrcweir 			for ( nMasterPages = PageHelper.getMasterPageCount( xDrawDoc );
141*cdf0e10cSrcweir 				nMasterPages < ( ( nDrawPages + 1 ) / 2 ); nMasterPages++ )
142*cdf0e10cSrcweir 				PageHelper.insertNewMasterPageByIndex( xDrawDoc, nMasterPages );
143*cdf0e10cSrcweir 
144*cdf0e10cSrcweir 			// Now connect master page 1 to draw page 1 and 2,
145*cdf0e10cSrcweir 			// master page 2 to draw page 3 and 4 and so on.
146*cdf0e10cSrcweir 			for ( i = 0; i < nDrawPages; i++ )
147*cdf0e10cSrcweir 			{
148*cdf0e10cSrcweir 				XDrawPage xDrawPage = PageHelper.getDrawPageByIndex( xDrawDoc, i );
149*cdf0e10cSrcweir 				XDrawPage xMasterPage = PageHelper.getMasterPageByIndex(
150*cdf0e10cSrcweir                     xDrawDoc, i / 2 );
151*cdf0e10cSrcweir 				PageHelper.setMasterPage( xDrawPage, xMasterPage );
152*cdf0e10cSrcweir 			}
153*cdf0e10cSrcweir 		}
154*cdf0e10cSrcweir 		catch( Exception ex )
155*cdf0e10cSrcweir 		{
156*cdf0e10cSrcweir 			System.out.println("Demo_PageCreation: I have a page creation problem");
157*cdf0e10cSrcweir 		}
158*cdf0e10cSrcweir 	}
159*cdf0e10cSrcweir 
160*cdf0e10cSrcweir 	// this method shows how to name a page, this is exemplary
161*cdf0e10cSrcweir 	// be done for the last draw page
162*cdf0e10cSrcweir 	public static void Demo_PageNaming(
163*cdf0e10cSrcweir 		XComponent xDrawDoc, String sLastPageName )
164*cdf0e10cSrcweir 	{
165*cdf0e10cSrcweir 		try
166*cdf0e10cSrcweir 		{
167*cdf0e10cSrcweir 			XDrawPage xLastPage = PageHelper.getDrawPageByIndex( xDrawDoc,
168*cdf0e10cSrcweir 				PageHelper.getDrawPageCount( xDrawDoc ) - 1 );
169*cdf0e10cSrcweir 
170*cdf0e10cSrcweir 			// each drawpage is supporting an XNamed interface
171*cdf0e10cSrcweir 			XNamed xNamed = (XNamed)UnoRuntime.queryInterface(
172*cdf0e10cSrcweir 				XNamed.class, xLastPage );
173*cdf0e10cSrcweir 
174*cdf0e10cSrcweir 			// beware, the page must have an unique name
175*cdf0e10cSrcweir 			xNamed.setName( sLastPageName );
176*cdf0e10cSrcweir 		}
177*cdf0e10cSrcweir 		catch( Exception ex )
178*cdf0e10cSrcweir 		{
179*cdf0e10cSrcweir 			System.out.println( "Demo_PageNaming: can't set page name" );
180*cdf0e10cSrcweir 		}
181*cdf0e10cSrcweir 	}
182*cdf0e10cSrcweir 
183*cdf0e10cSrcweir 	// This method will add one rectangle shape into the lower left quarter of
184*cdf0e10cSrcweir 	// every page that is available,
185*cdf0e10cSrcweir 	public static void Demo_ShapeCreation( XComponent xDrawDoc )
186*cdf0e10cSrcweir 	{
187*cdf0e10cSrcweir 		try
188*cdf0e10cSrcweir 		{
189*cdf0e10cSrcweir 			boolean bIsImpressDocument = PageHelper.isImpressDocument( xDrawDoc );
190*cdf0e10cSrcweir 
191*cdf0e10cSrcweir 			int nDrawingPages = PageHelper.getDrawPageCount( xDrawDoc );
192*cdf0e10cSrcweir 			int nMasterPages =  PageHelper.getMasterPageCount( xDrawDoc );
193*cdf0e10cSrcweir 			int nGlobalPageCount = nDrawingPages + nMasterPages;
194*cdf0e10cSrcweir 
195*cdf0e10cSrcweir 			if ( bIsImpressDocument )
196*cdf0e10cSrcweir 			{
197*cdf0e10cSrcweir 				// in impress each draw page also has a notes page
198*cdf0e10cSrcweir 				nGlobalPageCount += nDrawingPages;
199*cdf0e10cSrcweir 				// for each drawing master is also a notes master available
200*cdf0e10cSrcweir 				nGlobalPageCount += nMasterPages;
201*cdf0e10cSrcweir 				// one handout is existing
202*cdf0e10cSrcweir 				nGlobalPageCount += 1;
203*cdf0e10cSrcweir 			}
204*cdf0e10cSrcweir 
205*cdf0e10cSrcweir 			// create and fill a container with all draw pages
206*cdf0e10cSrcweir 			XDrawPage[] pPages = new XDrawPage[ nGlobalPageCount ];
207*cdf0e10cSrcweir 			int i, nCurrentPageIndex = 0;
208*cdf0e10cSrcweir 
209*cdf0e10cSrcweir 			// insert handout page
210*cdf0e10cSrcweir 			if ( bIsImpressDocument )
211*cdf0e10cSrcweir 				pPages[ nCurrentPageIndex++ ] = PageHelper.getHandoutMasterPage(
212*cdf0e10cSrcweir                     xDrawDoc );
213*cdf0e10cSrcweir 
214*cdf0e10cSrcweir 			// inserting all master pages
215*cdf0e10cSrcweir 			for( i = 0; i < nMasterPages; i++ )
216*cdf0e10cSrcweir 			{
217*cdf0e10cSrcweir 				XDrawPage xMasterPage = PageHelper.getMasterPageByIndex(
218*cdf0e10cSrcweir                     xDrawDoc, i );
219*cdf0e10cSrcweir 				pPages[ nCurrentPageIndex++ ] = xMasterPage;
220*cdf0e10cSrcweir 
221*cdf0e10cSrcweir 				// if the document is an impress, get the corresponding notes
222*cdf0e10cSrcweir 				// master page
223*cdf0e10cSrcweir 				if ( bIsImpressDocument )
224*cdf0e10cSrcweir 					pPages[ nCurrentPageIndex++ ] = PageHelper.getNotesPage(
225*cdf0e10cSrcweir                         xMasterPage );
226*cdf0e10cSrcweir 			}
227*cdf0e10cSrcweir 			for ( i = 0; i < nDrawingPages; i++ )
228*cdf0e10cSrcweir 			{
229*cdf0e10cSrcweir 				XDrawPage xDrawPage = PageHelper.getDrawPageByIndex( xDrawDoc, i );
230*cdf0e10cSrcweir 				pPages[ nCurrentPageIndex++ ] = xDrawPage;
231*cdf0e10cSrcweir 
232*cdf0e10cSrcweir 				// if the document is an impress, get the corresponding notes page
233*cdf0e10cSrcweir 				if ( bIsImpressDocument )
234*cdf0e10cSrcweir 					pPages[ nCurrentPageIndex++ ] = PageHelper.getNotesPage(
235*cdf0e10cSrcweir                         xDrawPage );
236*cdf0e10cSrcweir 			}
237*cdf0e10cSrcweir 
238*cdf0e10cSrcweir 			// Now a complete list of pages is available in pPages.
239*cdf0e10cSrcweir 			// The following code will insert a rectangle into each page.
240*cdf0e10cSrcweir 			for ( i = 0; i < nGlobalPageCount; i++ )
241*cdf0e10cSrcweir 			{
242*cdf0e10cSrcweir 				Size aPageSize = PageHelper.getPageSize( pPages[ i ] );
243*cdf0e10cSrcweir 				int nHalfWidth  = aPageSize.Width / 2;
244*cdf0e10cSrcweir 				int nHalfHeight = aPageSize.Height / 2;
245*cdf0e10cSrcweir 
246*cdf0e10cSrcweir 	            Random aRndGen = new Random();
247*cdf0e10cSrcweir 				int nRndObjWidth  = aRndGen.nextInt( nHalfWidth );
248*cdf0e10cSrcweir 				int nRndObjHeight = aRndGen.nextInt( nHalfHeight );
249*cdf0e10cSrcweir 
250*cdf0e10cSrcweir 				int	nRndObjPosX = aRndGen.nextInt( nHalfWidth - nRndObjWidth );
251*cdf0e10cSrcweir 				int nRndObjPosY = aRndGen.nextInt( nHalfHeight - nRndObjHeight )
252*cdf0e10cSrcweir                     + nHalfHeight;
253*cdf0e10cSrcweir 
254*cdf0e10cSrcweir 				XShapes xShapes = (XShapes)
255*cdf0e10cSrcweir 					UnoRuntime.queryInterface( XShapes.class, pPages[ i ] );
256*cdf0e10cSrcweir 				ShapeHelper.createAndInsertShape( xDrawDoc, xShapes,
257*cdf0e10cSrcweir 					new Point( nRndObjPosX, nRndObjPosY ),
258*cdf0e10cSrcweir 						new Size( nRndObjWidth, nRndObjHeight ),
259*cdf0e10cSrcweir 							"com.sun.star.drawing.RectangleShape" );
260*cdf0e10cSrcweir 			}
261*cdf0e10cSrcweir 		}
262*cdf0e10cSrcweir 		catch( Exception ex )
263*cdf0e10cSrcweir 		{
264*cdf0e10cSrcweir 			System.out.println( "Demo_ShapeCreation:" + ex );
265*cdf0e10cSrcweir 		}
266*cdf0e10cSrcweir 	}
267*cdf0e10cSrcweir 
268*cdf0e10cSrcweir 	// This method will show how to create a PolyPolygonBezier that lies is in the
269*cdf0e10cSrcweir 	// topleft quarter of the page and positioned at the back
270*cdf0e10cSrcweir 	public static void Demo_PolyPolygonBezier( XComponent xDrawDoc )
271*cdf0e10cSrcweir 	{
272*cdf0e10cSrcweir 		try
273*cdf0e10cSrcweir 		{
274*cdf0e10cSrcweir 			XShape xPolyPolygonBezier = ShapeHelper.createShape( xDrawDoc,
275*cdf0e10cSrcweir 				new Point( 0, 0 ),
276*cdf0e10cSrcweir 					new Size( 0, 0 ),
277*cdf0e10cSrcweir 						"com.sun.star.drawing.ClosedBezierShape" );
278*cdf0e10cSrcweir 
279*cdf0e10cSrcweir 			// the fact that the shape must have been added to the page before
280*cdf0e10cSrcweir 			// it is possible to apply changes to the PropertySet, it is a good
281*cdf0e10cSrcweir 			// proceeding to add the shape as soon as possible
282*cdf0e10cSrcweir 			XDrawPage xDrawPage;
283*cdf0e10cSrcweir 			// if possible insert our new shape in the master page
284*cdf0e10cSrcweir 			if ( PageHelper.isImpressDocument( xDrawDoc ) )
285*cdf0e10cSrcweir 				xDrawPage = PageHelper.getMasterPageByIndex( xDrawDoc, 0 );
286*cdf0e10cSrcweir 			else
287*cdf0e10cSrcweir 				xDrawPage = PageHelper.getDrawPageByIndex( xDrawDoc, 0 );
288*cdf0e10cSrcweir 			XShapes xShapes = (XShapes)
289*cdf0e10cSrcweir 				UnoRuntime.queryInterface( XShapes.class, xDrawPage );
290*cdf0e10cSrcweir 			xShapes.add( xPolyPolygonBezier );
291*cdf0e10cSrcweir 
292*cdf0e10cSrcweir 			XPropertySet xShapeProperties = (XPropertySet)
293*cdf0e10cSrcweir 				UnoRuntime.queryInterface( XPropertySet.class, xPolyPolygonBezier );
294*cdf0e10cSrcweir 
295*cdf0e10cSrcweir 			// get pagesize
296*cdf0e10cSrcweir 			XPropertySet xPageProperties = (XPropertySet)
297*cdf0e10cSrcweir 				UnoRuntime.queryInterface( XPropertySet.class, xDrawPage );
298*cdf0e10cSrcweir 			int nPageWidth = ((Integer)xPageProperties.getPropertyValue( "Width" )).intValue() / 2;
299*cdf0e10cSrcweir 			int nPageHeight = ((Integer)xPageProperties.getPropertyValue( "Height" )).intValue() / 2;
300*cdf0e10cSrcweir 
301*cdf0e10cSrcweir 			PolyPolygonBezierCoords aCoords = new PolyPolygonBezierCoords();
302*cdf0e10cSrcweir 			// allocating the outer sequence
303*cdf0e10cSrcweir 			int nPolygonCount = 50;
304*cdf0e10cSrcweir 			aCoords.Coordinates = new Point[ nPolygonCount ][ ];
305*cdf0e10cSrcweir 			aCoords.Flags = new PolygonFlags[ nPolygonCount ][ ];
306*cdf0e10cSrcweir 			int i, n, nY;
307*cdf0e10cSrcweir 			// fill the inner point sequence now
308*cdf0e10cSrcweir 			for ( nY = 0, i = 0; i < nPolygonCount; i++, nY += nPageHeight / nPolygonCount )
309*cdf0e10cSrcweir 			{
310*cdf0e10cSrcweir 				// create a polygon using two normal and two control points
311*cdf0e10cSrcweir 				// allocating the inner sequence
312*cdf0e10cSrcweir 				int nPointCount = 8;
313*cdf0e10cSrcweir 				Point[]			pPolyPoints = new Point[ nPointCount ];
314*cdf0e10cSrcweir 				PolygonFlags[]	pPolyFlags	= new PolygonFlags[ nPointCount ];
315*cdf0e10cSrcweir 
316*cdf0e10cSrcweir 				for ( n = 0; n < nPointCount; n++ )
317*cdf0e10cSrcweir 					pPolyPoints[ n ] = new Point();
318*cdf0e10cSrcweir 
319*cdf0e10cSrcweir 				pPolyPoints[ 0 ].X = 0;
320*cdf0e10cSrcweir 				pPolyPoints[ 0 ].Y = nY;
321*cdf0e10cSrcweir 				pPolyFlags[ 0 ] = PolygonFlags.NORMAL;
322*cdf0e10cSrcweir 				pPolyPoints[ 1 ].X = nPageWidth / 2;
323*cdf0e10cSrcweir 				pPolyPoints[ 1 ].Y = nPageHeight;
324*cdf0e10cSrcweir 				pPolyFlags[ 1 ] = PolygonFlags.CONTROL;
325*cdf0e10cSrcweir 				pPolyPoints[ 2 ].X = nPageWidth / 2;;
326*cdf0e10cSrcweir 				pPolyPoints[ 2 ].Y = nPageHeight;
327*cdf0e10cSrcweir 				pPolyFlags[ 2 ] = PolygonFlags.CONTROL;
328*cdf0e10cSrcweir 				pPolyPoints[ 3 ].X = nPageWidth;
329*cdf0e10cSrcweir 				pPolyPoints[ 3 ].Y = nY;
330*cdf0e10cSrcweir 				pPolyFlags[ 3 ] = PolygonFlags.NORMAL;
331*cdf0e10cSrcweir 
332*cdf0e10cSrcweir 				pPolyPoints[ 4 ].X = nPageWidth - 1000;
333*cdf0e10cSrcweir 				pPolyPoints[ 4 ].Y = nY;
334*cdf0e10cSrcweir 				pPolyFlags[ 4 ] = PolygonFlags.NORMAL;
335*cdf0e10cSrcweir 				pPolyPoints[ 5 ].X = nPageWidth / 2;
336*cdf0e10cSrcweir 				pPolyPoints[ 5 ].Y = nPageHeight / 2;
337*cdf0e10cSrcweir 				pPolyFlags[ 5 ] = PolygonFlags.CONTROL;
338*cdf0e10cSrcweir 				pPolyPoints[ 6 ].X = nPageWidth / 2;;
339*cdf0e10cSrcweir 				pPolyPoints[ 6 ].Y = nPageHeight / 2;
340*cdf0e10cSrcweir 				pPolyFlags[ 6 ] = PolygonFlags.CONTROL;
341*cdf0e10cSrcweir 				pPolyPoints[ 7 ].X = 1000;
342*cdf0e10cSrcweir 				pPolyPoints[ 7 ].Y = nY;
343*cdf0e10cSrcweir 				pPolyFlags[ 7 ] = PolygonFlags.NORMAL;
344*cdf0e10cSrcweir 
345*cdf0e10cSrcweir 				aCoords.Coordinates[ i ]= pPolyPoints;
346*cdf0e10cSrcweir 				aCoords.Flags[ i ]		= pPolyFlags;
347*cdf0e10cSrcweir 			}
348*cdf0e10cSrcweir 			xShapeProperties.setPropertyValue( "PolyPolygonBezier", aCoords );
349*cdf0e10cSrcweir 
350*cdf0e10cSrcweir 			// move the shape to the back by changing the ZOrder
351*cdf0e10cSrcweir 			xShapeProperties.setPropertyValue( "ZOrder", new Integer( 1 ) );
352*cdf0e10cSrcweir 		}
353*cdf0e10cSrcweir 		catch ( Exception ex )
354*cdf0e10cSrcweir 		{
355*cdf0e10cSrcweir 			System.out.println( "Demo_PolyPolygonBezier:" + ex );
356*cdf0e10cSrcweir 		}
357*cdf0e10cSrcweir 	}
358*cdf0e10cSrcweir 
359*cdf0e10cSrcweir 	// This method will create a group containing two ellipses
360*cdf0e10cSrcweir 	// the shapes will be added into the top right corner of the first
361*cdf0e10cSrcweir 	// draw page
362*cdf0e10cSrcweir 	public static void Demo_Group1( XComponent xDrawDoc )
363*cdf0e10cSrcweir 	{
364*cdf0e10cSrcweir 		try
365*cdf0e10cSrcweir 		{
366*cdf0e10cSrcweir 			XShape xGroup = ShapeHelper.createShape( xDrawDoc,
367*cdf0e10cSrcweir 				new Point( 0, 0 ),
368*cdf0e10cSrcweir 					new Size( 0, 0 ),
369*cdf0e10cSrcweir 						"com.sun.star.drawing.GroupShape" );
370*cdf0e10cSrcweir 
371*cdf0e10cSrcweir 			// before it is possible to insert shapes,
372*cdf0e10cSrcweir 			// the group must have been added to the page
373*cdf0e10cSrcweir 			XDrawPage xDrawPage = PageHelper.getDrawPageByIndex( xDrawDoc, 0 );
374*cdf0e10cSrcweir 			XShapes xShapes = (XShapes)
375*cdf0e10cSrcweir 				UnoRuntime.queryInterface( XShapes.class, xDrawPage );
376*cdf0e10cSrcweir 			xShapes.add( xGroup );
377*cdf0e10cSrcweir 
378*cdf0e10cSrcweir 			XShapes xShapesGroup = (XShapes)
379*cdf0e10cSrcweir 				UnoRuntime.queryInterface( XShapes.class, xGroup );
380*cdf0e10cSrcweir 
381*cdf0e10cSrcweir 			Size aPageSize = PageHelper.getPageSize( xDrawPage );
382*cdf0e10cSrcweir 
383*cdf0e10cSrcweir 			int nWidth  = 4000;
384*cdf0e10cSrcweir 			int nHeight = 2000;
385*cdf0e10cSrcweir 			int nPosX = ( aPageSize.Width * 3 ) / 4 - nWidth / 2;
386*cdf0e10cSrcweir 			int nPosY1 = 2000;
387*cdf0e10cSrcweir 			int nPosY2 = aPageSize.Height / 2 - ( nPosY1 + nHeight );
388*cdf0e10cSrcweir 			XShape xRect1 = ShapeHelper.createShape( xDrawDoc,
389*cdf0e10cSrcweir 				new Point( nPosX, nPosY1 ),
390*cdf0e10cSrcweir 					new Size( nWidth, nHeight ),
391*cdf0e10cSrcweir 						"com.sun.star.drawing.EllipseShape" );
392*cdf0e10cSrcweir 			XShape xRect2 = ShapeHelper.createShape( xDrawDoc,
393*cdf0e10cSrcweir 				new Point( nPosX, nPosY2 ),
394*cdf0e10cSrcweir 					new Size( nWidth, nHeight ),
395*cdf0e10cSrcweir 						"com.sun.star.drawing.EllipseShape" );
396*cdf0e10cSrcweir 
397*cdf0e10cSrcweir 			xShapesGroup.add( xRect1 );
398*cdf0e10cSrcweir 			xShapesGroup.add( xRect2 );
399*cdf0e10cSrcweir 		}
400*cdf0e10cSrcweir 		catch ( Exception ex )
401*cdf0e10cSrcweir 		{
402*cdf0e10cSrcweir 			System.out.println( "Demo_Group1:" + ex );
403*cdf0e10cSrcweir 		}
404*cdf0e10cSrcweir 	}
405*cdf0e10cSrcweir 
406*cdf0e10cSrcweir 	// This method will group all available objects on the
407*cdf0e10cSrcweir 	// first page.
408*cdf0e10cSrcweir 	public static void Demo_Group2( XComponent xDrawDoc )
409*cdf0e10cSrcweir 	{
410*cdf0e10cSrcweir 		try
411*cdf0e10cSrcweir 		{
412*cdf0e10cSrcweir 			XDrawPage xDrawPage = PageHelper.getDrawPageByIndex( xDrawDoc, 0 );
413*cdf0e10cSrcweir 			XShapeGrouper xShapeGrouper = (XShapeGrouper)
414*cdf0e10cSrcweir 				UnoRuntime.queryInterface( XShapeGrouper.class, xDrawPage );
415*cdf0e10cSrcweir 
416*cdf0e10cSrcweir 			XShapes xShapesPage = (XShapes)
417*cdf0e10cSrcweir 				UnoRuntime.queryInterface( XShapes.class, xDrawPage );
418*cdf0e10cSrcweir 
419*cdf0e10cSrcweir 			xShapeGrouper.group( xShapesPage );
420*cdf0e10cSrcweir 		}
421*cdf0e10cSrcweir 		catch ( Exception ex )
422*cdf0e10cSrcweir 		{
423*cdf0e10cSrcweir 			System.out.println( "Demo_Group2:" + ex );
424*cdf0e10cSrcweir 		}
425*cdf0e10cSrcweir 	}
426*cdf0e10cSrcweir }
427