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

📄 casediagrampanel.java

📁 一个数据挖掘软件ALPHAMINERR的整个过程的JAVA版源代码
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
/*
 *    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.Component;
import java.awt.Cursor;
import java.awt.DefaultKeyboardFocusManager;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Insets;
import java.awt.KeyEventDispatcher;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.Toolkit;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.awt.dnd.DnDConstants;
import java.awt.dnd.DropTarget;
import java.awt.dnd.DropTargetDragEvent;
import java.awt.dnd.DropTargetDropEvent;
import java.awt.dnd.DropTargetEvent;
import java.awt.dnd.DropTargetListener;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.io.UnsupportedEncodingException;
import java.math.BigInteger;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Vector;

import javax.swing.AbstractAction;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JInternalFrame;
import javax.swing.JLabel;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.KeyStroke;
import javax.swing.SwingConstants;
import javax.swing.UIManager;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;

import com.prudsys.pdm.Core.MiningException;

import eti.bi.alphaminer.tools.Exporter;
import eti.bi.alphaminer.tools.print.Printer;
import eti.bi.alphaminer.ui.dialog.MessageDialog;
import eti.bi.alphaminer.core.Node.NodeLoader;
import eti.bi.alphaminer.core.handler.CaseHandler;
import eti.bi.alphaminer.core.handler.ICaseHandler;
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.observer.OperatorResultObserver;
import eti.bi.alphaminer.jhelpcomponent.HelpCursor;
import eti.bi.alphaminer.operation.operator.ArrowComponent;
import eti.bi.alphaminer.operation.operator.NodeInfo;
import eti.bi.alphaminer.operation.operator.Operator;
import eti.bi.alphaminer.operation.operator.OperatorFactory;
import eti.bi.alphaminer.operation.property.OperatorProperty;
import eti.bi.alphaminer.operation.property.OperatorPropertyFactory;
import eti.bi.alphaminer.operation.result.OperatorResult;
import eti.bi.alphaminer.operation.result.OperatorResultFactory;
import eti.bi.alphaminer.vo.BICase;
import eti.bi.alphaminer.vo.Node;
import eti.bi.alphaminer.vo.NodeConnection;
import eti.bi.alphaminer.vo.NodeFactory;
import eti.bi.alphaminer.vo.OperatorNode;
import eti.bi.alphaminer.vo.TaskNode;
import eti.bi.exception.AppException;
import eti.bi.exception.BaseException;
import eti.bi.exception.SysException;
import eti.bi.util.ResourceLoader;

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

/**
 * CaseDiagramPanel is a Panel that shows the process visualization of a Case.
 * User can modify the process visualization (diagram) by adding or removing
 * operator nodes. In addtion user can modify Case basic information and detail
 * information possessed by each node.
 */
