下面列出了javax.swing.tree.TreeModel#getIndexOfChild ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
TreePath getNextPath(TreePath path, boolean down) {
TreeModel _model = model.treeModel;
TreeNode node = (TreeNode)path.getLastPathComponent();
if (down && _model.getChildCount(node) > 0)
return path.pathByAddingChild(_model.getChild(node, 0));
TreePath parentPath = path.getParentPath();
if (!down && parentPath == null)
return path.pathByAddingChild(_model.getChild(node, 0));
TreeNode parent = (TreeNode)parentPath.getLastPathComponent();
int idx = _model.getIndexOfChild(parent, node) + 1;
if (_model.getChildCount(parent) > idx)
return parentPath.pathByAddingChild(_model.getChild(parent, idx));
if (!down && parentPath.getParentPath() == null) {
return parentPath.pathByAddingChild(_model.getChild(parent, 0));
} else {
return getNextPath(parentPath, false);
}
}
TreePath getNextPath(TreePath path, boolean down) {
TreeModel _model = model.treeModel;
TreeNode node = (TreeNode)path.getLastPathComponent();
if (down && _model.getChildCount(node) > 0)
return path.pathByAddingChild(_model.getChild(node, 0));
TreePath parentPath = path.getParentPath();
if (!down && parentPath == null)
return path.pathByAddingChild(_model.getChild(node, 0));
TreeNode parent = (TreeNode)parentPath.getLastPathComponent();
int idx = _model.getIndexOfChild(parent, node) + 1;
if (_model.getChildCount(parent) > idx)
return parentPath.pathByAddingChild(_model.getChild(parent, idx));
if (!down && parentPath.getParentPath() == null) {
return parentPath.pathByAddingChild(_model.getChild(parent, 0));
} else {
return getNextPath(parentPath, false);
}
}
@Nonnull
private static List<PathElement> createPath(@Nonnull TreeModel model, @Nonnull TreePath treePath) {
Object prev = null;
int count = treePath.getPathCount();
PathElement[] result = new PathElement[count];
for (int i = 0; i < count; i++) {
Object cur = treePath.getPathComponent(i);
Object userObject = TreeUtil.getUserObject(cur);
int childIndex = prev == null ? 0 : model.getIndexOfChild(prev, cur);
result[i] = new PathElement(calcId(userObject), calcType(userObject), childIndex, userObject);
prev = cur;
}
return Arrays.asList(result);
}
@Override
protected int getIndexOfChild ( @NotNull final TreeModel model, @NotNull final N parent, @NotNull final N child )
{
return model.getIndexOfChild ( parent, child );
}
static void path2str(Object[] path, String[] strs, int idxs[], TreeModel model) {
for(int i = 0; i < strs.length; i++) {
strs[i] = path[i + 1].toString();
idxs[i] = model.getIndexOfChild(path[i], path[i + 1]);
}
}