1*34dd1e25SAndrew Rist /************************************************************** 2*34dd1e25SAndrew Rist * 3*34dd1e25SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*34dd1e25SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*34dd1e25SAndrew Rist * distributed with this work for additional information 6*34dd1e25SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*34dd1e25SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*34dd1e25SAndrew Rist * "License"); you may not use this file except in compliance 9*34dd1e25SAndrew Rist * with the License. You may obtain a copy of the License at 10*34dd1e25SAndrew Rist * 11*34dd1e25SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*34dd1e25SAndrew Rist * 13*34dd1e25SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*34dd1e25SAndrew Rist * software distributed under the License is distributed on an 15*34dd1e25SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*34dd1e25SAndrew Rist * KIND, either express or implied. See the License for the 17*34dd1e25SAndrew Rist * specific language governing permissions and limitations 18*34dd1e25SAndrew Rist * under the License. 19*34dd1e25SAndrew Rist * 20*34dd1e25SAndrew Rist *************************************************************/ 21*34dd1e25SAndrew Rist 22*34dd1e25SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // __________ Imports __________ 25cdf0e10cSrcweir 26cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime; 27cdf0e10cSrcweir import com.sun.star.lang.XComponent; 28cdf0e10cSrcweir 29cdf0e10cSrcweir import com.sun.star.awt.Point; 30cdf0e10cSrcweir import com.sun.star.awt.Size; 31cdf0e10cSrcweir 32cdf0e10cSrcweir import com.sun.star.beans.PropertyValue; 33cdf0e10cSrcweir import com.sun.star.beans.XPropertySet; 34cdf0e10cSrcweir 35cdf0e10cSrcweir import com.sun.star.drawing.XShape; 36cdf0e10cSrcweir import com.sun.star.drawing.XShapes; 37cdf0e10cSrcweir import com.sun.star.drawing.XDrawPage; 38cdf0e10cSrcweir 39cdf0e10cSrcweir 40cdf0e10cSrcweir 41cdf0e10cSrcweir // __________ Implementation __________ 42cdf0e10cSrcweir 43cdf0e10cSrcweir /** ChangeOrderDemo 44cdf0e10cSrcweir @author Sven Jacobi 45cdf0e10cSrcweir */ 46cdf0e10cSrcweir 47cdf0e10cSrcweir public class ChangeOrderDemo 48cdf0e10cSrcweir { main( String args[] )49cdf0e10cSrcweir public static void main( String args[] ) 50cdf0e10cSrcweir { 51cdf0e10cSrcweir XComponent xDrawDoc = null; 52cdf0e10cSrcweir try 53cdf0e10cSrcweir { 54cdf0e10cSrcweir // get the remote office context of a running office (a new office 55cdf0e10cSrcweir // instance is started if necessary) 56cdf0e10cSrcweir com.sun.star.uno.XComponentContext xOfficeContext = Helper.connect(); 57cdf0e10cSrcweir 58cdf0e10cSrcweir // suppress Presentation Autopilot when opening the document 59cdf0e10cSrcweir // properties are the same as described for 60cdf0e10cSrcweir // com.sun.star.document.MediaDescriptor 61cdf0e10cSrcweir PropertyValue[] pPropValues = new PropertyValue[ 1 ]; 62cdf0e10cSrcweir pPropValues[ 0 ] = new PropertyValue(); 63cdf0e10cSrcweir pPropValues[ 0 ].Name = "Silent"; 64cdf0e10cSrcweir pPropValues[ 0 ].Value = new Boolean( true ); 65cdf0e10cSrcweir 66cdf0e10cSrcweir xDrawDoc = Helper.createDocument( xOfficeContext, 67cdf0e10cSrcweir "private:factory/sdraw", "_blank", 0, pPropValues ); 68cdf0e10cSrcweir 69cdf0e10cSrcweir // create two rectangles 70cdf0e10cSrcweir XDrawPage xPage = PageHelper.getDrawPageByIndex( xDrawDoc, 0 ); 71cdf0e10cSrcweir XShapes xShapes = (XShapes) 72cdf0e10cSrcweir UnoRuntime.queryInterface( XShapes.class, xPage ); 73cdf0e10cSrcweir 74cdf0e10cSrcweir XShape xShape1 = ShapeHelper.createShape( xDrawDoc, 75cdf0e10cSrcweir new Point( 1000, 1000 ), new Size( 5000, 5000 ), 76cdf0e10cSrcweir "com.sun.star.drawing.RectangleShape" ); 77cdf0e10cSrcweir 78cdf0e10cSrcweir XShape xShape2 = ShapeHelper.createShape( xDrawDoc, 79cdf0e10cSrcweir new Point( 2000, 2000 ), new Size( 5000, 5000 ), 80cdf0e10cSrcweir "com.sun.star.drawing.EllipseShape" ); 81cdf0e10cSrcweir 82cdf0e10cSrcweir xShapes.add( xShape1 ); 83cdf0e10cSrcweir ShapeHelper.addPortion( xShape1, " this shape was inserted first", false ); 84cdf0e10cSrcweir ShapeHelper.addPortion( xShape1, "by changing the ZOrder it lie now on top", true ); 85cdf0e10cSrcweir xShapes.add( xShape2 ); 86cdf0e10cSrcweir 87cdf0e10cSrcweir XPropertySet xPropSet1 = (XPropertySet) 88cdf0e10cSrcweir UnoRuntime.queryInterface( XPropertySet.class, xShape1 ); 89cdf0e10cSrcweir XPropertySet xPropSet2 = (XPropertySet) 90cdf0e10cSrcweir UnoRuntime.queryInterface( XPropertySet.class, xShape2 ); 91cdf0e10cSrcweir 92cdf0e10cSrcweir int nOrderOfShape1 = ((Integer)xPropSet1.getPropertyValue( "ZOrder" )).intValue(); 93cdf0e10cSrcweir int nOrderOfShape2 = ((Integer)xPropSet2.getPropertyValue( "ZOrder" )).intValue(); 94cdf0e10cSrcweir 95cdf0e10cSrcweir xPropSet1.setPropertyValue( "ZOrder", new Integer( nOrderOfShape2 ) ); 96cdf0e10cSrcweir xPropSet2.setPropertyValue( "ZOrder", new Integer( nOrderOfShape1 ) ); 97cdf0e10cSrcweir } 98cdf0e10cSrcweir catch( Exception ex ) 99cdf0e10cSrcweir { 100cdf0e10cSrcweir System.out.println( ex ); 101cdf0e10cSrcweir } 102cdf0e10cSrcweir System.exit( 0 ); 103cdf0e10cSrcweir } 104cdf0e10cSrcweir } 105