applicationwindow.java

来自「为了下东西 随便发了个 datamining 的源代码」· Java 代码 · 共 1,413 行 · 第 1/3 页

JAVA
1,413
字号
/*
 *    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.
 */

package eti.bi.alphaminer.ui;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Cursor;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Point;
import java.awt.event.WindowEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseEvent;
import java.awt.event.WindowStateListener;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Vector;

import javax.swing.BorderFactory;
import javax.swing.DefaultDesktopManager;
import javax.swing.JComponent;
import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JInternalFrame;
import javax.swing.JInternalFrame.JDesktopIcon;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.WindowConstants;
import javax.swing.border.BevelBorder;

import eti.bi.alphaminer.Locale.LocalesManager;
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.HelpObserver;
import eti.bi.alphaminer.core.observer.HelpObserveSubject;
import eti.bi.alphaminer.core.observer.ObserveSubject;
import eti.bi.alphaminer.core.observer.Observer;
import eti.bi.alphaminer.core.workspace.WorkspacesManager;
import eti.bi.alphaminer.jhelpcomponent.HelpCursor;
import eti.bi.alphaminer.jhelpcomponent.JHelpDesktopPane;
import eti.bi.alphaminer.jhelpcomponent.JHelpPanel;
import eti.bi.common.Locale.Resource;
import eti.bi.common.System.AlphaMinerConstants;
import eti.bi.common.System.SysConfig;
import eti.bi.alphaminer.tools.SystemTools.CaseHelpToolBarHandler;
import eti.bi.alphaminer.ui.Dialog.MessageDialog;
import eti.bi.alphaminer.ui.ToolBar.StatusToolBar;
import eti.bi.alphaminer.ui.ToolBar.ToolBarHandler;
import eti.bi.alphaminer.ui.menu.MainMenuBarHandler;
import eti.bi.alphaminer.vo.BICase;
import eti.bi.exception.BaseException;
import eti.bi.exception.SysException;

/**
 * ApplicationWindow is the main frame of the KBBI-client standalone
 * application.
 */
