1 /*************************************************************************
3 * $RCSfile: Organigram.java,v $
7 * last change: $Author: rt $ $Date: 2005-01-31 16:24:11 $
9 * The Contents of this file are made available subject to the terms of
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
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 import com
.sun
.star
.beans
.PropertyValue
;
42 import com
.sun
.star
.beans
.XPropertySet
;
44 import com
.sun
.star
.bridge
.XUnoUrlResolver
;
46 import com
.sun
.star
.frame
.XComponentLoader
;
48 import com
.sun
.star
.lang
.XComponent
;
49 import com
.sun
.star
.lang
.XMultiComponentFactory
;
51 import com
.sun
.star
.uno
.UnoRuntime
;
52 import com
.sun
.star
.uno
.AnyConverter
;
53 import com
.sun
.star
.uno
.XComponentContext
;
59 * Created on 6. Juli 2002, 10:25
66 public class Organigram
{
68 private XComponentContext xRemoteContext
= null;
69 private XMultiComponentFactory xRemoteServiceManager
= null;
71 /** Creates a new instance of OpenQuery */
76 * @param args the command line arguments
78 public static void main(String
[] args
) {
79 Organigram organigram1
= new Organigram();
81 organigram1
.drawOrganigram();
83 catch (java
.lang
.Exception e
){
90 public void drawOrganigram() throws java
.lang
.Exception
{
91 // get the remote office component context
92 xRemoteContext
= com
.sun
.star
.comp
.helper
.Bootstrap
.bootstrap();
93 System
.out
.println("Connected to a running office ...");
94 // get the remote service manager
95 xRemoteServiceManager
= xRemoteContext
.getServiceManager();
97 Object desktop
= xRemoteServiceManager
.createInstanceWithContext(
98 "com.sun.star.frame.Desktop", xRemoteContext
);
99 XComponentLoader xComponentLoader
= (XComponentLoader
)
100 UnoRuntime
.queryInterface(XComponentLoader
.class, desktop
);
102 PropertyValue
[] loadProps
= new PropertyValue
[0];
103 XComponent xDrawComponent
= xComponentLoader
.loadComponentFromURL(
104 "private:factory/sdraw", "_blank", 0, loadProps
);
106 // get draw page by index
107 com
.sun
.star
.drawing
.XDrawPagesSupplier xDrawPagesSupplier
=
108 (com
.sun
.star
.drawing
.XDrawPagesSupplier
)UnoRuntime
.queryInterface(
109 com
.sun
.star
.drawing
.XDrawPagesSupplier
.class, xDrawComponent
);
110 com
.sun
.star
.drawing
.XDrawPages xDrawPages
=
111 xDrawPagesSupplier
.getDrawPages();
112 Object drawPage
= xDrawPages
.getByIndex(0);
113 com
.sun
.star
.drawing
.XDrawPage xDrawPage
= (com
.sun
.star
.drawing
.XDrawPage
)
114 UnoRuntime
.queryInterface(com
.sun
.star
.drawing
.XDrawPage
.class,
117 com
.sun
.star
.lang
.XMultiServiceFactory xDocumentFactory
=
118 (com
.sun
.star
.lang
.XMultiServiceFactory
)UnoRuntime
.queryInterface(
119 com
.sun
.star
.lang
.XMultiServiceFactory
.class, xDrawComponent
);
121 com
.sun
.star
.beans
.XPropertySet xPageProps
=
122 (com
.sun
.star
.beans
.XPropertySet
)UnoRuntime
.queryInterface(
123 com
.sun
.star
.beans
.XPropertySet
.class, xDrawPage
);
125 int pageWidth
= AnyConverter
.toInt(xPageProps
.getPropertyValue("Width"));
126 int pageHeight
= AnyConverter
.toInt(xPageProps
.getPropertyValue("Height"));
127 int pageBorderTop
= AnyConverter
.toInt(xPageProps
.getPropertyValue("BorderTop"));
128 int pageBorderLeft
= AnyConverter
.toInt(xPageProps
.getPropertyValue("BorderLeft"));
129 int pageBorderRight
= AnyConverter
.toInt(xPageProps
.getPropertyValue("BorderRight"));
130 int drawWidth
= pageWidth
- pageBorderLeft
- pageBorderRight
;
131 int horCenter
= pageBorderLeft
+ drawWidth
/ 2;
133 String
[][] orgUnits
= new String
[2][4];
134 orgUnits
[0][0] = "Management";
135 orgUnits
[1][0] = "Production";
136 orgUnits
[1][1] = "Purchasing";
137 orgUnits
[1][2] = "IT Services";
138 orgUnits
[1][3] = "Sales";
139 int[] levelCount
= {1, 4};
144 int shapeWidth
= (drawWidth
- (levelCount
[1] - 1) * horSpace
) / levelCount
[1];
145 int shapeHeight
= pageHeight
/ 20;
146 int shapeX
= pageWidth
/ 2 - shapeWidth
/ 2;
147 int shapeY
= pageBorderTop
;
152 com
.sun
.star
.drawing
.XShape xStartShape
= null;
154 for (int level
= 0; level
<= 1; level
++) {
155 levelY
= pageBorderTop
+ 2000 + level
* (shapeHeight
+ verSpace
);
156 for (int i
= levelCount
[level
] - 1; i
> -1; i
--) {
157 shapeX
= horCenter
- (levelCount
[level
] * shapeWidth
+
158 (levelCount
[level
] - 1) * horSpace
) / 2
159 + i
* shapeWidth
+ i
* horSpace
;
160 Object shape
= xDocumentFactory
.createInstance("com.sun.star.drawing.RectangleShape");
161 com
.sun
.star
.drawing
.XShape xShape
= (com
.sun
.star
.drawing
.XShape
)
162 UnoRuntime
.queryInterface(
163 com
.sun
.star
.drawing
.XShape
.class, shape
);
164 xShape
.setPosition(new com
.sun
.star
.awt
.Point(shapeX
, levelY
));
165 xShape
.setSize(new com
.sun
.star
.awt
.Size(shapeWidth
, shapeHeight
));
166 xDrawPage
.add(xShape
);
168 com
.sun
.star
.text
.XText xText
= (com
.sun
.star
.text
.XText
)
169 UnoRuntime
.queryInterface(
170 com
.sun
.star
.text
.XText
.class, xShape
);
172 xText
.setString(orgUnits
[level
][i
]);
174 // memorize the root shape
175 if (level
== 0 && i
== 0)
176 xStartShape
= xShape
;
179 Object connector
= xDocumentFactory
.createInstance("com.sun.star.drawing.ConnectorShape");
180 com
.sun
.star
.beans
.XPropertySet xConnectorProps
=
181 (com
.sun
.star
.beans
.XPropertySet
)UnoRuntime
.queryInterface(
182 com
.sun
.star
.beans
.XPropertySet
.class, connector
);
183 com
.sun
.star
.drawing
.XShape xConnector
=
184 (com
.sun
.star
.drawing
.XShape
)UnoRuntime
.queryInterface(
185 com
.sun
.star
.drawing
.XShape
.class, connector
);
186 xDrawPage
.add(xConnector
);
187 xConnectorProps
.setPropertyValue("StartShape", xStartShape
);
188 xConnectorProps
.setPropertyValue("EndShape", xShape
);
189 xConnectorProps
.setPropertyValue("StartGluePointIndex",
190 new Integer(2)); // 2 = bottom glue point
191 xConnectorProps
.setPropertyValue("EndGluePointIndex",
192 new Integer(0)); // 0 = top glue point