1 4 package org.oddjob.monitor.control; 5 6 import javax.swing.JTree ; 7 import javax.swing.event.TreeExpansionEvent ; 8 import javax.swing.event.TreeExpansionListener ; 9 import javax.swing.event.TreeModelEvent ; 10 import javax.swing.event.TreeModelListener ; 11 import javax.swing.tree.TreePath ; 12 13 import org.apache.log4j.Logger; 14 import org.oddjob.monitor.model.JobTreeNode; 15 16 22 public class IconControl implements TreeExpansionListener , TreeModelListener { 23 private static final Logger logger = Logger.getLogger(IconControl.class); 24 25 26 private JTree theTree; 27 28 33 public IconControl(JTree theTree) { 34 this.theTree = theTree; 35 } 36 37 40 public void treeCollapsed(TreeExpansionEvent event) { 41 JobTreeNode node = (JobTreeNode)event.getPath().getLastPathComponent(); 42 JobTreeNode[] children = node.getChildren(); 43 for (int i = 0; i < children.length; ++i) { 44 logger.debug("Tree Node [" + children[i].getComponent() 45 + "] no longer visible."); 46 children[i].inVisible(); 47 } 48 } 49 50 53 public void treeExpanded(TreeExpansionEvent event) { 54 JobTreeNode node = (JobTreeNode)event.getPath().getLastPathComponent(); 55 JobTreeNode[] children = node.getChildren(); 56 for (int i = 0; i < children.length; ++i) { 57 logger.debug("Tree Node [" + children[i].getComponent() 58 + "] now visible."); 59 children[i].visible(); 60 } 61 62 } 63 64 public void treeNodesInserted(TreeModelEvent event) { 65 JobTreeNode node = (JobTreeNode)event.getSource(); 66 TreePath path = new TreePath (event.getPath()); 67 if (theTree.isVisible(path)) { 68 logger.debug("Tree Node [" + node.getComponent() 69 + "] now visible."); 70 node.visible(); 71 } 72 } 73 74 public void treeStructureChanged(TreeModelEvent event) { 75 } 77 78 public void treeNodesChanged(TreeModelEvent event) { 79 } 81 82 public void treeNodesRemoved(TreeModelEvent event) { 83 JobTreeNode node = (JobTreeNode)event.getSource(); 84 logger.debug("Tree Node [" + node.getComponent() 85 + "] no longer visible."); 86 node.inVisible(); 87 } 88 } 89 | Popular Tags |