1 /************************************************************************* 2 * 3 * The Contents of this file are made available subject to the terms of 4 * the BSD license. 5 * 6 * Copyright 2000, 2010 Oracle and/or its affiliates. 7 * All rights reserved. 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions 11 * are met: 12 * 1. Redistributions of source code must retain the above copyright 13 * notice, this list of conditions and the following disclaimer. 14 * 2. Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in the 16 * documentation and/or other materials provided with the distribution. 17 * 3. Neither the name of Sun Microsystems, Inc. nor the names of its 18 * contributors may be used to endorse or promote products derived 19 * from this software without specific prior written permission. 20 * 21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 25 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 28 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 29 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 30 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 31 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 * 33 *************************************************************************/ 34 35 // __________ Imports __________ 36 37 import com.sun.star.uno.UnoRuntime; 38 import com.sun.star.lang.XComponent; 39 40 import com.sun.star.awt.Point; 41 import com.sun.star.awt.Size; 42 43 import com.sun.star.beans.PropertyValue; 44 import com.sun.star.beans.XPropertySet; 45 46 import com.sun.star.drawing.XShape; 47 import com.sun.star.drawing.XShapes; 48 import com.sun.star.drawing.XDrawPage; 49 50 51 52 // __________ Implementation __________ 53 54 /** ChangeOrderDemo 55 @author Sven Jacobi 56 */ 57 58 public class ChangeOrderDemo 59 { 60 public static void main( String args[] ) 61 { 62 XComponent xDrawDoc = null; 63 try 64 { 65 // get the remote office context of a running office (a new office 66 // instance is started if necessary) 67 com.sun.star.uno.XComponentContext xOfficeContext = Helper.connect(); 68 69 // suppress Presentation Autopilot when opening the document 70 // properties are the same as described for 71 // com.sun.star.document.MediaDescriptor 72 PropertyValue[] pPropValues = new PropertyValue[ 1 ]; 73 pPropValues[ 0 ] = new PropertyValue(); 74 pPropValues[ 0 ].Name = "Silent"; 75 pPropValues[ 0 ].Value = new Boolean( true ); 76 77 xDrawDoc = Helper.createDocument( xOfficeContext, 78 "private:factory/sdraw", "_blank", 0, pPropValues ); 79 80 // create two rectangles 81 XDrawPage xPage = PageHelper.getDrawPageByIndex( xDrawDoc, 0 ); 82 XShapes xShapes = (XShapes) 83 UnoRuntime.queryInterface( XShapes.class, xPage ); 84 85 XShape xShape1 = ShapeHelper.createShape( xDrawDoc, 86 new Point( 1000, 1000 ), new Size( 5000, 5000 ), 87 "com.sun.star.drawing.RectangleShape" ); 88 89 XShape xShape2 = ShapeHelper.createShape( xDrawDoc, 90 new Point( 2000, 2000 ), new Size( 5000, 5000 ), 91 "com.sun.star.drawing.EllipseShape" ); 92 93 xShapes.add( xShape1 ); 94 ShapeHelper.addPortion( xShape1, " this shape was inserted first", false ); 95 ShapeHelper.addPortion( xShape1, "by changing the ZOrder it lie now on top", true ); 96 xShapes.add( xShape2 ); 97 98 XPropertySet xPropSet1 = (XPropertySet) 99 UnoRuntime.queryInterface( XPropertySet.class, xShape1 ); 100 XPropertySet xPropSet2 = (XPropertySet) 101 UnoRuntime.queryInterface( XPropertySet.class, xShape2 ); 102 103 int nOrderOfShape1 = ((Integer)xPropSet1.getPropertyValue( "ZOrder" )).intValue(); 104 int nOrderOfShape2 = ((Integer)xPropSet2.getPropertyValue( "ZOrder" )).intValue(); 105 106 xPropSet1.setPropertyValue( "ZOrder", new Integer( nOrderOfShape2 ) ); 107 xPropSet2.setPropertyValue( "ZOrder", new Integer( nOrderOfShape1 ) ); 108 } 109 catch( Exception ex ) 110 { 111 System.out.println( ex ); 112 } 113 System.exit( 0 ); 114 } 115 } 116