1 /*************************************************************************
3 * $RCSfile: LayerDemo.java,v $
7 * last change: $Author: rt $ $Date: 2005-01-31 16:23:20 $
9 * The Contents of this file are made available subject to the terms of
12 * Copyright (c) 2003 by Sun Microsystems, Inc.
13 * All rights reserved.
15 * Redistribution and use in source and binary forms, with or without
16 * modification, are permitted provided that the following conditions
18 * 1. Redistributions of source code must retain the above copyright
19 * notice, this list of conditions and the following disclaimer.
20 * 2. Redistributions in binary form must reproduce the above copyright
21 * notice, this list of conditions and the following disclaimer in the
22 * documentation and/or other materials provided with the distribution.
23 * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
24 * contributors may be used to endorse or promote products derived
25 * from this software without specific prior written permission.
27 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
30 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
31 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
32 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
33 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
34 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
35 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
36 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
37 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 *************************************************************************/
41 // __________ Imports __________
43 import com
.sun
.star
.uno
.UnoRuntime
;
44 import com
.sun
.star
.lang
.XComponent
;
46 import com
.sun
.star
.awt
.Point
;
47 import com
.sun
.star
.awt
.Size
;
49 import com
.sun
.star
.beans
.PropertyValue
;
50 import com
.sun
.star
.beans
.XPropertySet
;
52 import com
.sun
.star
.container
.XNameAccess
;
54 import com
.sun
.star
.style
.ParagraphAdjust
;
56 import com
.sun
.star
.drawing
.XShape
;
57 import com
.sun
.star
.drawing
.XShapes
;
58 import com
.sun
.star
.drawing
.XDrawPage
;
59 import com
.sun
.star
.drawing
.XLayer
;
60 import com
.sun
.star
.drawing
.XLayerManager
;
61 import com
.sun
.star
.drawing
.XLayerSupplier
;
64 // __________ Implementation __________
70 public class LayerDemo
72 public static void main( String args
[] )
74 XComponent xDrawDoc
= null;
77 // get the remote office context of a running office (a new office
78 // instance is started if necessary)
79 com
.sun
.star
.uno
.XComponentContext xOfficeContext
= Helper
.connect();
81 // suppress Presentation Autopilot when opening the document
82 // properties are the same as described for
83 // com.sun.star.document.MediaDescriptor
84 PropertyValue
[] pPropValues
= new PropertyValue
[ 1 ];
85 pPropValues
[ 0 ] = new PropertyValue();
86 pPropValues
[ 0 ].Name
= "Silent";
87 pPropValues
[ 0 ].Value
= new Boolean( true );
89 xDrawDoc
= Helper
.createDocument( xOfficeContext
,
90 "private:factory/sdraw", "_blank", 0, pPropValues
);
93 // create two rectangles
94 XDrawPage xPage
= PageHelper
.getDrawPageByIndex( xDrawDoc
, 0 );
95 XShapes xShapes
= (XShapes
)
96 UnoRuntime
.queryInterface( XShapes
.class, xPage
);
98 XShape xRect1
= ShapeHelper
.createShape( xDrawDoc
,
99 new Point( 1000, 1000 ), new Size( 5000, 5000 ),
100 "com.sun.star.drawing.RectangleShape" );
102 XShape xRect2
= ShapeHelper
.createShape( xDrawDoc
,
103 new Point( 1000, 7000 ), new Size( 5000, 5000 ),
104 "com.sun.star.drawing.RectangleShape" );
106 xShapes
.add( xRect1
);
107 xShapes
.add( xRect2
);
108 XPropertySet xTextProp
= ShapeHelper
.addPortion( xRect2
,
109 "this shape is locked",
111 xTextProp
.setPropertyValue( "ParaAdjust", ParagraphAdjust
.CENTER
);
112 ShapeHelper
.addPortion( xRect2
, "and the shape above is not visible",
114 ShapeHelper
.addPortion( xRect2
,
115 "(switch to the layer view to gain access)",
119 // query for the XLayerManager
120 XLayerSupplier xLayerSupplier
= (XLayerSupplier
)
121 (XLayerSupplier
)UnoRuntime
.queryInterface(
122 XLayerSupplier
.class, xDrawDoc
);
123 XNameAccess xNameAccess
= xLayerSupplier
.getLayerManager();
124 XLayerManager xLayerManager
= (XLayerManager
)
125 (XLayerManager
)UnoRuntime
.queryInterface(
126 XLayerManager
.class, xNameAccess
);
128 // create a layer and set its properties
129 XPropertySet xLayerPropSet
;
130 XLayer xNotVisibleAndEditable
= xLayerManager
.insertNewByIndex(
131 xLayerManager
.getCount() );
133 xLayerPropSet
= (XPropertySet
)
134 (XPropertySet
)UnoRuntime
.queryInterface(
135 XPropertySet
.class, xNotVisibleAndEditable
);
136 xLayerPropSet
.setPropertyValue( "Name", "NotVisibleAndEditable" );
137 xLayerPropSet
.setPropertyValue( "IsVisible", new Boolean( false ) );
138 xLayerPropSet
.setPropertyValue( "IsLocked", new Boolean( true ) );
140 // create a second layer
141 XLayer xNotEditable
= xLayerManager
.insertNewByIndex(
142 xLayerManager
.getCount() );
144 xLayerPropSet
= (XPropertySet
)
145 (XPropertySet
)UnoRuntime
.queryInterface(
146 XPropertySet
.class, xNotEditable
);
147 xLayerPropSet
.setPropertyValue( "Name", "NotEditable" );
148 xLayerPropSet
.setPropertyValue( "IsVisible", new Boolean( true ) );
149 xLayerPropSet
.setPropertyValue( "IsLocked", new Boolean( true ) );
151 // attach the layer to the rectangles
152 xLayerManager
.attachShapeToLayer( xRect1
, xNotVisibleAndEditable
);
153 xLayerManager
.attachShapeToLayer( xRect2
, xNotEditable
);
156 catch( Exception ex
)
158 System
.out
.println( ex
);