FileDocCategorySizeDatePackage
MenuItemImpl.javaAPI DocAzureus 3.0.3.46859Thu Sep 13 09:25:16 BST 2007org.gudy.azureus2.pluginsimpl.local.ui.menus

MenuItemImpl

public class MenuItemImpl extends Object implements MenuItem
amc1: This class was largely derived from TableContextMenuImpl.

Fields Summary
private String
sMenuID
private String
sName
private int
style
private boolean
enabled
private Object
data
private org.gudy.azureus2.plugins.ui.Graphic
graphic
private List
listeners
private List
m_listeners
private List
fill_listeners
private List
children
private MenuItemImpl
parent
private String
display_text
private boolean
visible
Constructors Summary
public MenuItemImpl(String menuID, String key)


	     
		sMenuID = menuID;
		sName = key;
	
public MenuItemImpl(MenuItemImpl ti, String key)

		this.parent = ti;
		this.parent.addChildMenuItem(this);
		this.sMenuID = this.parent.getMenuID();
		this.sName = key;
	
Methods Summary
private voidaddChildMenuItem(MenuItem child)

		if (this.style != MenuItem.STYLE_MENU) {
			throw new RuntimeException("cannot add to non-container MenuItem");
		}
		this.children.add(child);
	
public voidaddFillListener(MenuItemFillListener listener)

		fill_listeners.add(listener);
	
public voidaddListener(MenuItemListener l)

		listeners.add(l);
	
public voidaddMultiListener(MenuItemListener l)

		  m_listeners.add(l);
	  
public java.lang.ObjectgetData()

		return (data);
	
public org.gudy.azureus2.plugins.ui.GraphicgetGraphic()

		return (graphic);
	
public MenuItemgetItem(java.lang.String key)

		if (this.style != MenuItem.STYLE_MENU) {
			return null;
		}
		java.util.Iterator itr = this.children.iterator();
		MenuItem result = null;
		while (itr.hasNext()) {
			result = (MenuItem) itr.next();
			if (key.equals(result.getResourceKey())) {
				return result;
			}
		}
		return null;
	
public MenuItem[]getItems()

		if (this.style != MenuItem.STYLE_MENU) {
			return null;
		}
		return (MenuItem[]) this.children.toArray(new MenuItem[this.children
				.size()]);
	
public java.lang.StringgetMenuID()

		return sMenuID;
	
public MenuItemgetParent()

		return this.parent;
	
public java.lang.StringgetResourceKey()

		return sName;
	
public intgetStyle()

		return (style);
	
public java.lang.StringgetText()

		if (this.display_text == null) {
			return MessageText.getString(this.getResourceKey());
		}
		return this.display_text;
	
public voidinvokeListenersMulti(java.lang.Object[] rows)

		  // We invoke the multi listeners first...
		  invokeListenersOnList(this.m_listeners, rows);
		  if (rows == null) {invokeListenersSingle(null); return;}
		  for (int i=0; i<rows.length; i++) {
			  invokeListenersSingle(rows[i]);
		  }
	  
protected voidinvokeListenersOnList(java.util.List listeners_to_notify, java.lang.Object o)

		for (int i = 0; i < listeners_to_notify.size(); i++) {
			try {
				((MenuItemListener) (listeners_to_notify.get(i))).selected(
						this, o);
			} catch (Throwable e) {
				Debug.printStackTrace(e);
			}
		}
	
private voidinvokeListenersSingle(java.lang.Object o)

		invokeListenersOnList(this.listeners, o);
	
public voidinvokeMenuWillBeShownListeners(java.lang.Object o)

		for (int i = 0; i < fill_listeners.size(); i++) {
			try {
				((MenuItemFillListener) (fill_listeners.get(i)))
						.menuWillBeShown(this, o);
			} catch (Throwable e) {
				Debug.printStackTrace(e);
			}
		}
	
public booleanisEnabled()

		return (enabled);
	
public booleanisSelected()

		if (style != STYLE_CHECK && style != STYLE_RADIO) {
			throw new RuntimeException("Style is not STYLE_CHECK or STYLE_RADIO");
		}
		if (data == null) {
			throw new RuntimeException("Item is neither selected or deselected");
		}
		if (!(data instanceof Boolean)) {
			throw new RuntimeException("Invalid data assigned to menu item, should be boolean: " + data);
		}
		return ((Boolean)data).booleanValue();
	
public booleanisVisible()

return visible;
public voidremove()

		removeWithEvents(UIManagerEvent.ET_REMOVE_MENU_ITEM, UIManagerEvent.ET_REMOVE_SUBMENU_ITEM);
	
public voidremoveAllChildItems()

		// This should make this.children be empty...
		MenuItem[] children = this.getItems();
		if (children != null) {
			for (int i=0; i<children.length; i++) {children[i].remove();}
		}
	
public voidremoveFillListener(MenuItemFillListener listener)

		fill_listeners.remove(listener);
	
public voidremoveListener(MenuItemListener l)

		listeners.remove(l);
	
public voidremoveMultiListener(MenuItemListener l)

		  m_listeners.remove(l);
	  
protected voidremoveWithEvents(int root_menu_event, int sub_menu_event)

		removeAllChildItems();
		if (this.parent != null) {
			UIManagerImpl.fireEvent(sub_menu_event, new Object[]{this.parent, this});
			parent.children.remove(this);
			this.parent = null;
		}
		else {
			UIManagerImpl.fireEvent(root_menu_event, this);
		}
		this.data = null;
		this.graphic = null;
		this.listeners.clear();
		this.fill_listeners.clear();
		this.m_listeners.clear();		
	
public voidsetData(java.lang.Object _data)

		data = _data;
	
public voidsetEnabled(boolean _enabled)

		enabled = _enabled;
	
public voidsetGraphic(org.gudy.azureus2.plugins.ui.Graphic _graphic)

		graphic = _graphic;
	
public voidsetStyle(int _style)

		if (this.style == MenuItem.STYLE_MENU && _style != MenuItem.STYLE_MENU) {
			throw new RuntimeException(
					"cannot revert menu style MenuItem object to another style");
		}
		style = _style;
	
public voidsetText(java.lang.String text)

		this.display_text = text;
	
public voidsetVisible(boolean visible)

this.visible = visible;