psmith 2003/09/02 01:19:59 Modified: src/java/org/apache/log4j/chainsaw LoggerNameTreePanel.java Log: Added collapse current node's children action, button, and icon. Revision Changes Path 1.4 +78 -6 jakarta-log4j/src/java/org/apache/log4j/chainsaw/LoggerNameTreePanel.java Index: LoggerNameTreePanel.java =================================================================== RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/chainsaw/LoggerNameTreePanel.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- LoggerNameTreePanel.java 2 Sep 2003 03:38:38 -0000 1.3 +++ LoggerNameTreePanel.java 2 Sep 2003 08:19:59 -0000 1.4 @@ -105,9 +105,11 @@ private final JScrollPane scrollTree; private final JToolBar toolbar = new JToolBar(); private final JButton expandButton = new SmallButton(); + private final JButton collapseButton = new SmallButton(); private final JButton closeButton = new SmallButton(); private final JButton editLoggerButton = new SmallButton(); private final Action expandAction; + private final Action collapseAction; private final Action closeAction; private final Action editLoggerAction; @@ -166,10 +168,6 @@ ensureRootExpanded(); } - private void ensureRootExpanded() { - logTree.expandRow(0); - } - public void treeStructureChanged(TreeModelEvent e) { ensureRootExpanded(); } @@ -190,7 +188,7 @@ expandAction = createExpandAction(); editLoggerAction = createEditLoggerAction(); closeAction = createCloseAction(); - + collapseAction = createCollapseAction(); setupListeners(); configureToolbarPanel(); @@ -198,10 +196,36 @@ add(scrollTree, BorderLayout.CENTER); } + private void ensureRootExpanded() { + logTree.expandRow(0); + } + /** - * An action that closes (hides) this panel * @return */ + private Action createCollapseAction() { + Action action = + new AbstractAction() { + public void actionPerformed(ActionEvent e) { + collapseCurrentlySelectedNode(); + } + }; + + action.putValue(Action.NAME, "Collapse"); + action.putValue( + Action.SHORT_DESCRIPTION, + "Collapses all the children of the currently selected node"); + action.putValue( + Action.SMALL_ICON, new ImageIcon(ChainsawIcons.ICON_COLLAPSE)); + action.setEnabled(false); + + return action; + } + + /** + * An action that closes (hides) this panel + * @return + */ private Action createCloseAction() { Action action = new AbstractAction() { @@ -231,6 +255,7 @@ TreePath path = e.getNewLeadSelectionPath(); expandAction.setEnabled(path != null); editLoggerAction.setEnabled(path != null); + collapseAction.setEnabled(path != null); } }); @@ -299,6 +324,49 @@ } /** + * Given the currently selected nodes + * collapses all the children of those nodes. + * + */ + private void collapseCurrentlySelectedNode() { + TreePath[] paths = logTree.getSelectionPaths(); + + if (paths == null) { + return; + } + + LogLog.debug("Collapsing all children of selected node"); + + for (int i = 0; i < paths.length; i++) { + TreePath path = paths[i]; + DefaultMutableTreeNode node = + (DefaultMutableTreeNode) path.getLastPathComponent(); + Enumeration enumeration = node.depthFirstEnumeration(); + + while (enumeration.hasMoreElements()) { + DefaultMutableTreeNode child = + (DefaultMutableTreeNode) enumeration.nextElement(); + + if (child.getParent() != null) { + TreeNode[] nodes = + ((DefaultMutableTreeNode) child.getParent()).getPath(); + + TreePath treePath = new TreePath(nodes); + + while ((treePath != null) && (treePath.getPathCount() > 0)) { + DefaultMutableTreeNode potentialRoot = + (DefaultMutableTreeNode) treePath.getPathComponent(0); + logTree.collapsePath(treePath); + treePath = treePath.getParentPath(); + } + } + } + } + + ensureRootExpanded(); + } + + /** * Expands the currently selected node (if any) * including all the children. * @@ -368,12 +436,16 @@ expandButton.setAction(expandAction); expandButton.setText(null); + collapseButton.setAction(collapseAction); + collapseButton.setText(null); + editLoggerButton.setAction(editLoggerAction); editLoggerButton.setText(null); closeButton.setAction(closeAction); closeButton.setText(null); toolbar.add(expandButton); + toolbar.add(collapseButton); toolbar.add(editLoggerButton); toolbar.addSeparator();
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]