Java 类javax.swing.tree.TreeModel 实例源码

项目:incubator-netbeans    文件:ProjectTab.java   
public void scrollToNode(final Node n) {
        // has to be delayed to be sure that events for Visualizers
        // were processed and TreeNodes are already in hierarchy
        SwingUtilities.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));
                Rectangle r = tree.getPathBounds(path);
                if (r != null) {
                    tree.scrollRectToVisible(r);
                }
            }
        });
}
项目:incubator-netbeans    文件:DefaultOutlineModel.java   
/** Creates a new instance of DefaultOutlineModel.  <strong><b>Note</b> 
 * Do not fire table structure changes from the wrapped TableModel (value
 * changes are okay).  Changes that affect the number of rows must come
 * from the TreeModel.
 * @param treeModel The tree model
 * @param tableModel The table model
 * @param largeModel <code>true</code> if it's a large model tree, <code>false</code> otherwise.
 * @param nodesColumnLabel Label of the node's column
 */
protected DefaultOutlineModel(TreeModel treeModel, TableModel tableModel, boolean largeModel, String nodesColumnLabel) {
    this.treeModel = treeModel;
    this.tableModel = tableModel;
    if (nodesColumnLabel != null) {
        this.nodesColumnLabel = nodesColumnLabel;
    }

    layout = largeModel ? (AbstractLayoutCache) new FixedHeightLayoutCache() 
        : (AbstractLayoutCache) new VariableHeightLayoutCache();

    broadcaster = new EventBroadcaster (this);

    layout.setRootVisible(true);
    layout.setModel(this);
    treePathSupport = new TreePathSupport(this, layout);
    treePathSupport.addTreeExpansionListener(broadcaster);
    treePathSupport.addTreeWillExpandListener(broadcaster);
    treeModel.addTreeModelListener(broadcaster);
    tableModel.addTableModelListener(broadcaster);
    if (tableModel instanceof ProxyTableModel) {
        ((ProxyTableModel) tableModel).setOutlineModel(this);
    }
}
项目:incubator-netbeans    文件:ProfilerTreeTable.java   
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);
    }
}
项目:incubator-netbeans    文件:ProfilerTreeTable.java   
public void collapseChildren(int row) {
    if (tree != null) try {
        markExpansionTransaction();

        TreePath tpath = tree.getPathForRow(row);
        if (tpath == null || tree.isCollapsed(tpath)) return;

        TreeModel tmodel = tree.getModel();
        Object selected = tpath.getLastPathComponent();

        int nchildren = tmodel.getChildCount(selected);
        for (int i = 0; i < nchildren; i++)
            tree.collapsePath(tpath.pathByAddingChild(tmodel.getChild(selected, i)));

    } finally {
        clearExpansionTransaction();
    }
}
项目:incubator-netbeans    文件:ProfilerTreeTable.java   
public void expandPlainPath(int row, int maxChildren) {
    if (tree != null) try {
        markExpansionTransaction();

        TreePath tpath = tree.getPathForRow(row);
        if (tpath == null) return;

        TreeModel tmodel = tree.getModel();            
        int childCount = tmodel.getChildCount(tpath.getLastPathComponent());

        while (childCount > 0 && childCount <= maxChildren) {
            tpath = tpath.pathByAddingChild(tmodel.getChild(tpath.getLastPathComponent(), 0));
            childCount = tmodel.getChildCount(tpath.getLastPathComponent());
        }

        tree.putClientProperty(UIUtils.PROP_AUTO_EXPANDING, Boolean.TRUE);
        try { tree.expandPath(tpath); selectPath(tpath, true); }
        finally { tree.putClientProperty(UIUtils.PROP_AUTO_EXPANDING, null); }

    } finally {
        clearExpansionTransaction();
    }
}
项目:incubator-netbeans    文件:ProfilerTreeTable.java   
public void expandFirstPath(int row) {
    if (tree != null) try {
        markExpansionTransaction();

        TreePath tpath = tree.getPathForRow(row);
        if (tpath == null) return;

        TreeModel tmodel = tree.getModel();    

        while (tmodel.getChildCount(tpath.getLastPathComponent()) > 0)
            tpath = tpath.pathByAddingChild(tmodel.getChild(tpath.getLastPathComponent(), 0));

        tree.putClientProperty(UIUtils.PROP_AUTO_EXPANDING, Boolean.TRUE);
        try { selectPath(tpath, true); }
        finally { tree.putClientProperty(UIUtils.PROP_AUTO_EXPANDING, null); }

    } finally {
        clearExpansionTransaction();
    }
}
项目:incubator-netbeans    文件:DebuggingViewComponent.java   
private void createTreeView() {
    synchronized (lock) {
        releaseTreeView();
        treeView = new DebugTreeView();
        treeView.setRootVisible(false);
        treeView.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
        treeView.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);
        treeView.getAccessibleContext().setAccessibleName(NbBundle.getMessage(DebuggingViewComponent.class, "DebuggingViewComponent.treeView.AccessibleContext.accessibleName")); // NOI18N
        treeView.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(DebuggingViewComponent.class, "DebuggingViewComponent.treeView.AccessibleContext.accessibleDescription")); // NOI18N
        treeView.getTree().addMouseWheelListener(this);
        treeView.addTreeExpansionListener(this);
        TreeModel model = treeView.getTree().getModel();
        model.addTreeModelListener(this);
        treeView.getViewport().addChangeListener(this);
        treeView.getTree().setScrollsOnExpand(false);
        mainPanel.add(treeView, BorderLayout.CENTER);
    }
}
项目:incubator-netbeans    文件:Tab.java   
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);
            }
        }
    });
}
项目:rapidminer    文件:PlotConfigurationTree.java   
/**
 * Opens all paths in the given node and all nodes below that.
 *
 * @param path
 *            the tree path to the node to expand
 * @param treeModel
 *            the tree model
 * @see JTree#expandPath(TreePath)
 */
