Search in sources :

Example 1 with TreeModel

use of javax.swing.tree.TreeModel in project processing by processing.

the class ExamplesFrame method expandTree.

void expandTree(JTree tree, Object object, String[] items, DefaultMutableTreeNode[] nodes, int index) {
    //    if (object == null) {
    //      object = model.getRoot();
    //    }
    TreeModel model = tree.getModel();
    if (index == 0) {
        nodes[0] = (DefaultMutableTreeNode) model.getRoot();
        expandTree(tree, nodes[0], items, nodes, 1);
    } else if (index < items.length) {
        //    String item = items[0];
        //    TreeModel model = object.getModel();
        //    System.out.println(object.getClass().getName());
        DefaultMutableTreeNode node = (DefaultMutableTreeNode) object;
        int count = model.getChildCount(node);
        //    System.out.println("child count is " + count);
        for (int i = 0; i < count; i++) {
            DefaultMutableTreeNode child = (DefaultMutableTreeNode) model.getChild(node, i);
            if (items[index].equals(child.getUserObject())) {
                nodes[index] = child;
                expandTree(tree, child, items, nodes, index + 1);
            }
        }
    } else {
        // last one
        //      PApplet.println(nodes);
        tree.expandPath(new TreePath(nodes));
    }
}
Also used : TreeModel(javax.swing.tree.TreeModel) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) TreePath(javax.swing.tree.TreePath)

Example 2 with TreeModel

use of javax.swing.tree.TreeModel in project gephi by gephi.

the class ReportPanel method fillIssues.

private void fillIssues(Report report) {
    final List<Issue> issues = new ArrayList<>();
    Iterator<Issue> itr = report.getIssues(ISSUES_LIMIT);
    while (itr.hasNext()) {
        issues.add(itr.next());
    }
    if (issues.isEmpty()) {
        JLabel label = new JLabel(NbBundle.getMessage(getClass(), "ReportPanel.noIssues"));
        label.setHorizontalAlignment(SwingConstants.CENTER);
        tab1ScrollPane.setViewportView(label);
    } else {
        //Busy label
        final BusyUtils.BusyLabel busyLabel = BusyUtils.createCenteredBusyLabel(tab1ScrollPane, "Retrieving issues...", issuesOutline);
        //Thread
        Thread thread = new Thread(fillingThreads, new Runnable() {

            @Override
            public void run() {
                busyLabel.setBusy(true);
                final TreeModel treeMdl = new IssueTreeModel(issues);
                final OutlineModel mdl = DefaultOutlineModel.createOutlineModel(treeMdl, new IssueRowModel(), true);
                SwingUtilities.invokeLater(new Runnable() {

                    @Override
                    public void run() {
                        issuesOutline.setRootVisible(false);
                        issuesOutline.setRenderDataProvider(new IssueRenderer());
                        issuesOutline.setModel(mdl);
                        busyLabel.setBusy(false);
                    }
                });
            }
        }, "Report Panel Issues Outline");
        if (NbPreferences.forModule(ReportPanel.class).getBoolean(SHOW_ISSUES, true)) {
            thread.start();
        }
    }
}
Also used : BusyUtils(org.gephi.ui.components.BusyUtils) Issue(org.gephi.io.importer.api.Issue) ArrayList(java.util.ArrayList) JLabel(javax.swing.JLabel) TreeModel(javax.swing.tree.TreeModel) OutlineModel(org.netbeans.swing.outline.OutlineModel) DefaultOutlineModel(org.netbeans.swing.outline.DefaultOutlineModel)

Example 3 with TreeModel

use of javax.swing.tree.TreeModel in project pcgen by PCGen.

the class NotesView method initTree.

