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

📄 assessmentoperatorevaluationchartview.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 2005-1-27
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package eti.bi.alphaminer.patch.standard.operation.result.view;


import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import javax.swing.BorderFactory;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;


import com.prudsys.pdm.Core.MiningException;

import eti.bi.alphaminer.operation.result.ResultView;
import eti.bi.alphaminer.operation.result.export.JPEGImageExporter;
import eti.bi.alphaminer.patch.standard.operation.operator.EvaluationChartData;
import eti.bi.alphaminer.patch.standard.operation.operator.PredictionAssessmentOperator;
import eti.bi.alphaminer.patch.standard.operation.property.PredictionAssessmentOperatorProperty;
import eti.bi.alphaminer.vo.IOperatorNode;
import eti.bi.common.Locale.Resource;
import eti.bi.exception.AppException;
import eti.bi.exception.SysException;

/**
 * @author twang
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class AssessmentOperatorEvaluationChartView extends ResultView { 
		
		/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
		// Java Scroll Pane that contains the graph
		private JScrollPane m_ScrollPane;  
		private CurveDrawPanel m_CurveDrawPanel;
		private Color backColor = new Color(0.98f, 0.99f, 1f);
	 	
	    private ArrayList m_EvaluationChartDataLists;
	 		 	
	 	private final static int DEFAULT_PANEL_WIDTH = 600;
	 	
		/**
		 * Create a ScrollPane with a GridBagLayout to hold the visualization graph.
		 * 
		 * @param a_ClusteringModel
		 * @param a_Attributes
		 * @throws AppException
		 * @throws SysException
		 * @throws MiningException
		 * @throws InterruptedException
		 */
		@SuppressWarnings("unchecked")
		public AssessmentOperatorEvaluationChartView(ArrayList a_EvaluationDataLists, IOperatorNode a_OperatorNode) throws AppException {
			
			super(Resource.srcStr("GraphView"));   
			m_ViewType = ResultView.TYPE_GRAPH;			
			m_EvaluationChartDataLists = a_EvaluationDataLists;
			
			if(DEFAULT_PANEL_WIDTH >getPanelWidth(a_EvaluationDataLists))
			{
			    m_CurveDrawPanel = new CurveDrawPanel(getPanelWidth(a_EvaluationDataLists), 500);			    
			}else{
			    m_CurveDrawPanel = new CurveDrawPanel(DEFAULT_PANEL_WIDTH, 500);
			}
			
			
			Map dataMap = new HashMap();
			for (int i=0; i<m_EvaluationChartDataLists.size(); i++){
				Object object = m_EvaluationChartDataLists.get(i);
				if ( !(object instanceof EvaluationChartData) ) {
					throw new AppException("The input DataList is not of type EvaluationChartData");
				}
				EvaluationChartData eChartData = (EvaluationChartData) m_EvaluationChartDataLists.get(i); 
				double[][] chartData = eChartData.getM_ChartDataElements(); 
				dataMap.put( eChartData.getM_ModelName() + ", " + eChartData.getM_DataName(), chartData);
			} 
			
			// set parameters in curve draw panel
			m_CurveDrawPanel.setData(dataMap);
			String chartType = (String) a_OperatorNode.getParameterValue(PredictionAssessmentOperator.CHART_TYPE);
			m_CurveDrawPanel.setChartTitle(chartType);
			m_CurveDrawPanel.setChartType(chartType);
			String drawStyle = (String) a_OperatorNode.getParameterValue(PredictionAssessmentOperator.DRAW_STYLE);
			
			if (drawStyle.equalsIgnoreCase(PredictionAssessmentOperatorProperty.DRAW_STYLE_LINE)){
				m_CurveDrawPanel.setLineShowEnable(true);
			}else{
				m_CurveDrawPanel.setLineShowEnable(false);
			}
			
			// Set the X,Y axis labels
			if (chartType.equalsIgnoreCase(PredictionAssessmentOperatorProperty.CHART_TYPE_CUMULATIVE_GAIN)){
				m_CurveDrawPanel.setLabelY(Resource.srcStr("ASSESSMENT_GAIN_VALUE")); 
			}else{
				m_CurveDrawPanel.setLabelY(Resource.srcStr("ASSESSMENT_LIFT_VALUE")); 
			} 
			m_CurveDrawPanel.setLabelX(Resource.srcStr("ASSESSMENT_POPULATION"));
		
			m_CurveDrawPanel.setAutoscrolls(true);
			m_CurveDrawPanel.setBackground(backColor);
			//m_CurveDrawPanel.setPreferredSize(new Dimension(500,560));
			m_CurveDrawPanel.setPreferredSize(new Dimension(getPanelWidth(a_EvaluationDataLists),getPanelHeight(a_EvaluationDataLists)));

			m_ScrollPane = new JScrollPane(m_CurveDrawPanel);   
			
			this.setLayout(new BorderLayout());
			this.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0)); 
			this.add(m_ScrollPane, BorderLayout.CENTER);  
		 
	 	}  

		public void export() throws SysException, AppException
	 	{
			// Use user home directory 
			File directory = new File(System.getProperty("user.dir"));
			
			// Create and initialize file chooser for jpg
			JFileChooser chooser = new JFileChooser(directory);
			chooser.setDialogTitle(Resource.srcStr("GraphExport"));
			chooser.setFileFilter(JPEGImageExporter.FILTER);
			chooser.setSelectedFile(JPEGImageExporter.DEFAULT_FILE);
	
			// pop up the file chooser dialog and return the file value
			int returnVal = chooser.showSaveDialog(this);	  
			if (returnVal == JFileChooser.APPROVE_OPTION) 
			{
				File exportFile = chooser.getSelectedFile();	
				
				//<<tyleung 20/4/2005
				if (exportFile.exists()) {
					int option = JOptionPane
							.showConfirmDialog(
									(Component) this,
									"The file  \""
											+ exportFile.getName()
											+ "\""
											+ " already exists. Do you want to replace the existing file?",//						
									"AlphaMiner", JOptionPane.YES_NO_OPTION,
									JOptionPane.QUESTION_MESSAGE);
					if (option != JOptionPane.CANCEL_OPTION) {
						if (option == JOptionPane.YES_OPTION) {
						    JPEGImageExporter aExporter = new JPEGImageExporter(m_CurveDrawPanel, exportFile, true);
						    aExporter.export(); 
							
						}else{
							returnVal = chooser.showSaveDialog(this);
						}
					}
				}else {
 
					JPEGImageExporter aExporter = new JPEGImageExporter(m_CurveDrawPanel, exportFile, true);
				    aExporter.export(); 
				} 
			} 
			//tyleung 20/4/2005>>
	 	}
		//<<06/06/2005 Mark Li: Size of assessment graph could be determined automatically : Begin
		private int getPanelHeight(ArrayList a_EvaluationDataLists){
		    int aHeight = a_EvaluationDataLists.size();
		    return (450+30*aHeight);
		}
		private int getPanelWidth(ArrayList a_EvaluationDataLists){
		    int aSize = a_EvaluationDataLists.size();
		    int len = 0;
		    
		    for(int i = 0; i< aSize; i++){
		        if(len <((EvaluationChartData)a_EvaluationDataLists.get(i)).getM_DataName().length())
		            len = ((EvaluationChartData)a_EvaluationDataLists.get(i)).getM_DataName().length();
		    }
		    if(len >50) 
		    {
		        return DEFAULT_PANEL_WIDTH+ (len - 54)*9;
		    }
		    else return DEFAULT_PANEL_WIDTH;
		}
		//06/06/2005 Mark Li: Size of assessment graph could be determined automatically : End>>
}

⌨️ 快捷键说明

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