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

📄 systemmessagepanel.java

📁 一个数据挖掘软件ALPHAMINERR的整个过程的JAVA版源代码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*
 *    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$
 * 
 */
package eti.bi.alphaminer.ui;

import java.awt.Cursor;
import java.awt.BorderLayout;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.ClipboardOwner;
import java.awt.datatransfer.StringSelection;
import java.awt.datatransfer.Transferable;
import java.awt.dnd.DnDConstants;
import java.awt.dnd.DropTarget;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Hashtable;

import javax.swing.AbstractAction;
import javax.swing.BorderFactory;
import javax.swing.JFileChooser;
import javax.swing.JLabel;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.JTextArea;
import javax.swing.KeyStroke;
import javax.swing.filechooser.FileFilter;
import eti.bi.alphaminer.tools.SearchDialog;
import eti.bi.alphaminer.tools.print.Printer;
import eti.bi.alphaminer.core.observer.HelpObserver;
import eti.bi.alphaminer.jhelpcomponent.HelpCursor;
import eti.bi.exception.SysException;

import eti.bi.common.Locale.Resource;
import eti.bi.common.System.SysLog;

/**
 * SystemMessagePanel is a Panel residing in the bottom part of a CaseWindow.
 * It displays any system message available to notify user about the updated
 * information.
 */
