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