KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > oddjob > monitor > control > IconControl


1 /*
2  * Copyright © 2004, Rob Gordon.
3  */

4 package org.oddjob.monitor.control;
5
6 import javax.swing.JTree JavaDoc;
7 import javax.swing.event.TreeExpansionEvent JavaDoc;
8 import javax.swing.event.TreeExpansionListener JavaDoc;
9 import javax.swing.event.TreeModelEvent JavaDoc;
10 import javax.swing.event.TreeModelListener JavaDoc;
11 import javax.swing.tree.TreePath JavaDoc;
12
13 import org.apache.log4j.Logger;
14 import org.oddjob.monitor.model.JobTreeNode;
15
16 /**
17  * Listens for changes in the view and update the icon properties
18  * of the model.
19  *
20  * @author Rob Gordon.
21  */

22 public class IconControl implements TreeExpansionListener JavaDoc, TreeModelListener JavaDoc {
23     private static final Logger logger = Logger.getLogger(IconControl.class);
24     
25     /** The view */
26     private JTree JavaDoc theTree;
27     
28     /**
29      * Constructor.
30      *
31      * @param theTree The JTree view to listen to.
32      */

33     public IconControl(JTree JavaDoc theTree) {
34         this.theTree = theTree;
35     }
36     
37     /* (non-Javadoc)
38      * @see javax.swing.event.TreeExpansionListener#treeCollapsed(javax.swing.event.TreeExpansionEvent)
39      */

40     public void treeCollapsed(TreeExpansionEvent JavaDoc 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     /* (non-Javadoc)
51      * @see javax.swing.event.TreeExpansionListener#treeExpanded(javax.swing.event.TreeExpansionEvent)
52      */

53     public void treeExpanded(TreeExpansionEvent JavaDoc 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 JavaDoc event) {
65         JobTreeNode node = (JobTreeNode)event.getSource();
66         TreePath JavaDoc path = new TreePath JavaDoc(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 JavaDoc event) {
75         // don't think this should happend
76
}
77     
78     public void treeNodesChanged(TreeModelEvent JavaDoc event) {
79         // or this
80
}
81     
82     public void treeNodesRemoved(TreeModelEvent JavaDoc 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