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

📄 brecasediagrampanel.java

📁 一个数据挖掘软件ALPHAMINERR的整个过程的JAVA版源代码
💻 JAVA
字号:
/*
 *    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.
 */

/*
 * Created on 2006/09/01
 *
 * @Author: Xiaojun Chen
 * $Revision$ 1.0
 *
 */
package eti.bi.alphaminer.tools.ExportCase;

import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Rectangle;
import java.util.Hashtable;
import java.util.Vector;
import javax.swing.JComponent;
import javax.swing.JPanel;
import eti.bi.alphaminer.core.Node.NodeLoader;
import eti.bi.alphaminer.core.handler.CaseHandler;
import eti.bi.alphaminer.core.observer.Observer;
import eti.bi.alphaminer.operation.operator.Operator;
import eti.bi.alphaminer.ui.ApplicationWindow;
import eti.bi.alphaminer.vo.BICase;
import eti.bi.alphaminer.vo.Node;
import eti.bi.alphaminer.vo.NodeConnection;
import eti.bi.alphaminer.vo.OperatorNode;
import eti.bi.exception.BaseException;

public class BreCaseDiagramPanel extends JPanel implements Observer{

	/**
	 * 
	 */
	private static final long serialVersionUID = 6375713492762764993L;
	
	private String caseID;
	private Dimension dimension;
	private Rectangle DiagramRectangle;
	
	BreCaseDiagramPanel(String aCaseID) throws Exception {
		caseID = aCaseID;
		setLayout(null);
		setBackground(Color.white);
		BICase drawCase = null;
		try {
			drawCase = CaseHandler.getInstance().getCase(aCaseID, false);
		} catch (BaseException be) {
			System.err.println(be.getMessage());
		}
		if (drawCase == null)
			return;
		Node[] nodes = drawCase.getOperatorNodeListArray();
		if (nodes == null) {
			setPreferredSize(new Dimension());
			return;
		}
		Hashtable<String, JPanel> processedNode = new Hashtable<String, JPanel>();
		PlainOperator operator = null;
		
		for (int i = 0; i < nodes.length; i++) {
			try{
				operator = new PlainOperator(nodes[i],NodeLoader.getNodeInfo(((OperatorNode)nodes[i]).getOperatorDefinitionID()));
				add(operator);
				processedNode.put(nodes[i].getNodeID(), operator);
			}
			catch(Exception e) {
				e.printStackTrace();
			}
		}
		
		refresh();
		drawArrow(drawCase, processedNode);
		dimension = get_Dimension();
		setSize(dimension);
		setPreferredSize(dimension);
	}
	
	private void reCreate() throws Exception {
		removeAll();
		BICase drawCase = null;
		try {
			drawCase = CaseHandler.getInstance().getCase(caseID, false);
		} catch (BaseException be) {
			System.err.println(be.getMessage());
		}
		if (drawCase == null)
			return;
		Node[] nodes = drawCase.getOperatorNodeListArray();
		if (nodes == null) {
			setPreferredSize(new Dimension());
			return;
		}
		Hashtable<String, JPanel> processedNode = new Hashtable<String, JPanel>();
		PlainOperator operator = null;
		for (int i = 0; i < nodes.length; i++) {
			operator = new PlainOperator(nodes[i],NodeLoader.getNodeInfo(((OperatorNode)nodes[i]).getOperatorDefinitionID()));
			add(operator);
			processedNode.put(nodes[i].getNodeID(), operator);
		}
		refresh();
		drawArrow(drawCase, processedNode);
		dimension = get_Dimension();
		setSize(dimension);
		setPreferredSize(dimension);
	}
	
	private Dimension get_Dimension() {
		Component[] comp = getComponents();
		if (comp == null || comp.length == 1) {
			return new Dimension();
		}
		int width = 0;
		int height = 0;
		
		for (int i = 0; i < comp.length; i++) {
			if(comp[i] instanceof PlainOperator) {
				Component operator = comp[i];
				if (operator.getX() + operator.getWidth() > width) {
					width = operator.getX() + operator.getWidth();
				}
				if (operator.getY() + operator.getHeight() > height) {
					height = operator.getY() + operator.getHeight();
				}
			}
		}
		return new Dimension(width, height);
	}
	
