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

📄 curvedrawpanel.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.
 */

/*
 * Created on 2005-2-1
 */
package eti.bi.alphaminer.patch.standard.operation.result.view;

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.Shape;
import java.awt.geom.AffineTransform;
import java.awt.geom.CubicCurve2D;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import javax.swing.BorderFactory;
import javax.swing.JPanel;

import eti.bi.alphaminer.patch.standard.operation.property.PredictionAssessmentOperatorProperty;


public class CurveDrawPanel extends JPanel {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private static Graphics2D g2; 
	private String chartTitle; 
	private String chartType;  
	
	// relative value calculated to windows size
	private int origX; 
	private int origY;
	private int maxY; 
	private int maxX;  
	private int legendOrigX;
	private int legendOrigY;
	private int m_LiftChartJumpValue;
	private int spaceAxisX;  
	private int spaceAxisY; 
	private int axisScale;  
	private int legendSpace;
	
	// candidate colors and line gaps
	private Color[] curveColor = { Color.BLUE, Color.MAGENTA,
			Color.GREEN, new Color(1, 50, 50), Color.CYAN,  Color.ORANGE};
	private float lineGap[][] = { { 2.0F }, { 4.0F }, { 6.0F }, { 8.0f },
			{ 10.0F } };
	
	private int circleRadius = 4; // for point drawing
	private int circleRadiusDemo = 6; // for point legend
	private float curveLineWidth = 4.0f; //for curve line width
	private int baseLineWidth = 4; // for base line width
	
	private boolean lineShowEnable = true; //default show line is enable
	private String labelX;
	private String labelY;
	private Map curveData = new HashMap();

	// NOT used, may be useful later.
	private final static int PHREATIC = 0;
	private final static int DELTA = 1;
	private final static int RECTANGLE = 2;
	private final static int CIRCLE = 3;
	private final static int STAR = 4;
	private int[] symbolType = { PHREATIC, DELTA, RECTANGLE, CIRCLE, STAR };
	private boolean symbolEnable = true; //default symbol enable
	private boolean lineFormatEnable = true; //default line format enable
	private static int symbolFreq = 4; //default symbol frequence is 4;
	/**
	 * Constructor to set the default value for the chart
	 * 
	 * @param width:
	 *            the width of the whole window
	 * @param height:
	 *            the height of the whole window
	 */
	public CurveDrawPanel(int width, int height) {
		this.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0)); 
		
		// the space between the axis and marker 
		spaceAxisX = (int) ((float) width  * 0.06f);
		spaceAxisY = (int) ((float) height * 0.03f);
		
		maxY = (int) ((float) height * 0.65f);
		maxX = maxY;
		axisScale = maxX / 105;
		
		origX = (int) ((float) width * 0.13f);
		origY = (int) ((float) height * 0.8f);
		// Move the cutline original x,y from right to bottom
 		legendOrigX = 10;
		legendOrigY = origY + 60; 
		legendSpace = 25;  
	}

	public void setChartTitle(String title) {
		chartTitle = title;
	}

	public String getChartTitle() {
		return chartTitle;
	}
	
	public void setChartType(String a_ChartType){
		chartType = a_ChartType;
	}

	/**
	 * Set X axis label name
	 * 
	 * @param label:
	 *            label name
	 */
	public void setLabelX(String label) {
		labelX = label;
	}

	/**
	 * return the X axis label name
	 * 
	 * @return
	 */
	public String getLabelX() {
		return labelX;
	}

	/**
	 * Set Y axis label name
	 * 
	 * @param label:
	 *            label name
	 */
	public void setLabelY(String label) {
		labelY = label;
	}

	/**
	 * return the Y axis label name
	 * 
	 * @return
	 */
	public String getLabelY() {
		return labelY;
	}

	/**
	 * Load the curve data Set for this panel
	 * 
	 * @param dataMap
	 */
	public void setData(Map dataMap) {
		curveData = dataMap;
	}

	public void setSymbolFrequency(int freq) {
		symbolFreq = freq;
	}

	public int getSymbolFrequency() {
		return symbolFreq;
	}

	public void setSymbolEnable(boolean enableFlag) {
		symbolEnable = enableFlag;
	}

	public boolean isSymbolEnable() {
		return symbolEnable;
	}

	public void setLineFormatEnable(boolean enableFlag) {
		lineFormatEnable = enableFlag;
	}

	public boolean isLineFormatEnable() {
		return lineFormatEnable;
	}

	public void setLineShowEnable(boolean enableFlag) {
		lineShowEnable = enableFlag;
	}

	public boolean isLineShowEnable() {
		return lineShowEnable;
	}

	/**
	 * Draw the input data through connect point to point with a line
	 * 
	 * @param displayDataSet:
	 *            Input data Set
	 */
	private void DataDisplay(Map displayDataSet) { 
		int tmpCounter = 0;
		Iterator keySet = displayDataSet.keySet().iterator();

		//Define the line format
		if (isLineFormatEnable() == true) {
			g2.setStroke(new BasicStroke(1.5f, BasicStroke.JOIN_MITER,
					BasicStroke.JOIN_MITER, 5.0f, lineGap[tmpCounter
							% lineGap.length], 0.0f));
		} else {
			g2.setStroke(new BasicStroke(1.5f, BasicStroke.JOIN_MITER,
					BasicStroke.JOIN_MITER, 5.0f));
		}
		while (keySet.hasNext()) {
			String CurveName = (String) keySet.next();
			// should judge if the input map is of type double[][].
			double[][] dataSet = (double[][]) displayDataSet.get(CurveName);

			//Draw one curve according to the input data Set
			drawCurve(dataSet, symbolType[tmpCounter % symbolType.length],
					curveColor[tmpCounter % curveColor.length]);
			//set the cutline to the corresponding line
			drawLegend("  " + CurveName, legendOrigX + 30, legendOrigY + 8 + legendSpace * tmpCounter,
					symbolType[tmpCounter % symbolType.length]);
			tmpCounter++;

		}
	}

	/**
	 * paintComponent(Graphics g) use for draw this panel. Here the main
	 * function is to draw the frame for curve.
	 */
	public void paintComponent(Graphics g) {

		super.paintComponent(g);
		g2 = (Graphics2D) g;
		float dash[] = { 5.0f };

		g2.setPaint(Color.BLACK.brighter().brighter());
		//set x, y axis
		g2.drawRect(origX, origY - maxY, maxX, maxY);
		//if (origX+maxX > windowsWidth) windowsWidth = origX+maxX;
		//if (origY > windowsHeight) windowsHeight = origY;
		

⌨️ 快捷键说明

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