1 package net.suberic.util.gui; 2 import javax.swing.*; 3 import net.suberic.util.VariableBundle; 4 import java.util.Hashtable ; 5 import java.util.StringTokenizer ; 6 import java.util.MissingResourceException ; 7 import javax.swing.Action ; 8 9 14 15 public class ConfigurableMenuBar extends JMenuBar implements ConfigurableUI { 16 17 20 private Hashtable commands = new Hashtable (); 21 22 30 31 public ConfigurableMenuBar(String menuBarID, VariableBundle vars) { 32 super(); 33 34 configureComponent(menuBarID, vars); 35 } 36 37 43 44 public void configureComponent(String menubarID, VariableBundle vars) { 45 if ((menubarID != null) && (vars.getProperty(menubarID, "") != "")) { 46 StringTokenizer tokens = new StringTokenizer (vars.getProperty(menubarID, ""), ":"); 47 while (tokens.hasMoreTokens()) { 48 String currentMenu = tokens.nextToken(); 49 ConfigurableMenu m; 50 if (vars.getProperty(menubarID + "." + currentMenu + ".class", "").equals("")) { 51 m = new ConfigurableMenu(menubarID + "." + currentMenu, vars); 52 } else { 53 55 try { 56 Class menuClass = Class.forName(vars.getProperty(menubarID + "." + currentMenu + ".class", "net.suberic.util.gui.ConfigurableMenu")); 57 m = (ConfigurableMenu) menuClass.newInstance(); 58 m.configureComponent(menubarID + "." + currentMenu, vars); 59 } catch (Exception e) { 60 m = new ConfigurableMenu(menubarID + "." + currentMenu, vars); 63 } 64 } 65 if (m != null) { 66 this.add(m); 67 } 68 } 69 } 70 } 71 72 73 76 public void setActive(javax.swing.Action [] newActions) { 77 Hashtable tmpHash = new Hashtable (); 78 if (newActions != null && newActions.length > 0) { 79 for (int i = 0; i < newActions.length; i++) { 80 String cmdName = (String )newActions[i].getValue(Action.NAME); 81 tmpHash.put(cmdName, newActions[i]); 82 } 83 } 84 setActive(tmpHash); 85 } 86 87 90 public void setActive(Hashtable newCommands) { 91 commands = newCommands; 92 setActiveMenus(); 93 } 94 95 private void setActiveMenus() { 96 for (int i = 0; i < getMenuCount(); i++) { 97 ((ConfigurableMenu)getMenu(i)).setActive(commands); 98 } 99 } 100 101 105 106 public Action getAction(String command) { 107 return (Action )commands.get(command); 108 } 109 110 111 } 112 | Popular Tags |