⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mainmenubarhandler.java

📁 一个数据挖掘软件ALPHAMINERR的整个过程的JAVA版源代码
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
/*
 *    This program is free software; you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation; either version 2 of the License, or
 *    (at your option) any later version.
 *
 *    This program is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License
 *    along with this program; if not, write to the Free Software
 *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */
/*
 * $Author$
 * $Date$
 * $Revision$
 * 
 * This is the handler of the Menu bar of Main Application Windows.
 */
package eti.bi.alphaminer.ui.menu;
import java.awt.Cursor;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.util.Enumeration;
import java.util.Vector;
import javax.swing.ButtonGroup;
import javax.swing.JCheckBoxMenuItem;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.KeyStroke;
import eti.bi.alphaminer.Locale.LocalesManager;
import eti.bi.alphaminer.core.Plugin.PluginFactory;
import eti.bi.alphaminer.core.handler.AccessController;
import eti.bi.alphaminer.core.handler.CaseHandler;
import eti.bi.alphaminer.core.handler.CaseInfoListHandler;
import eti.bi.alphaminer.core.observer.Observer;
import eti.bi.alphaminer.core.observer.HelpObserver;
import eti.bi.alphaminer.core.observer.HelpObserveSubject;
import eti.bi.alphaminer.core.workspace.WorkspacesManager;
import eti.bi.alphaminer.core.help.AlphaminerHelpHandler;
import eti.bi.alphaminer.jhelpcomponent.HelpCursor;
import eti.bi.common.Constants;
import eti.bi.common.ImageLocation;
import eti.bi.common.Locale.Resource;
import eti.bi.common.System.SysConfig;
import eti.bi.alphaminer.ui.ApplicationWindow;
import eti.bi.alphaminer.ui.dialog.MessageDialog;
import eti.bi.alphaminer.vo.BICase;
import eti.bi.alphaminer.vo.CaseInfoList;
import eti.bi.alphaminer.vo.CaseInformation;
import eti.bi.exception.BaseException;
import eti.bi.exception.SysException;
import eti.bi.util.ResourceLoader;

/**
 * MenuBarHandler is responsible for creating and managing the menu bar of the
 * KBBI-client Applciation.
 */
public class MainMenuBarHandler extends MouseAdapter implements Observer, ActionListener, ItemListener {
	/* ApplicationWindow containing the tool bar */
	private ApplicationWindow m_Container;
	/* Tool bar handled by this handler */
	// private JMenuBar m_MenuBar;
	private JHelpMenuBar m_MenuBar; // <<27/07/2005 Kenneth Lai: Modify for
									// JHelp>>
	private Vector m_RecentlyOpenedCase;
	private JMenu m_MenuCase;
	private JMenu m_MenuEdit;
	// <<17/02/2005 Mark Li: Remove Configuration from menu
	// private JMenu m_MenuConfiguration;
	// 17/02/2005 Mark Li: Remove Configuration from menu>>
	private JMenu m_MenuWindow;
	private JMenu m_MenuAdvance;
	private JMenu m_MenuHelp;
	private JMenu m_MenuCaseRecentCases;
	private ButtonGroup m_CaseWindowGroup;
	private JCheckBoxMenuItem m_Emtpy;
	private JMenu m_MenuWorkSpace;
	private JMenu m_MenuLocale;
	private JMenuItem pluginItem;
	private static String ACTION_WINDOWS_CASCADE = "ACTION_WINDOWS_CASCADE";
	private static String ACTION_WINDOWS_VERTICAL = "ACTION_WINDOWS_VERTICAL";
	private static String ACTION_WINDOWS_HORIZONTAL = "ACTION_WINDOWS_HORIZONTAL";
	private static String ACTION_WINDOWS_MINIMIZE = "ACTION_WINDOWS_MINIMIZE";
	private static String ACTION_WINDOWS_MANAGEMENT = "ACTION_WINDOWS_MANAGEMENT";
	private static String ACTION_HELP_ABOUT = "ACTION_HELP_ABOUT";
	private static int INDEX_CONNECT = 0;
	private static int INDEX_DISCONNECT = 1;
	private static int INDEX_NEW = 2;
	private static int INDEX_COPY_CASE = 3;
	private static int INDEX_SAVE = 4;
	private static int INDEX_SAVE_ALL = 5;
	private static int INDEX_CLOSE = 6;
	private static int INDEX_CLOSE_ALL = 7;
	private static int INDEX_DELETE = 8;
	private static int INDEX_VIEW = 9;
	private static int INDEX_EDIT = 10;
	private static int INDEX_EXIT = 11;
	private static int INDEX_SEARCH = 12;
	private static int INDEX_RECENT = 13;
	private static int INDEX_ACTIVE = 14;
	// private static int INDEX_OPTION = 0;
	private static int INDEX_WORKSPACES = 0;
	private static int INDEX_LOCALE = 1;
	
