1 /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * The Contents of this file are made available subject to the terms of
7 * Copyright 2000, 2010 Oracle and/or its affiliates.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
19 * contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
29 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
30 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
31 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
32 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 *************************************************************************/
36 // __________ Imports __________
38 import com
.sun
.star
.uno
.UnoRuntime
;
39 import com
.sun
.star
.lang
.XComponent
;
41 import com
.sun
.star
.awt
.Point
;
42 import com
.sun
.star
.awt
.Size
;
44 import com
.sun
.star
.beans
.PropertyValue
;
45 import com
.sun
.star
.beans
.XPropertySet
;
47 import com
.sun
.star
.container
.XNameAccess
;
49 import com
.sun
.star
.style
.ParagraphAdjust
;
51 import com
.sun
.star
.drawing
.XShape
;
52 import com
.sun
.star
.drawing
.XShapes
;
53 import com
.sun
.star
.drawing
.XDrawPage
;
54 import com
.sun
.star
.drawing
.XLayer
;
55 import com
.sun
.star
.drawing
.XLayerManager
;
56 import com
.sun
.star
.drawing
.XLayerSupplier
;
59 // __________ Implementation __________
63 public class LayerDemo
65 public static void main( String args
[] )
67 XComponent xDrawDoc
= null;
70 // get the remote office context of a running office (a new office
71 // instance is started if necessary)
72 com
.sun
.star
.uno
.XComponentContext xOfficeContext
= Helper
.connect();
74 // suppress Presentation Autopilot when opening the document
75 // properties are the same as described for
76 // com.sun.star.document.MediaDescriptor
77 PropertyValue
[] pPropValues
= new PropertyValue
[ 1 ];
78 pPropValues
[ 0 ] = new PropertyValue();
79 pPropValues
[ 0 ].Name
= "Silent";
80 pPropValues
[ 0 ].Value
= Boolean
.TRUE
;
82 xDrawDoc
= Helper
.createDocument( xOfficeContext
,
83 "private:factory/sdraw", "_blank", 0, pPropValues
);
86 // create two rectangles
87 XDrawPage xPage
= PageHelper
.getDrawPageByIndex( xDrawDoc
, 0 );
88 XShapes xShapes
= UnoRuntime
.queryInterface( XShapes
.class, xPage
);
90 XShape xRect1
= ShapeHelper
.createShape( xDrawDoc
,
91 new Point( 1000, 1000 ), new Size( 5000, 5000 ),
92 "com.sun.star.drawing.RectangleShape" );
94 XShape xRect2
= ShapeHelper
.createShape( xDrawDoc
,
95 new Point( 1000, 7000 ), new Size( 5000, 5000 ),
96 "com.sun.star.drawing.RectangleShape" );
98 xShapes
.add( xRect1
);
99 xShapes
.add( xRect2
);
100 XPropertySet xTextProp
= ShapeHelper
.addPortion( xRect2
,
101 "this shape is locked",
103 xTextProp
.setPropertyValue( "ParaAdjust", ParagraphAdjust
.CENTER
);
104 ShapeHelper
.addPortion( xRect2
, "and the shape above is not visible",
106 ShapeHelper
.addPortion( xRect2
,
107 "(switch to the layer view to gain access)",
111 // query for the XLayerManager
112 XLayerSupplier xLayerSupplier
= UnoRuntime
.queryInterface(
113 XLayerSupplier
.class, xDrawDoc
);
114 XNameAccess xNameAccess
= xLayerSupplier
.getLayerManager();
115 XLayerManager xLayerManager
= UnoRuntime
.queryInterface(
116 XLayerManager
.class, xNameAccess
);
118 // create a layer and set its properties
119 XPropertySet xLayerPropSet
;
120 XLayer xNotVisibleAndEditable
= xLayerManager
.insertNewByIndex(
121 xLayerManager
.getCount() );
123 xLayerPropSet
= UnoRuntime
.queryInterface(
124 XPropertySet
.class, xNotVisibleAndEditable
);
125 xLayerPropSet
.setPropertyValue( "Name", "NotVisibleAndEditable" );
126 xLayerPropSet
.setPropertyValue( "IsVisible", Boolean
.FALSE
);
127 xLayerPropSet
.setPropertyValue( "IsLocked", Boolean
.TRUE
);
129 // create a second layer
130 XLayer xNotEditable
= xLayerManager
.insertNewByIndex(
131 xLayerManager
.getCount() );
133 xLayerPropSet
= UnoRuntime
.queryInterface(
134 XPropertySet
.class, xNotEditable
);
135 xLayerPropSet
.setPropertyValue( "Name", "NotEditable" );
136 xLayerPropSet
.setPropertyValue( "IsVisible", Boolean
.TRUE
);
137 xLayerPropSet
.setPropertyValue( "IsLocked", Boolean
.TRUE
);
139 // attach the layer to the rectangles
140 xLayerManager
.attachShapeToLayer( xRect1
, xNotVisibleAndEditable
);
141 xLayerManager
.attachShapeToLayer( xRect2
, xNotEditable
);
144 catch( Exception ex
)
146 System
.out
.println( ex
);
152 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */