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

📄 fwkmeansclusteringoperatorproperty.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 2004/9/7
 * 
 * $Author$
 * $Date$
 * $Revision$
 *
 */
package eti.bi.alphaminer.patch.standard.operation.property;


import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.border.CompoundBorder;
import javax.swing.border.TitledBorder;


import com.prudsys.pdm.Models.Clustering.Distance;

import eti.bi.alphaminer.core.handler.ICaseHandler;
import eti.bi.alphaminer.operation.operator.INodeInfo;
import eti.bi.alphaminer.operation.property.OperatorProperty;
import eti.bi.alphaminer.patch.standard.operation.operator.FWKMeansClusteringOperator;
import eti.bi.exception.SysException;
import eti.bi.util.ValueValidator;
import eti.bi.common.Locale.Resource;
/**
 * Xiaoguang Xu.  2006/04/21 
 */
public class FWKMeansClusteringOperatorProperty extends OperatorProperty {

	/**
	 * 
	 */
	private static final long serialVersionUID = -5737108576656740502L;
	/* UI controls */
	private JButton m_ButtonReset = new JButton();
	private JButton m_ButtonSave = new JButton();
	private JButton m_ButtonCancel = new JButton();
	
	private JTextField m_NumClusters = new JTextField();
	private int m_DistanceStartIndex = Distance.TYPE_EUCLIDEAN;
	private String []m_WeightOptions={"Yes","No"};
	private JTextField m_Beta=new JTextField();
	private JTextField m_Alpha=new JTextField();

	private String[] m_DistanceTypeOptions = {"Euclidean", "Squared Euclidean"};
	private JComboBox m_ComboIsWeight=new JComboBox(m_WeightOptions);
	private JComboBox m_ComboDistanceType = new JComboBox(m_DistanceTypeOptions);

	private int m_CompareFnStartIndex = Distance.COMPARISON_FUNCTION_ABS_DIFF;
	private String[] m_CompareFnOptions = {"Absolute difference", /*"Gaussian Similarity",*/ /*"Delta", "Equal"*/ /*, "Table"*/};	
	private JComboBox m_ComboCompareFn = new JComboBox(m_CompareFnOptions);

	private JPanel propertyPanel = new JPanel();
	private JPanel buttonPanel = new JPanel();
	private JLabel numOfClusters = new JLabel(Resource.srcStr("numOfClusters"));
	private JLabel isWeight = new JLabel(Resource.srcStr("isWeight"));
	private JLabel beta = new JLabel(Resource.srcStr("setBeta"));
	private JLabel alpha=new JLabel(Resource.srcStr("setAlpha"));
	private JLabel distType = new JLabel(Resource.srcStr("distType"));
	private JLabel compareFn = new JLabel(Resource.srcStr("compareFn"));	
	
	@SuppressWarnings("unused")
	private JCheckBox m_CheckBoxNormalize = new JCheckBox(Resource.srcStr("m_CheckBoxNormalize"));		

	/**
	 * Constructs an ClusteringOperatorProperty object.
	 * @param a_CaseID ID of the Case containing the Operator Node to be set by this
	 * ClusteringOperatorProperty.
	 * @param a_NodeID ID of the Operator node to be set by this ClusteringOperatorProperty.
	 * @throws SysException
	 */
	public FWKMeansClusteringOperatorProperty(String a_CaseID, String a_NodeID, String a_Name,  INodeInfo a_NodeInfo, ICaseHandler a_CaseHandler) throws SysException
	{
		super(a_CaseID, a_NodeID, Resource.srcStr("Clustering")+" ["+a_NodeID+"]",  a_NodeInfo, a_CaseHandler);		
		createClusteringOperatorProperty();
	}
	
	/**
	 * Create the UI for this ClusteringOperatorProperty
	 */
	private void createClusteringOperatorProperty()
	{
		
		
		propertyPanel.setBorder(BorderFactory.createCompoundBorder(
									BorderFactory.createTitledBorder(Resource.srcStr("ClusteringAlgorithm")),
									BorderFactory.createEmptyBorder(2,4,0,6)));
		
	
		int leftMargin = 4;
		numOfClusters.setBorder(BorderFactory.createEmptyBorder(0,leftMargin,0,0));
		isWeight.setBorder(BorderFactory.createEmptyBorder(0,leftMargin,0,0));
		beta.setBorder(BorderFactory.createEmptyBorder(0,leftMargin,0,0));
		alpha.setBorder(BorderFactory.createEmptyBorder(0,leftMargin,0,0));
		distType.setBorder(BorderFactory.createEmptyBorder(0,leftMargin,0,0));
		compareFn.setBorder(BorderFactory.createEmptyBorder(0,leftMargin,0,0));
	
		
		propertyPanel.setLayout(new GridLayout(6, 2, 0, 5));
		JPanel clusterPanel = new JPanel(new GridLayout(1,2,50,0));
		clusterPanel.add(m_NumClusters);
		clusterPanel.add(new JPanel());
		propertyPanel.add(numOfClusters);
		propertyPanel.add(clusterPanel);
		
		JPanel betaPanel = new JPanel(new GridLayout(1,2,50,0));
		betaPanel.add(m_Beta);
		betaPanel.add(new JPanel());
		propertyPanel.add(beta);
		propertyPanel.add(betaPanel);
		
		JPanel alphaPanel = new JPanel(new GridLayout(1,2,50,0));
		alphaPanel.add(m_Alpha);
		alphaPanel.add(new JPanel());
		propertyPanel.add(alpha);
		propertyPanel.add(alphaPanel);
		
		propertyPanel.add(isWeight);
		propertyPanel.add(m_ComboIsWeight);
		propertyPanel.add(distType);
		propertyPanel.add(m_ComboDistanceType);
		propertyPanel.add(compareFn);
		propertyPanel.add(m_ComboCompareFn);

						   
		m_ButtonReset.setText(Resource.srcStr("m_ButtonReset"));
		m_ButtonSave.setText(Resource.srcStr("m_ButtonApply"));
		m_ButtonCancel.setSelected(false);
		m_ButtonCancel.setText(Resource.srcStr("m_ButtonClose"));
		buttonPanel.add(m_ButtonSave);
		buttonPanel.add(m_ButtonReset);
		buttonPanel.add(m_ButtonCancel);
		
		m_ButtonReset.addActionListener(this);
		m_ButtonSave.addActionListener(this);
		m_ButtonCancel.addActionListener(this);
		
		this.getContentPane().add(propertyPanel, BorderLayout.CENTER);
		this.getContentPane().add(buttonPanel, BorderLayout.SOUTH);
		this.setSize(300, 300);
		
		getContent();
	}

	/**
	 * @see java.awt.event.ActionListener#actionPerformed(ActionEvent)
	 */
	public void actionPerformed(ActionEvent e) {
		
		if (e.getSource() == m_ButtonSave) {
			if (applyContent())
			{
				m_ParameterChanged = true;
			}				
		} else if (e.getSource() == m_ButtonReset) {
			getContent();
		} else if (e.getSource() == m_ButtonCancel)
			close();
	}
	
	/**
	 * Validate values entered in the ClusteringOperatorProperty UI before setting
	 * them into the the Operator Node.
	 */
	private boolean applyContent(){
		if (validateProperty())
		{
			return setContent();
		}else
		{
			return false;
		}
	}
	
	/**
	 * Validate input values.
	 * @return true if all values are valid; false otherwise.
	 */
	private boolean validateProperty(){
		String message = null;
		
		String num = m_NumClusters.getText().trim();
		if (!ValueValidator.isNumber(num)){
			message = Resource.srcStr("kNotNumberMessage");		 
		} 
		else if (!ValueValidator.isInteger(num)){
			message = Resource.srcStr("kNotIntegerMessage");
		}
		else if( !ValueValidator.largerThan(num, 0, false)) {
			message = Resource.srcStr("notLargerZeroMessage");
		}		
		if(message != null){ 
			m_NumClusters.requestFocus();
			m_NumClusters.selectAll();		
			m_MessageDialog.showWarning(message, Resource.srcStr("InvalidValueMessage"));
			return false;
		}
		
		num = m_Beta.getText().trim();
		if(num.charAt(0)=='-')
		{
		  if (!ValueValidator.isNumber(num.substring(1))){
			message = Resource.srcStr("notNumberMessage");		 
		  } 
		}
		else if (!ValueValidator.isInteger(num)){
			message = Resource.srcStr("notIntegerMessage");
		}
		else if(Integer.parseInt(num)==0||Integer.parseInt(num)==1) {
			message = Resource.srcStr("notZeroOneMessage");
		}		
		if (message != null) {	
			m_Beta.requestFocus();
			m_Beta.selectAll();			
			m_MessageDialog.showWarning(message, Resource.srcStr("InvalidValueMessage"));
			return false;
		}

		return true;
	}
	