protected void expandAllPaths(TreePath path, TreeModel treeModel) {
    expandPath(path);
    final Object node = path.getLastPathComponent();
    final int n = treeModel.getChildCount(node);
    for (int index = 0; index < n; index++) {
        final Object child = treeModel.getChild(node, index);
        expandAllPaths(path.pathByAddingChild(child));
    }
}
项目:jdbacl    文件:DatabasePane.java   
@Override
public void run() {
    try {
        Database database = JDBCMetaDataUtil.getMetaData(environment, true, true, true, true, 
                ".*", exclusionPatternProvider.getValue(), true, true);
        DatabasePane.this.importer = importer;
        final TreeModel model = new SwingTreeModelAdapter<DBObject>(new DatabaseTreeModel(database));
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                tree = new DatabaseTree(model);
                scrollPane.setViewportView(tree);
            }
        });
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
项目:jfrog-idea-plugin    文件:XrayToolWindow.java   
private void populateTrees() {
    licenseFilterMenu.setLicenses();
    TreeModel issuesTreeModel = new DefaultTreeModel(new ScanTreeNode("SeveritiesTree"));
    TreeModel licensesTreeModel = new DefaultTreeModel(new ScanTreeNode("LicensesTree"));
    ScanManager scanManager = ScanManagerFactory.getScanManager(project);
    if (scanManager != null) {
        scanManager.filterAndSort(issuesTreeModel, licensesTreeModel);
    }

    ScanTreeNode root = (ScanTreeNode) issuesTreeModel.getRoot();
    issuesCount.setText("Issues (" + root.getIssueCount() + ") ");

    issuesComponentsTree.setModel(issuesTreeModel);
    issuesComponentsTree.validate();
    issuesComponentsTree.repaint();
    licensesComponentsTree.setModel(licensesTreeModel);
    licensesComponentsTree.validate();
    licensesComponentsTree.repaint();

    issuesTreeExpansionListener.setIssuesCountPanel();
}
项目:openjdk-jdk10    文件:LastNodeLowerHalfDrop.java   
protected static TreeModel getTreeModel() {
    root = new DefaultMutableTreeNode("Root");

    a = new DefaultMutableTreeNode("A");
    root.add(a);
    a1 = new DefaultMutableTreeNode("a1");
    a.add(a1);

    b = new DefaultMutableTreeNode("B");
    root.add(b);
    b1 = new DefaultMutableTreeNode("b1");
    b.add(b1);
    b2 = new DefaultMutableTreeNode("b2");
    b.add(b2);

    c = new DefaultMutableTreeNode("C");
    root.add(c);
    c1 = new DefaultMutableTreeNode("c1");
    c.add(c1);
    return new DefaultTreeModel(root);
}
项目:alevin-svn2    文件:SelectionTreeItemListener.java   
public SelectionTreeItemListener(SelectionPanel owner) {
    if (owner == null)
        throw new IllegalArgumentException();
    this.owner = owner;

    TreeModel model = owner.getTree().getModel();
    Object root = owner.getTree().getModel().getRoot();

    ePath = new TreePath(new Object[] { root, model.getChild(root, 0) });
    vPath = new TreePath(new Object[] { root, model.getChild(root, 1) });
}
项目:incubator-netbeans    文件:TreeModelCustomizer.java   
/**
 * Updates the tree according to the textual representation of the tree
 * model in the text area.
 */
