FileDocCategorySizeDatePackage
MenuItemManager.javaAPI DocAzureus 3.0.3.43844Fri Aug 03 16:30:14 BST 2007org.gudy.azureus2.ui.common.util

MenuItemManager

public class MenuItemManager extends Object
Similar to TableContextMenuManager - this keeps references to created menu items by plugins to be used by external code.
author
amc1

Fields Summary
private static MenuItemManager
instance
private static org.gudy.azureus2.core3.util.AEMonitor
class_mon
private Map
items
private org.gudy.azureus2.core3.util.AEMonitor
items_mon
Constructors Summary
private MenuItemManager()


	  
		this.items = new HashMap();
	
Methods Summary
public voidaddMenuItem(org.gudy.azureus2.plugins.ui.menus.MenuItem item)

		try {
			String name = item.getResourceKey();
			String sMenuID = item.getMenuID();
			try {
				this.items_mon.enter();
				Map mTypes = (Map) this.items.get(sMenuID);
				if (mTypes == null) {
					// LinkedHashMap to preserve order
					mTypes = new LinkedHashMap();
					this.items.put(sMenuID, mTypes);
				}
				mTypes.put(name, item);

			} finally {
				this.items_mon.exit();
			}
		} catch (Exception e) {
			System.out.println("Error while adding Menu Item");
			Debug.printStackTrace(e);
		}
	
private voidaddMenuItems(java.lang.String menu_id, java.util.ArrayList l)

		Map menu_map = (Map)this.items.get(menu_id);
		if (menu_map != null) {l.addAll(menu_map.values());}
	
public org.gudy.azureus2.plugins.ui.menus.MenuItem[]getAllAsArray(java.lang.String sMenuID)

		Map local_menu_item_map = (Map)this.items.get(sMenuID);
		Map global_menu_item_map = (Map)this.items.get(null);
		if (local_menu_item_map == null && global_menu_item_map == null) {
			return new MenuItem[0];
		}
		
		if (sMenuID == null) {local_menu_item_map = null;}
		
		ArrayList l = new ArrayList();
		if (local_menu_item_map != null) {l.addAll(local_menu_item_map.values());}
		if (global_menu_item_map != null) {l.addAll(global_menu_item_map.values());}
		return (MenuItem[]) l.toArray(new MenuItem[l.size()]);
	
public org.gudy.azureus2.plugins.ui.menus.MenuItem[]getAllAsArray(java.lang.String[] menu_ids)

		ArrayList l  = new ArrayList();
		for (int i=0; i<menu_ids.length; i++) {
			addMenuItems(menu_ids[i], l);
		}
		addMenuItems(null, l);
		return (MenuItem[]) l.toArray(new MenuItem[l.size()]);
	
public static org.gudy.azureus2.ui.common.util.MenuItemManagergetInstance()
Return the static MenuManager instance

		try {
			class_mon.enter();
			if (instance == null)
				instance = new MenuItemManager();
			return instance;
		} finally {
			class_mon.exit();
		}
	
public voidremoveMenuItem(org.gudy.azureus2.plugins.ui.menus.MenuItem item)

		Map menu_item_map = (Map)this.items.get(item.getMenuID());
		if (menu_item_map != null) {menu_item_map.remove(item.getResourceKey());}