1 /*************************************************************************
3 * $RCSfile: ChangeOrderDemo.java,v $
7 * last change: $Author: rt $ $Date: 2005-01-31 16:21:03 $
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
.drawing
.XShape
;
53 import com
.sun
.star
.drawing
.XShapes
;
54 import com
.sun
.star
.drawing
.XDrawPage
;
58 // __________ Implementation __________
64 public class ChangeOrderDemo
66 public static void main( String args
[] )
68 XComponent xDrawDoc
= null;
71 // get the remote office context of a running office (a new office
72 // instance is started if necessary)
73 com
.sun
.star
.uno
.XComponentContext xOfficeContext
= Helper
.connect();
75 // suppress Presentation Autopilot when opening the document
76 // properties are the same as described for
77 // com.sun.star.document.MediaDescriptor
78 PropertyValue
[] pPropValues
= new PropertyValue
[ 1 ];
79 pPropValues
[ 0 ] = new PropertyValue();
80 pPropValues
[ 0 ].Name
= "Silent";
81 pPropValues
[ 0 ].Value
= new Boolean( true );
83 xDrawDoc
= Helper
.createDocument( xOfficeContext
,
84 "private:factory/sdraw", "_blank", 0, pPropValues
);
86 // create two rectangles
87 XDrawPage xPage
= PageHelper
.getDrawPageByIndex( xDrawDoc
, 0 );
88 XShapes xShapes
= (XShapes
)
89 UnoRuntime
.queryInterface( XShapes
.class, xPage
);
91 XShape xShape1
= ShapeHelper
.createShape( xDrawDoc
,
92 new Point( 1000, 1000 ), new Size( 5000, 5000 ),
93 "com.sun.star.drawing.RectangleShape" );
95 XShape xShape2
= ShapeHelper
.createShape( xDrawDoc
,
96 new Point( 2000, 2000 ), new Size( 5000, 5000 ),
97 "com.sun.star.drawing.EllipseShape" );
99 xShapes
.add( xShape1
);
100 ShapeHelper
.addPortion( xShape1
, " this shape was inserted first", false );
101 ShapeHelper
.addPortion( xShape1
, "by changing the ZOrder it lie now on top", true );
102 xShapes
.add( xShape2
);
104 XPropertySet xPropSet1
= (XPropertySet
)
105 UnoRuntime
.queryInterface( XPropertySet
.class, xShape1
);
106 XPropertySet xPropSet2
= (XPropertySet
)
107 UnoRuntime
.queryInterface( XPropertySet
.class, xShape2
);
109 int nOrderOfShape1
= ((Integer
)xPropSet1
.getPropertyValue( "ZOrder" )).intValue();
110 int nOrderOfShape2
= ((Integer
)xPropSet2
.getPropertyValue( "ZOrder" )).intValue();
112 xPropSet1
.setPropertyValue( "ZOrder", new Integer( nOrderOfShape2
) );
113 xPropSet2
.setPropertyValue( "ZOrder", new Integer( nOrderOfShape1
) );
115 catch( Exception ex
)
117 System
.out
.println( ex
);