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.container.XNameAccess; 47 48 import com.sun.star.style.ParagraphAdjust; 49 50 import com.sun.star.drawing.XShape; 51 import com.sun.star.drawing.XShapes; 52 import com.sun.star.drawing.XDrawPage; 53 import com.sun.star.drawing.XLayer; 54 import com.sun.star.drawing.XLayerManager; 55 import com.sun.star.drawing.XLayerSupplier; 56 57 58 // __________ Implementation __________ 59 60 /** LayerDemo 61 @author Sven Jacobi 62 */ 63 64 public class LayerDemo 65 { 66 public static void main( String args[] ) 67 { 68 XComponent xDrawDoc = null; 69 try 70 { 71 // get the remote office context of a running office (a new office 72 // instance is started if necessary) 73 com.sun.star.uno.XComponentContext xOfficeContext = Helper.connect(); 74 75 // suppress Presentation Autopilot when opening the document 76 // properties are the same as described for 77 // com.sun.star.document.MediaDescriptor 78 PropertyValue[] pPropValues = new PropertyValue[ 1 ]; 79 pPropValues[ 0 ] = new PropertyValue(); 80 pPropValues[ 0 ].Name = "Silent"; 81 pPropValues[ 0 ].Value = new Boolean( true ); 82 83 xDrawDoc = Helper.createDocument( xOfficeContext, 84 "private:factory/sdraw", "_blank", 0, pPropValues ); 85 86 87 // create two rectangles 88 XDrawPage xPage = PageHelper.getDrawPageByIndex( xDrawDoc, 0 ); 89 XShapes xShapes = (XShapes) 90 UnoRuntime.queryInterface( XShapes.class, xPage ); 91 92 XShape xRect1 = ShapeHelper.createShape( xDrawDoc, 93 new Point( 1000, 1000 ), new Size( 5000, 5000 ), 94 "com.sun.star.drawing.RectangleShape" ); 95 96 XShape xRect2 = ShapeHelper.createShape( xDrawDoc, 97 new Point( 1000, 7000 ), new Size( 5000, 5000 ), 98 "com.sun.star.drawing.RectangleShape" ); 99 100 xShapes.add( xRect1 ); 101 xShapes.add( xRect2 ); 102 XPropertySet xTextProp = ShapeHelper.addPortion( xRect2, 103 "this shape is locked", 104 false ); 105 xTextProp.setPropertyValue( "ParaAdjust", ParagraphAdjust.CENTER ); 106 ShapeHelper.addPortion( xRect2, "and the shape above is not visible", 107 true ); 108 ShapeHelper.addPortion( xRect2, 109 "(switch to the layer view to gain access)", 110 true ); 111 112 113 // query for the XLayerManager 114 XLayerSupplier xLayerSupplier = (XLayerSupplier) 115 (XLayerSupplier)UnoRuntime.queryInterface( 116 XLayerSupplier.class, xDrawDoc ); 117 XNameAccess xNameAccess = xLayerSupplier.getLayerManager(); 118 XLayerManager xLayerManager = (XLayerManager) 119 (XLayerManager)UnoRuntime.queryInterface( 120 XLayerManager.class, xNameAccess ); 121 122 // create a layer and set its properties 123 XPropertySet xLayerPropSet; 124 XLayer xNotVisibleAndEditable = xLayerManager.insertNewByIndex( 125 xLayerManager.getCount() ); 126 127 xLayerPropSet = (XPropertySet) 128 (XPropertySet)UnoRuntime.queryInterface( 129 XPropertySet.class, xNotVisibleAndEditable ); 130 xLayerPropSet.setPropertyValue( "Name", "NotVisibleAndEditable" ); 131 xLayerPropSet.setPropertyValue( "IsVisible", new Boolean( false ) ); 132 xLayerPropSet.setPropertyValue( "IsLocked", new Boolean( true ) ); 133 134 // create a second layer 135 XLayer xNotEditable = xLayerManager.insertNewByIndex( 136 xLayerManager.getCount() ); 137 138 xLayerPropSet = (XPropertySet) 139 (XPropertySet)UnoRuntime.queryInterface( 140 XPropertySet.class, xNotEditable ); 141 xLayerPropSet.setPropertyValue( "Name", "NotEditable" ); 142 xLayerPropSet.setPropertyValue( "IsVisible", new Boolean( true ) ); 143 xLayerPropSet.setPropertyValue( "IsLocked", new Boolean( true ) ); 144 145 // attach the layer to the rectangles 146 xLayerManager.attachShapeToLayer( xRect1, xNotVisibleAndEditable ); 147 xLayerManager.attachShapeToLayer( xRect2, xNotEditable ); 148 149 } 150 catch( Exception ex ) 151 { 152 System.out.println( ex ); 153 } 154 System.exit( 0 ); 155 } 156 } 157