private void updateTree() {
    String txt = textArea.getText();
    int tabSize = textArea.getTabSize();
    StringBuilder sb = new StringBuilder(tabSize);
    for (int i=0; i<tabSize; i++) {
        sb.append(" "); // NOI18N
    }
    txt = txt.replace("\t", sb.toString()); // NOI18N
    TreeModel model = propEditor.createTreeModel(txt);
    tree.setModel(model);
    expandTree();
    propEditor.setValue(model);
}
项目:incubator-netbeans    文件:TreeView.java   
ExplorerTree(TreeModel model) {
    super(model);
    toggleClickCount = 0;

    // fix for #18292
    // default action map for JTree defines these shortcuts
    // but we use our own mechanism for handling them
    // following lines disable default L&F handling (if it is
    // defined on Ctrl-c, Ctrl-v and Ctrl-x)
    getInputMap().put(KeyStroke.getKeyStroke("control C"), "none"); // NOI18N
    getInputMap().put(KeyStroke.getKeyStroke("control V"), "none"); // NOI18N
    getInputMap().put(KeyStroke.getKeyStroke("control X"), "none"); // NOI18N
    getInputMap().put(KeyStroke.getKeyStroke("COPY"), "none"); // NOI18N
    getInputMap().put(KeyStroke.getKeyStroke("PASTE"), "none"); // NOI18N
    getInputMap().put(KeyStroke.getKeyStroke("CUT"), "none"); // NOI18N

    if (Utilities.isMac()) {
        getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_C, InputEvent.META_MASK), "none"); // NOI18N
        getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_X, InputEvent.META_MASK), "none"); // NOI18N
        getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_V, InputEvent.META_MASK), "none"); // NOI18N
    }

    setupSearch();

    if (!GraphicsEnvironment.isHeadless()) {
        setDragEnabled(true);
    }
}
项目:incubator-netbeans    文件:DefaultOutlineCellRendererTest.java   
/**
 * Test of getTableCellRendererComponent method, of class
 * DefaultOutlineCellRenderer.
 */