	/**
	 * Constructs a MenuBarHandler.
	 * 
	 * @param a_Window
	 *            the ApplicationWindow containing menu bar handled by this
	 *            MenuBarHandler.
	 * @throws SysException
	 */
	public MainMenuBarHandler(ApplicationWindow a_Window) throws SysException {
		AccessController.getInstance().registerInterest(this);
		m_Container = a_Window;
		m_RecentlyOpenedCase = new Vector();
		m_CaseWindowGroup = new ButtonGroup();
		m_Emtpy = new JCheckBoxMenuItem();
		m_CaseWindowGroup.add(m_Emtpy);
		createMenuBar();
		logoffState();
	}

	/**
	 * Updates recent file sub-menu. Insert the specific Case ID to the top of
	 * the list.
	 */
	public void updateRecentFileList(String a_CaseID) {
		// update file m_FileName
		// update m_RecentlyOpenedCase
		updateRecentFileSubMenu(a_CaseID);
	}

	/**
	 * Updates Window Menu to select a pariticular case checkbox item. TWang.
	 * Apri. 6, 2005.
	 */
	public void updateWindowMenuRecentCase(String a_CaseID) {
		for (Enumeration em = m_CaseWindowGroup.getElements(); em.hasMoreElements();) {
			JCheckBoxMenuItem caseWindow = (JCheckBoxMenuItem) em.nextElement();
			String text = caseWindow.getText();
			int startIndex = text.indexOf(". ");
			if (text.indexOf(a_CaseID) != -1 && startIndex != -1) {
				if (text.substring(startIndex + 2, text.length()).equals(a_CaseID)) {
					caseWindow.setState(true);
				}
			}
		}
	}

	/**
	 * Updates Window Menu.
	 * 
	 * @param a_CaseID
	 *            ID of the Case to be inserted into or removed from the Window
	 *            Menu.
	 * @param a_isOpen
	 *            true to insert the specific entry into Window Menu; false to
	 *            remove the specific entry from the Window Menu.
	 */
	public void updateWindowMenu(String a_CaseID, boolean a_IsOpen) {
		if (a_IsOpen) {
			JCheckBoxMenuItem caseWindow = new JCheckBoxMenuItem(m_CaseWindowGroup.getButtonCount() + ". " + a_CaseID);
			caseWindow.setActionCommand("switch|" + a_CaseID);
			caseWindow.addActionListener(this);
			m_CaseWindowGroup.add(caseWindow);
			m_MenuWindow.add(caseWindow);
		} else {
			boolean found = false;
			JCheckBoxMenuItem removeCaseWindow = null;
			for (Enumeration em = m_CaseWindowGroup.getElements(); em.hasMoreElements();) {
				JCheckBoxMenuItem caseWindow = (JCheckBoxMenuItem) em.nextElement();
				if (found) {
					String text = caseWindow.getText();
					int num = Integer.parseInt(text.substring(0, text.indexOf(".")));
					String caseID = text.substring(text.indexOf(". "));
					text = String.valueOf(num - 1) + caseID;
					caseWindow.setText(text);
				}
				if (caseWindow.getActionCommand().equals("switch|" + a_CaseID)) {
					m_MenuWindow.remove(caseWindow);
					removeCaseWindow = caseWindow;
					found = true;
				}
			}
			if (found)
				m_CaseWindowGroup.remove(removeCaseWindow);
		}
	}

