diff --git a/src/java.desktop/macosx/classes/sun/lwawt/macosx/CAccessibility.java b/src/java.desktop/macosx/classes/sun/lwawt/macosx/CAccessibility.java index 67c8f184ecc..d4526324c58 100644 --- a/src/java.desktop/macosx/classes/sun/lwawt/macosx/CAccessibility.java +++ b/src/java.desktop/macosx/classes/sun/lwawt/macosx/CAccessibility.java @@ -36,6 +36,7 @@ import java.awt.event.KeyEvent; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.lang.annotation.Native; +import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; import java.util.HashSet; @@ -63,6 +64,7 @@ import javax.swing.JTextArea; import javax.swing.JList; import javax.swing.JTree; import javax.swing.KeyStroke; +import javax.swing.tree.TreePath; import sun.awt.AWTAccessor; import sun.lwawt.LWWindowPeer; @@ -757,14 +759,75 @@ class CAccessibility implements PropertyChangeListener { return new Object[]{childrenAndRoles.get(whichChildren * 2), childrenAndRoles.get((whichChildren * 2) + 1)}; } + private static Accessible createAccessibleTreeNode(JTree t, TreePath p) { + Accessible a = null; + + try { + Class accessibleJTreeNodeClass = Class.forName("javax.swing.JTree$AccessibleJTree$AccessibleJTreeNode"); + Constructor constructor = accessibleJTreeNodeClass.getConstructor(t.getAccessibleContext().getClass(), JTree.class, TreePath.class, Accessible.class); + constructor.setAccessible(true); + a = ((Accessible) constructor.newInstance(t.getAccessibleContext(), t, p, null)); + } catch (Exception e) { + e.printStackTrace(); + } + + return a; + } + // This method is called from the native // Each child takes up three entries in the array: one for itself, one for its role, and one for the recursion level private static Object[] getChildrenAndRolesRecursive(final Accessible a, final Component c, final int whichChildren, final boolean allowIgnored, final int level) { if (a == null) return null; return invokeAndWait(new Callable() { public Object[] call() throws Exception { - ArrayList currentLevelChildren = new ArrayList(); ArrayList allChildren = new ArrayList(); + + Accessible at = null; + if (a instanceof CAccessible) { + at = CAccessible.getSwingAccessible(a); + } else { + at = a; + } + + if (at instanceof JTree) { + JTree tree = ((JTree) at); + + if (whichChildren == JAVA_AX_ALL_CHILDREN) { + int count = tree.getRowCount(); + for (int i = 0; i < count; i++) { + TreePath path = tree.getPathForRow(i); + Accessible an = createAccessibleTreeNode(tree, path); + if (an != null) { + AccessibleContext ac = an.getAccessibleContext(); + if (ac != null) { + allChildren.add(an); + allChildren.add(ac.getAccessibleRole());; + allChildren.add(String.valueOf((tree.isRootVisible() ? path.getPathCount() : path.getPathCount() - 1))); + } + } + } + } + + if (whichChildren == JAVA_AX_SELECTED_CHILDREN) { + int count = tree.getSelectionCount(); + for (int i = 0; i < count; i++) { + TreePath path = tree.getSelectionPaths()[i]; + Accessible an = createAccessibleTreeNode(tree, path); + if (an != null) { + AccessibleContext ac = an.getAccessibleContext(); + if (ac != null) { + allChildren.add(an); + allChildren.add(ac.getAccessibleRole()); + allChildren.add(String.valueOf((tree.isRootVisible() ? path.getPathCount() : path.getPathCount() - 1))); + } + } + } + } + + return allChildren.toArray(); + } + + ArrayList currentLevelChildren = new ArrayList(); ArrayList parentStack = new ArrayList(); parentStack.add(a); ArrayList indexses = new ArrayList();