1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 package org.openoffice.java.accessibility;
25 
26 import javax.accessibility.AccessibleState;
27 
28 import com.sun.star.uno.AnyConverter;
29 import com.sun.star.uno.UnoRuntime;
30 import com.sun.star.accessibility.*;
31 
32 public class Table extends DescendantManager implements javax.accessibility.Accessible {
33 
Table(XAccessible xAccessible, XAccessibleContext xAccessibleContext, boolean multiselectable)34     protected Table(XAccessible xAccessible, XAccessibleContext xAccessibleContext, boolean multiselectable) {
35         super(xAccessible, xAccessibleContext, multiselectable);
36     }
37 
setActiveDescendant(javax.accessibility.Accessible descendant)38     protected void setActiveDescendant(javax.accessibility.Accessible descendant) {
39         javax.accessibility.Accessible oldAD = activeDescendant;
40         activeDescendant = descendant;
41         firePropertyChange(javax.accessibility.AccessibleContext.ACCESSIBLE_ACTIVE_DESCENDANT_PROPERTY,
42             oldAD, descendant);
43     }
44 
setActiveDescendant(Object any)45     protected void setActiveDescendant(Object any) {
46         javax.accessibility.Accessible descendant = null;
47         try {
48             if (AnyConverter.isObject(any)) {
49                 XAccessible unoAccessible = (XAccessible) AnyConverter.toObject(
50                     AccessibleObjectFactory.XAccessibleType, any);
51                 if (unoAccessible != null) {
52                     // FIXME: have to handle non transient objects here ..
53                     descendant = new TableCell(unoAccessible);
54                 }
55             }
56             setActiveDescendant(descendant);
57         } catch (com.sun.star.lang.IllegalArgumentException e) {
58         }
59     }
60 
add(XAccessible unoAccessible)61     protected void add(XAccessible unoAccessible) {
62         if (unoAccessible != null) {
63             TableCell cell = new TableCell(unoAccessible);
64             // The AccessBridge for Windows expects an instance of AccessibleContext
65             // as parameters
66             firePropertyChange(javax.accessibility.AccessibleContext.ACCESSIBLE_CHILD_PROPERTY,
67                 null, cell.getAccessibleContext());
68         }
69     }
70 
remove(XAccessible unoAccessible)71     protected void remove(XAccessible unoAccessible) {
72         if (unoAccessible != null) {
73             TableCell cell = new TableCell(unoAccessible);
74             // The AccessBridge for Windows expects an instance of AccessibleContext
75             // as parameters
76             firePropertyChange(javax.accessibility.AccessibleContext.ACCESSIBLE_CHILD_PROPERTY,
77                 cell.getAccessibleContext(), null);
78         }
79     }
80 
add(Object any)81     protected void add(Object any) {
82         try {
83             add((XAccessible) AnyConverter.toObject(AccessibleObjectFactory.XAccessibleType, any));
84         } catch (com.sun.star.lang.IllegalArgumentException e) {
85         }
86     }
87 
remove(Object any)88     protected void remove(Object any) {
89         try {
90             remove((XAccessible) AnyConverter.toObject(AccessibleObjectFactory.XAccessibleType, any));
91         } catch (com.sun.star.lang.IllegalArgumentException e) {
92         }
93     }
94 
95     /**
96     * Update the proxy objects appropriatly on property change events
97     */
98     protected class AccessibleTableListener extends AccessibleDescendantManagerListener {
99 
AccessibleTableListener()100         protected AccessibleTableListener() {
101             super();
102         }
103 
104         /** Called by OpenOffice process to notify property changes */
notifyEvent(AccessibleEventObject event)105         public void notifyEvent(AccessibleEventObject event) {
106             switch (event.EventId) {
107                 case AccessibleEventId.ACTIVE_DESCENDANT_CHANGED:
108                     setActiveDescendant(event.NewValue);
109                     break;
110                 case AccessibleEventId.CHILD:
111                     if (AnyConverter.isObject(event.OldValue)) {
112                         remove(event.OldValue);
113                     }
114                     if (AnyConverter.isObject(event.NewValue)) {
115                         add(event.NewValue);
116                     }
117                     break;
118                 default:
119                     super.notifyEvent(event);
120             }
121         }
122     }
123 
createEventListener()124     protected XAccessibleEventListener createEventListener() {
125         return new AccessibleTableListener();
126     }
127 
128     /** Creates the AccessibleContext associated with this object */
createAccessibleContext()129     public javax.accessibility.AccessibleContext createAccessibleContext() {
130         return new AccessibleTable();
131     }
132 
133     protected class AccessibleTable extends AccessibleDescendantManager implements javax.accessibility.AccessibleExtendedTable {
134 
135         protected XAccessibleTable unoAccessibleTable;
136 
AccessibleTable()137         public AccessibleTable() {
138             unoAccessibleTable = (XAccessibleTable) UnoRuntime.queryInterface(XAccessibleTable.class, unoAccessibleContext);
139         }
140 
141         /** Gets the role of this object */
getAccessibleRole()142         public javax.accessibility.AccessibleRole getAccessibleRole() {
143             return javax.accessibility.AccessibleRole.TABLE;
144         }
145 
146         /** Returns the AccessibleTable interface of this object */
getAccessibleTable()147         public javax.accessibility.AccessibleTable getAccessibleTable() {
148             return this;
149         }
150 
151         /** Returns the specified Accessible child of the object */
getAccessibleChild(int i)152         public javax.accessibility.Accessible getAccessibleChild(int i) {
153             javax.accessibility.Accessible child = null;
154             try {
155                 XAccessible xAccessible = unoAccessibleContext.getAccessibleChild(i);
156                 if (xAccessible != null) {
157                     // Re-use the active descandant wrapper if possible
158                     javax.accessibility.Accessible activeDescendant = Table.this.activeDescendant;
159                     if ((activeDescendant instanceof TableCell) && xAccessible.equals(((TableCell) activeDescendant).unoAccessible)) {
160                         child = activeDescendant;
161                     } else {
162                         child = new TableCell(xAccessible);
163                     }
164                 }
165             } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
166             } catch (com.sun.star.uno.RuntimeException e) {
167             }
168             return child;
169         }
170 
171         /*
172         * AccessibleComponent
173         */
174 
175         /** Returns the Accessible child, if one exists, contained at the local coordinate Point */
getAccessibleAt(java.awt.Point p)176         public javax.accessibility.Accessible getAccessibleAt(java.awt.Point p) {
177             javax.accessibility.Accessible child = null;
178             try {
179                 XAccessible xAccessible = unoAccessibleComponent.getAccessibleAtPoint(
180 					new com.sun.star.awt.Point(p.x, p.y));
181                 if (xAccessible != null) {
182                     // Re-use the active descandant wrapper if possible
183                     javax.accessibility.Accessible activeDescendant = Table.this.activeDescendant;
184                     if ((activeDescendant instanceof TableCell) && xAccessible.equals(((TableCell) activeDescendant).unoAccessible)) {
185                         child = activeDescendant;
186                     } else {
187                         child = new TableCell(xAccessible);
188                     }
189                 }
190             } catch (com.sun.star.uno.RuntimeException e) {
191             }
192 			return child;
193         }
194 
195         /*
196         * AccessibleSelection
197         */
198 
199         /** Returns an Accessible representing the specified selected child of the object */
getAccessibleSelection(int i)200         public javax.accessibility.Accessible getAccessibleSelection(int i) {
201             javax.accessibility.Accessible child = null;
202             try {
203                 XAccessible xAccessible = unoAccessibleSelection.getSelectedAccessibleChild(i);
204                 if (xAccessible != null) {
205                     // Re-use the active descandant wrapper if possible
206                     javax.accessibility.Accessible activeDescendant = Table.this.activeDescendant;
207                     if ((activeDescendant instanceof TableCell) && xAccessible.equals(((TableCell) activeDescendant).unoAccessible)) {
208                         child = activeDescendant;
209                     } else {
210                         child = new TableCell(xAccessible);
211                     }
212                 }
213             } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
214             } catch (com.sun.star.uno.RuntimeException e) {
215             }
216             return child;
217         }
218 
219         /*
220         * AccessibleTable
221         */
222 
223         /** Returns the Accessible at a specified row and column in the table. */
getAccessibleAt(int r, int c)224         public javax.accessibility.Accessible getAccessibleAt(int r, int c) {
225             javax.accessibility.Accessible child = null;
226             try {
227                 XAccessible xAccessible = unoAccessibleTable.getAccessibleCellAt(r,c);
228                 if (xAccessible != null) {
229                     // Re-use the active descandant wrapper if possible
230                     javax.accessibility.Accessible activeDescendant = Table.this.activeDescendant;
231                     if ((activeDescendant instanceof TableCell) && xAccessible.equals(((TableCell) activeDescendant).unoAccessible)) {
232                         child = activeDescendant;
233                     } else {
234                         child = new TableCell(xAccessible);
235                     }
236                 }
237             } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
238             } catch (com.sun.star.uno.RuntimeException e) {
239             }
240             return child;
241         }
242 
243         /** Returns the caption for the table. */
getAccessibleCaption()244         public javax.accessibility.Accessible getAccessibleCaption() {
245             // Not yet supported.
246             return null;
247         }
248 
249         /** Returns the number of columns in the table. */
getAccessibleColumnCount()250         public int getAccessibleColumnCount() {
251              try {
252                 return unoAccessibleTable.getAccessibleColumnCount();
253             } catch (com.sun.star.uno.RuntimeException e) {
254                 return 0;
255             }
256        }
257 
258         /** Returns the description text of the specified column in the table. */
getAccessibleColumnDescription(int c)259         public javax.accessibility.Accessible getAccessibleColumnDescription(int c) {
260             try {
261                 return new javax.swing.JLabel(
262                     unoAccessibleTable.getAccessibleColumnDescription(c));
263             } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
264                 return null;
265             } catch (com.sun.star.uno.RuntimeException e) {
266                 return null;
267             }
268         }
269 
270         /**
271          * Returns the number of columns occupied by the Accessible
272          * at a specified row and column in the table.
273          */
getAccessibleColumnExtentAt(int r, int c)274         public int getAccessibleColumnExtentAt(int r, int c) {
275             try {
276                 return unoAccessibleTable.getAccessibleColumnExtentAt(r,c);
277             } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
278                 return 0;
279             } catch (com.sun.star.uno.RuntimeException e) {
280                 return 0;
281             }
282         }
283 
284         /** Returns the column headers as an AccessibleTable. */
getAccessibleColumnHeader()285         public javax.accessibility.AccessibleTable getAccessibleColumnHeader() {
286             // Not yet supported
287             return null;
288         }
289 
290         /** Returns the number of rows in the table. */
getAccessibleRowCount()291         public int getAccessibleRowCount() {
292              try {
293                 return unoAccessibleTable.getAccessibleRowCount();
294             } catch (com.sun.star.uno.RuntimeException e) {
295                 return 0;
296             }
297         }
298 
299         /** Returns the description of the specified row in the table. */
getAccessibleRowDescription(int r)300         public javax.accessibility.Accessible getAccessibleRowDescription(int r) {
301             try {
302                 return new javax.swing.JLabel(
303                     unoAccessibleTable.getAccessibleRowDescription(r));
304             } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
305                 return null;
306             } catch (com.sun.star.uno.RuntimeException e) {
307                 return null;
308             }
309         }
310 
311         /**
312          * Returns the number of rows occupied by the Accessible
313          * at a specified row and column in the table.
314          */
getAccessibleRowExtentAt(int r, int c)315         public int getAccessibleRowExtentAt(int r, int c) {
316             try {
317                 return unoAccessibleTable.getAccessibleRowExtentAt(r,c);
318             } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
319                 return 0;
320             } catch (com.sun.star.uno.RuntimeException e) {
321                 return 0;
322             }
323         }
324 
325         /** Returns the row headers as an AccessibleTable. */
getAccessibleRowHeader()326         public javax.accessibility.AccessibleTable getAccessibleRowHeader() {
327             // Not yet supported
328             return null;
329         }
330 
331         /** Returns the summary description of the table. */
getAccessibleSummary()332         public javax.accessibility.Accessible getAccessibleSummary() {
333             // Not yet supported.
334             return null;
335         }
336 
337         /** Returns the selected columns in a table. */
getSelectedAccessibleColumns()338         public int[] getSelectedAccessibleColumns() {
339             try {
340                 return unoAccessibleTable.getSelectedAccessibleColumns();
341             } catch (com.sun.star.uno.RuntimeException e) {
342                 return null;
343             }
344         }
345 
346         /** Returns the selected rows in a table. */
getSelectedAccessibleRows()347         public int[] getSelectedAccessibleRows() {
348             try {
349                 return unoAccessibleTable.getSelectedAccessibleRows();
350             } catch (com.sun.star.uno.RuntimeException e) {
351                 return null;
352             }
353         }
354 
355         /** Returns a boolean value indicating whether the specified column is selected. */
isAccessibleColumnSelected(int c)356         public boolean isAccessibleColumnSelected(int c) {
357             try {
358                 return unoAccessibleTable.isAccessibleColumnSelected(c);
359             } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
360                 return false;
361             } catch (com.sun.star.uno.RuntimeException e) {
362                 return false;
363             }
364         }
365 
366         /** Returns a boolean value indicating whether the specified row is selected. */
isAccessibleRowSelected(int r)367         public boolean isAccessibleRowSelected(int r) {
368             try {
369                 return unoAccessibleTable.isAccessibleRowSelected(r);
370             } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
371                 return false;
372             } catch (com.sun.star.uno.RuntimeException e) {
373                 return false;
374             }
375         }
376 
377         /**
378          * Returns a boolean value indicating whether the accessible
379          * at a specified row and column is selected.
380          */
isAccessibleSelected(int r, int c)381         public boolean isAccessibleSelected(int r, int c) {
382             try {
383                 return unoAccessibleTable.isAccessibleSelected(r,c);
384             } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
385                 return false;
386             } catch (com.sun.star.uno.RuntimeException e) {
387                 return false;
388             }
389         }
390 
391         /** Sets the caption for the table. */
setAccessibleCaption(javax.accessibility.Accessible accessible)392         public void setAccessibleCaption(javax.accessibility.Accessible accessible) {
393             // Not supported by the UNO Accessibility API
394         }
395 
396         /** Sets the description text of the specified column in the table. */
setAccessibleColumnDescription(int param, javax.accessibility.Accessible accessible)397         public void setAccessibleColumnDescription(int param, javax.accessibility.Accessible accessible) {
398             // Not supported by the UNO Accessibility API
399         }
400 
401         /** Sets the column headers. */
setAccessibleColumnHeader(javax.accessibility.AccessibleTable accessibleTable)402         public void setAccessibleColumnHeader(javax.accessibility.AccessibleTable accessibleTable) {
403             // Not supported by the UNO Accessibility API
404         }
405 
406         /** Sets the description text of the specified row of the table. */
setAccessibleRowDescription(int param, javax.accessibility.Accessible accessible)407         public void setAccessibleRowDescription(int param, javax.accessibility.Accessible accessible) {
408             // Not supported by the UNO Accessibility API
409         }
410 
411         /** Sets the row headers. */
setAccessibleRowHeader(javax.accessibility.AccessibleTable accessibleTable)412         public void setAccessibleRowHeader(javax.accessibility.AccessibleTable accessibleTable) {
413             // Not supported by the UNO Accessibility API
414         }
415 
416         /** Sets the summary description of the table */
setAccessibleSummary(javax.accessibility.Accessible accessible)417         public void setAccessibleSummary(javax.accessibility.Accessible accessible) {
418             // Not supported by the UNO Accessibility API
419         }
420 
421         /** Returns the column number of an index in the table */
getAccessibleColumn(int index)422         public int getAccessibleColumn(int index) {
423             try {
424                 return unoAccessibleTable.getAccessibleColumn(index);
425             } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
426                 return -1;
427             } catch (com.sun.star.uno.RuntimeException e) {
428                 return -1;
429             }
430         }
431 
432         /** Returns the index of a specified row and column in the table. */
getAccessibleIndex(int r, int c)433         public int getAccessibleIndex(int r, int c) {
434             try {
435                 return unoAccessibleTable.getAccessibleIndex(r,c);
436             } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
437                 return -1;
438             } catch (com.sun.star.uno.RuntimeException e) {
439                 return -1;
440             }
441         }
442 
443         /** Returns the row number of an index in the table */
getAccessibleRow(int index)444         public int getAccessibleRow(int index) {
445             try {
446                 return unoAccessibleTable.getAccessibleRow(index);
447             } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
448                 return -1;
449             } catch (com.sun.star.uno.RuntimeException e) {
450                 return -1;
451             }
452         }
453     }
454 
455     class TableCell extends java.awt.Component implements javax.accessibility.Accessible {
456 
457         protected XAccessible unoAccessible;
458 
TableCell(XAccessible xAccessible)459         public TableCell(XAccessible xAccessible) {
460             unoAccessible = xAccessible;
461         }
462 
create(Object[] targetSet)463         public Object[] create(Object[] targetSet) {
464             try {
465                 java.util.ArrayList list = new java.util.ArrayList(targetSet.length);
466                 for (int i=0; i < targetSet.length; i++) {
467                     XAccessible xAccessible = (XAccessible) UnoRuntime.queryInterface(
468                         XAccessible.class, targetSet[i]);
469                     if (xAccessible != null) {
470                         list.add(new TableCell(xAccessible));
471                     }
472                 }
473                 list.trimToSize();
474                 return list.toArray();
475             } catch (com.sun.star.uno.RuntimeException e) {
476                 return null;
477             }
478         }
479 
480         javax.accessibility.AccessibleContext accessibleContext = null;
481 
482         /** Returns the AccessibleContext associated with this object */
getAccessibleContext()483         public javax.accessibility.AccessibleContext getAccessibleContext() {
484             if (accessibleContext == null) {
485                 try {
486                     XAccessibleContext xAccessibleContext = unoAccessible.getAccessibleContext();
487                     if (xAccessibleContext != null) {
488                                             javax.accessibility.AccessibleContext ac = new AccessibleTableCell(xAccessibleContext);
489                                             if (ac != null) {
490                                                 ac.setAccessibleParent(Table.this);
491                                                 accessibleContext = ac;
492                                             }
493                     }
494                 } catch (com.sun.star.uno.RuntimeException e) {
495                 }
496             }
497             return accessibleContext;
498         }
499 
500         protected class AccessibleTableCell extends javax.accessibility.AccessibleContext {
501 
502             XAccessibleContext unoAccessibleContext;
503 
AccessibleTableCell(XAccessibleContext xAccessibleContext)504             public AccessibleTableCell(XAccessibleContext xAccessibleContext) {
505                 unoAccessibleContext = xAccessibleContext;
506             }
507 
508             /** Returns the accessible name of this object */
getAccessibleName()509             public String getAccessibleName() {
510                 try {
511                     return unoAccessibleContext.getAccessibleName();
512                 } catch (com.sun.star.uno.RuntimeException e) {
513                     return null;
514                 }
515             }
516 
517             /** Sets the accessible name of this object */
setAccessibleName(String name)518             public void setAccessibleName(String name) {
519                 // Not supported
520             }
521 
522             /** Returns the accessible name of this object */
getAccessibleDescription()523             public String getAccessibleDescription() {
524                 try {
525                     return unoAccessibleContext.getAccessibleDescription();
526                 } catch (com.sun.star.uno.RuntimeException e) {
527                     return null;
528                 }
529             }
530 
531             /** Sets the accessible name of this object */
setAccessibleDescription(String name)532             public void setAccessibleDescription(String name) {
533                 // Not supported
534             }
535 
536             /** Returns the accessible role of this object */
getAccessibleRole()537             public javax.accessibility.AccessibleRole getAccessibleRole() {
538                 try {
539                     javax.accessibility.AccessibleRole role = AccessibleRoleAdapter.getAccessibleRole(
540                         unoAccessibleContext.getAccessibleRole());
541                     return (role != null) ? role : javax.accessibility.AccessibleRole.LABEL;
542                 } catch(com.sun.star.uno.RuntimeException e) {
543                     return null;
544                 }
545             }
546 
547             /** Gets the locale of the component */
getLocale()548             public java.util.Locale getLocale() throws java.awt.IllegalComponentStateException {
549                 try {
550                     com.sun.star.lang.Locale unoLocale = unoAccessibleContext.getLocale();
551                     return new java.util.Locale(unoLocale.Language, unoLocale.Country);
552                 } catch (IllegalAccessibleComponentStateException e) {
553                     throw new java.awt.IllegalComponentStateException(e.getMessage());
554                 } catch (com.sun.star.uno.RuntimeException e) {
555                     return Table.this.getLocale();
556                 }
557             }
558 
559             /** Gets the 0-based index of this object in its accessible parent */
getAccessibleIndexInParent()560             public int getAccessibleIndexInParent() {
561                 try {
562                     return unoAccessibleContext.getAccessibleIndexInParent();
563                 } catch (com.sun.star.uno.RuntimeException e) {
564                     return -1;
565                 }
566             }
567 
568             /** Returns the number of accessible children of the object. */
getAccessibleChildrenCount()569             public int getAccessibleChildrenCount() {
570                 try {
571                     return unoAccessibleContext.getAccessibleChildCount();
572                 } catch (com.sun.star.uno.RuntimeException e) {
573                     return 0;
574                 }
575             }
576 
577             /** Returns the specified Accessible child of the object. */
getAccessibleChild(int i)578             public javax.accessibility.Accessible getAccessibleChild(int i) {
579                 javax.accessibility.Accessible child = null;
580                 try {
581                     XAccessible xAccessible = unoAccessibleContext.getAccessibleChild(i);
582                     // Re-use the active descandant wrapper if possible
583                     javax.accessibility.Accessible activeDescendant = Table.this.activeDescendant;
584                     if ((activeDescendant instanceof TableCell) && ((TableCell) activeDescendant).unoAccessible.equals(xAccessible)) {
585                         child = activeDescendant;
586                     } else if (xAccessible != null) {
587                         child = new TableCell(xAccessible);
588                     }
589                 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
590                 } catch (com.sun.star.uno.RuntimeException e) {
591                 }
592                 return child;
593             }
594 
595             /** Returns the state set of this object */
getAccessibleStateSet()596             public javax.accessibility.AccessibleStateSet getAccessibleStateSet() {
597                 try {
598                     return AccessibleStateAdapter.getAccessibleStateSet(TableCell.this,
599                         unoAccessibleContext.getAccessibleStateSet());
600                 } catch (com.sun.star.uno.RuntimeException e) {
601                     return AccessibleStateAdapter.getDefunctStateSet();
602                 }
603             }
604 
605             /** Returns the relation set of this object */
getAccessibleRelationSet()606             public javax.accessibility.AccessibleRelationSet getAccessibleRelationSet() {
607                 try {
608                     XAccessibleRelationSet unoAccessibleRelationSet = unoAccessibleContext.getAccessibleRelationSet();
609                     if (unoAccessibleRelationSet == null) {
610                         return null;
611                     }
612 
613                     javax.accessibility.AccessibleRelationSet relationSet = new javax.accessibility.AccessibleRelationSet();
614                     int count = unoAccessibleRelationSet.getRelationCount();
615                     for (int i = 0; i < count; i++) {
616                         AccessibleRelation unoAccessibleRelation = unoAccessibleRelationSet.getRelation(i);
617                         switch (unoAccessibleRelation.RelationType) {
618                             case AccessibleRelationType.CONTROLLED_BY:
619                                 relationSet.add(new javax.accessibility.AccessibleRelation(
620                                     javax.accessibility.AccessibleRelation.CONTROLLED_BY,
621                                     create(unoAccessibleRelation.TargetSet)));
622                                 break;
623                             case AccessibleRelationType.CONTROLLER_FOR:
624                                 relationSet.add(new javax.accessibility.AccessibleRelation(
625                                     javax.accessibility.AccessibleRelation.CONTROLLER_FOR,
626                                     create(unoAccessibleRelation.TargetSet)));
627                                 break;
628                             case AccessibleRelationType.LABELED_BY:
629                                 relationSet.add(new javax.accessibility.AccessibleRelation(
630                                     javax.accessibility.AccessibleRelation.LABELED_BY,
631                                     create(unoAccessibleRelation.TargetSet)));
632                                 break;
633                             case AccessibleRelationType.LABEL_FOR:
634                                 relationSet.add(new javax.accessibility.AccessibleRelation(
635                                     javax.accessibility.AccessibleRelation.LABEL_FOR,
636                                     create(unoAccessibleRelation.TargetSet)));
637                                 break;
638                             case AccessibleRelationType.MEMBER_OF:
639                                 relationSet.add(new javax.accessibility.AccessibleRelation(
640                                     javax.accessibility.AccessibleRelation.MEMBER_OF,
641                                     create(unoAccessibleRelation.TargetSet)));
642                                 break;
643                             default:
644                                 break;
645                         }
646                     }
647                     return relationSet;
648                 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
649                     return null;
650                 } catch (com.sun.star.uno.RuntimeException e) {
651                     return null;
652                 }
653             }
654 
655             /** Gets the AccessibleComponent associated with this object that has a graphical representation */
getAccessibleComponent()656             public javax.accessibility.AccessibleComponent getAccessibleComponent() {
657                 try {
658                     XAccessibleComponent unoAccessibleComponent = (XAccessibleComponent)
659                         UnoRuntime.queryInterface(XAccessibleComponent.class, unoAccessibleContext);
660                     return (unoAccessibleComponent != null) ?
661                         new AccessibleComponentImpl(unoAccessibleComponent) : null;
662                 } catch (com.sun.star.uno.RuntimeException e) {
663                     return null;
664                 }
665             }
666 
667             /** Gets the AccessibleAction associated with this object that has a graphical representation */
getAccessibleAction()668             public javax.accessibility.AccessibleAction getAccessibleAction() {
669                 try {
670                     XAccessibleAction unoAccessibleAction = (XAccessibleAction)
671                         UnoRuntime.queryInterface(XAccessibleAction.class, unoAccessibleContext);
672                     return (unoAccessibleAction != null) ?
673                         new AccessibleActionImpl(unoAccessibleAction) : null;
674                 } catch (com.sun.star.uno.RuntimeException e) {
675                     return null;
676                 }
677             }
678 
679             /** Gets the AccessibleText associated with this object that has a graphical representation */
getAccessibleText()680             public javax.accessibility.AccessibleText getAccessibleText() {
681 
682                 if (disposed)
683                     return null;
684 
685                 try {
686                     XAccessibleText unoAccessibleText = (XAccessibleText)
687                         UnoRuntime.queryInterface(XAccessibleText.class, unoAccessibleContext);
688                     return (unoAccessibleText != null) ?
689                         new AccessibleTextImpl(unoAccessibleText) : null;
690                 } catch (com.sun.star.uno.RuntimeException e) {
691                     return null;
692                 }
693             }
694 
695             /** Gets the AccessibleValue associated with this object that has a graphical representation */
getAccessibleValue()696             public javax.accessibility.AccessibleValue getAccessibleValue() {
697                 try {
698                     XAccessibleValue unoAccessibleValue = (XAccessibleValue)
699                         UnoRuntime.queryInterface(XAccessibleValue.class, unoAccessibleContext);
700                     return (unoAccessibleValue != null) ?
701                         new AccessibleValueImpl(unoAccessibleValue) : null;
702                 } catch (com.sun.star.uno.RuntimeException e) {
703                     return null;
704                 }
705             }
706 
707             /** Gets the AccessibleText associated with this object presenting text on the display */
getAccessibleIcon()708             public javax.accessibility.AccessibleIcon[] getAccessibleIcon() {
709                 try {
710                     XAccessibleImage unoAccessibleImage = (XAccessibleImage)
711                         UnoRuntime.queryInterface(XAccessibleImage.class, unoAccessibleContext);
712                     if (unoAccessibleImage != null) {
713                         javax.accessibility.AccessibleIcon[] icons = { new AccessibleIconImpl(unoAccessibleImage) };
714                         return icons;
715                     }
716                 } catch (com.sun.star.uno.RuntimeException e) {
717                 }
718                 return null;
719             }
720         }
721     }
722 }
723 
724