1*34dd1e25SAndrew Rist /************************************************************** 2*34dd1e25SAndrew Rist * 3*34dd1e25SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*34dd1e25SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*34dd1e25SAndrew Rist * distributed with this work for additional information 6*34dd1e25SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*34dd1e25SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*34dd1e25SAndrew Rist * "License"); you may not use this file except in compliance 9*34dd1e25SAndrew Rist * with the License. You may obtain a copy of the License at 10*34dd1e25SAndrew Rist * 11*34dd1e25SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*34dd1e25SAndrew Rist * 13*34dd1e25SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*34dd1e25SAndrew Rist * software distributed under the License is distributed on an 15*34dd1e25SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*34dd1e25SAndrew Rist * KIND, either express or implied. See the License for the 17*34dd1e25SAndrew Rist * specific language governing permissions and limitations 18*34dd1e25SAndrew Rist * under the License. 19*34dd1e25SAndrew Rist * 20*34dd1e25SAndrew Rist *************************************************************/ 21*34dd1e25SAndrew Rist 22*34dd1e25SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // __________ Imports __________ 25cdf0e10cSrcweir 26cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime; 27cdf0e10cSrcweir import com.sun.star.lang.XComponent; 28cdf0e10cSrcweir 29cdf0e10cSrcweir import com.sun.star.awt.Point; 30cdf0e10cSrcweir import com.sun.star.awt.Size; 31cdf0e10cSrcweir 32cdf0e10cSrcweir import com.sun.star.beans.PropertyValue; 33cdf0e10cSrcweir import com.sun.star.beans.XPropertySet; 34cdf0e10cSrcweir 35cdf0e10cSrcweir import com.sun.star.container.XIndexContainer; 36cdf0e10cSrcweir import com.sun.star.container.XIdentifierContainer; 37cdf0e10cSrcweir 38cdf0e10cSrcweir import com.sun.star.drawing.Alignment; 39cdf0e10cSrcweir import com.sun.star.drawing.EscapeDirection; 40cdf0e10cSrcweir import com.sun.star.drawing.GluePoint2; 41cdf0e10cSrcweir import com.sun.star.drawing.XShape; 42cdf0e10cSrcweir import com.sun.star.drawing.XShapes; 43cdf0e10cSrcweir import com.sun.star.drawing.XDrawPage; 44cdf0e10cSrcweir import com.sun.star.drawing.XGluePointsSupplier; 45cdf0e10cSrcweir 46cdf0e10cSrcweir 47cdf0e10cSrcweir 48cdf0e10cSrcweir // __________ Implementation __________ 49cdf0e10cSrcweir 50cdf0e10cSrcweir /** GluePointDemo 51cdf0e10cSrcweir @author Sven Jacobi 52cdf0e10cSrcweir */ 53cdf0e10cSrcweir 54cdf0e10cSrcweir public class GluePointDemo 55cdf0e10cSrcweir { main( String args[] )56cdf0e10cSrcweir public static void main( String args[] ) 57cdf0e10cSrcweir { 58cdf0e10cSrcweir XComponent xDrawDoc = null; 59cdf0e10cSrcweir try 60cdf0e10cSrcweir { 61cdf0e10cSrcweir // get the remote office context of a running office (a new office 62cdf0e10cSrcweir // instance is started if necessary) 63cdf0e10cSrcweir com.sun.star.uno.XComponentContext xOfficeContext = Helper.connect(); 64cdf0e10cSrcweir 65cdf0e10cSrcweir // suppress Presentation Autopilot when opening the document 66cdf0e10cSrcweir // properties are the same as described for 67cdf0e10cSrcweir // com.sun.star.document.MediaDescriptor 68cdf0e10cSrcweir PropertyValue[] pPropValues = new PropertyValue[ 1 ]; 69cdf0e10cSrcweir pPropValues[ 0 ] = new PropertyValue(); 70cdf0e10cSrcweir pPropValues[ 0 ].Name = "Silent"; 71cdf0e10cSrcweir pPropValues[ 0 ].Value = new Boolean( true ); 72cdf0e10cSrcweir 73cdf0e10cSrcweir xDrawDoc = Helper.createDocument( xOfficeContext, 74cdf0e10cSrcweir "private:factory/sdraw", "_blank", 0, pPropValues ); 75cdf0e10cSrcweir 76cdf0e10cSrcweir 77cdf0e10cSrcweir XDrawPage xPage = PageHelper.getDrawPageByIndex( xDrawDoc, 0 ); 78cdf0e10cSrcweir XShapes xShapes = (XShapes) 79cdf0e10cSrcweir UnoRuntime.queryInterface( XShapes.class, xPage ); 80cdf0e10cSrcweir 81cdf0e10cSrcweir // create two rectangles 82cdf0e10cSrcweir XShape xShape1 = ShapeHelper.createShape( xDrawDoc, 83cdf0e10cSrcweir new Point( 15000, 1000 ), new Size( 5000, 5000 ), 84cdf0e10cSrcweir "com.sun.star.drawing.RectangleShape" ); 85cdf0e10cSrcweir 86cdf0e10cSrcweir XShape xShape2 = ShapeHelper.createShape( xDrawDoc, 87cdf0e10cSrcweir new Point( 2000, 15000 ), new Size( 5000, 5000 ), 88cdf0e10cSrcweir "com.sun.star.drawing.EllipseShape" ); 89cdf0e10cSrcweir 90cdf0e10cSrcweir // and a connector 91cdf0e10cSrcweir XShape xConnector = ShapeHelper.createShape( xDrawDoc, 92cdf0e10cSrcweir new Point( 0, 0 ), 93cdf0e10cSrcweir new Size( 0, 0 ), 94cdf0e10cSrcweir "com.sun.star.drawing.ConnectorShape" ); 95cdf0e10cSrcweir 96cdf0e10cSrcweir xShapes.add( xShape1 ); 97cdf0e10cSrcweir xShapes.add( xShape2 ); 98cdf0e10cSrcweir xShapes.add( xConnector ); 99cdf0e10cSrcweir 100cdf0e10cSrcweir XPropertySet xConnectorPropSet = (XPropertySet) 101cdf0e10cSrcweir UnoRuntime.queryInterface( XPropertySet.class, xConnector ); 102cdf0e10cSrcweir 103cdf0e10cSrcweir // Index value of 0 : the shape is connected at the top 104cdf0e10cSrcweir // Index value of 1 : the shape is connected at the left 105cdf0e10cSrcweir // Index value of 2 : the shape is connected at the bottom 106cdf0e10cSrcweir // Index value of 3 : the shape is connected at the right 107cdf0e10cSrcweir 108cdf0e10cSrcweir int nStartIndex = 3; 109cdf0e10cSrcweir int nEndIndex = 1; 110cdf0e10cSrcweir 111cdf0e10cSrcweir // the "StartPosition" or "EndPosition" property needs not to be set 112cdf0e10cSrcweir // if there is a shape to connect 113cdf0e10cSrcweir xConnectorPropSet.setPropertyValue( "StartShape", xShape1 ); 114cdf0e10cSrcweir xConnectorPropSet.setPropertyValue( "StartGluePointIndex", 115cdf0e10cSrcweir new Integer( nStartIndex ) ); 116cdf0e10cSrcweir 117cdf0e10cSrcweir xConnectorPropSet.setPropertyValue( "EndShape", xShape2 ); 118cdf0e10cSrcweir xConnectorPropSet.setPropertyValue( "EndGluePointIndex", 119cdf0e10cSrcweir new Integer( nEndIndex ) ); 120cdf0e10cSrcweir 121cdf0e10cSrcweir XGluePointsSupplier xGluePointsSupplier; 122cdf0e10cSrcweir XIndexContainer xIndexContainer; 123cdf0e10cSrcweir XIdentifierContainer xIdentifierContainer; 124cdf0e10cSrcweir 125cdf0e10cSrcweir GluePoint2 aGluePoint = new GluePoint2(); 126cdf0e10cSrcweir aGluePoint.IsRelative = false; 127cdf0e10cSrcweir aGluePoint.PositionAlignment = Alignment.CENTER; 128cdf0e10cSrcweir aGluePoint.Escape = EscapeDirection.SMART; 129cdf0e10cSrcweir aGluePoint.IsUserDefined = true; 130cdf0e10cSrcweir aGluePoint.Position.X = 0; 131cdf0e10cSrcweir aGluePoint.Position.Y = 0; 132cdf0e10cSrcweir 133cdf0e10cSrcweir // create and insert a glue point at shape1 134cdf0e10cSrcweir xGluePointsSupplier = (XGluePointsSupplier) 135cdf0e10cSrcweir UnoRuntime.queryInterface( XGluePointsSupplier.class, xShape1 ); 136cdf0e10cSrcweir xIndexContainer = xGluePointsSupplier.getGluePoints(); 137cdf0e10cSrcweir xIdentifierContainer = (XIdentifierContainer) 138cdf0e10cSrcweir UnoRuntime.queryInterface( XIdentifierContainer.class, 139cdf0e10cSrcweir xIndexContainer ); 140cdf0e10cSrcweir int nIndexOfGluePoint1 = xIdentifierContainer.insert( aGluePoint ); 141cdf0e10cSrcweir 142cdf0e10cSrcweir // create and insert a glue point at shape2 143cdf0e10cSrcweir xGluePointsSupplier = (XGluePointsSupplier) 144cdf0e10cSrcweir UnoRuntime.queryInterface( XGluePointsSupplier.class, xShape2 ); 145cdf0e10cSrcweir xIndexContainer = xGluePointsSupplier.getGluePoints(); 146cdf0e10cSrcweir xIdentifierContainer = (XIdentifierContainer) 147cdf0e10cSrcweir UnoRuntime.queryInterface( XIdentifierContainer.class, 148cdf0e10cSrcweir xIndexContainer ); 149cdf0e10cSrcweir int nIndexOfGluePoint2 = xIdentifierContainer.insert( aGluePoint ); 150cdf0e10cSrcweir 151cdf0e10cSrcweir // create and add a connector 152cdf0e10cSrcweir XShape xConnector2 = ShapeHelper.createShape( xDrawDoc, 153cdf0e10cSrcweir new Point( 0, 0 ), 154cdf0e10cSrcweir new Size( 0, 0 ), 155cdf0e10cSrcweir "com.sun.star.drawing.ConnectorShape" ); 156cdf0e10cSrcweir xShapes.add( xConnector2 ); 157cdf0e10cSrcweir 158cdf0e10cSrcweir XPropertySet xConnector2PropSet = (XPropertySet) 159cdf0e10cSrcweir UnoRuntime.queryInterface( XPropertySet.class, xConnector2 ); 160cdf0e10cSrcweir 161cdf0e10cSrcweir xConnector2PropSet.setPropertyValue( "StartShape", xShape1 ); 162cdf0e10cSrcweir xConnector2PropSet.setPropertyValue( "StartGluePointIndex", 163cdf0e10cSrcweir new Integer( nIndexOfGluePoint1 ) ); 164cdf0e10cSrcweir 165cdf0e10cSrcweir xConnector2PropSet.setPropertyValue( "EndShape", xShape2 ); 166cdf0e10cSrcweir xConnector2PropSet.setPropertyValue( "EndGluePointIndex", 167cdf0e10cSrcweir new Integer( nIndexOfGluePoint2 ) ); 168cdf0e10cSrcweir 169cdf0e10cSrcweir 170cdf0e10cSrcweir } 171cdf0e10cSrcweir catch( Exception ex ) 172cdf0e10cSrcweir { 173cdf0e10cSrcweir System.out.println( ex ); 174cdf0e10cSrcweir } 175cdf0e10cSrcweir System.exit( 0 ); 176cdf0e10cSrcweir } 177cdf0e10cSrcweir } 178