	/**
	 * Selects entry of the specific CaseWindow in the Window Menu.
	 * 
	 * @param a_CaseID
	 *            ID of the Case whose CaseWindow is to be selected.
	 */
	public void selectCaseWindow(String a_CaseID) {
		JCheckBoxMenuItem selectCaseWindow = null;
		if (a_CaseID == null)
			m_Emtpy.setSelected(true);
		else {
			for (Enumeration em = m_CaseWindowGroup.getElements(); em.hasMoreElements();) {
				selectCaseWindow = (JCheckBoxMenuItem) em.nextElement();
				if (selectCaseWindow.getActionCommand().equals("switch|" + a_CaseID)) {
					selectCaseWindow.setSelected(true);
					break;
				}
			}
		}
	}

	/**
	 * Update a specific CaseWindow item in the Window Menu.
	 * 
	 * @param a_OldCaseID
	 *            original ID of the Case indicated in the menu item.
	 * @param a_NewCaseID
	 *            new ID to be sed to indicated the Case.
	 */
	public void updateWindowMenuItem(String a_OldCaseID, String a_NewCaseID) {
		JCheckBoxMenuItem selectCaseWindow = null;
		for (Enumeration em = m_CaseWindowGroup.getElements(); em.hasMoreElements();) {
			selectCaseWindow = (JCheckBoxMenuItem) em.nextElement();
			if (selectCaseWindow.getActionCommand().equals("switch|" + a_OldCaseID)) {
				String text = selectCaseWindow.getText();
				text = text.substring(0, text.indexOf(a_OldCaseID)) + a_NewCaseID;
				selectCaseWindow.setText(text);
				selectCaseWindow.setActionCommand("switch|" + a_NewCaseID);
				break;
			}
		}
	}

	/**
	 * Enables/disables File->Connect item.
	 * 
	 * @param a_IsEnabled
	 *            true to enable; false to disable.
	 */
	public void setEnabledConnect(boolean a_IsEnabled) {
		m_MenuCase.getItem(INDEX_CONNECT).setEnabled(a_IsEnabled);
	}

	/**
	 * Returns if File->Connect item is enabled.
	 * 
	 * @return true if it is enabled; false otherwise.
	 */
	public boolean isEnabledConnect() {
		return m_MenuCase.getItem(INDEX_CONNECT).isEnabled();
	}

	/**
	 * Enables/disables File->Disconnect item.
	 * 
	 * @param a_IsEnabled
	 *            true to enable; false to disable.
	 */
	public void setEnabledDisconnect(boolean a_IsEnabled) {
		m_MenuCase.getItem(INDEX_DISCONNECT).setEnabled(a_IsEnabled);
	}

	/**
	 * Returns if File->Disconnect item is enabled.
	 * 
	 * @return true if it is enabled; false otherwise.
	 */
	public boolean isEnabledDisconnect() {
		return m_MenuCase.getItem(INDEX_DISCONNECT).isEnabled();
	}

	/**
	 * Enables/disables File->New item.
	 * 
	 * @param a_IsEnabled
	 *            true to enable; false to disable.
	 */
	public void setEnabledNew(boolean a_IsEnabled) {
		m_MenuCase.getItem(INDEX_NEW).setEnabled(a_IsEnabled);
	}

	/**
	 * Returns if File->New item is enabled.
	 * 
	 * @return true if it is enabled; false otherwise.
	 */
	public boolean isEnabledNew() {
		return m_MenuCase.getItem(INDEX_NEW).isEnabled();
	}

	/**
	 * Enables/disables File->Copy Case item.
	 * 
	 * @param a_IsEnabled
	 *            true to enable; false to disable.
	 */
	public void setEnabledCopyCase(boolean a_IsEnabled) {
		m_MenuCase.getItem(INDEX_COPY_CASE).setEnabled(a_IsEnabled);
	}

	/**
	 * Returns if File->Copy Case item is enabled.
	 * 
	 * @return true if it is enabled; false otherwise.
	 */
	public boolean isEnabledCopyCase() {
		return m_MenuCase.getItem(INDEX_COPY_CASE).isEnabled();
	}

