1 package org.columba.core.gui.menu; 19 20 import java.util.Enumeration ; 21 import java.util.Hashtable ; 22 import java.util.logging.Logger ; 23 24 import javax.swing.JMenuBar ; 25 import javax.swing.JMenuItem ; 26 27 import org.columba.core.gui.action.AbstractColumbaAction; 28 29 30 42 public class ExtendableMenuBar extends JMenuBar { 43 44 private static final Logger LOG = Logger 45 .getLogger("org.columba.core.gui.menu"); 46 47 private Hashtable <String , ExtendableMenu> map = new Hashtable <String , ExtendableMenu>(); 48 49 50 public ExtendableMenuBar() { 51 super(); 52 } 53 54 public void add(ExtendableMenu menu) { 55 if ( menu == null ) throw new IllegalArgumentException ("menu == null"); 56 Enumeration <ExtendableMenu> e = menu.getSubmenuEnumeration(); 57 while (e.hasMoreElements()) { 58 ExtendableMenu submenu = e.nextElement(); 59 map.put(submenu.getId(), submenu); 60 } 61 62 super.add(menu); 63 } 64 65 public void insert(ExtendableMenu menu) { 66 if ( menu == null ) throw new IllegalArgumentException ("menu == null"); 67 68 Enumeration <ExtendableMenu> e = menu.getSubmenuEnumeration(); 69 while (e.hasMoreElements()) { 70 ExtendableMenu submenu = e.nextElement(); 71 map.put(submenu.getId(), submenu); 72 } 73 74 super.add(menu, getMenuCount()-2); 76 } 77 78 public boolean exists(String menuId) { 79 if ( menuId == null ) throw new IllegalArgumentException ("menuId == null"); 80 81 if ( map.containsKey(menuId)) return true; 82 83 return false; 84 } 85 86 public ExtendableMenu getMenu(String menuId) { 87 if ( menuId == null ) throw new IllegalArgumentException ("menuId == null"); 88 89 if (map.containsKey(menuId) == false) 90 throw new IllegalArgumentException ("no menu for "+menuId+" found"); 91 92 93 ExtendableMenu menu = (ExtendableMenu) map.get(menuId); 94 95 return menu; 96 } 97 98 public void insertMenuItem(String menuId, String placeholderId, 99 JMenuItem menuItem) { 100 if ( menuId == null ) throw new IllegalArgumentException ("menuId == null"); 101 102 if (map.containsKey(menuId) == false) 103 throw new IllegalArgumentException ("no menu with id " + menuId 104 + " found"); 105 106 ExtendableMenu menu = (ExtendableMenu) map.get(menuId); 107 menu.insert(menuItem, placeholderId); 108 } 109 110 public void insertAction(String menuId, String placeholderId, 111 AbstractColumbaAction action) { 112 if ( menuId == null ) throw new IllegalArgumentException ("menuId == null"); 113 114 if (map.containsKey(menuId) == false) 115 throw new IllegalArgumentException ("no menu with id " + menuId 116 + " found"); 117 118 ExtendableMenu menu = (ExtendableMenu) map.get(menuId); 119 menu.insert(action, placeholderId); 120 123 } 124 125 } 126 | Popular Tags |