//Initialization methods
private void initTree() {
    dataDir.listFiles();
    root = new NotesTreeNode(dataDir.getName(), dataDir, notesTree);
    TreeModel model = new DefaultTreeModel(root);
    notesTree.setModel(model);
    notesTree.addTreeSelectionListener(new TreeSelectionListener() {

        @Override
        public void valueChanged(TreeSelectionEvent evt) {
            notesTreeActionPerformed();
        }
    });
    notesTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    notesTree.setEditable(true);
    model.addTreeModelListener(new TreeModelListener() {

        @Override
        public void treeNodesChanged(TreeModelEvent e) {
            notesTreeNodesChanged();
        }

        @Override
        public void treeNodesInserted(TreeModelEvent e) {
        // TODO:  Method does nothing?
        }

        @Override
        public void treeNodesRemoved(TreeModelEvent e) {
        // TODO:  Method does nothing?
        }

        @Override
        public void treeStructureChanged(TreeModelEvent e) {
        // TODO:  Method does nothing?
        }
    });
}
Also used : TreeModel(javax.swing.tree.TreeModel) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) TreeModelEvent(javax.swing.event.TreeModelEvent) TreeModelListener(javax.swing.event.TreeModelListener) TreeSelectionListener(javax.swing.event.TreeSelectionListener) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) TreeSelectionEvent(javax.swing.event.TreeSelectionEvent)

Example 4 with TreeModel

use of javax.swing.tree.TreeModel in project intellij-community by JetBrains.

the class MavenArtifactSearchPanel method doSearch.

private void doSearch(String searchText) {
    MavenSearcher searcher = myClassMode ? new MavenClassSearcher() : new MavenArtifactSearcher(USE_LUCENE_INDEXES);
    List<MavenArtifactSearchResult> result = searcher.search(myProject, searchText, MAX_RESULT);
    resortUsingDependencyVersionMap(result);
    final TreeModel model = new MyTreeModel(result);
    SwingUtilities.invokeLater(() -> {
        if (!myDialog.isVisible())
            return;
        myResultList.getEmptyText().setText("No results");
        myResultList.setModel(model);
        myResultList.setSelectionRow(0);
        myResultList.setPaintBusy(false);
    });
}
Also used : TreeModel(javax.swing.tree.TreeModel)

Example 5 with TreeModel

use of javax.swing.tree.TreeModel in project zaproxy by zaproxy.

the class JCheckBoxTreeUnitTest method shouldSetATreeModelWithUndefinedRoot.

@Test
public void shouldSetATreeModelWithUndefinedRoot() {
    // Given
    TreeModel treeModel = new DefaultTreeModel(null);
    JCheckBoxTree checkBoxTree = new JCheckBoxTree();
    // When
    checkBoxTree.setModel(treeModel);
    // Then
    assertThat(checkBoxTree.getModel(), is(equalTo(treeModel)));
}
Also used : TreeModel(javax.swing.tree.TreeModel) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) Test(org.junit.Test)

Aggregations

TreeModel (javax.swing.tree.TreeModel)17 DefaultTreeModel (javax.swing.tree.DefaultTreeModel)8 TreePath (javax.swing.tree.TreePath)4 Test (org.junit.Test)4 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)3 NavigatablePsiElement (com.intellij.psi.NavigatablePsiElement)1 PsiElement (com.intellij.psi.PsiElement)1 Insets (java.awt.Insets)1 Rectangle (java.awt.Rectangle)1 ArrayList (java.util.ArrayList)1 Enumeration (java.util.Enumeration)1 HashSet (java.util.HashSet)1 JLabel (javax.swing.JLabel)1 TreeModelEvent (javax.swing.event.TreeModelEvent)1 TreeModelListener (javax.swing.event.TreeModelListener)1 TreeSelectionEvent (javax.swing.event.TreeSelectionEvent)1 TreeSelectionListener (javax.swing.event.TreeSelectionListener)1 Element (javax.swing.text.Element)1 DefaultTreeCellRenderer (javax.swing.tree.DefaultTreeCellRenderer)1 TreeCellRenderer (javax.swing.tree.TreeCellRenderer)1