1 4 package org.oddjob.monitor.view; 5 6 import java.util.HashMap ; 7 import java.util.Map ; 8 9 import javax.swing.Action ; 10 import javax.swing.JComponent ; 11 import javax.swing.JMenuItem ; 12 import javax.swing.KeyStroke ; 13 14 import org.apache.log4j.Logger; 15 import org.oddjob.monitor.Standards; 16 import org.oddjob.monitor.action.ExecuteAction; 17 import org.oddjob.monitor.action.HardResetAction; 18 import org.oddjob.monitor.action.SchedulerMenu; 19 import org.oddjob.monitor.action.SetPropertyAction; 20 import org.oddjob.monitor.action.SoftResetAction; 21 import org.oddjob.monitor.action.StopAction; 22 import org.oddjob.monitor.model.JobAction; 23 import org.oddjob.monitor.model.JobMenu; 24 import org.oddjob.monitor.model.JobOptionProcessor; 25 26 31 public class JobMenuProcessor implements JobOptionProcessor { 32 private static final Logger logger = Logger.getLogger(SchedulerMenu.class); 33 34 35 private final JComponent menu; 36 37 38 private Map keys = new HashMap (); 39 40 46 public JobMenuProcessor(JComponent menu) { 47 this.menu = menu; 48 keys.put(SetPropertyAction.class, 49 new Keys(Standards.PROPERTY_MNEMONIC_KEY, Standards.PROPERTY_ACCELERATOR_KEY)); 50 keys.put(ExecuteAction.class, 51 new Keys(Standards.RUN_MNEMONIC_KEY, Standards.RUN_ACCELERATOR_KEY)); 52 keys.put(SoftResetAction.class, 53 new Keys(Standards.SOFT_RESET_MNEMONIC_KEY, Standards.SOFT_RESET_ACCELERATOR_KEY)); 54 keys.put(HardResetAction.class, 55 new Keys(Standards.HARD_RESET_MNEMONIC_KEY, Standards.HARD_RESET_ACCELERATOR_KEY)); 56 keys.put(StopAction.class, 57 new Keys(Standards.STOP_MNEMONIC_KEY, Standards.STOP_ACCELERATOR_KEY)); 58 } 59 60 64 public void processMenu(JobMenu jobMenu) { 65 JobSwingMenu swingMenu = new JobSwingMenu(jobMenu); 66 menu.add(swingMenu); 67 swingMenu.update(); 68 logger.debug("Added sub menu [" + jobMenu.getName() + "]"); 69 } 70 71 75 public void processAction(JobAction jobAction) { 76 Action action = new JobSwingAction(jobAction); 77 Keys key = (Keys) keys.get(jobAction.getClass()); 78 if (key != null) { 79 action.putValue(Action.MNEMONIC_KEY, key.getMnumonicKey()); 80 action.putValue(Action.ACCELERATOR_KEY, key.getAcceleratorKey()); 81 } 82 menu.add(new JMenuItem ( 83 action)); 84 logger.debug("Added action [" + jobAction.getName() + "]"); 85 } 86 87 91 class Keys { 92 private final Integer mnumonicKey; 93 private final KeyStroke acceleratorKey; 94 Keys(Integer mnumonicKey, KeyStroke acceleratorKey) { 95 this.mnumonicKey = mnumonicKey; 96 this.acceleratorKey = acceleratorKey; 97 } 98 public KeyStroke getAcceleratorKey() { 99 return acceleratorKey; 100 } 101 public Integer getMnumonicKey() { 102 return mnumonicKey; 103 } 104 } 105 } 106 | Popular Tags |