use of javax.swing.tree.TreeNode in project jabref by JabRef.
the class FindUnlinkedFilesDialog method expandTree.
/**
* Expands or collapses the specified tree according to the
* <code>expand</code>-parameter.
*/
private void expandTree(JTree currentTree, TreePath parent, boolean expand) {
TreeNode node = (TreeNode) parent.getLastPathComponent();
if (node.getChildCount() >= 0) {
for (Enumeration<TreeNode> e = node.children(); e.hasMoreElements(); ) {
TreePath path = parent.pathByAddingChild(e.nextElement());
expandTree(currentTree, path, expand);
}
}
if (expand) {
currentTree.expandPath(parent);
} else {
currentTree.collapsePath(parent);
}
}
use of javax.swing.tree.TreeNode in project JMRI by JMRI.
the class MultiPaneWindow method makeNavTreePane.
protected JScrollPane makeNavTreePane(String treeFile) {
final JTree tree;
TreeNode topNode;
rightTopWI = new PanedInterface(this);
topNode = makeNavTreeTopNode(treeFile, rightTopWI);
tree = new JTree(topNode);
tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
// allow multiple roots
tree.setRootVisible(false);
// install listener
tree.addTreeSelectionListener(new javax.swing.event.TreeSelectionListener() {
@Override
public void valueChanged(javax.swing.event.TreeSelectionEvent e) {
DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent();
if (node == null) {
//Nothing is selected.
return;
}
if (node.getUserObject() == null) {
// Not an interesting node
return;
}
if (node.getUserObject() instanceof AbstractAction) {
AbstractAction action = (AbstractAction) node.getUserObject();
action.actionPerformed(null);
}
}
});
// install in scroll area
JScrollPane treeView = new JScrollPane(tree);
treeView.setMinimumSize(new Dimension(0, 0));
treeView.setPreferredSize(new Dimension(150, 600));
return treeView;
}
use of javax.swing.tree.TreeNode in project JMRI by JMRI.
the class CatalogPanel method getCorrespondingNode.
/**
* The tree held in the CatalogTreeManager must be kept in sync with the
* tree displayed as the Image Index. Required in order to save the Index to
* disc.
*/
private CatalogTreeNode getCorrespondingNode(CatalogTreeNode node) {
TreeNode[] nodes = node.getPath();
CatalogTreeNode cNode = null;
for (int i = 0; i < _branchModel.size(); i++) {
CatalogTreeNode cRoot = _branchModel.get(i).getRoot();
cNode = match(cRoot, nodes, 1);
if (cNode != null) {
break;
}
}
return cNode;
}
use of javax.swing.tree.TreeNode in project intellij-plugins by JetBrains.
the class TreeTableRowSorter method sortOnKey.
private void sortOnKey(SortKey key) {
if (key.getSortOrder() == SortOrder.UNSORTED) {
return;
}
final int columnModelIndex = key.getColumn();
TableColumnModel colModel = table.getColumnModel();
int modelIndex = colModel.getColumn(columnModelIndex).getModelIndex();
if (modelIndex < 0 || getComparator(modelIndex) == null) {
return;
}
final Comparator<TreeNode> comparator = new ComparatorWrapper<>(getComparator(modelIndex), key.getSortOrder() == SortOrder.ASCENDING);
final List<TreePath> paths = TreeUtil.collectExpandedPaths(table.getTree());
if (JTreeUtil.isSorted(paths, comparator, table.getTableModel())) {
return;
}
for (TreePath path : paths) {
Object node = path.getLastPathComponent();
if (!(node instanceof DefaultMutableTreeNode)) {
continue;
}
JTreeUtil.sortChildren((DefaultMutableTreeNode) node, comparator, table.getTableModel().getChildCount(node));
}
table.reload();
TreeUtil.restoreExpandedPaths(table.getTree(), paths);
}
use of javax.swing.tree.TreeNode in project intellij-plugins by JetBrains.
the class FoundUsersModelTest method testUserIn2Groups.
public void testUserIn2Groups() throws Exception {
MockUser bob = new MockUser("BobName", null);
bob.setProjects(new String[] { "bobProject", "anotherBobProject" });
FoundUsersModel model = createModel(Arrays.asList(new User[] { bob }));
assertEquals("2 projects expected", 2, getRoot(model).getChildCount());
TreeNode projectNode1 = getRoot(model).getChildAt(0);
assertEquals("Invalid project node", "anotherBobProject", projectNode1.toString());
TreeNode projectNode2 = getRoot(model).getChildAt(1);
assertEquals("Invalid project node", "bobProject", projectNode2.toString());
assertEquals("One user in group expected", 1, projectNode1.getChildCount());
assertEquals("One user in group expected", 1, projectNode2.getChildCount());
}
Aggregations