	private void drawArrow(BICase a_Case, Hashtable<String, JPanel> a_Hashtable) {
		Vector connections = a_Case.getProcess().getConnectionList();
		NodeConnection con = null;
		JComponent parent = null;
		JComponent child = null;
		Arrow arrow = null;
		for (int i = 0; i < connections.size(); i++) {
			con = (NodeConnection) connections.elementAt(i);
			parent = a_Hashtable.get(con.getHeadNodeID());
			child = a_Hashtable.get(con.getTailNodeID());
			if (parent!=null && child!=null){
				arrow = new Arrow(parent, child);
				add(arrow);
			}
		}
	}
	
	private void refresh() {
		Component[] comp = getComponents();
		PlainOperator operator = null;
		int startX = -1;
		int startY = -1;
		int x = 0;
		int y = 0;
		double unitX = Operator.OPERATOR_WIDTH * 1.1;
		double unitY = Operator.OPERATOR_HEIGHT * 1.1;

		for (int i = 0; comp != null && i < comp.length; i++) {
			if (comp[i] instanceof PlainOperator) {
				operator = (PlainOperator) comp[i];
				if (startX < 0 || operator.getX() < startX)
					startX = operator.getX();
				if (startY < 0 || operator.getY() < startY)
					startY = operator.getY();
			}
		}

		for (int i = 0; comp != null && i < comp.length; i++) {
			if (comp[i] instanceof PlainOperator) {
				operator = (PlainOperator) comp[i];
				x = (int) (((operator.getX() - startX) / unitX) + 0.5);
				y = (int) (((operator.getY() - startY) / unitY) + 0.5);
				operator.setLocation(
					(int) (startX + unitX * x),
					(int) (startY + unitY * y));
			}
		}
	}
	
	public String getCaseID() {
		return caseID;
	}
	
	public Rectangle getDiagramRectangle() {
		if(DiagramRectangle==null) {
			computeDiagramRectangle();
		}
		return DiagramRectangle;
	}

	private void computeDiagramRectangle() {
		Component[] comp = getComponents();
		PlainOperator operator = null;
		
		int startX = -1;
		int startY = -1;
		
		for(int i=0;i<comp.length;i++) {
			if(comp[i] instanceof PlainOperator) {
				operator = (PlainOperator) comp[i];
				if (startX < 0 || operator.getX() < startX)
					startX = operator.getX();
				if (startY < 0 || operator.getY() < startY)
					startY = operator.getY();
			}
		}
		
		startX -= dimension.getWidth()/20;
		if(startX<0) {
			startX = 0;
		}
		startY -= dimension.getHeight()/20;
		if(startY<0) {
			startY = 0;
		}
		
		DiagramRectangle = new Rectangle();
		DiagramRectangle.setBounds(startX,startY,(int)dimension.getWidth(),(int)dimension.getHeight());
	}

	public void sendNotify(String a_Message) {
		if(a_Message==null) {
			return;
		}
		if(a_Message.startsWith(ApplicationWindow.NOTIFY_SAVE_CASE)) {
			
			try{
				int index = a_Message.indexOf('|');
				String caseID = a_Message.substring(index+1);
				if(caseID.equals(this.caseID)) {
					updateDiagram();
				}
			}
			catch(Exception e) {
				e.printStackTrace();
			}
		}
	}

	public void dispose() {
		
	}

	private void updateDiagram() throws Exception {
		reCreate();
	}
	
	public void sendNotify(int a_Message) {
		// TODO Auto-generated method stub
		
	}

	public void sendNotify(int a_Message, Object a_Object) {
		// TODO Auto-generated method stub
		
	}
}

⌨️ 快捷键说明

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