|
36 | 36 | import java.beans.PropertyChangeEvent;
|
37 | 37 | import java.beans.PropertyChangeListener;
|
38 | 38 | import java.lang.annotation.Native;
|
| 39 | +import java.lang.reflect.Constructor; |
39 | 40 | import java.lang.reflect.InvocationTargetException;
|
40 | 41 | import java.util.ArrayList;
|
41 | 42 | import java.util.HashSet;
|
|
63 | 64 | import javax.swing.JList;
|
64 | 65 | import javax.swing.JTree;
|
65 | 66 | import javax.swing.KeyStroke;
|
| 67 | +import javax.swing.tree.TreePath; |
66 | 68 |
|
67 | 69 | import sun.awt.AWTAccessor;
|
68 | 70 | import sun.lwawt.LWWindowPeer;
|
@@ -757,14 +759,75 @@ private static Object[] getChildrenAndRolesImpl(Accessible a, Component c, int w
|
757 | 759 | return new Object[]{childrenAndRoles.get(whichChildren * 2), childrenAndRoles.get((whichChildren * 2) + 1)};
|
758 | 760 | }
|
759 | 761 |
|
| 762 | + private static Accessible createAccessibleTreeNode(JTree t, TreePath p) { |
| 763 | + Accessible a = null; |
| 764 | + |
| 765 | + try { |
| 766 | + Class<?> accessibleJTreeNodeClass = Class.forName("javax.swing.JTree$AccessibleJTree$AccessibleJTreeNode"); |
| 767 | + Constructor<?> constructor = accessibleJTreeNodeClass.getConstructor(t.getAccessibleContext().getClass(), JTree.class, TreePath.class, Accessible.class); |
| 768 | + constructor.setAccessible(true); |
| 769 | + a = ((Accessible) constructor.newInstance(t.getAccessibleContext(), t, p, null)); |
| 770 | + } catch (Exception e) { |
| 771 | + e.printStackTrace(); |
| 772 | + } |
| 773 | + |
| 774 | + return a; |
| 775 | + } |
| 776 | + |
760 | 777 | // This method is called from the native
|
761 | 778 | // Each child takes up three entries in the array: one for itself, one for its role, and one for the recursion level
|
762 | 779 | private static Object[] getChildrenAndRolesRecursive(final Accessible a, final Component c, final int whichChildren, final boolean allowIgnored, final int level) {
|
763 | 780 | if (a == null) return null;
|
764 | 781 | return invokeAndWait(new Callable<Object[]>() {
|
765 | 782 | public Object[] call() throws Exception {
|
766 |
| - ArrayList<Object> currentLevelChildren = new ArrayList<Object>(); |
767 | 783 | ArrayList<Object> allChildren = new ArrayList<Object>();
|
| 784 | + |
| 785 | + Accessible at = null; |
| 786 | + if (a instanceof CAccessible) { |
| 787 | + at = CAccessible.getSwingAccessible(a); |
| 788 | + } else { |
| 789 | + at = a; |
| 790 | + } |
| 791 | + |
| 792 | + if (at instanceof JTree) { |
| 793 | + JTree tree = ((JTree) at); |
| 794 | + |
| 795 | + if (whichChildren == JAVA_AX_ALL_CHILDREN) { |
| 796 | + int count = tree.getRowCount(); |
| 797 | + for (int i = 0; i < count; i++) { |
| 798 | + TreePath path = tree.getPathForRow(i); |
| 799 | + Accessible an = createAccessibleTreeNode(tree, path); |
| 800 | + if (an != null) { |
| 801 | + AccessibleContext ac = an.getAccessibleContext(); |
| 802 | + if (ac != null) { |
| 803 | + allChildren.add(an); |
| 804 | + allChildren.add(ac.getAccessibleRole());; |
| 805 | + allChildren.add(String.valueOf((tree.isRootVisible() ? path.getPathCount() : path.getPathCount() - 1))); |
| 806 | + } |
| 807 | + } |
| 808 | + } |
| 809 | + } |
| 810 | + |
| 811 | + if (whichChildren == JAVA_AX_SELECTED_CHILDREN) { |
| 812 | + int count = tree.getSelectionCount(); |
| 813 | + for (int i = 0; i < count; i++) { |
| 814 | + TreePath path = tree.getSelectionPaths()[i]; |
| 815 | + Accessible an = createAccessibleTreeNode(tree, path); |
| 816 | + if (an != null) { |
| 817 | + AccessibleContext ac = an.getAccessibleContext(); |
| 818 | + if (ac != null) { |
| 819 | + allChildren.add(an); |
| 820 | + allChildren.add(ac.getAccessibleRole()); |
| 821 | + allChildren.add(String.valueOf((tree.isRootVisible() ? path.getPathCount() : path.getPathCount() - 1))); |
| 822 | + } |
| 823 | + } |
| 824 | + } |
| 825 | + } |
| 826 | + |
| 827 | + return allChildren.toArray(); |
| 828 | + } |
| 829 | + |
| 830 | + ArrayList<Object> currentLevelChildren = new ArrayList<Object>(); |
768 | 831 | ArrayList<Accessible> parentStack = new ArrayList<Accessible>();
|
769 | 832 | parentStack.add(a);
|
770 | 833 | ArrayList<Integer> indexses = new ArrayList<Integer>();
|
|
0 commit comments