public class SystemMessagePanel extends JPanel implements 
	HelpObserver, 
	ISystemMessageHandler, MouseListener, ClipboardOwner, ActionListener {

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

	private JTabbedPane m_Tab;

	private JScrollPane m_ScrollPaneMessage;
//	private JTextPane m_TextPaneMessage;
	private JTextArea m_TextPaneMessage; //<26/07/2005 Kenneth Lai: Add for JHelp>>
	private JPanel m_PanelMessage;
	private JLabel m_LabelMessage;
//	private JButton m_ButtonClear;
	//private JHelpButton m_ButtonClear; //<27/07/2005 Kenneth Lai: Add for JHelp>>
	private boolean m_HelpState; //<26/07/2005 Kenneth Lai: Add for JHelp>>
	
	private static Hashtable s_MultipleInstances;
	
	private JPopupMenu popupmenu;
	private JMenuItem copyMessageItem;
	private JMenuItem copyAllMessageItem;
	private JMenuItem clearMessageItem;
	private JMenuItem saveMessageItem;
	private JMenuItem searchItem;
	private JMenuItem printItem;
	private SearchDialog searchdialog;
	
	private String[] superscript;
	
//	SystemMessagePanel systemMessage = (SystemMessagePanel) m_CaseWindow.getSystemMessagePanel();

	static{
		s_MultipleInstances = new Hashtable();
	}
	
	@SuppressWarnings("unchecked")
	public static void createInstance(String a_CaseID,String[] superscript, JTabbedPane tab) throws SysException
	{
		SystemMessagePanel aPanel = new SystemMessagePanel(tab,superscript);
		s_MultipleInstances.put(a_CaseID, aPanel);		
	}
	
	public static SystemMessagePanel getInstance(String a_CaseID)
	{
		return (SystemMessagePanel)s_MultipleInstances.get(a_CaseID);
	}
	
	public static void removeInstance(String a_CaseID) {
		SystemMessagePanel sysPanel = (SystemMessagePanel)s_MultipleInstances.get(a_CaseID);
		if(sysPanel!=null) {
			s_MultipleInstances.remove(a_CaseID);
			sysPanel.dispose();
		}
	}
	
	/**
	 * Constructs a SystemMessagePanel.
	 * @throws SysException
	 */
	private SystemMessagePanel(JTabbedPane tab, String[] superscript) throws SysException {
		m_Tab = tab;
		this.superscript = superscript;
		createSystemMessagePanel();
		
		setHelpState(false); // <<26/07/2005 Kenneth Lai: Add for JHelp>>
		
		new DropTarget(m_TextPaneMessage, DnDConstants.ACTION_NONE,
		        null, false);
		
		createPopupMenu();
		addActionMap();
		this.addMouseListener(this);
		m_TextPaneMessage.addMouseListener(this);
	}

	private void createPopupMenu() {
		popupmenu = new JPopupMenu();
		
		copyMessageItem = new JMenuItem(Resource.srcStr("Copy_systemmessages"));
		copyMessageItem.addActionListener(this);
		copyMessageItem.setAccelerator(KeyStroke.getKeyStroke('C', java.awt.event.KeyEvent.CTRL_MASK, false));
		
		copyAllMessageItem = new JMenuItem(Resource.srcStr("Copy_All_systemmessages"));
		copyAllMessageItem.addActionListener(this);
		copyAllMessageItem.setAccelerator(KeyStroke.getKeyStroke('D', java.awt.event.KeyEvent.CTRL_MASK, false));
		
		clearMessageItem = new JMenuItem(Resource.srcStr("Clear_systemmessages"));
		clearMessageItem.addActionListener(this);
		clearMessageItem.setAccelerator(KeyStroke.getKeyStroke('M', java.awt.event.KeyEvent.CTRL_MASK, false));
		
		saveMessageItem = new JMenuItem(Resource.srcStr("Save_systemmessages"));
		saveMessageItem.addActionListener(this);
		saveMessageItem.setAccelerator(KeyStroke.getKeyStroke('S', java.awt.event.KeyEvent.CTRL_MASK, false));
		
		searchItem = new JMenuItem(Resource.srcStr("SearchDialogSearch"));
		searchItem.addActionListener(this);
		searchItem.setAccelerator(KeyStroke.getKeyStroke('F', java.awt.event.KeyEvent.CTRL_MASK, false));

		printItem = new JMenuItem(Resource.srcStr("Print"));
		printItem.addActionListener(this);
		printItem.setAccelerator(KeyStroke.getKeyStroke('P', java.awt.event.KeyEvent.CTRL_MASK, false));
		
		
		popupmenu.add(copyMessageItem);
		popupmenu.add(copyAllMessageItem);
		popupmenu.add(new JPopupMenu.Separator());
		popupmenu.add(clearMessageItem);
		popupmenu.add(saveMessageItem);
		popupmenu.add(new JPopupMenu.Separator());
		
		popupmenu.add(searchItem);
		
		popupmenu.add(new JPopupMenu.Separator());
		
		popupmenu.add(printItem);
	}
	
	public void addActionMap() {
		
		m_TextPaneMessage.getActionMap().put("copyMessage", new AbstractAction("copyMessage") {
			/**
			 * 
			 */
		
			private static final long serialVersionUID = 1L;

			public void actionPerformed(ActionEvent evt) {
				m_TextPaneMessage.copy();
			}
		});
		m_TextPaneMessage.getInputMap().put(KeyStroke.getKeyStroke("control C"), "copyMessage");
		
		m_TextPaneMessage.getActionMap().put("copyAllMessage", new AbstractAction("copyAllMessage") {
			/**
			 * 
			 */
		
			private static final long serialVersionUID = 1L;

			public void actionPerformed(ActionEvent evt) {
				if(m_TextPaneMessage.getSelectedText()==null) {
					StringSelection sSelection = new StringSelection(m_TextPaneMessage.getText());
					SystemMessagePanel.this.getToolkit().getSystemClipboard().setContents(sSelection, SystemMessagePanel.this);
				}
			}
		});
		m_TextPaneMessage.getInputMap().put(KeyStroke.getKeyStroke("control D"), "copyAllMessage");
		
		m_TextPaneMessage.getActionMap().put("clearMessage", new AbstractAction("clearMessage") {
			/**
			 * 
			 */
		
			private static final long serialVersionUID = 1L;

			public void actionPerformed(ActionEvent evt) {
				clearMessage();
			}
		});
		m_TextPaneMessage.getInputMap().put(KeyStroke.getKeyStroke("control M"), "clearMessage");
		
		m_TextPaneMessage.getActionMap().put("saveMessage", new AbstractAction("saveMessage") {
			/**
			 * 
			 */
		
			private static final long serialVersionUID = 1L;

			public void actionPerformed(ActionEvent evt) {
				saveMessage();
			}
		});
		m_TextPaneMessage.getInputMap().put(KeyStroke.getKeyStroke("control S"), "saveMessage");
		
		m_TextPaneMessage.getActionMap().put("search", new AbstractAction("search") {
			/**
			 * 
			 */
		
			private static final long serialVersionUID = 1L;

			public void actionPerformed(ActionEvent evt) {
				search();
			}
		});
		m_TextPaneMessage.getInputMap().put(KeyStroke.getKeyStroke("control F"), "search");
		
		m_TextPaneMessage.getActionMap().put("print", new AbstractAction("print") {
			/**
			 * 
			 */
		
			private static final long serialVersionUID = 1L;

			public void actionPerformed(ActionEvent evt) {
				print();
			}
		});
		m_TextPaneMessage.getInputMap().put(KeyStroke.getKeyStroke("control P"), "print");
	}
	
	
	/**
	 * Appends text after the existing system message.
	 * @param a_Message the message to be appended.
	 */
	public static void appendMessage(String a_CaseID, String a_Message) {
		if (s_MultipleInstances.containsKey(a_CaseID))
		{
			SystemMessagePanel aPanel = (SystemMessagePanel)s_MultipleInstances.get(a_CaseID);
			aPanel.performAppendMessage(a_Message+"\n");
		}
	}

	/**
	 * @see eti.bi.alphaminer.ui.ISystemMessageHandler#appendMessage(String)
	 * */
	public void appendMessage(String a_Message) {
		performAppendMessage(a_Message);
	}
	
	/**
	 * @see eti.bi.alphaminer.ui.ISystemMessageHandler#appendLineMessage(String)
	 * */
	public void appendLineMessage(String a_Message) {

⌨️ 快捷键说明

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