public void testGetTableCellRendererComponent() {
    System.out.println("getTableCellRendererComponent");
    UIManager.put("Table.alternateRowColor", Color.red);
    final DefaultMutableTreeNode node1 = new DefaultMutableTreeNode();
    final DefaultMutableTreeNode node2 = new DefaultMutableTreeNode();
    final Object[][] values = new Object[][]{{node1, "01"}, {node2, "11"}};
    final String[] names = new String[]{"col1", "col2"};
    TreeModel treeModel = new DefaultTreeModel(new DefaultMutableTreeNode());
    DefaultTableModel tableModel = new DefaultTableModel(values, names);
    OutlineModel model = new DefaultOutlineModel(treeModel, tableModel, false, "Col1") {
    };
    final Outline outline = new Outline(model);
    ColorRenderDataProvider rdp = new ColorRenderDataProvider();
    outline.setRenderDataProvider(rdp);
    DefaultOutlineCellRenderer instance = new DefaultOutlineCellRenderer();
    Component result = instance.getTableCellRendererComponent(outline, node1, false, false, 0, 0);
    assertEquals("First line backgroundColor defaults to", outline.getBackground(), result.getBackground());
    assertEquals("Foreground defaults to", outline.getForeground(), result.getForeground());
    result = instance.getTableCellRendererComponent(outline, node2, false, false, 1, 0);
    assertEquals("Second line backgroundColor defaults to", Color.red, result.getBackground());
    assertEquals("Foreground defaults to", outline.getForeground(), result.getForeground());

    rdp.backgroundColor = Color.BLUE; // Custom background color
    rdp.foregroundColor = Color.GREEN; // Custom foreground color

    result = instance.getTableCellRendererComponent(outline, node1, false, false, 0, 0);
    assertEquals("First line backgroundColor is set as", Color.BLUE, result.getBackground());
    assertEquals("Foreground is set as", Color.GREEN, result.getForeground());
    result = instance.getTableCellRendererComponent(outline, node2, false, false, 1, 0);
    assertEquals("Second line backgroundColor is set as", Color.BLUE, result.getBackground());
    assertEquals("Foreground is set as", Color.GREEN, result.getForeground());
}
项目:incubator-netbeans    文件:PhadhailViews.java   
/** use Phadhail directly in a JTree */
public static Component rawView(Phadhail root) {
    TreeModel model = new PhadhailTreeModel(root);
    JTree tree = new JTree(model) {
        // Could also use a custom TreeCellRenderer, but this is a bit simpler for now.
        public String convertValueToText(Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
            Phadhail ph = (Phadhail)value;
            return ph.getPath();
        }
    };
    tree.setLargeModel(true);
    return new JScrollPane(tree);
}
项目:geomapapp    文件:SearchTree.java   
public void closePaths(JTree tree, TreePath path) {
    Object node = path.getLastPathComponent();
    TreeModel model = tree.getModel();
    if (model.isLeaf(node))
        return;
    int num = model.getChildCount(node);
    for (int i = 0; i < num; i++)
        closePaths(tree, path.pathByAddingChild(model.getChild(node, i)));
    tree.collapsePath(path);
}
项目:incubator-netbeans    文件:UIUtils.java   
/** Checks give TreePath for the last node, and if it ends with a node with just one child,
 * it keeps expanding further.
 * Current implementation expands through the first child that is not leaf. To more correctly
 * fulfil expected semantics in case maxChildToExpand is > 1, it should expand all paths through
 * all children.
 *
 * @param tree
 * @param path
 * @param maxChildToExpand
 */
