merged tag ooo/DEV300_m102
[LibreOffice.git] / toolkit / test / accessibility / InformationWriter.java
blobe119d2037350f41925415a1d5f4550a290f48c96
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)
53 try
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");
63 catch (Exception e)
65 System.out.println ("caught exception while testing draw page:" + e);
69 public void printProperty (XInterface xObject, String prefix, String name)
71 try
73 XPropertySet xPropertySet = (XPropertySet) UnoRuntime.queryInterface(
74 XPropertySet.class, xObject);
75 MessageArea.println (prefix +
76 xPropertySet.getPropertyValue (name));
78 catch (Exception e)
80 MessageArea.println ("caught exception while getting property "
81 + name + " : " + e);
87 public void showShapes (XDrawPage xPage)
89 try
91 XIndexAccess xShapeList = (XIndexAccess) UnoRuntime.queryInterface(
92 XIndexAccess.class, xPage);
94 MessageArea.println ("There are " + xShapeList.getCount()
95 + " shapes");
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);
110 Integer nZOrder =
111 (Integer) xPropertySet.getPropertyValue ("ZOrder");
112 MessageArea.println (" zorder = " + nZOrder);
115 catch (Exception e)
117 MessageArea.println ("caught exception in showShapes: " + e);
124 /** @descr Print all available services of the given object to the
125 standard output.
127 public void showServices (XInterface xObject)
131 MessageArea.println ("Services:");
132 XMultiServiceFactory xMSF = (XMultiServiceFactory) UnoRuntime.queryInterface (
133 XMultiServiceFactory.class,
134 xObject
136 if (xMSF == null)
137 MessageArea.println (" object does not support interface XMultiServiceFactory");
138 else
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]);
147 catch (Exception e)
149 MessageArea.println ("caught exception in showServices : " + e);
153 /** @descr Print the service and implementation name of the given
154 object.
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);
164 if (xSN == null)
165 MessageArea.println (" interface XServiceName not supported");
166 else
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);
175 if (xSI == null)
176 MessageArea.println (" interface XServiceInfo not supported");
177 else
179 MessageArea.println (" Implementation name : "
180 + xSI.getImplementationName ());
183 catch (Exception e)
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
200 // interfaces.
201 XTypeProvider xTP = (XTypeProvider) UnoRuntime.queryInterface (
202 XTypeProvider.class, xObject);
203 if (xTP == null)
204 MessageArea.println (" interface XTypeProvider not supported");
205 else
207 Type[] aTypeList = xTP.getTypes ();
208 MessageArea.println (" object supports " + aTypeList.length
209 + " interfaces");
210 for (int i=0; i<aTypeList.length; i++)
211 MessageArea.println (" " + i + " : "
212 + aTypeList[i].getTypeName());
215 catch (Exception e)
217 MessageArea.println ("caught exception in showInterfaces : " + e);
222 /** @descr Print information concerning the accessibility of the given
223 object.
225 public boolean showAccessibility (XInterface xObject, int depth)
229 // Create indentation string.
230 String sIndent = "";
231 while (depth-- > 0)
232 sIndent += " ";
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");
248 return false;
250 else
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());
263 String sHasParent;
264 if (xContext.getAccessibleParent() != null)
266 MessageArea.println (sIndent + "Has parent : yes");
267 MessageArea.println (sIndent + "Parent index : "
268 + xContext.getAccessibleIndexInParent());
270 else
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++)
282 if (i > 0)
283 MessageArea.print (", ");
284 MessageArea.print (xRelationSet.getRelation(i).toString());
286 MessageArea.println (")");
288 else
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++)
302 if (i > 0)
303 MessageArea.print (", ");
304 MessageArea.print (xStates.getByIndex(i).toString());
306 MessageArea.println (")");
308 else
309 MessageArea.println ("no state set");
311 showAccessibleComponent (xContext, sIndent);
313 else
314 MessageArea.println ("object has no accessible context.");
316 // showInfo (xContext);
317 // showServices (xContext);
318 // showInterfaces (xContext);
320 catch (Exception e)
322 System.out.println ("caught exception in showAccessibility :" + e);
324 return true;
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);
354 catch (Exception e)
356 System.out.println (
357 "caught exception in showAccessibleComponent : " + e);
362 /** Show a textual representation of the accessibility subtree rooted in
363 xRoot.
365 public boolean showAccessibilityTree (XAccessible xRoot, int depth)
369 if ( ! showAccessibility (xRoot, depth))
370 return false;
372 String sIndent = "";
373 for (int i=0; i<depth; i++)
374 sIndent += " ";
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);
387 else
388 MessageArea.println ("Accessible object has no context");
390 catch (Exception e)
392 System.out.println (
393 "caught exception in showAccessibleTree : " + e);
394 return false;
397 return true;
400 public void showProperties (XInterface xObject)
402 XPropertySet xSet = (XPropertySet) UnoRuntime.queryInterface (
403 XPropertySet.class, xObject);
404 if (xSet == null)
405 MessageArea.println ("object does not support XPropertySet");
406 else
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);