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