public static void autoExpand(JTree tree, TreePath path, int maxLines, int maxChildToExpand, boolean dontExpandToLeafs) {
    TreeModel model = tree.getModel();
    Object node = path.getLastPathComponent();
    TreePath newPath = path;

    int currentLines = 0;

    while (currentLines++ < maxLines &&
            !model.isLeaf(node) &&
            (model.getChildCount(node) > 0) &&
            (model.getChildCount(node) <= maxChildToExpand)) {
        for (int i = 0; i < model.getChildCount(node); i++) {
            node = tree.getModel().getChild(node, i);

            if (!model.isLeaf(node)) {
                if (dontExpandToLeafs && hasOnlyLeafs(tree, node)) {
                    break;
                }

                newPath = newPath.pathByAddingChild(node); // if the leaf is added the path will not expand

                break; // from for
            }
        }
    }

    tree.expandPath(newPath);
}
项目:incubator-netbeans    文件:UIUtils.java   
public static boolean hasOnlyLeafs(JTree tree, Object node) {
    TreeModel model = tree.getModel();

    for (int i = 0; i < model.getChildCount(node); i++) {
        if (!model.isLeaf(model.getChild(node, i))) {
            return false;
        }
    }

    return true;
}
项目:incubator-netbeans    文件:ProfilerTreeTable.java   
private TreePath getSimilarPath(TreePath oldPath) {
    if (oldPath == null || oldPath.getPathCount() < 1) return null;

    TreeModel currentModel = getModel();
    Object currentRoot = currentModel.getRoot();
    if (!currentRoot.equals(oldPath.getPathComponent(0))) return null;

    TreePath p = new TreePath(currentRoot);
    Object[] op = oldPath.getPath();
    Object n = currentRoot;

    for (int i = 1; i < op.length; i++) {
        Object nn = null;

        for (int ii = 0; ii < currentModel.getChildCount(n); ii++) {
            Object c = currentModel.getChild(n, ii);
            if (c.equals(op[i])) {
                nn = c;
                break;
            }
        }

        if (nn == null) return null;

        n = nn;
        p = p.pathByAddingChild(n);
    }

    return p;
}
项目:incubator-netbeans    文件:JTreeTable.java   
public TreeTableCellRenderer(TreeModel model) {
    super(model);

    offsetX = 0;
    setOpaque(false);
    treeCellRenderer = new EnhancedTreeCellRenderer();
    setCellRenderer(treeCellRenderer);
    unselectedBackground = UIUtils.getProfilerResultsBackground();
    darkerUnselectedBackground = UIUtils.getDarker(unselectedBackground);
}
项目:incubator-netbeans    文件:JCheckTree.java   
protected static TreeModel getDefaultTreeModel() {
    CheckTreeNode root = new CheckTreeNode("JTree"); // NOI18N
    CheckTreeNode parent;

    parent = new CheckTreeNode("colors"); // NOI18N
    root.add(parent);
    parent.add(new CheckTreeNode("blue")); // NOI18N
    parent.add(new CheckTreeNode("violet")); // NOI18N
    parent.add(new CheckTreeNode("red")); // NOI18N
    parent.add(new CheckTreeNode("yellow")); // NOI18N

    parent = new CheckTreeNode("sports"); // NOI18N
    root.add(parent);
    parent.add(new CheckTreeNode("basketball")); // NOI18N
    parent.add(new CheckTreeNode("soccer")); // NOI18N
    parent.add(new CheckTreeNode("football")); // NOI18N
    parent.add(new CheckTreeNode("hockey")); // NOI18N

    parent = new CheckTreeNode("food"); // NOI18N
    root.add(parent);
    parent.add(new CheckTreeNode("hot dogs")); // NOI18N
    parent.add(new CheckTreeNode("pizza")); // NOI18N
    parent.add(new CheckTreeNode("ravioli")); // NOI18N
    parent.add(new CheckTreeNode("bananas")); // NOI18N

    return new DefaultTreeModel(root);
}
项目:incubator-netbeans    文件:DebuggingViewComponent.java   
private void releaseTreeView() {
    synchronized (lock) {
        if (treeView == null) {
            return ;
        }
        treeView.getTree().removeMouseWheelListener(this);
        treeView.removeTreeExpansionListener(this);
        TreeModel model = treeView.getTree().getModel();
        model.removeTreeModelListener(this);
        treeView.getViewport().removeChangeListener(this);
        treeView.resetSelection();
        mainPanel.remove(treeView);
        treeView = null;
    }
}
项目:incubator-netbeans    文件:NavigatorContent.java   
private TreeModel createTreeModel(DocumentModel dm) {
    DocumentElement rootElement = dm.getRootElement();
    DefaultTreeModel dtm = new DefaultTreeModel(null);
    TreeNodeAdapter rootTna = new TreeNodeAdapter(rootElement, dtm, tree, null);
    dtm.setRoot(rootTna);

    return dtm;
}
项目:incubator-netbeans    文件:HintsPanel.java   
HintsPanel() {        
        initComponents();

        descriptionTextArea.setContentType("text/html"); // NOI18N

//        if( "Windows".equals(UIManager.getLookAndFeel().getID()) ) //NOI18N
//            setOpaque( false );

        errorTree.setCellRenderer( this );
        errorTree.setRootVisible( false );
        errorTree.setShowsRootHandles( true );
        errorTree.getSelectionModel().setSelectionMode( TreeSelectionModel.SINGLE_TREE_SELECTION );

        DefaultComboBoxModel model = new DefaultComboBoxModel();
        model.addElement( NbBundle.getMessage(HintsPanel.class, "CTL_AsError"));
        model.addElement( NbBundle.getMessage(HintsPanel.class, "CTL_AsWarning"));
        severityComboBox.setModel(model);

        toProblemCheckBox.setVisible(false);

        update();

        DefaultTreeModel mdl = new DefaultTreeModel(new DefaultMutableTreeNode());
        errorTree.setModel( mdl );
        RequestProcessor.getDefault().post(new Runnable() {
            @Override
            public void run() {
                final TreeModel m = RulesManager.getHintsTreeModel();
                SwingUtilities.invokeLater(new Runnable() {

                    @Override
                    public void run() {
                        errorTree.setModel( m );
                    }
                });
            }
        });


    }
