/* 	ApplicationMBar.java	Title:			Virtual Control Surface	Author:			root	Description:	Copyright © 2001 Jason LamportAll Rights Reserved*/package com.strangelight.v4control;import com.strangelight.salsa.*;import java.awt.*;import java.awt.event.*;public final class ApplicationMBar extends J_MenuBar {	static class MenuCommandItem extends MenuItem {	/**		Makes the following modifications to the usual behaviour of <code>MenuItem</code>:<br>		1. 	Allows no more than one ActionListener to be active at a time (see			<code>addActionListener</code> and <code>swapActionListener</code> for			details).		2.	Automatically enables/disables itself based on whether there is a			currently-registered ActionListener.	*/		protected ActionListener curActionListener;				public MenuCommandItem() {			setEnabled( false );		}		public MenuCommandItem(String label) {			super(label);			setEnabled( false );		}		public MenuCommandItem(String label, MenuShortcut s) {			super(label, s);			setEnabled( false );		}		/**			Exactly like <CODE>addActionListener</CODE> except removes the current 			ActionListener (if any) before adding the new one, and sets enabled to			true.			@see java.awt.MenuItem#addActionListener		*/		public void swapActionListener(ActionListener l) {			removeActionListener();			super.addActionListener( l );			curActionListener = l;			setEnabled( true );		}				/**			@deprecated use <code>swapActionListener</code> instead.			@see #swapActionListener		*/		public void addActionListener(ActionListener l) {			swapActionListener( l );		}				/**			Removes the current ActionListener (if any) and disables			the menu item.		*/		public void removeActionListener() {			setEnabled( false );			if ( curActionListener != null ) {				super.removeActionListener( curActionListener );				curActionListener = null;			}		}				/**			Removes the ActionListener l and disables			the menu item.  If l is not the current ActionListener,			then this method does nothing.		*/		public void removeActionListener(ActionListener l) {			if ( curActionListener == l ) {				removeActionListener();			}		}	}	public static final int NEW 		= 0;	public static final int OPEN 		= 1;	public static final int CLOSE 		= 2;	public static final int SAVE 		= 3;	public static final int SAVE_AS_ 	= 4;	public static final int REVERT 		= 5;	public static final int QUIT 		= 6;		public static final int UNDO 		= 7;	public static final int REDO 		= 8;	public static final int CUT 		= 9;	public static final int COPY 		= 10;	public static final int PASTE 	 	= 11;	public static final int CLEAR 	 	= 12;	public static final int DUPLICATE  	= 13;	public static final int SELECT_ALL  = 14;		public static final int INPUT_SETTINGS_ 	 	= 15;	public static final int NEW_VIRTUAL_4CONTROL 	= 16;	public static final int PREFERENCES_ 		 	= 17;		public static final int TEST_1 		 	= 18;	public static final int TEST_2 		 	= 19;	public static final int TEST_3 		 	= 20;		static final int k_NumberOfMenuItems 			= 21;	static MenuCommandItem[]	mItems = new  MenuCommandItem[k_NumberOfMenuItems];		static final int _FILE		= 0;	static final int _EDIT		= 1;	static final int _4CONTROL	= 2;	static final int _DEBUG		= 3;	static final int k_NumberOfMenus 			= 4;	static Menu[]	mBarMenus = new Menu[k_NumberOfMenus];			public static MenuCommandItem getItem(int i ) {		return mItems[i];	}	/**		Similar to <code>MenuItem</code>'s <code>addActionListener</code>		method, except that in ApplicationMBar, a menu item can have		at most one ActionListener at a time.  A call to 		<code>swapActionListener</code> removes the old ActionListener		(if any) before adding the new one.  Note that ApplicationMBar automatically		enables any menu item for which there is a registered ActionListener,		and disables any menu item for which there isn't.				@param what an integer constant representing the menu item		@param who the ActionListener object requesting ActionEvents				@see java.awt.MenuItem#addActionListener	*/	public static void swapActionListener( int what, ActionListener who) {		mItems[what].swapActionListener(who);	}	/**		Similar to <code>MenuItem</code>'s <code>removeActionListener</code>.		Note that ApplicationMBar automatically enables any menu item for which 		there is a registered ActionListener, and disables any menu item 		for which there isn't.				@param what an integer constant representing the menu item		@param who the ActionListener object requesting no longer to receive ActionEvents				@see java.awt.MenuItem#removeActionListener	*/	public static void removeActionListener( int what, ActionListener who) {		mItems[what].removeActionListener(who);	}	/**		Similar to <code>MenuItem</code>'s <code>removeActionListener</code>.		Removes the currently-registered ActionListener object.		Note that ApplicationMBar automatically enables any menu item for which 		there is a registered ActionListener, and disables any menu item 		for which there isn't.				@param what an integer constant representing the menu item				@see java.awt.MenuItem#removeActionListener	*/	public static void removeActionListener( int what ) {		mItems[what].removeActionListener();	}		static {		mItems[NEW] = new MenuCommandItem( 			"New", 			new MenuShortcut(KeyEvent.VK_N) 		);		mItems[OPEN] = new MenuCommandItem( 			"Open", 			new MenuShortcut(KeyEvent.VK_O) 		);		mItems[CLOSE] = new MenuCommandItem( 			"Close", 			new MenuShortcut(KeyEvent.VK_W) 		);		mItems[SAVE] = new MenuCommandItem( 			"Save", 			new MenuShortcut(KeyEvent.VK_S) 		);		mItems[SAVE_AS_] = new MenuCommandItem( 			"Save AsÉ", 			new MenuShortcut(KeyEvent.VK_S, true) 		);		mItems[REVERT] = new MenuCommandItem( 			"Revert", 			new MenuShortcut(KeyEvent.VK_R, true) 		);		mItems[QUIT] = new MenuCommandItem( 			"Quit", 			new MenuShortcut(KeyEvent.VK_Q) 		);			mItems[UNDO] = new MenuCommandItem( 			"Undo", 			new MenuShortcut(KeyEvent.VK_Z) 		);		mItems[REDO] = new MenuCommandItem( 			"Redo", 			new MenuShortcut(KeyEvent.VK_Z, true) 		);		mItems[CUT] = new MenuCommandItem( 			"Cut", 			new MenuShortcut(KeyEvent.VK_X) 		);		mItems[COPY] = new MenuCommandItem( 			"Copy", 			new MenuShortcut(KeyEvent.VK_C) 		);		mItems[PASTE] = new MenuCommandItem( 			"Paste", 			new MenuShortcut(KeyEvent.VK_V) 		);		mItems[CLEAR] = new MenuCommandItem( 			"Clear", 			new MenuShortcut(KeyEvent.VK_DELETE) 		);		mItems[DUPLICATE] = new MenuCommandItem( 			"Duplicate", 			new MenuShortcut(KeyEvent.VK_D) 		);		mItems[SELECT_ALL] = new MenuCommandItem( 			"Select All", 			new MenuShortcut(KeyEvent.VK_A) 		);			mItems[INPUT_SETTINGS_] = new MenuCommandItem( 			"Input SettingsÉ", 			new MenuShortcut(KeyEvent.VK_I) 		);		mItems[NEW_VIRTUAL_4CONTROL] = new MenuCommandItem( 			"New Virtual 4Control", 			new MenuShortcut(KeyEvent.VK_R) 		);		mItems[PREFERENCES_] = new MenuCommandItem( 			"PreferencesÉ", 			new MenuShortcut(KeyEvent.VK_K) 		);			mItems[TEST_1] = new MenuCommandItem( 			"TEST_1", 			new MenuShortcut(KeyEvent.VK_1) 		);		mItems[TEST_2] = new MenuCommandItem( 			"TEST_2", 			new MenuShortcut(KeyEvent.VK_2) 		);		mItems[TEST_3] = new MenuCommandItem( 			"TEST_3", 			new MenuShortcut(KeyEvent.VK_3) 		);			mBarMenus[_FILE] = new Menu("File");		mBarMenus[_EDIT] = new Menu("Edit");		mBarMenus[_4CONTROL] = new Menu("4Control");		mBarMenus[_DEBUG] = new Menu("DEBUG");				mBarMenus[_FILE].add(mItems[NEW]);		mBarMenus[_FILE].add(mItems[OPEN]);		mBarMenus[_FILE].add(mItems[CLOSE]);		mBarMenus[_FILE].add(mItems[SAVE]);		mBarMenus[_FILE].add(mItems[SAVE_AS_]);		mBarMenus[_FILE].add(mItems[REVERT]);		mBarMenus[_FILE].addSeparator();		mBarMenus[_FILE].add(mItems[QUIT]);		mBarMenus[_EDIT].add(mItems[UNDO]);		mBarMenus[_EDIT].add(mItems[REDO]);		mBarMenus[_EDIT].addSeparator();		mBarMenus[_EDIT].add(mItems[CUT]);		mBarMenus[_EDIT].add(mItems[COPY]);		mBarMenus[_EDIT].add(mItems[PASTE]);		mBarMenus[_EDIT].add(mItems[CLEAR]);		mBarMenus[_EDIT].addSeparator();		mBarMenus[_EDIT].add(mItems[DUPLICATE]);		mBarMenus[_EDIT].add(mItems[SELECT_ALL]);						mBarMenus[_4CONTROL].add(mItems[INPUT_SETTINGS_]);		mBarMenus[_4CONTROL].add(mItems[NEW_VIRTUAL_4CONTROL]);		mBarMenus[_4CONTROL].addSeparator();		mBarMenus[_4CONTROL].add(mItems[PREFERENCES_]);		mBarMenus[_DEBUG].add(mItems[TEST_1]);		mBarMenus[_DEBUG].add(mItems[TEST_2]);		mBarMenus[_DEBUG].add(mItems[TEST_3]);		mBar.add(mBarMenus[_FILE]);		mBar.add(mBarMenus[_EDIT]);		mBar.add(mBarMenus[_4CONTROL]);		mBar.add(mBarMenus[_DEBUG]);	}}/*NEWOPENCLOSESAVESAVE_AS_REVERTQUITUNDOREDOCUTCOPYPASTECLEARDUPLICATESELECT_ALLINPUT_SETTINGS_NEW_VIRTUAL_4CONTROLPREFERENCES_*/