public class ApplicationWindow extends JFrame implements Observer,
		HelpObserver, ObserveSubject, WindowStateListener, MouseListener {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	/* Modal frames of ApplicationWindow */
	private AboutDialog m_AboutDialog;

	private SearchingCriteria m_SearchingCriteria;

	/* Internal frame of ApplicationWindow */
	private ManagementWindow m_ManagementWindow;

	/* Menubar handler */
	private MainMenuBarHandler m_MenuBarHandler;

	/*
	 * Content pane of ApplicationWindow frame containing panel content and
	 * status bar
	 */
	private JPanel m_ContentPaneApplicationWindow;

	/* Panel content containing a toolbar and a desktop pane */
	// private JPanel m_PanelContent; // <<27/07/2005 Kenneth Lai: Modify for
	// JHelp>>
	private JHelpPanel m_PanelContent; // <<27/07/2005 Kenneth Lai: Modify for
										// JHelp>>

	/* Toolbar handler */
	private ToolBarHandler m_ToolBarHandler;

	/* Desktop pane for internal frames */
	// private JDesktopPane m_ContentApplicationWindow; // <<27/07/2005 Kenneth
	// Lai: Modify for JHelp>>
	private JHelpDesktopPane m_ContentApplicationWindow; // <<27/07/2005
															// Kenneth Lai:
															// Modify for
															// JHelp>>

	/* Status bar */
	private StatusToolBar m_StatusToolBar;

	private JLabel m_StatusBarMessage;

	private ApplicationWindowDesktopManager m_ApplicationWindowDesktopManager;

	private int m_NewCaseIndex;

	private ArrayList<CaseWindow> CaseWindowList = new ArrayList<CaseWindow>();

	// <<11/12/2005, XJ. Chen
	// private ResourceBundle m_Messages;

	// <<20/01/2005, Frank J. Xu
	// To Adapt to Different Data Mining Engine
	private int m_DMEngineType;

	// 20/01/2005, Frank J. Xu>>

	// <<25/01/2005, Mark Li
	// Add a pop up picture before enter the main function
	// private final static String splashIconName =
	// "bin/kbbiapplication/ui/images/splash.png";
	// 25/01/2005, Mark Li>>

	// <<01/02/2005, Mark
	// Add an image as background
	// private final static String backgroundImage =
	// "bin/kbbiapplication/ui/images/Background.png";
	// private JLabel backgroundLabel;
	// 01/02/2005, Mark>>

	// <<23/03/2005 Mark Li: Set flag to show Search Window
	public boolean enableSerachResultPanel = true;

	// <<23/03/2005 Mark Li: Set flag to show Search Window

	private boolean m_HelpState;

	// 25/07/2005: Kenneth Lai: Add for JHelp>>

	public static boolean POPUP_WINDOW = false;

	public static final String NOTIFY_SAVE_CASE = "SAVE_CASE";

	public static final String NOTIFY_DELETE_CASE = "DELETE_CASE";

	private static Vector<Observer> observers = new Vector<Observer>();

	/**
	 * Constructs an ApplicationWindow.
	 * 
	 * @param a_Messages
	 *            the ResourceBundle to be used.
	 * @throws SysException
	 */
	// <<11/12/2005, XJ. Chen
	// public ApplicationWindow(ResourceBundle aMessages) throws SysException {
	public ApplicationWindow() throws SysException {
		// <<11/12/2005, XJ. Chen
		// m_Messages = aMessages;

		MessageDialog.setFrame(this);

		/*
		 * Frame splashFrame = SplashWindow.splash(splashImage);
		 * splashFrame.setAlwaysOnTop(true); splashFrame.
		 */

		createApplicationWindow();
		Resource.registerInterest(this);
	}

	/**
	 * Gets the toolbar handler.
	 * 
	 * @return ToolBarHandler the toolbar handler.
	 */
	public ToolBarHandler getToolBarHandler() {
		return m_ToolBarHandler;
	}

	/**
	 * Gets the menu bar handler.
	 * 
	 * @return MenuBarHandler the menu bar handler.
	 */
	public MainMenuBarHandler getMenuBarHandler() {
		return m_MenuBarHandler;
	}

	/**
	 * Gets the desktop pane of the ApplicationWindow frame.
	 * 
	 * @return ContentApplicationWindow the desktop pane.
	 */
	// public JDesktopPane getDesktopPane() {
	public JHelpDesktopPane getDesktopPane() {// <<22/07/2005 Kenneth Lai:
												// Modify for JHelp
		return m_ContentApplicationWindow;
	}

	// <<22/07/2005 Kenneth Lai: Add for JHelp
	public void setHelpState(boolean a_SetActive) {
		if (a_SetActive) {
			// setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
			m_HelpState = a_SetActive;
			// JInternalFrame[] frames =
			// m_ContentApplicationWindow.getAllFrames();
			// if (frames != null) {
			// for (int i = frames.length - 1; i >= 0; i--) {
			// frames[i].setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
			// }
			// }
		}
		// else {
		// setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
		// }
	}

	public boolean getHelpState() {
		return m_HelpState;
	}

	// 22/07/2005 Kenneth Lai: Add for JHelp>>

	// << 21/02/2005 Mark Li. Add for dynamic update the Case List window
	public ManagementWindow getManagementWindow() {
		return m_ManagementWindow;
	}

	// 21/02/2005 Mark Li. Add for dynamic update the Case List window>>
	/**
	 * Create a new Case.
	 * 
	 * @param a_CaseID
	 *            temporary ID of the new Case.
	 */
	public void newCase(String a_CaseID) {
		m_NewCaseIndex++;

		CaseWindow caseWin = new CaseWindow(this, true, a_CaseID, true,
				m_DMEngineType);
		caseWin.setSize(400, 300);// <<22/07/2005 Kenneth Lai: Add for new
									// Case Window cascade problem>>
		caseWin.setTitle(Resource.srcStr("UntitledTitle") + m_NewCaseIndex
				+ " *");
		caseWin.setVisible(true);
		caseWin.moveToFront();
		m_ContentApplicationWindow.add(caseWin);
		CaseWindowList.add(caseWin);
		// cascadeWindows();
		try {
			caseWin.setMaximum(true);
			caseWin.setSelected(true);
		} catch (java.beans.PropertyVetoException pe) {
		}
	}

	/**
	 * Copies a specific Case.
	 * 
	 * @param a_CaseID
	 *            ID of the case to be copied.
	 */
	public void copyCase(String a_CaseID) {
		if (a_CaseID == null || a_CaseID.trim().equals(""))
			System.err.println("Cannot copy case without case id");
		newCase(a_CaseID);
	}

	/**
	 * Saves the Case of a CaseWindow in focus.
	 */
	public void saveCase() {
		Component iFrame = m_ContentApplicationWindow.getSelectedFrame();
		if (iFrame instanceof CaseWindow) {
			CaseWindow caseWindow = (CaseWindow) iFrame;
			caseWindow.save();
			sendNotifytoObserver(NOTIFY_SAVE_CASE + "|"
					+ caseWindow.getCaseID());
		}
		;

	}

	/**
	 * Saves Cases of all openning CaseWindows.
	 */
	public void saveAllCase() {
		JInternalFrame[] frames = m_ContentApplicationWindow.getAllFrames();
		if (frames != null) {
			for (int i = 0; i < frames.length; i++) {
				if (frames[i].isVisible()) {
					if (frames[i] instanceof CaseWindow)
						((CaseWindow) frames[i]).save();
				}
			}
		}
	}

	/**
	 * Closes a CaseWindow in focus.
	 */
	public void closeCase() {
		Component iFrame = m_ContentApplicationWindow.getSelectedFrame();
		if (iFrame instanceof CaseWindow) {
			((CaseWindow) iFrame).close();
		}
	}

	/**
	 * Closes all openning CaseWindows. TWang. Apri 1, 2005.
	 * 
	 * @return true of all CaseWindows are sucessfully closed; false otherwise.
	 */
	public boolean closeAllCase() {
		JInternalFrame[] frames = m_ContentApplicationWindow.getAllFrames();
		if (frames != null) {
			// count how many CaseWindow should be closed.
			int shouldDeleteNum = 0;
			for (int i = 0; i < frames.length; i++) {
				if (frames[i].isVisible() && (frames[i] instanceof CaseWindow)) {
					shouldDeleteNum++;
				}
			}
			int previousShouldDel = 0;
			boolean isMax = false;
			while (shouldDeleteNum > 0) {
				previousShouldDel = shouldDeleteNum;
				for (int i = 0; i < frames.length; i++) {
					if (frames[i].isVisible()
							&& (frames[i] instanceof CaseWindow)) {
						// Close CaseWindow according to the selection sequence
						if (!((CaseWindow) frames[i]).close())
							return false;
						else {
							shouldDeleteNum--;
						}
					} else if (frames[i].isVisible()
							&& (frames[i] instanceof ManagementWindow && frames[i]
									.isSelected())) {
						// if the next focus is a ManagementWindow, record isMax
						// or not.
						isMax = ((ManagementWindow) frames[i]).isMaximum();
					}
				}
				if (previousShouldDel == shouldDeleteNum) {
					// if no Selected CaseWindow is found, select one.
					setFocusToFirstCaseWindow(isMax);
				}
			}
		}

		// finally, set focus on the Management Window if it is visible
		for (int i = 0; i < frames.length; i++) {
			if (frames[i].isVisible()
					&& (frames[i] instanceof ManagementWindow)) {
				try {
					frames[i].setSelected(true);
				} catch (java.beans.PropertyVetoException pe) {
				}
				break;
			}
		}
		return true;
	}

	/**
	 * Dispose all CaseWindows. Xiaojun Chen. July 14, 2006.
	 * 
	 * @return true of all CaseWindows are sucessfully disposed; false
	 *         otherwise.
	 */
	public boolean disposeAllCases() {
		JInternalFrame[] frames = m_ContentApplicationWindow.getAllFrames();
		if (frames != null) {
			// count how many CaseWindow should be closed.
			int shouldDeleteNum = 0;
			for (int i = 0; i < frames.length; i++) {
				if ((frames[i] instanceof CaseWindow)) {
					shouldDeleteNum++;
				}
			}
			int previousShouldDel = 0;
			boolean isMax = false;
			while (shouldDeleteNum > 0) {
				previousShouldDel = shouldDeleteNum;
				for (int i = 0; i < frames.length; i++) {
					if ((frames[i] instanceof CaseWindow)) {
						// Close CaseWindow according to the selection sequence
						if (!((CaseWindow) frames[i]).close())
							return false;
						else {
							shouldDeleteNum--;
						}
					} else if ((frames[i] instanceof ManagementWindow && frames[i]
							.isSelected())) {
						// if the next focus is a ManagementWindow, record isMax
						// or not.
						isMax = ((ManagementWindow) frames[i]).isMaximum();
					}
				}
				if (previousShouldDel == shouldDeleteNum) {
					// if no Selected CaseWindow is found, select one.
					setFocusToFirstCaseWindow(isMax);
				}
			}
		}

		// finally, set focus on the Management Window if it is visible
		for (int i = 0; i < frames.length; i++) {
			if (frames[i].isVisible()
					&& (frames[i] instanceof ManagementWindow)) {
				try {
					frames[i].setSelected(true);
				} catch (java.beans.PropertyVetoException pe) {
				}
				break;
			}
		}
		return true;
	}

	/**
	 * Deletes a specific Case.
	 * 
	 * @param a_CaseID
	 *            ID of the case to be deleted.
	 */
	public void deleteCase(String a_CaseID) {
		Component iFrame = m_ContentApplicationWindow.getSelectedFrame();
		if (iFrame instanceof CaseWindow) {
			((CaseWindow) iFrame).delete();
			m_ManagementWindow.getCaseListPanel().getCaseListTree()
					.removeChildNode(a_CaseID);
			sendNotifytoObserver(NOTIFY_DELETE_CASE + "|" + a_CaseID);
			return;
		} else if (iFrame instanceof ManagementWindow) {
			JInternalFrame[] frames = m_ContentApplicationWindow.getAllFrames();
			if (frames != null) {
				for (int i = 0; i < frames.length; i++) {
					if (frames[i].isVisible()) {
						if (frames[i] instanceof CaseWindow) {
							if (((CaseWindow) frames[i]).getCaseID().equals(
									a_CaseID)) {
								((CaseWindow) frames[i]).delete();
								m_ManagementWindow.getCaseListPanel()
										.getCaseListTree().removeChildNode(
												a_CaseID);
								sendNotifytoObserver(NOTIFY_DELETE_CASE + "|"
										+ a_CaseID);
								return;
							}
						}

⌨️ 快捷键说明

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