mirror of
https://github.com/JetBrains/JetBrainsRuntime.git
synced 2025-12-06 09:29:38 +01:00
JBR-3775 Optimize the algorithm for obtaining tree elements
(cherry picked from commit 01dbe66b3e)
This commit is contained in:
@@ -37,11 +37,13 @@ import java.beans.PropertyChangeEvent;
|
||||
import java.beans.PropertyChangeListener;
|
||||
import java.lang.annotation.Native;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.Arrays;
|
||||
|
||||
@@ -755,7 +757,7 @@ class CAccessibility implements PropertyChangeListener {
|
||||
|
||||
// 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) {
|
||||
private static Object[] getChildrenAndRolesRecursive(final Accessible a, final Component c, final int whichChildren, final boolean allowIgnored) {
|
||||
if (a == null) return null;
|
||||
return invokeAndWait(new Callable<Object[]>() {
|
||||
public Object[] call() throws Exception {
|
||||
@@ -766,7 +768,7 @@ class CAccessibility implements PropertyChangeListener {
|
||||
parentStack.add(a);
|
||||
ArrayList<Integer> indexses = new ArrayList<Integer>();
|
||||
Integer index = 0;
|
||||
int currentLevel = level;
|
||||
int currentLevel = 0;
|
||||
while (!parentStack.isEmpty()) {
|
||||
Accessible p = parentStack.get(parentStack.size() - 1);
|
||||
if (!childrenOfParent.containsKey(p)) {
|
||||
|
||||
@@ -55,7 +55,7 @@ static jmethodID jm_getChildrenAndRolesRecursive = NULL;
|
||||
#define GET_CHILDRENANDROLESRECURSIVE_METHOD_RETURN(ret) \
|
||||
GET_CACCESSIBILITY_CLASS_RETURN(ret); \
|
||||
GET_STATIC_METHOD_RETURN(jm_getChildrenAndRolesRecursive, sjc_CAccessibility, "getChildrenAndRolesRecursive",\
|
||||
"(Ljavax/accessibility/Accessible;Ljava/awt/Component;IZI)[Ljava/lang/Object;", ret);
|
||||
"(Ljavax/accessibility/Accessible;Ljava/awt/Component;IZ)[Ljava/lang/Object;", ret);
|
||||
|
||||
static jmethodID sjm_getAccessibleComponent = NULL;
|
||||
#define GET_ACCESSIBLECOMPONENT_STATIC_METHOD_RETURN(ret) \
|
||||
@@ -458,7 +458,7 @@ static jobject sAccessibilityClass = NULL;
|
||||
if (recursive) {
|
||||
GET_CHILDRENANDROLESRECURSIVE_METHOD_RETURN(nil);
|
||||
jchildrenAndRoles = (jobjectArray)(*env)->CallStaticObjectMethod(env, sjc_CAccessibility, jm_getChildrenAndRolesRecursive,
|
||||
parent->fAccessible, parent->fComponent, whichChildren, allowIgnored, 0);
|
||||
parent->fAccessible, parent->fComponent, whichChildren, allowIgnored);
|
||||
CHECK_EXCEPTION();
|
||||
} else {
|
||||
GET_CHILDRENANDROLES_METHOD_RETURN(nil);
|
||||
|
||||
@@ -4786,11 +4786,7 @@ public class JTree extends JComponent implements Scrollable, Accessible
|
||||
return null;
|
||||
} else {
|
||||
Object childObj = treeModel.getChild(obj, i);
|
||||
Object[] objPath = path.getPath();
|
||||
Object[] objChildPath = new Object[objPath.length+1];
|
||||
java.lang.System.arraycopy(objPath, 0, objChildPath, 0, objPath.length);
|
||||
objChildPath[objChildPath.length-1] = childObj;
|
||||
return new TreePath(objChildPath);
|
||||
return path.pathByAddingChild(childObj);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4981,16 +4977,12 @@ public class JTree extends JComponent implements Scrollable, Accessible
|
||||
// someone wants to know, so we need to create our parent
|
||||
// if we don't have one (hey, we're a talented kid!)
|
||||
if (accessibleParent == null) {
|
||||
Object[] objPath = path.getPath();
|
||||
if (objPath.length > 1) {
|
||||
Object objParent = objPath[objPath.length-2];
|
||||
TreePath parentPath = path.getParentPath();
|
||||
if (parentPath != null) {
|
||||
Object objParent = parentPath.getLastPathComponent();
|
||||
if (treeModel != null) {
|
||||
index = treeModel.getIndexOfChild(objParent, obj);
|
||||
}
|
||||
Object[] objParentPath = new Object[objPath.length-1];
|
||||
java.lang.System.arraycopy(objPath, 0, objParentPath,
|
||||
0, objPath.length-1);
|
||||
TreePath parentPath = new TreePath(objParentPath);
|
||||
accessibleParent = new AccessibleJTreeNode(tree,
|
||||
parentPath,
|
||||
null);
|
||||
@@ -5032,6 +5024,7 @@ public class JTree extends JComponent implements Scrollable, Accessible
|
||||
* @return the number of accessible children in the object.
|
||||
*/
|
||||
public int getAccessibleChildrenCount() {
|
||||
if (tree.isCollapsed(path)) return 0; // skip children of collapsed node
|
||||
// Tree nodes can't be so complex that they have
|
||||
// two sets of children -> we're ignoring that case
|
||||
return treeModel.getChildCount(obj);
|
||||
@@ -5044,17 +5037,10 @@ public class JTree extends JComponent implements Scrollable, Accessible
|
||||
* @return the Accessible child of the object
|
||||
*/
|
||||
public Accessible getAccessibleChild(int i) {
|
||||
// Tree nodes can't be so complex that they have
|
||||
// two sets of children -> we're ignoring that case
|
||||
if (i < 0 || i >= getAccessibleChildrenCount()) {
|
||||
TreePath childPath = getChildTreePath(i);
|
||||
if (childPath == null) {
|
||||
return null;
|
||||
} else {
|
||||
Object childObj = treeModel.getChild(obj, i);
|
||||
Object[] objPath = path.getPath();
|
||||
Object[] objChildPath = new Object[objPath.length+1];
|
||||
java.lang.System.arraycopy(objPath, 0, objChildPath, 0, objPath.length);
|
||||
objChildPath[objChildPath.length-1] = childObj;
|
||||
TreePath childPath = new TreePath(objChildPath);
|
||||
return new AccessibleJTreeNode(JTree.this, childPath, this);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user