KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.oddjob.monitor.control;
2
3 import javax.swing.JTree JavaDoc;
4 import javax.swing.event.ChangeEvent JavaDoc;
5 import javax.swing.event.ChangeListener JavaDoc;
6 import javax.swing.event.TreeSelectionEvent JavaDoc;
7 import javax.swing.event.TreeSelectionListener JavaDoc;
8
9 import org.oddjob.monitor.model.DetailModel;
10 import org.oddjob.monitor.model.JobTreeNode;
11 import org.oddjob.monitor.view.DetailView;
12
13 /**
14  * Controller for the detail pane of the monitor. This listens
15  * for tab change event in the view and updates the model.
16  *
17  * @author Rob Gordon
18  */

19
20 public class DetailController implements TreeSelectionListener JavaDoc {
21
22     /** The model. */
23     private final DetailModel detailModel;
24     
25     /** The view. */
26     private final DetailView detailView;
27     
28     /** The current/last node */
29     private JobTreeNode currentNode;
30     
31     /**
32      * Constructor
33      */

34     public DetailController(DetailModel detailModel, DetailView detailView) {
35         this.detailModel = detailModel;
36         this.detailView = detailView;
37         
38         // create detailed view
39
detailView.addChangeListener(new ChangeListener JavaDoc() {
40             public void stateChanged(ChangeEvent JavaDoc e) {
41                 if (currentNode != null) {
42                     DetailController.this.detailModel.deSelect(
43                             currentNode.getExplorerContext(), currentNode.getComponent());
44                     DetailController.this.detailModel.setTabSelected(
45                             DetailController.this.detailView.getSelectedIndex());
46                     DetailController.this.detailModel.select(currentNode.getExplorerContext(), currentNode.getComponent());
47     
48                 }
49             }
50         });
51     }
52
53     /*
54      * (non-Javadoc)
55      * @see javax.swing.event.TreeSelectionListener#valueChanged(javax.swing.event.TreeSelectionEvent)
56      */

57     public void valueChanged(TreeSelectionEvent JavaDoc event) {
58         if (currentNode != null) {
59             detailModel.deSelect(currentNode.getExplorerContext(), currentNode.getComponent());
60             currentNode = null;
61         }
62         JTree JavaDoc tree = (JTree JavaDoc)event.getSource();
63         JobTreeNode node = (JobTreeNode)tree.getLastSelectedPathComponent();
64         if (node != null) {
65             currentNode = node;
66             detailModel.setTabSelected(detailView.getSelectedIndex());
67             detailModel.select(node.getExplorerContext(), node.getComponent());
68         }
69     }
70     
71 }
72
Popular Tags