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 import com
.sun
.star
.beans
.PropertyValue
;
37 import com
.sun
.star
.frame
.XComponentLoader
;
39 import com
.sun
.star
.lang
.XComponent
;
40 import com
.sun
.star
.lang
.XMultiComponentFactory
;
42 import com
.sun
.star
.uno
.UnoRuntime
;
43 import com
.sun
.star
.uno
.AnyConverter
;
44 import com
.sun
.star
.uno
.XComponentContext
;
47 public class Organigram
{
49 private XComponentContext xRemoteContext
= null;
50 private XMultiComponentFactory xRemoteServiceManager
= null;
52 /** Creates a new instance of OpenQuery */
57 * @param args the command line arguments
59 public static void main(String
[] args
) {
60 Organigram organigram1
= new Organigram();
62 organigram1
.drawOrganigram();
64 catch (java
.lang
.Exception e
){
71 public void drawOrganigram() throws java
.lang
.Exception
{
72 // get the remote office component context
73 xRemoteContext
= com
.sun
.star
.comp
.helper
.Bootstrap
.bootstrap();
74 System
.out
.println("Connected to a running office ...");
75 // get the remote service manager
76 xRemoteServiceManager
= xRemoteContext
.getServiceManager();
78 Object desktop
= xRemoteServiceManager
.createInstanceWithContext(
79 "com.sun.star.frame.Desktop", xRemoteContext
);
80 XComponentLoader xComponentLoader
= UnoRuntime
.queryInterface(XComponentLoader
.class, desktop
);
82 PropertyValue
[] loadProps
= new PropertyValue
[0];
83 XComponent xDrawComponent
= xComponentLoader
.loadComponentFromURL(
84 "private:factory/sdraw", "_blank", 0, loadProps
);
86 // get draw page by index
87 com
.sun
.star
.drawing
.XDrawPagesSupplier xDrawPagesSupplier
=
88 UnoRuntime
.queryInterface(
89 com
.sun
.star
.drawing
.XDrawPagesSupplier
.class, xDrawComponent
);
90 com
.sun
.star
.drawing
.XDrawPages xDrawPages
=
91 xDrawPagesSupplier
.getDrawPages();
92 Object drawPage
= xDrawPages
.getByIndex(0);
93 com
.sun
.star
.drawing
.XDrawPage xDrawPage
= UnoRuntime
.queryInterface(com
.sun
.star
.drawing
.XDrawPage
.class,
96 com
.sun
.star
.lang
.XMultiServiceFactory xDocumentFactory
=
97 UnoRuntime
.queryInterface(
98 com
.sun
.star
.lang
.XMultiServiceFactory
.class, xDrawComponent
);
100 com
.sun
.star
.beans
.XPropertySet xPageProps
=
101 UnoRuntime
.queryInterface(
102 com
.sun
.star
.beans
.XPropertySet
.class, xDrawPage
);
104 int pageWidth
= AnyConverter
.toInt(xPageProps
.getPropertyValue("Width"));
105 int pageHeight
= AnyConverter
.toInt(xPageProps
.getPropertyValue("Height"));
106 int pageBorderTop
= AnyConverter
.toInt(xPageProps
.getPropertyValue("BorderTop"));
107 int pageBorderLeft
= AnyConverter
.toInt(xPageProps
.getPropertyValue("BorderLeft"));
108 int pageBorderRight
= AnyConverter
.toInt(xPageProps
.getPropertyValue("BorderRight"));
109 int drawWidth
= pageWidth
- pageBorderLeft
- pageBorderRight
;
110 int horCenter
= pageBorderLeft
+ drawWidth
/ 2;
112 String
[][] orgUnits
= new String
[2][4];
113 orgUnits
[0][0] = "Management";
114 orgUnits
[1][0] = "Production";
115 orgUnits
[1][1] = "Purchasing";
116 orgUnits
[1][2] = "IT Services";
117 orgUnits
[1][3] = "Sales";
118 int[] levelCount
= {1, 4};
123 int shapeWidth
= (drawWidth
- (levelCount
[1] - 1) * horSpace
) / levelCount
[1];
124 int shapeHeight
= pageHeight
/ 20;
125 int shapeX
= pageWidth
/ 2 - shapeWidth
/ 2;
126 int shapeY
= pageBorderTop
;
131 com
.sun
.star
.drawing
.XShape xStartShape
= null;
133 for (int level
= 0; level
<= 1; level
++) {
134 levelY
= pageBorderTop
+ 2000 + level
* (shapeHeight
+ verSpace
);
135 for (int i
= levelCount
[level
] - 1; i
> -1; i
--) {
136 shapeX
= horCenter
- (levelCount
[level
] * shapeWidth
+
137 (levelCount
[level
] - 1) * horSpace
) / 2
138 + i
* shapeWidth
+ i
* horSpace
;
139 Object shape
= xDocumentFactory
.createInstance("com.sun.star.drawing.RectangleShape");
140 com
.sun
.star
.drawing
.XShape xShape
= UnoRuntime
.queryInterface(
141 com
.sun
.star
.drawing
.XShape
.class, shape
);
142 xShape
.setPosition(new com
.sun
.star
.awt
.Point(shapeX
, levelY
));
143 xShape
.setSize(new com
.sun
.star
.awt
.Size(shapeWidth
, shapeHeight
));
144 xDrawPage
.add(xShape
);
146 com
.sun
.star
.text
.XText xText
= UnoRuntime
.queryInterface(
147 com
.sun
.star
.text
.XText
.class, xShape
);
149 xText
.setString(orgUnits
[level
][i
]);
151 // memorize the root shape
152 if (level
== 0 && i
== 0)
153 xStartShape
= xShape
;
156 Object connector
= xDocumentFactory
.createInstance("com.sun.star.drawing.ConnectorShape");
157 com
.sun
.star
.beans
.XPropertySet xConnectorProps
=
158 UnoRuntime
.queryInterface(
159 com
.sun
.star
.beans
.XPropertySet
.class, connector
);
160 com
.sun
.star
.drawing
.XShape xConnector
=
161 UnoRuntime
.queryInterface(
162 com
.sun
.star
.drawing
.XShape
.class, connector
);
163 xDrawPage
.add(xConnector
);
164 xConnectorProps
.setPropertyValue("StartShape", xStartShape
);
165 xConnectorProps
.setPropertyValue("EndShape", xShape
);
166 xConnectorProps
.setPropertyValue("StartGluePointIndex",
167 Integer
.valueOf(2)); // 2 = bottom glue point
168 xConnectorProps
.setPropertyValue("EndGluePointIndex",
169 Integer
.valueOf(0)); // 0 = top glue point
176 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */