1 package org.oddjob.monitor.view; 2 3 import java.awt.event.KeyEvent ; 4 5 import javax.swing.JMenu ; 6 import javax.swing.JMenuBar ; 7 import javax.swing.JPopupMenu ; 8 9 import org.oddjob.monitor.OddjobExplorer; 10 import org.oddjob.monitor.model.DetailModel; 11 12 17 18 public class MonitorMenuBar extends JMenuBar { 19 private static final long serialVersionUID = 0; 20 21 22 private final OddjobExplorer oddjobExplorer; 23 24 25 private final JMenu fileMenu; 26 27 28 private JMenu jobMenu; 29 30 31 private JPopupMenu popup; 32 33 34 private ExplorerJobActions jobActions; 35 36 37 private DetailModel detailModel; 38 39 43 public MonitorMenuBar(OddjobExplorer oddjobExplorer) { 44 this.oddjobExplorer = oddjobExplorer; 45 46 fileMenu = new JMenu ("File"); 47 fileMenu.setMnemonic(KeyEvent.VK_F); 48 49 this.add(fileMenu); 50 } 51 52 public JMenu getFileMenu() { 53 return fileMenu; 54 } 55 56 public JMenu getJobMenu() { 57 return jobMenu; 58 } 59 60 public JPopupMenu getPopupMenu() { 61 return popup; 62 } 63 64 69 public void setSession(DetailModel model) { 70 detailModel = model; 71 jobActions = new ExplorerJobActions(oddjobExplorer); 72 detailModel.addObserver(jobActions); 73 74 jobMenu = new JMenu ("Job"); 75 jobMenu.setMnemonic(KeyEvent.VK_J); 76 jobActions.populateMenu(jobMenu); 77 78 popup = new JPopupMenu (); 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 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 |