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 import com.sun.star.beans.PropertyValue; 25cdf0e10cSrcweir import com.sun.star.beans.XPropertySet; 26cdf0e10cSrcweir 27cdf0e10cSrcweir import com.sun.star.bridge.XUnoUrlResolver; 28cdf0e10cSrcweir 29cdf0e10cSrcweir import com.sun.star.frame.XComponentLoader; 30cdf0e10cSrcweir 31cdf0e10cSrcweir import com.sun.star.lang.XComponent; 32cdf0e10cSrcweir import com.sun.star.lang.XMultiComponentFactory; 33cdf0e10cSrcweir 34cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime; 35cdf0e10cSrcweir import com.sun.star.uno.AnyConverter; 36cdf0e10cSrcweir import com.sun.star.uno.XComponentContext; 37cdf0e10cSrcweir 38cdf0e10cSrcweir 39cdf0e10cSrcweir /* 40cdf0e10cSrcweir * OpenQuery.java 41cdf0e10cSrcweir * 42cdf0e10cSrcweir * Created on 6. Juli 2002, 10:25 43cdf0e10cSrcweir */ 44cdf0e10cSrcweir 45cdf0e10cSrcweir /** 46cdf0e10cSrcweir * 47cdf0e10cSrcweir * @author dschulten 48cdf0e10cSrcweir */ 49cdf0e10cSrcweir public class Organigram { 50cdf0e10cSrcweir 51cdf0e10cSrcweir private XComponentContext xRemoteContext = null; 52cdf0e10cSrcweir private XMultiComponentFactory xRemoteServiceManager = null; 53cdf0e10cSrcweir 54cdf0e10cSrcweir /** Creates a new instance of OpenQuery */ Organigram()55cdf0e10cSrcweir public Organigram() { 56cdf0e10cSrcweir } 57cdf0e10cSrcweir 58cdf0e10cSrcweir /** 59cdf0e10cSrcweir * @param args the command line arguments 60cdf0e10cSrcweir */ main(String[] args)61cdf0e10cSrcweir public static void main(String[] args) { 62cdf0e10cSrcweir Organigram organigram1 = new Organigram(); 63cdf0e10cSrcweir try { 64cdf0e10cSrcweir organigram1.drawOrganigram(); 65cdf0e10cSrcweir } 66cdf0e10cSrcweir catch (java.lang.Exception e){ 67cdf0e10cSrcweir e.printStackTrace(); 68cdf0e10cSrcweir } 69cdf0e10cSrcweir finally { 70cdf0e10cSrcweir System.exit(0); 71cdf0e10cSrcweir } 72cdf0e10cSrcweir } drawOrganigram()73cdf0e10cSrcweir public void drawOrganigram() throws java.lang.Exception { 74cdf0e10cSrcweir // get the remote office component context 75cdf0e10cSrcweir xRemoteContext = com.sun.star.comp.helper.Bootstrap.bootstrap(); 76cdf0e10cSrcweir System.out.println("Connected to a running office ..."); 77cdf0e10cSrcweir // get the remote service manager 78cdf0e10cSrcweir xRemoteServiceManager = xRemoteContext.getServiceManager(); 79cdf0e10cSrcweir 80cdf0e10cSrcweir Object desktop = xRemoteServiceManager.createInstanceWithContext( 81cdf0e10cSrcweir "com.sun.star.frame.Desktop", xRemoteContext); 82cdf0e10cSrcweir XComponentLoader xComponentLoader = (XComponentLoader) 83cdf0e10cSrcweir UnoRuntime.queryInterface(XComponentLoader.class, desktop); 84cdf0e10cSrcweir 85cdf0e10cSrcweir PropertyValue[] loadProps = new PropertyValue[0]; 86cdf0e10cSrcweir XComponent xDrawComponent = xComponentLoader.loadComponentFromURL( 87cdf0e10cSrcweir "private:factory/sdraw", "_blank", 0, loadProps); 88cdf0e10cSrcweir 89cdf0e10cSrcweir // get draw page by index 90cdf0e10cSrcweir com.sun.star.drawing.XDrawPagesSupplier xDrawPagesSupplier = 91cdf0e10cSrcweir (com.sun.star.drawing.XDrawPagesSupplier)UnoRuntime.queryInterface( 92cdf0e10cSrcweir com.sun.star.drawing.XDrawPagesSupplier.class, xDrawComponent ); 93cdf0e10cSrcweir com.sun.star.drawing.XDrawPages xDrawPages = 94cdf0e10cSrcweir xDrawPagesSupplier.getDrawPages(); 95cdf0e10cSrcweir Object drawPage = xDrawPages.getByIndex(0); 96cdf0e10cSrcweir com.sun.star.drawing.XDrawPage xDrawPage = (com.sun.star.drawing.XDrawPage) 97cdf0e10cSrcweir UnoRuntime.queryInterface(com.sun.star.drawing.XDrawPage.class, 98cdf0e10cSrcweir drawPage); 99cdf0e10cSrcweir 100cdf0e10cSrcweir com.sun.star.lang.XMultiServiceFactory xDocumentFactory = 101cdf0e10cSrcweir (com.sun.star.lang.XMultiServiceFactory)UnoRuntime.queryInterface( 102cdf0e10cSrcweir com.sun.star.lang.XMultiServiceFactory.class, xDrawComponent); 103cdf0e10cSrcweir 104cdf0e10cSrcweir com.sun.star.beans.XPropertySet xPageProps = 105cdf0e10cSrcweir (com.sun.star.beans.XPropertySet)UnoRuntime.queryInterface( 106cdf0e10cSrcweir com.sun.star.beans.XPropertySet.class, xDrawPage); 107cdf0e10cSrcweir 108cdf0e10cSrcweir int pageWidth = AnyConverter.toInt(xPageProps.getPropertyValue("Width")); 109cdf0e10cSrcweir int pageHeight = AnyConverter.toInt(xPageProps.getPropertyValue("Height")); 110cdf0e10cSrcweir int pageBorderTop = AnyConverter.toInt(xPageProps.getPropertyValue("BorderTop")); 111cdf0e10cSrcweir int pageBorderLeft = AnyConverter.toInt(xPageProps.getPropertyValue("BorderLeft")); 112cdf0e10cSrcweir int pageBorderRight = AnyConverter.toInt(xPageProps.getPropertyValue("BorderRight")); 113cdf0e10cSrcweir int drawWidth = pageWidth - pageBorderLeft - pageBorderRight; 114cdf0e10cSrcweir int horCenter = pageBorderLeft + drawWidth / 2; 115cdf0e10cSrcweir 116cdf0e10cSrcweir String[][] orgUnits = new String[2][4]; 117cdf0e10cSrcweir orgUnits[0][0] = "Management"; 118cdf0e10cSrcweir orgUnits[1][0] = "Production"; 119cdf0e10cSrcweir orgUnits[1][1] = "Purchasing"; 120cdf0e10cSrcweir orgUnits[1][2] = "IT Services"; 121cdf0e10cSrcweir orgUnits[1][3] = "Sales"; 122cdf0e10cSrcweir int[] levelCount = {1, 4}; 123cdf0e10cSrcweir 124cdf0e10cSrcweir int horSpace = 300; 125cdf0e10cSrcweir int verSpace = 3000; 126cdf0e10cSrcweir 127cdf0e10cSrcweir int shapeWidth = (drawWidth - (levelCount[1] - 1) * horSpace) / levelCount[1]; 128cdf0e10cSrcweir int shapeHeight = pageHeight / 20; 129cdf0e10cSrcweir int shapeX = pageWidth / 2 - shapeWidth / 2; 130cdf0e10cSrcweir int shapeY = pageBorderTop; 131cdf0e10cSrcweir 132cdf0e10cSrcweir int levelY; 133cdf0e10cSrcweir int levelX; 134cdf0e10cSrcweir 135cdf0e10cSrcweir com.sun.star.drawing.XShape xStartShape = null; 136cdf0e10cSrcweir 137cdf0e10cSrcweir for (int level = 0; level <= 1; level++) { 138cdf0e10cSrcweir levelY = pageBorderTop + 2000 + level * (shapeHeight + verSpace); 139cdf0e10cSrcweir for (int i = levelCount[level] - 1; i > -1; i--) { 140cdf0e10cSrcweir shapeX = horCenter - (levelCount[level] * shapeWidth + 141cdf0e10cSrcweir (levelCount[level] - 1) * horSpace) / 2 142cdf0e10cSrcweir + i * shapeWidth + i * horSpace; 143cdf0e10cSrcweir Object shape = xDocumentFactory.createInstance("com.sun.star.drawing.RectangleShape"); 144cdf0e10cSrcweir com.sun.star.drawing.XShape xShape = (com.sun.star.drawing.XShape) 145cdf0e10cSrcweir UnoRuntime.queryInterface( 146cdf0e10cSrcweir com.sun.star.drawing.XShape.class, shape); 147cdf0e10cSrcweir xShape.setPosition(new com.sun.star.awt.Point(shapeX, levelY)); 148cdf0e10cSrcweir xShape.setSize(new com.sun.star.awt.Size(shapeWidth, shapeHeight)); 149cdf0e10cSrcweir xDrawPage.add(xShape); 150cdf0e10cSrcweir 151cdf0e10cSrcweir com.sun.star.text.XText xText = (com.sun.star.text.XText) 152cdf0e10cSrcweir UnoRuntime.queryInterface( 153cdf0e10cSrcweir com.sun.star.text.XText.class, xShape); 154cdf0e10cSrcweir 155cdf0e10cSrcweir xText.setString(orgUnits[level][i]); 156cdf0e10cSrcweir 157cdf0e10cSrcweir // memorize the root shape 158cdf0e10cSrcweir if (level == 0 && i == 0) 159cdf0e10cSrcweir xStartShape = xShape; 160cdf0e10cSrcweir 161cdf0e10cSrcweir if (level == 1) { 162cdf0e10cSrcweir Object connector = xDocumentFactory.createInstance("com.sun.star.drawing.ConnectorShape"); 163cdf0e10cSrcweir com.sun.star.beans.XPropertySet xConnectorProps = 164cdf0e10cSrcweir (com.sun.star.beans.XPropertySet)UnoRuntime.queryInterface( 165cdf0e10cSrcweir com.sun.star.beans.XPropertySet.class, connector); 166cdf0e10cSrcweir com.sun.star.drawing.XShape xConnector = 167cdf0e10cSrcweir (com.sun.star.drawing.XShape)UnoRuntime.queryInterface( 168cdf0e10cSrcweir com.sun.star.drawing.XShape.class, connector); 169cdf0e10cSrcweir xDrawPage.add(xConnector); 170cdf0e10cSrcweir xConnectorProps.setPropertyValue("StartShape", xStartShape); 171cdf0e10cSrcweir xConnectorProps.setPropertyValue("EndShape", xShape); 172cdf0e10cSrcweir xConnectorProps.setPropertyValue("StartGluePointIndex", 173cdf0e10cSrcweir new Integer(2)); // 2 = bottom glue point 174cdf0e10cSrcweir xConnectorProps.setPropertyValue("EndGluePointIndex", 175cdf0e10cSrcweir new Integer(0)); // 0 = top glue point 176cdf0e10cSrcweir } 177cdf0e10cSrcweir } 178cdf0e10cSrcweir } 179cdf0e10cSrcweir } 180cdf0e10cSrcweir } 181