merge the formfield patch from ooo-build
[ooovba.git] / odk / examples / DevelopersGuide / Drawing / GluePointDemo.java
blob38f8a2224b2a832a1873530bcee5feac046072b2
1 /*************************************************************************
3 * $RCSfile: GluePointDemo.java,v $
5 * $Revision: 1.5 $
7 * last change: $Author: rt $ $Date: 2005-01-31 16:22:38 $
9 * The Contents of this file are made available subject to the terms of
10 * the BSD license.
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
17 * are met:
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.XIndexContainer;
53 import com.sun.star.container.XIdentifierContainer;
55 import com.sun.star.drawing.Alignment;
56 import com.sun.star.drawing.EscapeDirection;
57 import com.sun.star.drawing.GluePoint2;
58 import com.sun.star.drawing.XShape;
59 import com.sun.star.drawing.XShapes;
60 import com.sun.star.drawing.XDrawPage;
61 import com.sun.star.drawing.XGluePointsSupplier;
65 // __________ Implementation __________
67 /** GluePointDemo
68 @author Sven Jacobi
71 public class GluePointDemo
73 public static void main( String args[] )
75 XComponent xDrawDoc = null;
76 try
78 // get the remote office context of a running office (a new office
79 // instance is started if necessary)
80 com.sun.star.uno.XComponentContext xOfficeContext = Helper.connect();
82 // suppress Presentation Autopilot when opening the document
83 // properties are the same as described for
84 // com.sun.star.document.MediaDescriptor
85 PropertyValue[] pPropValues = new PropertyValue[ 1 ];
86 pPropValues[ 0 ] = new PropertyValue();
87 pPropValues[ 0 ].Name = "Silent";
88 pPropValues[ 0 ].Value = new Boolean( true );
90 xDrawDoc = Helper.createDocument( xOfficeContext,
91 "private:factory/sdraw", "_blank", 0, pPropValues );
94 XDrawPage xPage = PageHelper.getDrawPageByIndex( xDrawDoc, 0 );
95 XShapes xShapes = (XShapes)
96 UnoRuntime.queryInterface( XShapes.class, xPage );
98 // create two rectangles
99 XShape xShape1 = ShapeHelper.createShape( xDrawDoc,
100 new Point( 15000, 1000 ), new Size( 5000, 5000 ),
101 "com.sun.star.drawing.RectangleShape" );
103 XShape xShape2 = ShapeHelper.createShape( xDrawDoc,
104 new Point( 2000, 15000 ), new Size( 5000, 5000 ),
105 "com.sun.star.drawing.EllipseShape" );
107 // and a connector
108 XShape xConnector = ShapeHelper.createShape( xDrawDoc,
109 new Point( 0, 0 ),
110 new Size( 0, 0 ),
111 "com.sun.star.drawing.ConnectorShape" );
113 xShapes.add( xShape1 );
114 xShapes.add( xShape2 );
115 xShapes.add( xConnector );
117 XPropertySet xConnectorPropSet = (XPropertySet)
118 UnoRuntime.queryInterface( XPropertySet.class, xConnector );
120 // Index value of 0 : the shape is connected at the top
121 // Index value of 1 : the shape is connected at the left
122 // Index value of 2 : the shape is connected at the bottom
123 // Index value of 3 : the shape is connected at the right
125 int nStartIndex = 3;
126 int nEndIndex = 1;
128 // the "StartPosition" or "EndPosition" property needs not to be set
129 // if there is a shape to connect
130 xConnectorPropSet.setPropertyValue( "StartShape", xShape1 );
131 xConnectorPropSet.setPropertyValue( "StartGluePointIndex",
132 new Integer( nStartIndex ) );
134 xConnectorPropSet.setPropertyValue( "EndShape", xShape2 );
135 xConnectorPropSet.setPropertyValue( "EndGluePointIndex",
136 new Integer( nEndIndex ) );
138 XGluePointsSupplier xGluePointsSupplier;
139 XIndexContainer xIndexContainer;
140 XIdentifierContainer xIdentifierContainer;
142 GluePoint2 aGluePoint = new GluePoint2();
143 aGluePoint.IsRelative = false;
144 aGluePoint.PositionAlignment = Alignment.CENTER;
145 aGluePoint.Escape = EscapeDirection.SMART;
146 aGluePoint.IsUserDefined = true;
147 aGluePoint.Position.X = 0;
148 aGluePoint.Position.Y = 0;
150 // create and insert a glue point at shape1
151 xGluePointsSupplier = (XGluePointsSupplier)
152 UnoRuntime.queryInterface( XGluePointsSupplier.class, xShape1 );
153 xIndexContainer = xGluePointsSupplier.getGluePoints();
154 xIdentifierContainer = (XIdentifierContainer)
155 UnoRuntime.queryInterface( XIdentifierContainer.class,
156 xIndexContainer );
157 int nIndexOfGluePoint1 = xIdentifierContainer.insert( aGluePoint );
159 // create and insert a glue point at shape2
160 xGluePointsSupplier = (XGluePointsSupplier)
161 UnoRuntime.queryInterface( XGluePointsSupplier.class, xShape2 );
162 xIndexContainer = xGluePointsSupplier.getGluePoints();
163 xIdentifierContainer = (XIdentifierContainer)
164 UnoRuntime.queryInterface( XIdentifierContainer.class,
165 xIndexContainer );
166 int nIndexOfGluePoint2 = xIdentifierContainer.insert( aGluePoint );
168 // create and add a connector
169 XShape xConnector2 = ShapeHelper.createShape( xDrawDoc,
170 new Point( 0, 0 ),
171 new Size( 0, 0 ),
172 "com.sun.star.drawing.ConnectorShape" );
173 xShapes.add( xConnector2 );
175 XPropertySet xConnector2PropSet = (XPropertySet)
176 UnoRuntime.queryInterface( XPropertySet.class, xConnector2 );
178 xConnector2PropSet.setPropertyValue( "StartShape", xShape1 );
179 xConnector2PropSet.setPropertyValue( "StartGluePointIndex",
180 new Integer( nIndexOfGluePoint1 ) );
182 xConnector2PropSet.setPropertyValue( "EndShape", xShape2 );
183 xConnector2PropSet.setPropertyValue( "EndGluePointIndex",
184 new Integer( nIndexOfGluePoint2 ) );
188 catch( Exception ex )
190 System.out.println( ex );
192 System.exit( 0 );