use of javax.swing.tree.TreeNode in project selenium_java by sergueik.
the class JTreeZipFile method addTreeNode.
private DefaultMutableTreeNode addTreeNode(final DefaultMutableTreeNode parent, final String childText, final boolean isFolder, final ZipEntry ze) {
if (parent == null) {
throw new IllegalArgumentException("parent node cannot be null.");
}
if (childText == null || childText.isEmpty()) {
throw new IllegalArgumentException("child node text cannot be null or empty.");
}
DefaultMutableTreeNode child = null;
if (parent.isLeaf()) {
child = new DefaultMutableTreeNode(new JTreeNodeZipFile(childText, ze));
parent.add(child);
} else {
final int childCount = parent.getChildCount();
TreeNode childTreeNode = null;
for (int i = 0; i < childCount; i++) {
childTreeNode = parent.getChildAt(i);
if (childText.equals(childTreeNode.toString()) && childTreeNode instanceof DefaultMutableTreeNode) {
child = (DefaultMutableTreeNode) childTreeNode;
}
}
if (child == null) {
// Change the tree node icon here accroding to 'isFolder'.
child = new DefaultMutableTreeNode(new JTreeNodeZipFile(childText, ze));
parent.add(child);
}
}
return child;
}
use of javax.swing.tree.TreeNode in project keystore-explorer by kaikramer.
the class DProperties method expandTwoLevels.
private void expandTwoLevels(TreePath treePath) {
if (treePath.getPathCount() > 2) {
return;
}
TreeNode node = (TreeNode) treePath.getLastPathComponent();
if (node.getChildCount() >= 0) {
for (Enumeration<?> enumChildren = node.children(); enumChildren.hasMoreElements(); ) {
TreeNode subNode = (TreeNode) enumChildren.nextElement();
TreePath path = treePath.pathByAddingChild(subNode);
expandTwoLevels(path);
}
}
jtrProperties.expandPath(treePath);
}
use of javax.swing.tree.TreeNode in project keystore-explorer by kaikramer.
the class DViewCertificate method expandTree.
private void expandTree(JTree tree, TreePath parent) {
TreeNode node = (TreeNode) parent.getLastPathComponent();
if (node.getChildCount() >= 0) {
for (Enumeration<?> enumNodes = node.children(); enumNodes.hasMoreElements(); ) {
TreeNode subNode = (TreeNode) enumNodes.nextElement();
TreePath path = parent.pathByAddingChild(subNode);
expandTree(tree, path);
}
}
tree.expandPath(parent);
}
use of javax.swing.tree.TreeNode in project Spark by igniterealtime.
the class Tree method find2.
private TreePath find2(Tree tree, TreePath parent, Object[] nodes, int depth, boolean byName) {
TreeNode node = (TreeNode) parent.getLastPathComponent();
Object o = node;
// If by name, convert node to a string
if (byName) {
o = o.toString();
}
// If equal, go down the branch
if (o.equals(nodes[depth])) {
// If at end, return match
if (depth == nodes.length - 1) {
return parent;
}
// Traverse children
if (node.getChildCount() >= 0) {
for (Enumeration<TreeNode> e = node.children(); e.hasMoreElements(); ) {
TreeNode n = e.nextElement();
TreePath path = parent.pathByAddingChild(n);
TreePath result = find2(tree, path, nodes, depth + 1, byName);
// Found a match
if (result != null) {
return result;
}
}
}
}
// No match at this branch
return null;
}
use of javax.swing.tree.TreeNode in project triplea by triplea-game.
the class HistoryPanel method previous.
private void previous() {
if (tree.getSelectionCount() == 0) {
tree.setSelectionInterval(0, 0);
return;
}
final TreePath path = tree.getSelectionPath();
final TreeNode selected = (TreeNode) path.getLastPathComponent();
@SuppressWarnings("unchecked") final Enumeration<TreeNode> nodeEnum = ((DefaultMutableTreeNode) tree.getModel().getRoot()).depthFirstEnumeration();
TreeNode previous = null;
while (nodeEnum.hasMoreElements()) {
final TreeNode current = nodeEnum.nextElement();
if (current == selected) {
break;
} else if (current.getParent() instanceof Step) {
previous = current;
}
}
if (previous != null) {
navigateTo(previous);
}
}
Aggregations