	/**
	 * Enables/disables File->Save item.
	 * 
	 * @param a_IsEnabled
	 *            true to enable; false to disable.
	 */
	public void setEnabledSave(boolean a_IsEnabled) {
		m_MenuCase.getItem(INDEX_SAVE).setEnabled(a_IsEnabled);
	}

	/**
	 * Returns if File->Save item is enabled.
	 * 
	 * @return true if it is enabled; false otherwise.
	 */
	public boolean isEnabledSave() {
		return m_MenuCase.getItem(INDEX_SAVE).isEnabled();
	}

	/**
	 * Enables/disables File->Save All item.
	 * 
	 * @param a_IsEnabled
	 *            true to enable; false to disable.
	 */
	public void setEnabledSaveAll(boolean a_IsEnabled) {
		m_MenuCase.getItem(INDEX_SAVE_ALL).setEnabled(a_IsEnabled);
	}

	/**
	 * Returns if File->Save All item is enabled.
	 * 
	 * @return true if it is enabled; false otherwise.
	 */
	public boolean isEnabledSaveAll() {
		return m_MenuCase.getItem(INDEX_SAVE_ALL).isEnabled();
	}

	/**
	 * Enables/disables File->Close item.
	 * 
	 * @param a_IsEnabled
	 *            true to enable; false to disable.
	 */
	public void setEnabledClose(boolean a_IsEnabled) {
		m_MenuCase.getItem(INDEX_CLOSE).setEnabled(a_IsEnabled);
	}

	/**
	 * Returns if File->Close item is enabled.
	 * 
	 * @return true if it is enabled; false otherwise.
	 */
	public boolean isEnabledClose() {
		return m_MenuCase.getItem(INDEX_CLOSE).isEnabled();
	}

	/**
	 * Enables/disables File->Close All item.
	 * 
	 * @param a_IsEnabled
	 *            true to enable; false to disable.
	 */
	public void setEnabledCloseAll(boolean a_IsEnabled) {
		m_MenuCase.getItem(INDEX_CLOSE_ALL).setEnabled(a_IsEnabled);
	}

	/**
	 * Returns if File->Close All item is enabled.
	 * 
	 * @return true if it is enabled; false otherwise.
	 */
	public boolean isEnabledCloseAll() {
		return m_MenuCase.getItem(INDEX_CLOSE_ALL).isEnabled();
	}

	/**
	 * Enables/disables File->Delete item.
	 * 
	 * @param a_IsEnabled
	 *            true to enable; false to disable.
	 */
	public void setEnabledDelete(boolean a_IsEnabled) {
		m_MenuCase.getItem(INDEX_DELETE).setEnabled(a_IsEnabled);
	}

	/**
	 * Returns if File->Delete item is enabled.
	 * 
	 * @return true if it is enabled; false otherwise.
	 */
	public boolean isEnabledDelete() {
		return m_MenuCase.getItem(INDEX_DELETE).isEnabled();
	}

	/**
	 * Enables/disables File->View item.
	 * 
	 * @param a_IsEnabled
	 *            true to enable; false to disable.
	 */
	public void setEnabledView(boolean a_IsEnabled) {
		m_MenuCase.getItem(INDEX_VIEW).setEnabled(a_IsEnabled);
	}
	
	/**
	 * Returns <code>true<code> if File->View item is enabled.
	 * 
	 * @return true if it is enabled; false otherwise.
	 */
	public boolean isEnabledView() {
		return m_MenuCase.getItem(INDEX_VIEW).isEnabled();
	}

	/**
	 * Enables/disables File->Edit item.
	 * 
	 * @param a_IsEnabled
	 *            true to enable; false to disable.
	 */
	public void setEnabledEdit(boolean a_IsEnabled) {
		m_MenuCase.getItem(INDEX_EDIT).setEnabled(a_IsEnabled);
	}

	/**
	 * Returns if File->Edit item is enabled.
	 * 
	 * @return true if it is enabled; false otherwise.
	 */
	public boolean isEnabledEdit() {
		return m_MenuCase.getItem(INDEX_EDIT).isEnabled();
	}

	/**
	 * Enables/disables File->Activate item.
	 * 
	 * @param a_IsEnabled
	 *            true to enable; false to disable.
	 */
	public void setEnabledActivate(boolean a_IsEnabled) {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -