KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > oddjob > monitor > view > MonitorMenuBar


1 package org.oddjob.monitor.view;
2
3 import java.awt.event.KeyEvent JavaDoc;
4
5 import javax.swing.JMenu JavaDoc;
6 import javax.swing.JMenuBar JavaDoc;
7 import javax.swing.JPopupMenu JavaDoc;
8
9 import org.oddjob.monitor.OddjobExplorer;
10 import org.oddjob.monitor.model.DetailModel;
11
12 /**
13  * Implementation of the monitor menu bar.
14  *
15  * @author Rob Gordon
16  */

17
18 public class MonitorMenuBar extends JMenuBar JavaDoc {
19     private static final long serialVersionUID = 0;
20     
21     /** The owning OddjobExplorer */
22     private final OddjobExplorer oddjobExplorer;
23     
24     /** The file menu. */
25     private final JMenu JavaDoc fileMenu;
26     
27     /** The job menu. */
28     private JMenu JavaDoc jobMenu;
29     
30     /** The popup menu. */
31     private JPopupMenu JavaDoc popup;
32     
33     /** Job Actions for the job menu. */
34     private ExplorerJobActions jobActions;
35     
36     /** Explorer model for job actions to observe. */
37     private DetailModel detailModel;
38     
39     /**
40      * Constructor.
41      *
42      */

43     public MonitorMenuBar(OddjobExplorer oddjobExplorer) {
44         this.oddjobExplorer = oddjobExplorer;
45         
46         fileMenu = new JMenu JavaDoc("File");
47         fileMenu.setMnemonic(KeyEvent.VK_F);
48                 
49         this.add(fileMenu);
50     }
51     
52     public JMenu JavaDoc getFileMenu() {
53         return fileMenu;
54     }
55         
56     public JMenu JavaDoc getJobMenu() {
57         return jobMenu;
58     }
59     
60     public JPopupMenu JavaDoc getPopupMenu() {
61         return popup;
62     }
63
64     /**
65      * Associate the menu with an explorer session.
66      *
67      * @param model DetailModel.
68      */

69     public void setSession(DetailModel model) {
70         detailModel = model;
71         jobActions = new ExplorerJobActions(oddjobExplorer);
72         detailModel.addObserver(jobActions);
73         
74         jobMenu = new JMenu JavaDoc("Job");
75         jobMenu.setMnemonic(KeyEvent.VK_J);
76         jobActions.populateMenu(jobMenu);
77         
78         popup = new JPopupMenu JavaDoc();
79         jobActions.populateMenu(popup);
80         
81         this.removeAll();
82         this.add(fileMenu);
83         this.add(jobMenu);
84         this.validate();
85         this.repaint();
86     }
87     
88     /**
89      * Remove any association with an Explorer session.
90      *
91      */

92     public void noSession() {
93         detailModel.deleteObserver(jobActions);
94         detailModel = null;
95         jobActions = null;
96         
97         this.remove(jobMenu);
98         jobMenu = null;
99         
100         this.validate();
101         this.repaint();
102     }
103 }
104
Popular Tags