当前位置: 首页>>代码示例>>Java>>正文


Java TreeNode.getParent方法代码示例

本文整理汇总了Java中javax.swing.tree.TreeNode.getParent方法的典型用法代码示例。如果您正苦于以下问题:Java TreeNode.getParent方法的具体用法?Java TreeNode.getParent怎么用?Java TreeNode.getParent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.swing.tree.TreeNode的用法示例。


在下文中一共展示了TreeNode.getParent方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getTreePath

import javax.swing.tree.TreeNode; //导入方法依赖的package包/类
public static TreePath getTreePath(JTreeOperator treeOperator, String targetNode, NodeConverter converter) {
    Stack<TreeNode> lifo = new Stack<TreeNode>();        
    lifo.push((TreeNode) treeOperator.getRoot());
    while(!lifo.isEmpty()) {
        TreeNode actNode = lifo.pop();
        if(targetNode.equals(converter.getDisplayName(actNode))) {
            List<TreeNode> path = new LinkedList<TreeNode>();
            path.add(actNode);
            actNode = actNode.getParent();
            while(actNode!=null) {
                path.add(0,actNode);
                actNode = actNode.getParent();
            }
            TreeNode[] res = path.toArray(new TreeNode[path.size()]);                
            return new TreePath(res);
        }
        final Enumeration children = actNode.children();            
        while(children.hasMoreElements()) {
            lifo.add((TreeNode)children.nextElement());
        }            
    }
    return null;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:24,代码来源:BeansTestCase.java

示例2: getPathToRoot

import javax.swing.tree.TreeNode; //导入方法依赖的package包/类
private TreeNode[] getPathToRoot(TreeNode aNode) {
    TreeNode[] retNodes;
    ArrayList<TreeNode> temp = new ArrayList<TreeNode>();

    /* Check for null, in case someone passed in a null node, or
    they passed in an element that isn't rooted at root. */
    while (aNode != null) {
        temp.add(aNode);
        aNode = aNode.getParent();
    }

    int num = temp.size();
    retNodes = new TreeNode[num];
    for (int i = num - 1; i >= 0; i--) {
        retNodes[num - 1 - i] = temp.get(i);
    }

    return retNodes;
}
 
开发者ID:zeng198821,项目名称:CodeGenerate,代码行数:20,代码来源:CheckTreeSelectionModel.java

示例3: nodeChanged

import javax.swing.tree.TreeNode; //导入方法依赖的package包/类
/**
 * Invoke this method after you've changed how node is to be
 * represented in the tree.
 */
@Override
public void nodeChanged(TreeNode node) {
    if (listenerList != null && node != null) {
        TreeNode parent = node.getParent();

        if (parent == null && node != root) {
            parent = root;
        }
        if (parent != null) {
            int anIndex = getIndexOfChild(parent, node);

            if (anIndex != -1) {
                int[] cIndexs = new int[1];

                cIndexs[0] = anIndex;
                nodesChanged(parent, cIndexs);
            }
        }
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:25,代码来源:ElementTreePanel.java

示例4: getNextSibling

import javax.swing.tree.TreeNode; //导入方法依赖的package包/类
/**
 * Returns the next sibling of this node in the parent's children array.
 * Returns null if this node has no parent or is the parent's last child.
 * This method performs a linear search that is O(n) where n is the number
 * of children; to traverse the entire array, use the parent's child
 * enumeration instead.
 *
 * @param node
 * @see #children
 * @return the sibling of this node that immediately follows this node
 */
public TreeNode getNextSibling(TreeNode node) {
    TreeNode retval;

    TreeNode myParent = node.getParent();

    if (myParent == null) {
        retval = null;
    } else {
        retval = getChildAfter(myParent, node);      // linear search
    }

    if (retval != null && !isNodeSibling(node, retval)) {
        //            throw new Error("child of parent is not a sibling");
    }

    return retval;
}
 
开发者ID:CognizantQAHub,项目名称:Cognizant-Intelligent-Test-Scripter,代码行数:29,代码来源:TreeSearch.java

示例5: getPreviousSibling

import javax.swing.tree.TreeNode; //导入方法依赖的package包/类
/**
     * Returns the previous sibling of this node in the parent's children array.
     * Returns null if this node has no parent or is the parent's first child.
     * This method performs a linear search that is O(n) where n is the number
     * of children.
     *
     * @param node
     * @return the sibling of this node that immediately precedes this node
     */
    public TreeNode getPreviousSibling(TreeNode node) {
        TreeNode retval;

        TreeNode myParent = (TreeNode) node.getParent();

        if (myParent == null) {
            retval = null;
        } else {
            retval = getChildBefore(myParent, node);     // linear search
        }

        if (retval != null && !isNodeSibling(node, retval)) {
//            throw new Error("child of parent is not a sibling");
        }

        return retval;
    }
 
开发者ID:CognizantQAHub,项目名称:Cognizant-Intelligent-Test-Scripter,代码行数:27,代码来源:TreeSearch.java

示例6: isNodeSibling

import javax.swing.tree.TreeNode; //导入方法依赖的package包/类
/**
 * Returns true if <code>anotherNode</code> is a sibling of (has the same
 * parent as) this node. A node is its own sibling. If
 * <code>anotherNode</code> is null, returns false.
 *
 * @param node
 * @param anotherNode node to test as sibling of this node
 * @return true if <code>anotherNode</code> is a sibling of this node
 */
public boolean isNodeSibling(TreeNode node, TreeNode anotherNode) {
    boolean retval;

    if (anotherNode == null) {
        retval = false;
    } else if (anotherNode == node) {
        retval = true;
    } else {
        TreeNode myParent = node.getParent();
        retval = (myParent != null && myParent == anotherNode.getParent());

        if (retval && !isNodeChild(node.getParent(), anotherNode)) {
            throw new Error("sibling has different parent");
        }
    }

    return retval;
}
 
开发者ID:CognizantQAHub,项目名称:Cognizant-Intelligent-Test-Scripter,代码行数:28,代码来源:TreeSearch.java

示例7: getPathToRoot

import javax.swing.tree.TreeNode; //导入方法依赖的package包/类
/**
 * Returns the path to a particluar node. This is recursive.
 */
@Override
protected TreeNode[] getPathToRoot(TreeNode aNode, int depth) {
    TreeNode[] retNodes;

    /* Check for null, in case someone passed in a null node, or
    they passed in an element that isn't rooted at root. */
    if (aNode == null) {
        if (depth == 0) {
            return null;
        } else {
            retNodes = new TreeNode[depth];
        }
    } else {
        depth++;
        if (aNode == root) {
            retNodes = new TreeNode[depth];
        } else {
            TreeNode parent = aNode.getParent();

            if (parent == null) {
                parent = root;
            }
            retNodes = getPathToRoot(parent, depth);
        }
        retNodes[retNodes.length - depth] = aNode;
    }
    return retNodes;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:32,代码来源:ElementTreePanel.java

示例8: getIcon

import javax.swing.tree.TreeNode; //导入方法依赖的package包/类
public javax.swing.Icon getIcon(Object o) {
    if (!showIcons) {
        return emptyIcon;
    }
    Node n = Visualizer.findNode(o);
    if (n == null) {
        throw new IllegalStateException("TreeNode must be VisualizerNode but was: " + o + " of class " + o.getClass().getName());
    }
    boolean expanded = false;
    if (o instanceof TreeNode) {
        TreeNode tn = (TreeNode)o;
        ArrayList<TreeNode> al = new ArrayList<TreeNode> ();
        while (tn != null) {
            al.add(tn);
            tn = tn.getParent();
        }
        Collections.reverse(al);
        TreePath tp = new TreePath(al.toArray());
        AbstractLayoutCache layout = table.getLayoutCache();
        expanded = layout.isExpanded(tp);
    }
    java.awt.Image image = null;
    if (expanded) {
        image = n.getOpenedIcon(java.beans.BeanInfo.ICON_COLOR_16x16);
    } else {
        image = n.getIcon(java.beans.BeanInfo.ICON_COLOR_16x16);
    }
    return new ImageIcon(image);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:30,代码来源:NodeRenderDataProvider.java

示例9: expandSelection

import javax.swing.tree.TreeNode; //导入方法依赖的package包/类
/**
 * Tries to expand nodes selected in the explorer manager.
 */
private void expandSelection() {
    Node[] arr = manager.getSelectedNodes ();
    for (int i = 0; i < arr.length; i++) {
        if ( (arr[i].getParentNode() == null) && (! outline.isRootVisible())) {
            // don't try to show root if it is invisible
            continue;
        }
        TreeNode tn = Visualizer.findVisualizer(arr[i]);
        if (tn != null) {
            ArrayList<TreeNode> al = new ArrayList<TreeNode> ();
            while (tn != null) {
                al.add(tn);
                tn = tn.getParent();
            }
            Collections.reverse(al);
            TreePath tp = new TreePath(al.toArray());
            Deque<TreePath> pathsStack = new ArrayDeque<TreePath>(al.size());
            while ((tp != null) && (tp.getPathCount() > 0)) {
                tp = tp.getParentPath();
                if (tp != null) {
                    pathsStack.addFirst(tp);
                }
            }
            for (TreePath etp : pathsStack) {
                outline.expandPath(etp);
            }
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:33,代码来源:OutlineView.java

示例10: rowForNode

import javax.swing.tree.TreeNode; //导入方法依赖的package包/类
private int rowForNode(Node n) {
    TreeNode tn = Visualizer.findVisualizer(n);
    if (tn != null) {
        ArrayList<TreeNode> al = new ArrayList<TreeNode> ();
        while (tn != null) {
            al.add(tn);
            tn = tn.getParent();
        }
        Collections.reverse(al);
        TreePath tp = new TreePath(al.toArray());
        int row = outline.getLayoutCache().getRowForPath(tp);
        return row;
    }
    return -1;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:16,代码来源:PropertiesRowModel.java

示例11: configureNode

import javax.swing.tree.TreeNode; //导入方法依赖的package包/类
@Override
public void configureNode() {
    TreeNode parent = this.parent;
    while (!(parent instanceof ClassNode))
        parent = parent.getParent();
    file = ((ClassNode) parent).file;
    position = metDec.getBegin().get();
}
 
开发者ID:bufferhe4d,项目名称:call-IDE,代码行数:9,代码来源:MethodNode.java

示例12: configureNode

import javax.swing.tree.TreeNode; //导入方法依赖的package包/类
@Override
public void configureNode() {
    TreeNode parent = getParent();
    while (! (parent instanceof ClassNode))
        parent = parent.getParent();
    file = ((ClassNode) parent).file;
    
    position = conDec.getBegin().get();
}
 
开发者ID:bufferhe4d,项目名称:call-IDE,代码行数:10,代码来源:ConstructorNode.java

示例13: canMoveUp

import javax.swing.tree.TreeNode; //导入方法依赖的package包/类
@Override
public boolean canMoveUp(GenericTreeModel<T> model, T node)
{
	TreeNode parent = node.getParent();
	if( parent == null )
	{
		return false;
	}
	else
	{
		int index = parent.getIndex(node);
		return index > 0 || parent.getParent() != null;
	}
}
 
开发者ID:equella,项目名称:Equella,代码行数:15,代码来源:GenericTreeModel.java

示例14: canMoveDown

import javax.swing.tree.TreeNode; //导入方法依赖的package包/类
@Override
public boolean canMoveDown(GenericTreeModel<T> model, T node)
{
	TreeNode parent = node.getParent();
	if( parent == null )
	{
		return false;
	}
	else
	{
		int index = parent.getIndex(node);
		return index < parent.getChildCount() - 1 || parent.getParent() != null;
	}
}
 
开发者ID:equella,项目名称:Equella,代码行数:15,代码来源:GenericTreeModel.java

示例15: getTreePath

import javax.swing.tree.TreeNode; //导入方法依赖的package包/类
public static TreePath getTreePath(TreeNode treeNode) {
    List<Object> nodes = Lists.newArrayList(treeNode);
    while ((treeNode = treeNode.getParent()) != null) {
        nodes.add(0, treeNode);
    }
    return new TreePath(nodes.toArray());
}
 
开发者ID:JFrogDev,项目名称:jfrog-idea-plugin,代码行数:8,代码来源:ComponentUtils.java


注:本文中的javax.swing.tree.TreeNode.getParent方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。