Skip to content

Commit a26aa4d

Browse files
author
duke
committedJan 17, 2024
Automatic merge of jdk:master into master
2 parents b692700 + ffa33d7 commit a26aa4d

File tree

1 file changed

+64
-1
lines changed

1 file changed

+64
-1
lines changed
 

‎src/java.desktop/macosx/classes/sun/lwawt/macosx/CAccessibility.java

+64-1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import java.beans.PropertyChangeEvent;
3737
import java.beans.PropertyChangeListener;
3838
import java.lang.annotation.Native;
39+
import java.lang.reflect.Constructor;
3940
import java.lang.reflect.InvocationTargetException;
4041
import java.util.ArrayList;
4142
import java.util.HashSet;
@@ -63,6 +64,7 @@
6364
import javax.swing.JList;
6465
import javax.swing.JTree;
6566
import javax.swing.KeyStroke;
67+
import javax.swing.tree.TreePath;
6668

6769
import sun.awt.AWTAccessor;
6870
import sun.lwawt.LWWindowPeer;
@@ -757,14 +759,75 @@ private static Object[] getChildrenAndRolesImpl(Accessible a, Component c, int w
757759
return new Object[]{childrenAndRoles.get(whichChildren * 2), childrenAndRoles.get((whichChildren * 2) + 1)};
758760
}
759761

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+
760777
// This method is called from the native
761778
// Each child takes up three entries in the array: one for itself, one for its role, and one for the recursion level
762779
private static Object[] getChildrenAndRolesRecursive(final Accessible a, final Component c, final int whichChildren, final boolean allowIgnored, final int level) {
763780
if (a == null) return null;
764781
return invokeAndWait(new Callable<Object[]>() {
765782
public Object[] call() throws Exception {
766-
ArrayList<Object> currentLevelChildren = new ArrayList<Object>();
767783
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>();
768831
ArrayList<Accessible> parentStack = new ArrayList<Accessible>();
769832
parentStack.add(a);
770833
ArrayList<Integer> indexses = new ArrayList<Integer>();

0 commit comments

Comments
 (0)
Please sign in to comment.