1 import java
.lang
.Thread
;
3 import com
.sun
.star
.awt
.Rectangle
;
4 import com
.sun
.star
.awt
.XWindow
;
6 import com
.sun
.star
.beans
.Property
;
7 import com
.sun
.star
.beans
.PropertyValue
;
8 import com
.sun
.star
.beans
.XPropertySet
;
9 import com
.sun
.star
.beans
.XPropertySetInfo
;
11 import com
.sun
.star
.container
.XIndexAccess
;
12 import com
.sun
.star
.container
.XChild
;
13 import com
.sun
.star
.container
.XEnumerationAccess
;
14 import com
.sun
.star
.container
.XEnumeration
;
16 import com
.sun
.star
.frame
.XComponentLoader
;
17 import com
.sun
.star
.frame
.XController
;
18 import com
.sun
.star
.frame
.XDesktop
;
19 import com
.sun
.star
.frame
.XFrame
;
20 import com
.sun
.star
.frame
.XTasksSupplier
;
21 import com
.sun
.star
.frame
.XTask
;
23 import com
.sun
.star
.lang
.XComponent
;
24 import com
.sun
.star
.lang
.XMultiServiceFactory
;
25 import com
.sun
.star
.lang
.XServiceInfo
;
26 import com
.sun
.star
.lang
.XServiceName
;
27 import com
.sun
.star
.lang
.XTypeProvider
;
29 import com
.sun
.star
.uno
.UnoRuntime
;
30 import com
.sun
.star
.uno
.XInterface
;
31 import com
.sun
.star
.uno
.Type
;
33 import com
.sun
.star
.drawing
.XDrawView
;
34 import com
.sun
.star
.drawing
.XDrawPage
;
35 import com
.sun
.star
.drawing
.XShapes
;
36 import com
.sun
.star
.drawing
.XShape
;
37 import com
.sun
.star
.drawing
.XShapeDescriptor
;
39 import com
.sun
.star
.accessibility
.XAccessible
;
40 import com
.sun
.star
.accessibility
.XAccessibleContext
;
41 import com
.sun
.star
.accessibility
.XAccessibleComponent
;
42 import com
.sun
.star
.accessibility
.XAccessibleRelationSet
;
43 import com
.sun
.star
.accessibility
.XAccessibleStateSet
;
45 public class InformationWriter
47 public InformationWriter ()
51 public void drawPageTest (XInterface xPage
)
55 printProperty (xPage
, "BorderBottom ", "BorderBottom");
56 printProperty (xPage
, "BorderLeft ", "BorderLeft");
57 printProperty (xPage
, "BorderRight ", "BorderRight");
58 printProperty (xPage
, "BorderTop ", "BorderTop");
59 printProperty (xPage
, "Height ", "Height");
60 printProperty (xPage
, "Width ", "Width");
61 printProperty (xPage
, "Number ", "Number");
65 System
.out
.println ("caught exception while testing draw page:" + e
);
69 public void printProperty (XInterface xObject
, String prefix
, String name
)
73 XPropertySet xPropertySet
= (XPropertySet
) UnoRuntime
.queryInterface(
74 XPropertySet
.class, xObject
);
75 MessageArea
.println (prefix
+
76 xPropertySet
.getPropertyValue (name
));
80 MessageArea
.println ("caught exception while getting property "
87 public void showShapes (XDrawPage xPage
)
91 XIndexAccess xShapeList
= (XIndexAccess
) UnoRuntime
.queryInterface(
92 XIndexAccess
.class, xPage
);
94 MessageArea
.println ("There are " + xShapeList
.getCount()
96 for (int i
=0; i
<xShapeList
.getCount(); i
++)
98 XShape xShape
= (XShape
) UnoRuntime
.queryInterface(
99 XShape
.class, xShapeList
.getByIndex (i
));
101 XShapeDescriptor xShapeDescriptor
=
102 (XShapeDescriptor
) UnoRuntime
.queryInterface(
103 XShapeDescriptor
.class, xShape
);
104 String sName
= xShapeDescriptor
.getShapeType ();
105 MessageArea
.println (" shape " + i
+ " : " + sName
);
107 XPropertySet xPropertySet
=
108 (XPropertySet
) UnoRuntime
.queryInterface(
109 XPropertySet
.class, xShape
);
111 (Integer
) xPropertySet
.getPropertyValue ("ZOrder");
112 MessageArea
.println (" zorder = " + nZOrder
);
117 MessageArea
.println ("caught exception in showShapes: " + e
);
124 /** @descr Print all available services of the given object to the
127 public void showServices (XInterface xObject
)
131 MessageArea
.println ("Services:");
132 XMultiServiceFactory xMSF
= (XMultiServiceFactory
) UnoRuntime
.queryInterface (
133 XMultiServiceFactory
.class,
137 MessageArea
.println (" object does not support interface XMultiServiceFactory");
140 String
[] sServiceNames
= xMSF
.getAvailableServiceNames ();
141 MessageArea
.println (" object can create "
142 + sServiceNames
.length
+ " services");
143 for (int i
=0; i
<sServiceNames
.length
; i
++)
144 MessageArea
.println (" service " + i
+ " : " + sServiceNames
[i
]);
149 MessageArea
.println ("caught exception in showServices : " + e
);
153 /** @descr Print the service and implementation name of the given
156 public void showInfo (XInterface xObject
)
160 System
.out
.println ("Info:");
161 // Use interface XServiceName to retrieve name of (main) service.
162 XServiceName xSN
= (XServiceName
) UnoRuntime
.queryInterface (
163 XServiceName
.class, xObject
);
165 MessageArea
.println (" interface XServiceName not supported");
168 MessageArea
.println (" Service name : " + xSN
.getServiceName ());
171 // Use interface XServiceInfo to retrieve information about
172 // supported services.
173 XServiceInfo xSI
= (XServiceInfo
) UnoRuntime
.queryInterface (
174 XServiceInfo
.class, xObject
);
176 MessageArea
.println (" interface XServiceInfo not supported");
179 MessageArea
.println (" Implementation name : "
180 + xSI
.getImplementationName ());
185 MessageArea
.println ("caught exception in showInfo : " + e
);
192 /** @descr Print information about supported interfaces.
194 public void showInterfaces (XInterface xObject
)
198 MessageArea
.println ("Interfaces:");
199 // Use interface XTypeProvider to retrieve a list of supported
201 XTypeProvider xTP
= (XTypeProvider
) UnoRuntime
.queryInterface (
202 XTypeProvider
.class, xObject
);
204 MessageArea
.println (" interface XTypeProvider not supported");
207 Type
[] aTypeList
= xTP
.getTypes ();
208 MessageArea
.println (" object supports " + aTypeList
.length
210 for (int i
=0; i
<aTypeList
.length
; i
++)
211 MessageArea
.println (" " + i
+ " : "
212 + aTypeList
[i
].getTypeName());
217 MessageArea
.println ("caught exception in showInterfaces : " + e
);
222 /** @descr Print information concerning the accessibility of the given
225 public boolean showAccessibility (XInterface xObject
, int depth
)
229 // Create indentation string.
234 // Get XAccessibleContext object if given object does not
235 // already support this interface.
236 XAccessibleContext xContext
237 = (XAccessibleContext
) UnoRuntime
.queryInterface (
238 XAccessibleContext
.class, xObject
);
239 if (xContext
== null)
241 XAccessible xAccessible
242 = (XAccessible
) UnoRuntime
.queryInterface (
243 XAccessible
.class, xObject
);
244 if (xAccessible
== null)
246 MessageArea
.println (sIndent
+ "given object " + xObject
247 + " is not accessible");
251 xContext
= xAccessible
.getAccessibleContext();
254 // Print information about the accessible context.
255 if (xContext
!= null)
257 MessageArea
.println (sIndent
+ "Name : "
258 + xContext
.getAccessibleName());
259 MessageArea
.println (sIndent
+ "Description : "
260 + xContext
.getAccessibleDescription());
261 MessageArea
.println (sIndent
+ "Role : "
262 + xContext
.getAccessibleRole());
264 if (xContext
.getAccessibleParent() != null)
266 MessageArea
.println (sIndent
+ "Has parent : yes");
267 MessageArea
.println (sIndent
+ "Parent index : "
268 + xContext
.getAccessibleIndexInParent());
271 MessageArea
.println (sIndent
+ "Has parent : no");
272 MessageArea
.println (sIndent
+ "Child count : "
273 + xContext
.getAccessibleChildCount());
274 MessageArea
.print (sIndent
+ "Relation set : ");
275 XAccessibleRelationSet xRelationSet
276 = xContext
.getAccessibleRelationSet();
277 if (xRelationSet
!= null)
279 MessageArea
.print (xRelationSet
.getRelationCount() + " (");
280 for (int i
=0; i
<xRelationSet
.getRelationCount(); i
++)
283 MessageArea
.print (", ");
284 MessageArea
.print (xRelationSet
.getRelation(i
).toString());
286 MessageArea
.println (")");
289 MessageArea
.println ("no relation set");
291 MessageArea
.print (sIndent
+ "State set : ");
292 XAccessibleStateSet xStateSet
=
293 xContext
.getAccessibleStateSet();
294 if (xStateSet
!= null)
296 XIndexAccess xStates
=
297 (XIndexAccess
) UnoRuntime
.queryInterface (
298 XIndexAccess
.class, xStateSet
);
299 MessageArea
.print (xStates
.getCount() + " (");
300 for (int i
=0; i
<xStates
.getCount(); i
++)
303 MessageArea
.print (", ");
304 MessageArea
.print (xStates
.getByIndex(i
).toString());
306 MessageArea
.println (")");
309 MessageArea
.println ("no state set");
311 showAccessibleComponent (xContext
, sIndent
);
314 MessageArea
.println ("object has no accessible context.");
316 // showInfo (xContext);
317 // showServices (xContext);
318 // showInterfaces (xContext);
322 System
.out
.println ("caught exception in showAccessibility :" + e
);
330 /** @descr Print information about the given accessible component.
332 public void showAccessibleComponent (XInterface xObject
, String sIndent
)
336 XAccessibleComponent xComponent
=
337 (XAccessibleComponent
) UnoRuntime
.queryInterface (
338 XAccessibleComponent
.class, xObject
);
340 // Print information about the accessible context.
341 if (xComponent
!= null)
343 MessageArea
.println (sIndent
+ "Position : "
344 + xComponent
.getLocation().X
+", "
345 + xComponent
.getLocation().Y
);
346 MessageArea
.println (sIndent
+ "Screen position : "
347 + xComponent
.getLocationOnScreen().X
+", "
348 + xComponent
.getLocationOnScreen().Y
);
349 MessageArea
.println (sIndent
+ "Size : "
350 + xComponent
.getSize().Width
+", "
351 + xComponent
.getSize().Height
);
357 "caught exception in showAccessibleComponent : " + e
);
362 /** Show a textual representation of the accessibility subtree rooted in
365 public boolean showAccessibilityTree (XAccessible xRoot
, int depth
)
369 if ( ! showAccessibility (xRoot
, depth
))
373 for (int i
=0; i
<depth
; i
++)
376 // Iterate over children and show them.
377 XAccessibleContext xContext
= xRoot
.getAccessibleContext();
378 if (xContext
!= null)
380 int n
= xContext
.getAccessibleChildCount();
381 for (int i
=0; i
<n
; i
++)
383 MessageArea
.println (sIndent
+ "child " + i
+ " :");
384 showAccessibilityTree (xContext
.getAccessibleChild(i
),depth
+1);
388 MessageArea
.println ("Accessible object has no context");
393 "caught exception in showAccessibleTree : " + e
);
400 public void showProperties (XInterface xObject
)
402 XPropertySet xSet
= (XPropertySet
) UnoRuntime
.queryInterface (
403 XPropertySet
.class, xObject
);
405 MessageArea
.println ("object does not support XPropertySet");
408 XPropertySetInfo xInfo
= xSet
.getPropertySetInfo ();
409 Property
[] aProperties
= xInfo
.getProperties ();
410 int n
= aProperties
.length
;
411 for (int i
=0; i
<n
; i
++)
412 MessageArea
.println (i
+ " : " + aProperties
[i
].Name
+", " + aProperties
[i
].Type
);