📄 dbscanclusteringoperatorproperty.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 edu.xmu.operation.property;
import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import javax.swing.BorderFactory;
import javax.swing.DefaultComboBoxModel;
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.KMeansOperator;
import eti.bi.exception.SysException;
import eti.bi.util.ValueValidator;
import eti.bi.common.Locale.Resource;
/**
* Current clustering algorithm (k-means) only supports numeric attributes. For categorical
* or attributes of mixed types, the clustering results can be meaningless. More functions
* can be identified and added later.
* TWang. June 21, 2005
*/
public class DBScanClusteringOperatorProperty 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 JTextField m_NumIterations = new JTextField();
private int m_DistanceStartIndex = Distance.TYPE_EUCLIDEAN;
// private String[] m_DistanceTypeOptions = {"Euclidean", "Squared Euclidean", "Chebychev", "City Block", "Minkovsi", "Simple Matching", "Jaccard", "Tanimoto"/*, "Binary Similarity"*/};
private String[] m_DistanceTypeOptions = {"Euclidean", "Squared Euclidean", "Chebychev", "City Block" };
//Current algorithm only supports numerical attributes. TWang. June, 2005.
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 int m_MeasureStartIndex = Distance.MEASURE_TYPE_DISTANCE;
private String[] m_MeasureOptions = {Resource.srcStr("Distance"), Resource.srcStr("Similarity")};
private JComboBox m_ComboMeasure = new JComboBox(m_MeasureOptions);
private JPanel propertyPanel;
private JLabel numOfClusters;
private JLabel numOfIterations;
private JLabel distType;
private JLabel compareFn;
private JLabel measureType;
@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 DBScanClusteringOperatorProperty(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 = new JPanel();
JPanel buttonPanel = new JPanel();
propertyPanel.setBorder(BorderFactory.createCompoundBorder(
BorderFactory.createTitledBorder(Resource.srcStr("ClusteringAlgorithm")),
BorderFactory.createEmptyBorder(2,4,0,6)));
numOfClusters = new JLabel("Epslion");
numOfIterations = new JLabel("MinPoints");
distType = new JLabel(Resource.srcStr("distType"));
compareFn = new JLabel(Resource.srcStr("compareFn"));
measureType = new JLabel(Resource.srcStr("measureType"));
int leftMargin = 4;
numOfClusters.setBorder(BorderFactory.createEmptyBorder(0,leftMargin,0,0));
numOfIterations.setBorder(BorderFactory.createEmptyBorder(0,leftMargin,0,0));
distType.setBorder(BorderFactory.createEmptyBorder(0,leftMargin,0,0));
compareFn.setBorder(BorderFactory.createEmptyBorder(0,leftMargin,0,0));
measureType.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 iterationPanel = new JPanel(new GridLayout(1,2,50,0));
iterationPanel.add(m_NumIterations);
iterationPanel.add(new JPanel());
propertyPanel.add(numOfIterations);
propertyPanel.add(iterationPanel);
propertyPanel.add(distType);
propertyPanel.add(m_ComboDistanceType);
propertyPanel.add(compareFn);
propertyPanel.add(m_ComboCompareFn);
propertyPanel.add(measureType);
propertyPanel.add(m_ComboMeasure);
// propertyPanel.add(m_CheckBoxNormalize);
//This function is not implemented. TWang.
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, 260);
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("KMessage");
}
else if (!ValueValidator.isInteger(num)){
message = Resource.srcStr("KRangeMessage");
}
else if( !ValueValidator.largerThan(num, 0, false)) {
message = Resource.srcStr("KMessage");
}
if(message != null){
m_NumClusters.requestFocus();
m_NumClusters.selectAll();
m_MessageDialog.showWarning(message, Resource.srcStr("InvalidValueMessage"));
return false;
}
num = m_NumIterations.getText().trim();
if (!ValueValidator.isNumber(num)){
message = Resource.srcStr("MaxMessage");
}
else if (!ValueValidator.isInteger(num)){
message = Resource.srcStr("MaxRangeMessage");
}
else if( !ValueValidator.largerThan(num, 0, false)) {
message = Resource.srcStr("MaxMessage");
}
if (message != null) {
m_NumIterations.requestFocus();
m_NumIterations.selectAll();
m_MessageDialog.showWarning(message, Resource.srcStr("InvalidValueMessage"));
return false;
}
return true;
}
/**
* Set values input in this ClusteringOperatorProperty to the Operator Node.
*/
private boolean setContent(){
if (m_Node==null)
return false;
m_Node.setParameterValue("Eps Number", m_NumClusters.getText().trim());
m_Node.setParameterValue("Minpts Number", m_NumIterations.getText().trim());
m_Node.setParameterValue(KMeansOperator.DISTANCE_TYPE, String.valueOf(m_ComboDistanceType.getSelectedIndex()+m_DistanceStartIndex));
m_Node.setParameterValue(KMeansOperator.COMPARE_FUNCTION, String.valueOf(m_ComboCompareFn.getSelectedIndex()+m_CompareFnStartIndex));
m_Node.setParameterValue(KMeansOperator.MEASURE, String.valueOf(m_ComboMeasure.getSelectedIndex()+m_MeasureStartIndex));
m_Node.setParameterValue(KMeansOperator.NORMALIZE, String.valueOf(false));// m_CheckBoxNormalize.isSelected()));
//Operator op = m_ParentPanel.getOperator(m_NodeID);
//((ClusteringOperator) m_Operator).clearResult();
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("Eps Number");
if (num==null)
num = KMeansOperator.DEFAULT_CLUSTER_NUMBER;
m_NumClusters.setText(num);
String itr = (String) m_Node.getParameterValue("Minpts Number");
if (itr==null)
itr = KMeansOperator.DEFAULT_ITERATION_NUMBER;
m_NumIterations.setText(itr);
String type = (String) m_Node.getParameterValue(KMeansOperator.DISTANCE_TYPE);
if (type==null)
type = String.valueOf(m_DistanceStartIndex);
m_ComboDistanceType.setSelectedIndex(Integer.parseInt(type)-m_DistanceStartIndex);
String fn = (String) m_Node.getParameterValue(KMeansOperator.COMPARE_FUNCTION);
if (fn==null)
fn = String.valueOf(m_CompareFnStartIndex);
m_ComboCompareFn.setSelectedIndex(Integer.parseInt(fn)-m_CompareFnStartIndex);
String measure = (String) m_Node.getParameterValue(KMeansOperator.MEASURE);
if (measure==null)
measure = String.valueOf(m_MeasureStartIndex);
m_ComboMeasure.setSelectedIndex(Integer.parseInt(measure)-m_MeasureStartIndex);
String normalize = (String) m_Node.getParameterValue(KMeansOperator.NORMALIZE);
if (normalize==null)
normalize = KMeansOperator.DEFAULT_NORMALIZE;
@SuppressWarnings("unused") boolean norm = false;
if (normalize.equals(String.valueOf(true)))
norm = true;
// m_CheckBoxNormalize.setSelected(norm);
}
public void resetLocale() {
m_MeasureOptions[0] = Resource.srcStr("Distance");
m_MeasureOptions[1] = Resource.srcStr("Similarity");
DefaultComboBoxModel model = ((DefaultComboBoxModel)m_ComboMeasure.getModel());
model.removeAllElements();
model.addElement(m_MeasureOptions[0]);
model.addElement(m_MeasureOptions[1]);
m_ComboMeasure.setModel(model);
m_CheckBoxNormalize.setText(Resource.srcStr("m_CheckBoxNormalize"));
((TitledBorder)((CompoundBorder)propertyPanel.getBorder()).getOutsideBorder()).setTitle(Resource.srcStr("ClusteringAlgorithm"));
//label
numOfClusters.setText(Resource.srcStr("numOfClusters"));
numOfIterations.setText(Resource.srcStr("numOfIterations"));
distType.setText(Resource.srcStr("distType"));
compareFn.setText(Resource.srcStr("compareFn"));
measureType.setText(Resource.srcStr("measureType"));
//title
String title = getTitle();
int index = title.indexOf('[');
title = Resource.srcStr("Clustering")+title.substring(index);
setTitle(title);
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 + -