本文整理汇总了Java中javax.swing.tree.TreeNode.getChildAt方法的典型用法代码示例。如果您正苦于以下问题:Java TreeNode.getChildAt方法的具体用法?Java TreeNode.getChildAt怎么用?Java TreeNode.getChildAt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.tree.TreeNode
的用法示例。
在下文中一共展示了TreeNode.getChildAt方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testLazyVisDestroy
import javax.swing.tree.TreeNode; //导入方法依赖的package包/类
public void testLazyVisDestroy() throws Exception {
LazyChildren lch = new LazyChildren();
AbstractNode a = new AbstractNode(lch);
List<String> arr = Collections.nCopies(100, "A");
lch.keys(arr.toArray(new String[0]));
TreeNode ta = Visualizer.findVisualizer(a);
final TreeNode snd = ta.getChildAt(2);
Reference<Node> sndNode = new WeakReference<Node>(Visualizer.findNode(snd));
assertEquals("Child check", "A", snd.toString());
assertEquals("Counter should be 1", 1, lch.cnt);
a.destroy();
assertGC("Whole subtree under a can be GCed now", sndNode);
}
示例2: testLazyFilterGet
import javax.swing.tree.TreeNode; //导入方法依赖的package包/类
public void testLazyFilterGet() throws Exception {
LazyChildren lch = new LazyChildren();
AbstractNode a = new AbstractNode(lch);
FilterNode fnode = new FilterNode(a);
TreeNode ta = Visualizer.findVisualizer(fnode);
assertEquals("Child check", "c", ta.getChildAt(2).toString());
assertEquals("Counter should be 1", 1, lch.cnt);
VisualizerNode vn = (VisualizerNode)ta.getChildAt(2);
String msg = ((VisualizerNode)ta).getChildren().dumpIndexes(vn);
if (msg.indexOf("'c'") == -1) {
fail("Missing note about visualizer node 'c': " + msg);
}
}
示例3: areSiblingsFullyChecked
import javax.swing.tree.TreeNode; //导入方法依赖的package包/类
private boolean areSiblingsFullyChecked() {
TreeNode parent = getParent();
for (int i = 0; i < parent.getChildCount(); i++) {
TreeNode node = parent.getChildAt(i);
if (node == this) {
continue;
}
if (!(node instanceof CheckTreeNode) || (((CheckTreeNode) node).getCheckState() != STATE_CHECKED)) {
return false;
}
}
return true;
}
示例4: areSiblingsUnchecked
import javax.swing.tree.TreeNode; //导入方法依赖的package包/类
private boolean areSiblingsUnchecked() {
TreeNode parent = getParent();
for (int i = 0; i < parent.getChildCount(); i++) {
TreeNode node = parent.getChildAt(i);
if (node == this) {
continue;
}
if (!(node instanceof CheckTreeNode) || (((CheckTreeNode) node).getCheckState() != STATE_UNCHECKED)) {
return false;
}
}
return true;
}
示例5: find
import javax.swing.tree.TreeNode; //导入方法依赖的package包/类
/**
* Retrieves the child of a given parent node that is
* a numbered tree node with a given number, if any.
* @return the correctly numbered child, or {@code null} if there
* is none such
*/
private NumberedTreeNode find(TreeNode parent, int number) {
NumberedTreeNode result = null;
int lower = 0;
int upper = parent.getChildCount() - 1;
boolean found = false;
while (!found && lower <= upper) {
int mid = (lower + upper) / 2;
result = (NumberedTreeNode) parent.getChildAt(mid);
int resultNumber = result.getNumber();
if (result.contains(number)) {
found = true;
} else if (resultNumber < number) {
lower = mid + 1;
} else if (resultNumber > number) {
upper = mid - 1;
}
}
return found ? result : null;
}
示例6: execute
import javax.swing.tree.TreeNode; //导入方法依赖的package包/类
@Override
public void execute() {
TreeNode root = (TreeNode) this.tree.getModel().getRoot();
List<DefaultMutableTreeNode> collapsableNodes = new ArrayList<>();
for (int i = 0; i < root.getChildCount(); i++) {
TreeNode child = root.getChildAt(i);
if (isDirectoryNode(child)) {
for (int j = 0; j < child.getChildCount(); j++) {
collapsableNodes.add((DefaultMutableTreeNode) child.getChildAt(j));
}
} else {
collapsableNodes.add((DefaultMutableTreeNode) child);
}
}
for (DefaultMutableTreeNode node : collapsableNodes) {
TreePath path = new TreePath(node.getPath());
if (!this.tree.isCollapsed(path)) {
this.tree.collapsePath(path);
}
}
}
示例7: treeExpanded
import javax.swing.tree.TreeNode; //导入方法依赖的package包/类
@Override
public void treeExpanded(final TreeExpansionEvent event) {
final TreePath treePath = event.getPath();
final Object expandedTreePathObject = treePath.getLastPathComponent();
if (!(expandedTreePathObject instanceof TreeNode)) {
return;
}
final TreeNode expandedTreeNode = (TreeNode) expandedTreePathObject;
if (expandedTreeNode.getChildCount() == 1) {
final TreeNode descendantTreeNode = expandedTreeNode.getChildAt(0);
if (descendantTreeNode.isLeaf()) {
return;
}
final TreePath nextTreePath = treePath.pathByAddingChild(descendantTreeNode);
tree.expandPath(nextTreePath);
}
}
示例8: getChildAfter
import javax.swing.tree.TreeNode; //导入方法依赖的package包/类
/**
* Returns the child in this node's child array that immediately follows
* <code>aChild</code>, which must be a child of this node. If
* <code>aChild</code> is the last child, returns null. This method performs
* a linear search of this node's children for <code>aChild</code> and is
* O(n) where n is the number of children; to traverse the entire array of
* children, use an enumeration instead.
*
* @param parent
* @param aChild
* @see #children
* @exception IllegalArgumentException if <code>aChild</code> is null or is
* not a child of this node
* @return the child of this node that immediately follows
* <code>aChild</code>
*/
public TreeNode getChildAfter(TreeNode parent, TreeNode aChild) {
if (aChild == null) {
throw new IllegalArgumentException("argument is null");
}
int index = parent.getIndex(aChild); // linear search
if (index == -1) {
throw new IllegalArgumentException("node is not a child");
}
if (index < parent.getChildCount() - 1) {
return parent.getChildAt(index + 1);
} else {
return null;
}
}
示例9: getChildBefore
import javax.swing.tree.TreeNode; //导入方法依赖的package包/类
/**
* Returns the child in this node's child array that immediately precedes
* <code>aChild</code>, which must be a child of this node. If
* <code>aChild</code> is the first child, returns null. This method
* performs a linear search of this node's children for <code>aChild</code>
* and is O(n) where n is the number of children.
*
* @param parent
* @param aChild
* @exception IllegalArgumentException if <code>aChild</code> is null or is
* not a child of this node
* @return the child of this node that immediately precedes
* <code>aChild</code>
*/
public TreeNode getChildBefore(TreeNode parent, TreeNode aChild) {
if (aChild == null) {
throw new IllegalArgumentException("argument is null");
}
int index = parent.getIndex(aChild); // linear search
if (index == -1) {
throw new IllegalArgumentException("argument is not a child");
}
if (index > 0) {
return parent.getChildAt(index - 1);
} else {
return null;
}
}
示例10: getSelectedNodes
import javax.swing.tree.TreeNode; //导入方法依赖的package包/类
private List<StoreEntryNode> getSelectedNodes(TreeNode node) {
List<StoreEntryNode> ret = new LinkedList<StoreEntryNode>();
int count = node.getChildCount();
for (int i = 0; i < count; i++) {
TreeNode child = node.getChildAt(i);
if(child instanceof StoreEntryNode) {
StoreEntryNode sen = (StoreEntryNode) child;
if(sen.isSelected()) {
ret.add(sen);
}
}
ret.addAll(getSelectedNodes(child));
}
return ret;
}
示例11: getPosition
import javax.swing.tree.TreeNode; //导入方法依赖的package包/类
private static String getPosition(AndroidTreeNode node) {
int count = 0;
TreeNode parent = node.getParent();
String nodeName = node.getClassName();
for (int i = 0; i < parent.getChildCount(); i++) {
AndroidTreeNode currNode = (AndroidTreeNode) parent.getChildAt(i);
if (currNode.getClassName().equals(nodeName)) {
count++;
if (currNode.equals(node)) {
return nodeName + "[" + count + "]";
}
}
}
return nodeName;
}
示例12: addContributedGrids
import javax.swing.tree.TreeNode; //导入方法依赖的package包/类
private void addContributedGrids(Map<String, Rectangle2D.Double> namesToBounds, TreeNode root) {
if (root.isLeaf())
addContributedGrid(namesToBounds, root);
else
for (int i = 0; i < root.getChildCount(); i++) {
TreeNode node = root.getChildAt(i);
addContributedGrids(namesToBounds, node);
}
}
示例13: getChildAt
import javax.swing.tree.TreeNode; //导入方法依赖的package包/类
public TreeNode getChildAt(TreeNode parent, int index) {
return parent.getChildAt(index);
}
示例14: getLastChild
import javax.swing.tree.TreeNode; //导入方法依赖的package包/类
/**
* Returns this node's last child. If this node has no children, throws
* NoSuchElementException.
*
* @param node
* @return the last child of this node
*/
public TreeNode getLastChild(TreeNode node) {
if (node.getChildCount() == 0) {
throw new Error("node has no children");
}
return node.getChildAt(node.getChildCount() - 1);
}