public class CaseDiagramPanel
	extends JPanel
	implements
		DropTargetListener,  
		MouseListener,
		MouseMotionListener,
		KeyEventDispatcher,
		ActionListener,
		Observer,
		HelpObserver,
		ICaseDiagram{
/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	//	<<20/07/2005: Kenneth Lai: case panel margin
    private final static int SCROLLPANE_X_MARGIN = 45;
    private final static int SCROLLPANE_Y_MARGIN = 65;
    //	20/07/2005: Kenneth Lai: case panel margin>>    
    
	private JScrollPane m_ScrollPaneDiagram;
	private JPanel m_PanelDiagramDrawing;
	private DropTarget m_DropTarget;

//	private JButton m_CaseInformationButton;
	private JButton m_CaseInformationButton;//<<25/07/2005: Kenneth Lai: Add for JHelp>>
	private CaseInformationLayer m_CaseInformationLayer;

	private Point m_Start;
	private boolean m_IsDragging;
	private ArrowComponent tempArrow;
	private JButton transparent;
//	<<16/06/2005: Mark Li: MultiSelect the components in case diagram
	//private JComponent m_ActiveComponent;
	private JComponent m_ActiveComponent[];
	private Rectangle m_recActiveComponent;
	private Vector<ArrowComponent> m_ArrowInActiveComponents = new Vector<ArrowComponent>();
	private boolean isFirstMutiSelect = false;
//	16/06/2005: Mark Li: MultiSelect the components in case diagram>>
	private String m_CaseID;

	private boolean m_HelpState = false;
	
	private JInternalFrame m_Form;
	private CaseDiagramPanel m_CurrentPanel = this;
	private CaseWindow m_Parent;
	
	private int m_DMEngineType; //<<Frank Xu, 09/12/2004 flag to differentiate the type of data mining engines., Frank Xu, 09/12/2004>>.	

	private static Hashtable<String, CaseDiagramPanel> m_CaseDiagrams = new Hashtable<String, CaseDiagramPanel>(); 
	
	private IMessageDialog m_MessageDialog;
	private ISystemMessageHandler m_SystemMessageHandler;
	private ICaseHandler m_CaseHandler;
	private JMenuItem printItem;
	private JMenuItem exportWorkflowDiagramItem;
	
	private LinkedList<String> deletedNode = new LinkedList<String>();
	private LinkedList<ArrowNodes> deletedArrow = new LinkedList<ArrowNodes>();
	
	/**
	 * Constructs a CaseDiagramPanel.
	 */
	private CaseDiagramPanel(CaseWindow a_CaseWindow, String a_CaseID) throws SysException{
		m_Parent = a_CaseWindow;
		m_CaseHandler = CaseHandler.getInstance();
		m_MessageDialog = m_CaseHandler.getMessageDialog();
		createCaseDiagramPanel();
		m_DropTarget = new DropTarget(m_PanelDiagramDrawing, this);
		m_PanelDiagramDrawing.addMouseListener(this);
		m_PanelDiagramDrawing.addMouseMotionListener(this);
		DefaultKeyboardFocusManager
			.getCurrentKeyboardFocusManager()
			.addKeyEventDispatcher(this);
		m_Start = new Point(0, 0);
		m_IsDragging = false;
		setCaseID(a_CaseID);
		m_SystemMessageHandler = m_CaseHandler.getSystemMessageHandler(m_CaseID);
//		String str;
//		String aa=new String(str.getBytes("")),"GBK");
	}

	@SuppressWarnings("unchecked")
	public static CaseDiagramPanel createInstance(CaseWindow a_CaseWindow, String a_CaseID) throws SysException
	{
		CaseDiagramPanel newCaseDiagramPanel = new CaseDiagramPanel(a_CaseWindow, a_CaseID); 
		m_CaseDiagrams.put(a_CaseID, newCaseDiagramPanel);
		return newCaseDiagramPanel;
	}
	
	public static CaseDiagramPanel getCaseDiagramPanel(String a_CaseID)
	{
		return m_CaseDiagrams.get(a_CaseID);
	}
	
	/** update the case id of the case diagram
	 * 
	 * @param a_OldCaseID Old case id
	 * @param a_NewCaseID New case id
	 * @return
	 * @throws SysException
	 */ 
	@SuppressWarnings("unchecked")
	private static void updateCaseID(String a_OldCaseID, String a_NewCaseID) throws SysException
	{
		// Throw system exeception if it trying to set a null case id
		if (a_NewCaseID == null)
		{
			throw new SysException("Invalid new case ID during saving");
		}
		
		// Throw system exeception if the selected case id is null or not exists
		if (a_OldCaseID == null || !m_CaseDiagrams.containsKey(a_OldCaseID))
		{
			throw new SysException("Invalid case to save [" + a_OldCaseID + "]");
		}
		
		if (!a_NewCaseID.equals(a_OldCaseID))
		{
			// Retrieve the case
			CaseDiagramPanel caseToBeUpdate = m_CaseDiagrams.get(a_OldCaseID);
			
			// Remove it from store
			m_CaseDiagrams.remove(a_OldCaseID);
			
			m_CaseDiagrams.put(a_NewCaseID, caseToBeUpdate);
		}
	}

	/**
	 * Set ID of Case that its diagram is showing in this CaseDiagramPanel.
	 * @param a_CaseID ID to be set.
	 */
	public void setCaseID(String a_NewCaseID) throws SysException 
	{
		// Throw system exeception if it trying to set a null case id
		if (a_NewCaseID == null)
		{
			throw new SysException("Invalid new case ID during saving");
		}
		
		if (m_CaseID != null && !a_NewCaseID.equals(m_CaseID))
		{
			CaseDiagramPanel.updateCaseID(m_CaseID, a_NewCaseID);
		}
		
		m_CaseID = a_NewCaseID;
		
		// update all the case id of the operator components
		Component[] comp = m_PanelDiagramDrawing.getComponents();
		for (int i=0;i<comp.length;i++)
		{
			// only update operator components
			if (comp[i] instanceof Operator) 
			{
				Operator aOperator = (Operator) comp[i];
				aOperator.setCaseID(m_CaseID);
			}
		}
			
		//<<21/02/2005 Mark Li: Add Case Name		
//		if (!m_Parent.getIsNew())
//			m_CaseInformationLayer.setCaseName(m_CaseID);
		//21/02/2005 Mark Li: Add Case Name>>
	}

	/**
	 * Gets ID of Case that is currently showing on the CaseDiagramPanel.
	 * @return ID of the Case.
	 */
	public String getCaseID() {
		return m_CaseID;
	}

	/**
	 * Gets the OperatorProperty internal window.
	 * @return JInternalFrame the OperatorProperty internal window.
	 */
	public JInternalFrame getInternalForm() {
		return m_Form;
	}

	/**
	 * Sets the OperatorProperty internal window.
	 * @param a_Frame the OperatorProperty internal window to be set.
	 */
	public void setInternalForm(JInternalFrame a_Frame) {
		m_Form = a_Frame;
	}

	/**
	 * Gets DropTarget of CaseDiagramPanel.
	 * @return DropTarget
	 */
	public DropTarget getPanelDropTarget() {
		return m_DropTarget;
	}

	/**
	 * Gets the diagram drawing panel of the CaseDiagramPanel.
	 * @return JPanel
	 */
	public JPanel getPanelDiagramDrawing() {
		return m_PanelDiagramDrawing;
	}

	// <<22/07/2005 Kenneth Lai: Add for JHelp
	private boolean isHelpMode() {
	    return m_HelpState;
	}
	
	private void setHelpState(boolean a_State) {
	    m_HelpState = a_State;
	}
	// 22/07/2005 Kenneth Lai: Add for JHelp>>
	
	/**
	 * Sets the CaseWindow that contains this CaseDiagramPanel.
	 * @param a_Window the CaseWindow.
	 */
	public void setCaseWindow(CaseWindow a_Window) {
		m_Parent = a_Window;
		m_CaseInformationLayer.setCaseWindow(a_Window);
	}

	/**
	 * Gets the CaseWindow that contains this CaseDiagramPanel.
	 * @return CaseWindow
	 */
	public CaseWindow getCaseWindow() {
		return m_Parent;
	}

	/**
	 * Gets an specific OperatorNode that is contained in the diagram drawing panel.
	 * @param a_NodeID ID of the node represented by the OperatorNode.
	 * @return Operator the OperatorNode.
	 */
	public Operator getOperator(String a_NodeID) {
		Operator operator = null;
		Component[] comp = m_PanelDiagramDrawing.getComponents();
		for (int i = 0; comp != null && i < comp.length; i++) {
			if (comp[i] instanceof Operator
				&& ((Operator) comp[i]).getNodeID().equals(a_NodeID)) {

⌨️ 快捷键说明

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