1 4 package org.oddjob.monitor.view; 5 6 import java.util.Observable ; 7 import java.util.Observer ; 8 9 import javax.swing.JMenu ; 10 11 import org.oddjob.monitor.model.JobMenu; 12 import org.oddjob.monitor.model.JobOption; 13 14 20 public class JobSwingMenu extends JMenu { 21 private static final long serialVersionUID = 20051116; 22 private final JobMenu jobMenu; 23 24 28 private final Observer observer = new Observer () { 29 public void update(Observable o, Object arg) { 30 JobSwingMenu.this.update(); 31 } 32 }; 33 34 40 public JobSwingMenu(JobMenu jobMenu) { 41 super(jobMenu.getName()); 42 this.jobMenu = jobMenu; 43 this.setEnabled(jobMenu.enabled()); 44 jobMenu.addObserver(observer); 45 } 46 47 52 public void update() { 53 JobSwingMenu.this.removeAll(); 54 if (jobMenu.enabled()) { 55 JobMenuProcessor processor = new JobMenuProcessor(JobSwingMenu.this); 56 JobOption[] options = jobMenu.options(); 57 for (int i = 0; i < options.length; ++i) { 58 options[i].process(processor); 59 } 60 } 61 JobSwingMenu.this.setEnabled(jobMenu.enabled()); 62 63 } 64 } 65 | Popular Tags |