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 
29 import com.sun.star.awt.Point;
30 import com.sun.star.awt.Size;
31 
32 import com.sun.star.beans.PropertyValue;
33 import com.sun.star.beans.XPropertySet;
34 
35 import com.sun.star.drawing.XShape;
36 import com.sun.star.drawing.XShapes;
37 import com.sun.star.drawing.XDrawPage;
38 
39 
40 
41 // __________ Implementation __________
42 
43 /** ChangeOrderDemo
44     @author Sven Jacobi
45  */
46 
47 public class ChangeOrderDemo
48 {
main( String args[] )49     public static void main( String args[] )
50     {
51 		XComponent xDrawDoc = null;
52 		try
53 		{
54             // get the remote office context of a running office (a new office
55             // instance is started if necessary)
56 			com.sun.star.uno.XComponentContext xOfficeContext = Helper.connect();
57 
58 			// suppress Presentation Autopilot when opening the document
59 			// properties are the same as described for
60 			// com.sun.star.document.MediaDescriptor
61 			PropertyValue[] pPropValues = new PropertyValue[ 1 ];
62 			pPropValues[ 0 ] = new PropertyValue();
63 			pPropValues[ 0 ].Name = "Silent";
64 			pPropValues[ 0 ].Value = new Boolean( true );
65 
66 			xDrawDoc = Helper.createDocument( xOfficeContext,
67 				"private:factory/sdraw", "_blank", 0, pPropValues );
68 
69 			// create two rectangles
70 			XDrawPage xPage = PageHelper.getDrawPageByIndex( xDrawDoc, 0 );
71 			XShapes xShapes = (XShapes)
72 					UnoRuntime.queryInterface( XShapes.class, xPage );
73 
74 			XShape xShape1 = ShapeHelper.createShape( xDrawDoc,
75 				new Point( 1000, 1000 ), new Size( 5000, 5000 ),
76 					"com.sun.star.drawing.RectangleShape" );
77 
78 			XShape xShape2 = ShapeHelper.createShape( xDrawDoc,
79 				new Point( 2000, 2000 ), new Size( 5000, 5000 ),
80 					"com.sun.star.drawing.EllipseShape" );
81 
82 			xShapes.add( xShape1 );
83 			ShapeHelper.addPortion( xShape1, "     this shape was inserted first", false );
84 			ShapeHelper.addPortion( xShape1, "by changing the ZOrder it lie now on top", true );
85 			xShapes.add( xShape2 );
86 
87 			XPropertySet xPropSet1 = (XPropertySet)
88 					UnoRuntime.queryInterface( XPropertySet.class, xShape1 );
89 			XPropertySet xPropSet2 = (XPropertySet)
90 					UnoRuntime.queryInterface( XPropertySet.class, xShape2 );
91 
92 			int nOrderOfShape1 = ((Integer)xPropSet1.getPropertyValue( "ZOrder" )).intValue();
93 			int nOrderOfShape2 = ((Integer)xPropSet2.getPropertyValue( "ZOrder" )).intValue();
94 
95 			xPropSet1.setPropertyValue( "ZOrder", new Integer( nOrderOfShape2 ) );
96 			xPropSet2.setPropertyValue( "ZOrder", new Integer( nOrderOfShape1 ) );
97 		}
98 		catch( Exception ex )
99 		{
100             System.out.println( ex );
101 		}
102 		System.exit( 0 );
103     }
104 }
105