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


Java TreeNode类代码示例

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


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

示例1: expandAll

import javax.swing.tree.TreeNode; //导入依赖的package包/类
private void expandAll(JTree tree, TreePath path, boolean expand) {
    TreeNode node = (TreeNode) path.getLastPathComponent();

    if (node.getChildCount() >= 0) {
        Enumeration enumeration = node.children();
        while (enumeration.hasMoreElements()) {
            TreeNode n = (TreeNode) enumeration.nextElement();
            TreePath p = path.pathByAddingChild(n);

            expandAll(tree, p, expand);
        }
    }

    if (expand) {
        tree.expandPath(path);
    } else {
        tree.collapsePath(path);
    }
}
 
开发者ID:HML-UnBBayes,项目名称:hml,代码行数:20,代码来源:TreePanel.java

示例2: initChildren

import javax.swing.tree.TreeNode; //导入依赖的package包/类
private void initChildren () {
    if (children != null) return;
    children = new ArrayList<TreeNode> ();
    map = new HashMap<ASTItem,TreeNode> ();
    if (astItem == null) return;
    List<ASTItem> chList = astItem.getChildren ();
    
    if (chList != null) {
        Iterator<ASTItem> it = chList.iterator ();
        while (it.hasNext ()) {
            ASTItem item = it.next ();
            TreeNode tn = new TNode (this, item);
            children.add (tn);
            map.put (item, tn);
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:18,代码来源:ASTBrowserTopComponent.java

示例3: getComparator

import javax.swing.tree.TreeNode; //导入依赖的package包/类
private Comparator getComparator() {
    SortOrder sortOrder = getSortOrder();
    if (SortOrder.UNSORTED.equals(sortOrder)) return null;
    
    final boolean ascending = SortOrder.ASCENDING.equals(sortOrder);
    final int sortColumn = getSortColumn();
    boolean sortingTree = JTree.class.equals(model.getColumnClass(sortColumn));
    final Comparator comparator = sortingTree ? null : getComparator(sortColumn);
    
    return new Comparator() {
        public int compare(Object o1, Object o2) {
            int result;
            if (comparator == null) {
                String s1 = o1.toString();
                String s2 = o2.toString();
                result = s1.compareTo(s2);
            } else {
                Object v1 = model.getValueAt((TreeNode)o1, sortColumn);
                Object v2 = model.getValueAt((TreeNode)o2, sortColumn);
                result = comparator.compare(v1, v2);
            }
            
            return ascending ? result : result * -1;
        }
    };
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:27,代码来源:ProfilerTreeTable.java

示例4: caretUpdate

import javax.swing.tree.TreeNode; //导入依赖的package包/类
public void caretUpdate (CaretEvent e) {
    if (rootNode == null) return;
    ASTPath path = rootNode.findPath (e.getDot ());
    if (path == null) return;
    TreeNode tNode = (TreeNode) tree.getModel ().getRoot ();
    List<TreeNode> treePath = new ArrayList<TreeNode> ();
    Iterator it = path.listIterator ();
    if (!it.hasNext ()) return;
    it.next ();
    treePath.add (tNode);
    while (tNode instanceof TNode && it.hasNext ()) {
        tNode = ((TNode) tNode).getTreeNode (it.next ());
        if (tNode == null) throw new NullPointerException ();
        treePath.add (tNode);
    }
    TreePath treePath2 = new TreePath (treePath.toArray ());
    DefaultTreeModel model = new DefaultTreeModel ((TreeNode) tree.getModel ().getRoot ());
    tree.setModel (model);
    tree.setSelectionPath (treePath2);
    tree.scrollPathToVisible (treePath2);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:22,代码来源:ASTBrowserTopComponent.java

示例5: 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:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:25,代码来源:ElementTreePanel.java

示例6: getChildAt

import javax.swing.tree.TreeNode; //导入依赖的package包/类
@Override public TreeNode getChildAt(int index) {
    if (object instanceof List) {
        return getNodeForList((List<?>) object, index);
    }
    if (object instanceof Map) {
        return getNodeForMap((Map<?, ?>) object, index);
    }
    Method method;
    if (object instanceof RComponent) {
        Method o = ((RComponent) object).getMethods().get(index);
        method = o;
    } else {
        method = getMethods(object).get(index);
    }
    return getNodeForMethod(method);
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:17,代码来源:AssertionTreeNode.java

示例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);
	}
}
 
开发者ID:KevinPriv,项目名称:Luyten4Forge,代码行数:22,代码来源:Model.java

示例8: testRemoveNodeInOutlineView

import javax.swing.tree.TreeNode; //导入依赖的package包/类
public void testRemoveNodeInOutlineView () throws InterruptedException {
    StringKeys children = new StringKeys (true);
    children.doSetKeys (new String [] {"1", "3", "2"});
    Node root = new TestNode (children, "root");
    comp = new OutlineViewComponent (root);
    ETableColumnModel etcm = (ETableColumnModel) comp.getOutlineView ().getOutline ().getColumnModel ();
    ETableColumn etc = (ETableColumn) etcm.getColumn (0); // tree column
    etcm.setColumnSorted (etc, true, 1); // ascending order

    TreeNode ta = Visualizer.findVisualizer(root);

    DialogDescriptor dd = new DialogDescriptor (comp, "", false, null);
    Dialog d = DialogDisplayer.getDefault ().createDialog (dd);
    d.setVisible (true);

    Thread.sleep (1000);
    ((StringKeys) root.getChildren ()).doSetKeys (new String [] {"1", "2"});
    Thread.sleep (1000);
    
    assertEquals ("Node on 0nd position is '1'", "1", ta.getChildAt (0).toString ());
    assertEquals ("Node on 1st position is '2'", "2", ta.getChildAt (1).toString ());

    d.setVisible (false);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:25,代码来源:OutlineView152857Test.java

示例9: testRemoveNodeInTTV

import javax.swing.tree.TreeNode; //导入依赖的package包/类
public void testRemoveNodeInTTV () throws InterruptedException {
    StringKeys children = new StringKeys (true);
    children.doSetKeys (new String [] {"1", "3", "2"});
    Node root = new TestNode (children, "root");
    view = new TTV (root);
    TreeNode ta = Visualizer.findVisualizer(root);

    DialogDescriptor dd = new DialogDescriptor (view, "", false, null);
    Dialog d = DialogDisplayer.getDefault ().createDialog (dd);
    makeVisible(d);
    ((StringKeys) root.getChildren ()).doSetKeys (new String [] {"1", "2"});
    Thread.sleep (1000);

    assertEquals ("Node on 0nd position is '1'", "1", ta.getChildAt (0).toString ());
    assertEquals ("Node on 1st position is '2'", "2", ta.getChildAt (1).toString ());

    d.setVisible (false);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:19,代码来源:TreeTableView152857Test.java

示例10: expandAll

import javax.swing.tree.TreeNode; //导入依赖的package包/类
/**
 * iterate through every child and do the action
 *
 * @param parent
 * @param expand
 */
private void expandAll(TreePath parent, boolean expand) {
    TreeNode node = (TreeNode) parent.getLastPathComponent();
    if (getChildCount(node) >= 0) {
        for (int i = 0; i < getChildCount(node); i++) {
            TreePath path = parent.pathByAddingChild(getChildAt(node, i));
            expandAll(path, expand);
        }
    }
    if (expand) {
        expandPath(parent);
    } else {
        collapsePath(parent);
    }

}
 
开发者ID:CognizantQAHub,项目名称:Cognizant-Intelligent-Test-Scripter,代码行数:22,代码来源:JCheckBoxTree.java

示例11: 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;
}
 
开发者ID:meteoorkip,项目名称:JavaGraph,代码行数:26,代码来源:StateTree.java

示例12: getPath

import javax.swing.tree.TreeNode; //导入依赖的package包/类
private TreeNode[] getPath(Object node, String deap, String item, boolean debug) {
    if (node instanceof DefaultMutableTreeNode) {
        DefaultMutableTreeNode dmtn = (DefaultMutableTreeNode) node;
        if (debug) {
            System.out.println(deap + dmtn.toString());
        }
        if (dmtn.toString().equals(item)) {
            if (debug) {
                System.out.println("EQUAL!!! <" + item + ">");
            }
            return dmtn.getPath();
        }
        TreeNode[] curPath;
        for (int i = 0; i < dmtn.getChildCount(); i++) {
            curPath = getPath(dmtn.getChildAt(i), deap + "__", item, debug);
            if (curPath != null) {
                return curPath;
            }
        }
    }
    return null;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:23,代码来源:ManageInspectionsOperatot.java

示例13: scrollNodeToVisible

import javax.swing.tree.TreeNode; //导入依赖的package包/类
private void scrollNodeToVisible( final Node n ) {
    EventQueue.invokeLater(new Runnable() {

        @Override
        public void run() {
            TreeNode tn = Visualizer.findVisualizer(n);
            if (tn == null) {
                return;
            }
            TreeModel model = tree.getModel();
            if (!(model instanceof DefaultTreeModel)) {
                return;
            }
            TreePath path = new TreePath(((DefaultTreeModel) model).getPathToRoot(tn));
            if( null == path )
                return;
            Rectangle r = tree.getPathBounds(path);
            if (r != null) {
                tree.scrollRectToVisible(r);
            }
        }
    });
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:24,代码来源:Tab.java

示例14: applyEdit

import javax.swing.tree.TreeNode; //导入依赖的package包/类
private void applyEdit(DirectoryNode node) {
    TreeNode[] nodes = model.getPathToRoot(node);
    TreePath editingPath = new TreePath(nodes);
    tree.setEditable(true);
    tree.makeVisible(editingPath);
    tree.scrollPathToVisible(editingPath);
    tree.setSelectionPath(editingPath);
    tree.startEditingAtPath(editingPath);
    
    JTextField editField = DirectoryCellEditor.getTextField();
    editField.setCursor(Cursor.getPredefinedCursor(Cursor.TEXT_CURSOR));
    editField.setRequestFocusEnabled(true);
    editField.requestFocus();
    editField.setSelectionStart(0);
    editField.setSelectionEnd(editField.getText().length());
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:17,代码来源:DirectoryChooserUI.java

示例15: getSearchHelper

import javax.swing.tree.TreeNode; //导入依赖的package包/类
protected SearchUtils.TreeHelper getSearchHelper() {
    return new SearchUtils.TreeHelper() {
        public int getNodeType(TreeNode tnode) {
            PresoObjAllocCCTNode node = (PresoObjAllocCCTNode)tnode;
            CCTNode parent = node.getParent();
            if (parent == null) return SearchUtils.TreeHelper.NODE_SKIP_DOWN; // invisible root
            
            if (parent.getParent() == null) {
                if (searchObjects) {
                    return searchAllocations ? SearchUtils.TreeHelper.NODE_SEARCH_DOWN :
                                               SearchUtils.TreeHelper.NODE_SEARCH_NEXT;
                } else {
                    return searchAllocations ? SearchUtils.TreeHelper.NODE_SKIP_DOWN :
                                               SearchUtils.TreeHelper.NODE_SKIP_NEXT;
                }
            }
            
            return searchAllocations ? SearchUtils.TreeHelper.NODE_SEARCH_DOWN :
                                       SearchUtils.TreeHelper.NODE_SKIP_NEXT;
        }
    };
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:23,代码来源:AllocTreeTableView.java


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