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