项目:incubator-netbeans    文件:HintsPanel.java   
void setCurrentSubcategory(String subpath) {
    TreeModel mdl = errorTree.getModel();
    for (int i = 0; i < mdl.getChildCount(mdl.getRoot()); i++) {
        Object child = mdl.getChild(mdl.getRoot(), i);
        Object data = ((DefaultMutableTreeNode) child).getUserObject();
        if (data instanceof POMErrorFixBase) {
            POMErrorFixBase rule = (POMErrorFixBase) data;
            if (rule.getConfiguration().getId().equals(subpath)) {
                errorTree.setSelectionRow(i);
                break;
            }
        }
    }
}
项目:incubator-netbeans    文件:OptionsFilter.java   
public FilteringTreeModel(TreeModel delegate, Document filter, Acceptor acceptor, boolean delegatingTreeModelListeners) {
    this.delegate = delegate;
    this.filter = filter;
    this.acceptor = acceptor;
    this.delegatingTreeModelListener = delegatingTreeModelListeners;

    this.delegate.addTreeModelListener(this);
    this.filter.addDocumentListener(this);

    filter();
}
项目:incubator-netbeans    文件:NewProjectTest.java   
private ArrayList<String> getChildren(TreeModel tree, Object root, String spaces) {
    int categoriesCount = tree.getChildCount(root);
    ArrayList<String> returnList = new ArrayList<String>();
    for (int i = 0; i <= categoriesCount - 1; i++) {
        Object actualChild = tree.getChild(root, i);
        returnList.add(spaces + actualChild.toString());

        if (!tree.isLeaf(actualChild)) {
            spaces = "+-" + spaces;
            returnList.addAll(getChildren(tree, actualChild, spaces));
            spaces = spaces.substring(2);
        }
    }
    return returnList;
}
项目:rapidminer    文件:PlotConfigurationTree.java   
/**
 * Expands all paths in the tree.
 *
 * @see JTree#expandPath(TreePath)
 */
public void expandAll() {
    cancelEditing();
    final TreeModel tm = getModel();
    final Object root = tm.getRoot();

    /* nothing to expand, if no root */
    if (root != null) {
        expandAllPaths(new TreePath(root), tm);
    }
}
项目:marathonv5    文件:JTreeJavaElement.java   
private TreePath getPath(JTree tree, String path) {
    String[] tokens = path.substring(1).split("(?<!\\\\)/");
    TreeModel treeModel = tree.getModel();
    if (treeModel == null) {
        throw new RuntimeException("Could not find model for tree");
    }
    Object rootNode = treeModel.getRoot();
    int start = tree.isRootVisible() ? 1 : 0;
    TreePath treePath = new TreePath(rootNode);
    StringBuilder searchedPath = new StringBuilder();
    if (tree.isRootVisible()) {
        String rootNodeText = unescapeSpecialCharacters(tokens[0]);
        searchedPath.append("/" + rootNodeText);
        assertTrue("JTree does not have a root node!", rootNode != null);
        assertTrue("JTree root node does not match: Expected </" + getPathText(tree, treePath) + "> Actual: <"
                + searchedPath.toString() + ">", searchedPath.toString().equals("/" + getPathText(tree, treePath)));
    }
    for (int i = start; i < tokens.length; i++) {
        String childText = unescapeSpecialCharacters(tokens[i]);
        searchedPath.append("/" + childText);
        boolean matched = false;
        tree.expandPath(treePath);
        for (int j = 0; j < treeModel.getChildCount(treePath.getLastPathComponent()); j++) {
            Object child = treeModel.getChild(treePath.getLastPathComponent(), j);
            TreePath childPath = treePath.pathByAddingChild(child);
            if (childText.equals(getPathText(tree, childPath))) {
                treePath = childPath;
                matched = true;
                break;
            }
        }
        if (!matched) {
            return null;
        }
    }
    return treePath;
}
项目:marathonv5    文件:JTreeJavaElement.java   
public static String[][] getContent(JTree component) {
    TreeModel model = component.getModel();
    int rowCount = getNodeCount(model, model.getRoot()) + 1;
    String[][] content = new String[1][rowCount];
    List<String> treeContent = new Vector<String>(rowCount);
    getTreeContent(model, model.getRoot(), treeContent);
    treeContent.toArray(content[0]);
    return content;
}
项目:marathonv5    文件:JTreeJavaElement.java   
private static int getNodeCount(TreeModel model, Object root) {
    int count = model.getChildCount(root);
    for (int i = 0; i < model.getChildCount(root); i++) {
        Object node = model.getChild(root, i);
        count += getNodeCount(model, node);
    }
    return count;
}
项目:marathonv5    文件:FilterableTreeModel.java   
public FilterableTreeModel(TreeModel defaultTreeModel) {
    this.treeModel = defaultTreeModel;
    this.predicate = new Predicate<T>() {
        @Override public boolean apply(T o) {
            return true;
        }
    };
}
项目:RxJava2Swing    文件:TreeModelEventObservable.java   
@Override
protected void subscribeActual(Observer<? super TreeModelEvent> observer) {
    TreeModel w = widget;

    TreeModelEventConsumer aec = new TreeModelEventConsumer(observer, w);
    observer.onSubscribe(aec);

    w.addTreeModelListener(aec);
    if (aec.get() == null) {
        aec.onDispose(w);
    }
}
项目:oxygen-git-plugin    文件:TreeFormatter.java   
/**
 * Converts a file path to the TreePath that indentifies the file in the tree model.
 * 
 * @param model  The tree model.
 * @param path   File path from the working copy.
 * 
 * @return A file path to the TreePath.
 */
