bump product version to 7.2.5.1
[LibreOffice.git] / odk / examples / DevelopersGuide / Drawing / GluePointDemo.java
blobf45ea385a0993f06e352f332b965fa3f43a006e9
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
5 * the BSD license.
7 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * All rights reserved.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
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.XIndexContainer;
48 import com.sun.star.container.XIdentifierContainer;
50 import com.sun.star.drawing.Alignment;
51 import com.sun.star.drawing.EscapeDirection;
52 import com.sun.star.drawing.GluePoint2;
53 import com.sun.star.drawing.XShape;
54 import com.sun.star.drawing.XShapes;
55 import com.sun.star.drawing.XDrawPage;
56 import com.sun.star.drawing.XGluePointsSupplier;
60 // __________ Implementation __________
62 // GluePointDemo
64 public class GluePointDemo
66 public static void main( String args[] )
68 XComponent xDrawDoc = null;
69 try
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 = Boolean.TRUE;
83 xDrawDoc = Helper.createDocument( xOfficeContext,
84 "private:factory/sdraw", "_blank", 0, pPropValues );
87 XDrawPage xPage = PageHelper.getDrawPageByIndex( xDrawDoc, 0 );
88 XShapes xShapes = UnoRuntime.queryInterface( XShapes.class, xPage );
90 // create two rectangles
91 XShape xShape1 = ShapeHelper.createShape( xDrawDoc,
92 new Point( 15000, 1000 ), new Size( 5000, 5000 ),
93 "com.sun.star.drawing.RectangleShape" );
95 XShape xShape2 = ShapeHelper.createShape( xDrawDoc,
96 new Point( 2000, 15000 ), new Size( 5000, 5000 ),
97 "com.sun.star.drawing.EllipseShape" );
99 // and a connector
100 XShape xConnector = ShapeHelper.createShape( xDrawDoc,
101 new Point( 0, 0 ),
102 new Size( 0, 0 ),
103 "com.sun.star.drawing.ConnectorShape" );
105 xShapes.add( xShape1 );
106 xShapes.add( xShape2 );
107 xShapes.add( xConnector );
109 XPropertySet xConnectorPropSet = UnoRuntime.queryInterface( XPropertySet.class, xConnector );
111 // Index value of 0 : the shape is connected at the top
112 // Index value of 1 : the shape is connected at the left
113 // Index value of 2 : the shape is connected at the bottom
114 // Index value of 3 : the shape is connected at the right
116 int nStartIndex = 3;
117 int nEndIndex = 1;
119 // the "StartPosition" or "EndPosition" property needs not to be set
120 // if there is a shape to connect
121 xConnectorPropSet.setPropertyValue( "StartShape", xShape1 );
122 xConnectorPropSet.setPropertyValue( "StartGluePointIndex",
123 Integer.valueOf( nStartIndex ) );
125 xConnectorPropSet.setPropertyValue( "EndShape", xShape2 );
126 xConnectorPropSet.setPropertyValue( "EndGluePointIndex",
127 Integer.valueOf( nEndIndex ) );
129 XGluePointsSupplier xGluePointsSupplier;
130 XIndexContainer xIndexContainer;
131 XIdentifierContainer xIdentifierContainer;
133 GluePoint2 aGluePoint = new GluePoint2();
134 aGluePoint.IsRelative = false;
135 aGluePoint.PositionAlignment = Alignment.CENTER;
136 aGluePoint.Escape = EscapeDirection.SMART;
137 aGluePoint.IsUserDefined = true;
138 aGluePoint.Position.X = 0;
139 aGluePoint.Position.Y = 0;
141 // create and insert a glue point at shape1
142 xGluePointsSupplier = UnoRuntime.queryInterface( XGluePointsSupplier.class, xShape1 );
143 xIndexContainer = xGluePointsSupplier.getGluePoints();
144 xIdentifierContainer = UnoRuntime.queryInterface( XIdentifierContainer.class,
145 xIndexContainer );
146 int nIndexOfGluePoint1 = xIdentifierContainer.insert( aGluePoint );
148 // create and insert a glue point at shape2
149 xGluePointsSupplier = UnoRuntime.queryInterface( XGluePointsSupplier.class, xShape2 );
150 xIndexContainer = xGluePointsSupplier.getGluePoints();
151 xIdentifierContainer = UnoRuntime.queryInterface( XIdentifierContainer.class,
152 xIndexContainer );
153 int nIndexOfGluePoint2 = xIdentifierContainer.insert( aGluePoint );
155 // create and add a connector
156 XShape xConnector2 = ShapeHelper.createShape( xDrawDoc,
157 new Point( 0, 0 ),
158 new Size( 0, 0 ),
159 "com.sun.star.drawing.ConnectorShape" );
160 xShapes.add( xConnector2 );
162 XPropertySet xConnector2PropSet = UnoRuntime.queryInterface( XPropertySet.class, xConnector2 );
164 xConnector2PropSet.setPropertyValue( "StartShape", xShape1 );
165 xConnector2PropSet.setPropertyValue( "StartGluePointIndex",
166 Integer.valueOf( nIndexOfGluePoint1 ) );
168 xConnector2PropSet.setPropertyValue( "EndShape", xShape2 );
169 xConnector2PropSet.setPropertyValue( "EndGluePointIndex",
170 Integer.valueOf( nIndexOfGluePoint2 ) );
174 catch( Exception ex )
176 System.out.println( ex );
178 System.exit( 0 );
182 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */