faster generic tag editor

This commit is contained in:
Honfika
2014-03-25 20:34:24 +01:00
parent cb6fd64d6c
commit 2ca0c18b72
@@ -488,14 +488,25 @@ public class GenericTagTreePanel extends GenericTagPanel {
private final Object mtroot;
private final List<TreeModelListener> listeners = new ArrayList<>();
private final Map<String, Object> nodeCache = new HashMap<>();
// it is much faster to store the reverse mappings, too
private final Map<Object, String> nodeCacheReverse = new HashMap<>();
private Object getNodeByPath(String path) {
if (nodeCache.containsKey(path)) {
return nodeCache.get(path);
}
return null;
}
public String getNodePathName(Object find) {
if (nodeCacheReverse.containsKey(find)) {
return nodeCacheReverse.get(find);
}
return null;
}
public List<FieldNode> getDependentFields(FieldNode fnode) {
List<FieldNode> ret = new ArrayList<>();
getDependentFields(getNodePathName(fnode), mtroot.getClass().getSimpleName(), mtroot, ret);
@@ -522,22 +533,13 @@ public class GenericTagTreePanel extends GenericTagPanel {
}
}
}
for (int i = 0; i < getChildCount(node); i++) {
int count = getChildCount(node);
for (int i = 0; i < count; i++) {
FieldNode f = (FieldNode) getChild(node, i);
getDependentFields(dependence, currentPath + "." + f.getName(), f, ret);
}
}
public String getNodePathName(Object find) {
for (Map.Entry<String, Object> en : nodeCache.entrySet()) {
if (en.getValue().equals(find)) {
return en.getKey();
}
}
return null;
}
public MyTreeModel(Tag root) {
super(new DefaultMutableTreeNode(root));
this.mtroot = root;
@@ -555,7 +557,9 @@ public class GenericTagTreePanel extends GenericTagPanel {
parentPath += obj.getClass().getSimpleName();
}
nodeCache.put(parentPath, obj);
for (int i = 0; i < getChildCount(obj, false); i++) {
nodeCacheReverse.put(obj, parentPath);
int count = getChildCount(obj, false);
for (int i = 0; i < count; i++) {
buildCache(getChild(obj, i, false), parentPath);
}
}