public static TreePath getTreePath(TreeModel model, String path) {
  String[] strings = path.split("/");
  Object[] parts = new Object[1 + strings.length];
  parts[0] = model.getRoot();
  for (int i = 0; i < strings.length; i++) {
     parts[i + 1] = new GitTreeNode(strings[i]);
   }

  return new TreePath(parts);
 }
项目:jfrog-idea-plugin    文件:MavenScanManager.java   
@Override
protected TreeModel updateResultsTree(TreeModel currentScanResults) {
    ScanTreeNode rootNode = new ScanTreeNode(ROOT_NODE_HEADER);
    TreeModel issuesTree = new DefaultTreeModel(rootNode);
    // This set is used to make sure the artifacts added are unique
    Set<String> added = Sets.newHashSet();
    for (MavenProject mavenProject : MavenProjectsManager.getInstance(project).getProjects()) {
        for (MavenArtifactNode dependencyTree : mavenProject.getDependencyTree()) {
            if (added.add(dependencyTree.getArtifact().getDisplayStringForLibraryName())) {
                updateChildrenNodes(rootNode, dependencyTree);
            }
        }
    }
    return issuesTree;
}
项目:sbc-qsystem    文件:FMessager.java   
/**
 * Выбор услуги для перенаправления.
 *
 * @param owner относительно этого контрола модальность и позиционирование
 */
public static void getMessager(JFrame owner, int port, ListModel users, TreeModel services) {
    QLog.l().logger().info("Выбор услуги для перенаправления.");
    if (messagerForm == null) {
        messagerForm = new FMessager(owner, true, port, users, services);
    }
    messagerForm.setLocation(
        Math.round(owner.getLocation().x + owner.getWidth() / 2 - messagerForm.getWidth() / 2),
        Math.round(
            owner.getLocation().y + owner.getHeight() / 2 - messagerForm.getHeight() / 2));
    messagerForm.setVisible(true);
}
项目:jfrog-idea-plugin    文件:ScanManager.java   
/**
 * filter scan components tree model according to the user filters and sort the issues tree.
 */
public void filterAndSort(TreeModel issuesTreeModel, TreeModel licensesTreeModel) {
    if (scanResults == null) {
        return;
    }
    FilterManager filterManager = FilterManager.getInstance(project);
    ScanTreeNode issuesFilteredRoot = (ScanTreeNode) issuesTreeModel.getRoot();
    ScanTreeNode licenseFilteredRoot = (ScanTreeNode) licensesTreeModel.getRoot();
    filterManager.applyFilters((ScanTreeNode) scanResults.getRoot(), issuesFilteredRoot, licenseFilteredRoot);
    issuesFilteredRoot.setIssues(issuesFilteredRoot.processTreeIssues());
}
项目:OpenJSharp    文件:ElementTreePanel.java   
/**
 * Updates the tree based on the event type. This will invoke either
 * updateTree with the root element, or handleChange.
 */
protected void updateTree(DocumentEvent event) {
    updatingSelection = true;
    try {
        TreeModel model = getTreeModel();
        Object root = model.getRoot();

        for (int counter = model.getChildCount(root) - 1; counter >= 0;
                counter--) {
            updateTree(event, (Element) model.getChild(root, counter));
        }
    } finally {
        updatingSelection = false;
    }
}