	/**
	 * Set values input in this FWKMeansClusteringOperatorProperty to the Operator Node.
	 */
	private boolean setContent(){			
		if (m_Node==null)
			return false;
			
		m_Node.setParameterValue(FWKMeansClusteringOperator.CLUSTER_NUMBER, m_NumClusters.getText().trim());
		
		m_Node.setParameterValue(FWKMeansClusteringOperator.BETA, m_Beta.getText().trim());
		
		m_Node.setParameterValue(FWKMeansClusteringOperator.ALPHA, m_Alpha.getText().trim());
		
		if(m_ComboIsWeight.getSelectedIndex()==0)
			m_Node.setParameterValue(FWKMeansClusteringOperator.IS_WEIGHT,String.valueOf(true) );
		else
			m_Node.setParameterValue(FWKMeansClusteringOperator.IS_WEIGHT,String.valueOf(false) );
		
		m_Node.setParameterValue(FWKMeansClusteringOperator.DISTANCE_TYPE, String.valueOf(m_ComboDistanceType.getSelectedIndex()+m_DistanceStartIndex));
		
		m_Node.setParameterValue(FWKMeansClusteringOperator.COMPARE_FUNCTION, String.valueOf(m_ComboCompareFn.getSelectedIndex()+m_CompareFnStartIndex));

		clearOperatorTempResult();
		setPropertiesModified();
		return true;
	}
	
	/**
	 * Retrieve information from Operator Node and display those values in this ClusteringOperatorProperty.
	 */
	private void getContent() {
		if (m_Node==null)
			return;
		
		String num = (String) m_Node.getParameterValue(FWKMeansClusteringOperator.CLUSTER_NUMBER);
		if (num==null)
			num = FWKMeansClusteringOperator.DEFAULT_CLUSTER_NUMBER;
		m_NumClusters.setText(num);
		
		String beta = (String) m_Node.getParameterValue(FWKMeansClusteringOperator.BETA);
		if (beta==null)
			beta = FWKMeansClusteringOperator.DEFAULT_BETA;
		m_Beta.setText(beta);
		
		String alpha = (String) m_Node.getParameterValue(FWKMeansClusteringOperator.ALPHA);
		if (alpha==null)
			alpha = FWKMeansClusteringOperator.DEFAULT_ALPHA;
		m_Alpha.setText(alpha);
		
		
		String isWeight=(String) m_Node.getParameterValue(FWKMeansClusteringOperator.IS_WEIGHT);
		if(isWeight==null)
			isWeight=FWKMeansClusteringOperator.DEFAULT_IS_WEIGHT;
		if(isWeight.equals("true"))
		  m_ComboIsWeight.setSelectedIndex(0);
		else
		  m_ComboIsWeight.setSelectedIndex(1);
		
		String type = (String) m_Node.getParameterValue(FWKMeansClusteringOperator.DISTANCE_TYPE);
		if (type==null)
			type = String.valueOf(m_DistanceStartIndex);
		m_ComboDistanceType.setSelectedIndex(Integer.parseInt(type)-m_DistanceStartIndex);
			
		String fn = (String) m_Node.getParameterValue(FWKMeansClusteringOperator.COMPARE_FUNCTION);
		if (fn==null)
			fn = String.valueOf(m_CompareFnStartIndex);
		m_ComboCompareFn.setSelectedIndex(Integer.parseInt(fn)-m_CompareFnStartIndex);		

	}
	
	public void resetLocale() {
		
		//title
		String title = getTitle();
		int index = title.indexOf('[');
		title = Resource.srcStr("Clustering")+title.substring(index);
		setTitle(title);
		
		m_CheckBoxNormalize.setText(Resource.srcStr("m_CheckBoxNormalize"));
		
		((TitledBorder)(((CompoundBorder)propertyPanel.getBorder()).getOutsideBorder())).setTitle(Resource.srcStr("ClusteringAlgorithm"));
		
		numOfClusters.setText(Resource.srcStr("numOfClusters"));
		isWeight.setText(Resource.srcStr("isWeight"));
		beta.setText(Resource.srcStr("setBeta"));
		alpha.setText(Resource.srcStr("setAlpha"));
		distType.setText(Resource.srcStr("distType"));
		compareFn.setText(Resource.srcStr("compareFn"));
		
		
		m_ButtonReset.setText(Resource.srcStr("m_ButtonReset"));
		m_ButtonSave.setText(Resource.srcStr("m_ButtonApply"));
		m_ButtonCancel.setText(Resource.srcStr("m_ButtonClose"));
	}
}

⌨️ 快捷键说明

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