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
.drawing
.XShape
;
48 import com
.sun
.star
.drawing
.XShapes
;
49 import com
.sun
.star
.drawing
.XDrawPage
;
53 // __________ Implementation __________
57 public class ChangeOrderDemo
59 public static void main( String args
[] )
61 XComponent xDrawDoc
= null;
64 // get the remote office context of a running office (a new office
65 // instance is started if necessary)
66 com
.sun
.star
.uno
.XComponentContext xOfficeContext
= Helper
.connect();
68 // suppress Presentation Autopilot when opening the document
69 // properties are the same as described for
70 // com.sun.star.document.MediaDescriptor
71 PropertyValue
[] pPropValues
= new PropertyValue
[ 1 ];
72 pPropValues
[ 0 ] = new PropertyValue();
73 pPropValues
[ 0 ].Name
= "Silent";
74 pPropValues
[ 0 ].Value
= Boolean
.TRUE
;
76 xDrawDoc
= Helper
.createDocument( xOfficeContext
,
77 "private:factory/sdraw", "_blank", 0, pPropValues
);
79 // create two rectangles
80 XDrawPage xPage
= PageHelper
.getDrawPageByIndex( xDrawDoc
, 0 );
81 XShapes xShapes
= UnoRuntime
.queryInterface( XShapes
.class, xPage
);
83 XShape xShape1
= ShapeHelper
.createShape( xDrawDoc
,
84 new Point( 1000, 1000 ), new Size( 5000, 5000 ),
85 "com.sun.star.drawing.RectangleShape" );
87 XShape xShape2
= ShapeHelper
.createShape( xDrawDoc
,
88 new Point( 2000, 2000 ), new Size( 5000, 5000 ),
89 "com.sun.star.drawing.EllipseShape" );
91 xShapes
.add( xShape1
);
92 ShapeHelper
.addPortion( xShape1
, " this shape was inserted first", false );
93 ShapeHelper
.addPortion( xShape1
, "by changing the ZOrder it lie now on top", true );
94 xShapes
.add( xShape2
);
96 XPropertySet xPropSet1
= UnoRuntime
.queryInterface( XPropertySet
.class, xShape1
);
97 XPropertySet xPropSet2
= UnoRuntime
.queryInterface( XPropertySet
.class, xShape2
);
99 int nOrderOfShape1
= ((Integer
)xPropSet1
.getPropertyValue( "ZOrder" )).intValue();
100 int nOrderOfShape2
= ((Integer
)xPropSet2
.getPropertyValue( "ZOrder" )).intValue();
102 xPropSet1
.setPropertyValue( "ZOrder", Integer
.valueOf( nOrderOfShape2
) );
103 xPropSet2
.setPropertyValue( "ZOrder", Integer
.valueOf( nOrderOfShape1
) );
105 catch( Exception ex
)
107 System
.out
.println( ex
);
113 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */