public TreeNavigatorNode getCategoryNode(String category) { for (TreeNavigatorNode node : root.getChildren()) { if (node.getTitle().equals(category)) { return node; } } return null; }
public void removeChild(TreeNavigatorNode parent, TreeNavigatorNode child) { int i = getIndexOfChild(parent, child); parent.removeChild(child); TreeModelEvent tme = new TreeModelEvent(this, parent.getTreePath(), new int[] {i}, new Object[] {child}); for (TreeModelListener l : listeners) { l.treeNodesRemoved(tme); } }
public void addChild( TreeNavigatorNode parent, TreeNavigatorNode child, TreeNavigatorNode previousSibling) { // int i = parent.getChildCount(); int p = parent.addChild(child, previousSibling); TreeModelEvent tme = new TreeModelEvent(this, parent.getTreePath(), new int[] {p}, new Object[] {child}); for (TreeModelListener l : listeners) { l.treeNodesInserted(tme); } }
public List<String> getAllTitles() { List<String> result = new LinkedList<String>(); BreadthFirstSearch bfs = new BreadthFirstSearch(this); TreePath path; do { path = bfs.next(); if (path != null) { TreeNavigatorNode node = (TreeNavigatorNode) path.getLastPathComponent(); result.add(node.getTitle()); } } while (path != null); return result; }
protected void fireNodeChanged(TreeNavigatorNode node) { TreePath pathToParent; if (node.getParent() == null) { pathToParent = new TreePath(getRoot()); } else { pathToParent = node.getParent().getTreePath(); } int[] c = new int[] {getIndexOfChild(pathToParent.getLastPathComponent(), node)}; TreeModelEvent tme = new TreeModelEvent(this, pathToParent, c, new Object[] {node}); for (TreeModelListener l : listeners) { l.treeNodesChanged(tme); } }
public TreeNavigatorNode find(JComponent comp) { BreadthFirstSearch bfs = new BreadthFirstSearch(this); TreePath path; do { path = bfs.next(); if (path != null) { TreeNavigatorNode node = (TreeNavigatorNode) path.getLastPathComponent(); if (node.getComponent() == comp) { return node; } } } while (path != null); return null; }
/** * Returns the components managed by this <tt>TreeNavigatorModel</tt> in reverse BFS order * * @return */ public List<JComponent> getComponents() { LinkedList<JComponent> result = new LinkedList<JComponent>(); BreadthFirstSearch bfs = new BreadthFirstSearch(this); TreePath path; do { path = bfs.next(); if (path != null) { TreeNavigatorNode node = (TreeNavigatorNode) path.getLastPathComponent(); if (node.getComponent() != null) { result.addFirst(node.getComponent()); } } } while (path != null); return result; }
public void setTitle(TreeNavigatorNode node, String title) { node.setTitle(title); fireNodeChanged(node); }