1 /*************************************************************************
3 * The Contents of this file are made available subject to the terms of
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
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.
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.
33 *************************************************************************/
35 // __________ Imports __________
37 import com
.sun
.star
.uno
.UnoRuntime
;
38 import com
.sun
.star
.lang
.XComponent
;
40 import com
.sun
.star
.awt
.Point
;
41 import com
.sun
.star
.awt
.Size
;
43 import com
.sun
.star
.beans
.PropertyValue
;
44 import com
.sun
.star
.beans
.XPropertySet
;
46 import com
.sun
.star
.container
.XNameAccess
;
48 import com
.sun
.star
.style
.ParagraphAdjust
;
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
;
58 // __________ Implementation __________
62 public class LayerDemo
64 public static void main( String args
[] )
66 XComponent xDrawDoc
= null;
69 // get the remote office context of a running office (a new office
70 // instance is started if necessary)
71 com
.sun
.star
.uno
.XComponentContext xOfficeContext
= Helper
.connect();
73 // suppress Presentation Autopilot when opening the document
74 // properties are the same as described for
75 // com.sun.star.document.MediaDescriptor
76 PropertyValue
[] pPropValues
= new PropertyValue
[ 1 ];
77 pPropValues
[ 0 ] = new PropertyValue();
78 pPropValues
[ 0 ].Name
= "Silent";
79 pPropValues
[ 0 ].Value
= Boolean
.TRUE
;
81 xDrawDoc
= Helper
.createDocument( xOfficeContext
,
82 "private:factory/sdraw", "_blank", 0, pPropValues
);
85 // create two rectangles
86 XDrawPage xPage
= PageHelper
.getDrawPageByIndex( xDrawDoc
, 0 );
87 XShapes xShapes
= UnoRuntime
.queryInterface( XShapes
.class, xPage
);
89 XShape xRect1
= ShapeHelper
.createShape( xDrawDoc
,
90 new Point( 1000, 1000 ), new Size( 5000, 5000 ),
91 "com.sun.star.drawing.RectangleShape" );
93 XShape xRect2
= ShapeHelper
.createShape( xDrawDoc
,
94 new Point( 1000, 7000 ), new Size( 5000, 5000 ),
95 "com.sun.star.drawing.RectangleShape" );
97 xShapes
.add( xRect1
);
98 xShapes
.add( xRect2
);
99 XPropertySet xTextProp
= ShapeHelper
.addPortion( xRect2
,
100 "this shape is locked",
102 xTextProp
.setPropertyValue( "ParaAdjust", ParagraphAdjust
.CENTER
);
103 ShapeHelper
.addPortion( xRect2
, "and the shape above is not visible",
105 ShapeHelper
.addPortion( xRect2
,
106 "(switch to the layer view to gain access)",
110 // query for the XLayerManager
111 XLayerSupplier xLayerSupplier
= UnoRuntime
.queryInterface(
112 XLayerSupplier
.class, xDrawDoc
);
113 XNameAccess xNameAccess
= xLayerSupplier
.getLayerManager();
114 XLayerManager xLayerManager
= UnoRuntime
.queryInterface(
115 XLayerManager
.class, xNameAccess
);
117 // create a layer and set its properties
118 XPropertySet xLayerPropSet
;
119 XLayer xNotVisibleAndEditable
= xLayerManager
.insertNewByIndex(
120 xLayerManager
.getCount() );
122 xLayerPropSet
= UnoRuntime
.queryInterface(
123 XPropertySet
.class, xNotVisibleAndEditable
);
124 xLayerPropSet
.setPropertyValue( "Name", "NotVisibleAndEditable" );
125 xLayerPropSet
.setPropertyValue( "IsVisible", Boolean
.FALSE
);
126 xLayerPropSet
.setPropertyValue( "IsLocked", Boolean
.TRUE
);
128 // create a second layer
129 XLayer xNotEditable
= xLayerManager
.insertNewByIndex(
130 xLayerManager
.getCount() );
132 xLayerPropSet
= UnoRuntime
.queryInterface(
133 XPropertySet
.class, xNotEditable
);
134 xLayerPropSet
.setPropertyValue( "Name", "NotEditable" );
135 xLayerPropSet
.setPropertyValue( "IsVisible", Boolean
.TRUE
);
136 xLayerPropSet
.setPropertyValue( "IsLocked", Boolean
.TRUE
);
138 // attach the layer to the rectangles
139 xLayerManager
.attachShapeToLayer( xRect1
, xNotVisibleAndEditable
);
140 xLayerManager
.attachShapeToLayer( xRect2
, xNotEditable
);
143 catch( Exception ex
)
145 System
.out
.println( ex
);