📄 cattransformationoperatorproperty.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/19
*
* 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.property;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.Vector;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.UIManager;
import javax.swing.border.Border;
import javax.swing.border.EmptyBorder;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.event.TableModelEvent;
import javax.swing.event.TableModelListener;
import javax.swing.table.DefaultTableModel;
import com.prudsys.pdm.Core.CategoricalAttribute;
import com.prudsys.pdm.Core.Category;
import com.prudsys.pdm.Core.MiningAttribute;
import com.prudsys.pdm.Core.MiningDataSpecification;
import com.prudsys.pdm.Core.MiningException;
import com.prudsys.pdm.Core.NumericAttribute;
import eti.bi.alphaminer.core.handler.ICaseHandler;
import eti.bi.alphaminer.operation.operator.INodeInfo;
import eti.bi.alphaminer.operation.operator.Operator;
import eti.bi.alphaminer.operation.property.OperatorProperty;
import eti.bi.alphaminer.patch.standard.operation.operator.CategoricalTransformationOperator;
import eti.bi.exception.SysException;
import eti.bi.util.ValueValidator;
import eti.bi.common.Locale.Resource;
/**
* @author jyung
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class CatTransformationOperatorProperty extends OperatorProperty implements
ChangeListener {
/**
*
*/
private static final long serialVersionUID = -9160688359263512987L;
public final static int INIT = -1;
public final static int PLEASE_SELECT = 0;
public final static int CATEG = 1;
public final static int NUMERIC = 2;
private final static Color DISABLED_COLOR = UIManager.getColor("TableHeader.background");
private final static Color ENABLED_COLOR = UIManager.getColor("TextArea.background");
private static String DEFAULT = Resource.srcStr("SelectItem");
private static String [] TARGET_TYPE = {
Resource.srcStr("Categorical"),
Resource.srcStr("Numeric")};
private static String [] CATEG_DATA_TYPE = {
Resource.srcStr("String")};
private static String [] NUM_DATA_TYPE = {
Resource.srcStr("Double")};
private static int [] CATEG_DATA_TYPE_VAL = {
CategoricalAttribute.STRING};
private static int [] NUM_DATA_TYPE_VAL = {
NumericAttribute.DOUBLE};
private MiningDataSpecification m_MetaData;
private JCheckBox m_AutoCheckbox = new JCheckBox(Resource.srcStr("m_AutoCheckbox"));
private JComboBox m_AttributeCombo = new JComboBox();
private JComboBox m_TargetTypeCombo = new JComboBox();
private JComboBox m_TargetDataTypeCombo = new JComboBox();
private String[] m_MetaDataTableHeader = {
Resource.srcStr("Sourcecategory"),
Resource.srcStr("Targetcategory")};
private Hashtable<String, CatTransformationTableModel> m_MappingTableModel;
private JTable m_MappingTable = new JTable(){
/**
*
*/
private static final long serialVersionUID = 1L;
public boolean isCellEditable(int rowIndex, int vColIndex) {
if (vColIndex == 1)
return true;
else
return false;
}
};
private JButton m_ButtonReset = new JButton();
private JButton m_ButtonApply = new JButton();
private JButton m_ButtonClose = new JButton();
private JPanel targetLabelPanel;
/**
* @throws MiningException
* @throws SysException
*
*/
public CatTransformationOperatorProperty(String a_CaseID, String a_NodeID, String a_Name, INodeInfo a_NodeInfo, ICaseHandler a_CaseHandler) throws MiningException, SysException {
super(a_CaseID, a_NodeID, a_Name, a_NodeInfo, a_CaseHandler);
createCatTransformationOperatorProperty();
this.setTitle(Resource.srcStr("CategoricalTransformationTitle")+"["+a_NodeID+"]") ; // Added title menu by Joyce 2005/02/17
}
private void createCatTransformationOperatorProperty() throws MiningException{
JPanel m_NorthPanel = new JPanel(new BorderLayout());
m_NorthPanel.setPreferredSize( new Dimension(350,80));
Border margin = new EmptyBorder(5, 5, 10, 5);
m_NorthPanel.setBorder(margin);
JPanel m_CenterPanel = new JPanel(new BorderLayout());
JPanel buttonPanel = new JPanel();
targetLabelPanel = new JPanel(new GridLayout(3, 1, 2, 5));
targetLabelPanel.add(new JLabel(Resource.srcStr("m_AttributeLabel")+" "));
targetLabelPanel.add(new JLabel(Resource.srcStr("m_TargetTypeLabel")));
targetLabelPanel.add(new JLabel(Resource.srcStr("m_TargetDataTypeLabel")));
JPanel targetInputFieldPanel = new JPanel(new GridLayout(3, 1, 2, 5));
m_AttributeCombo.addActionListener(this);
targetInputFieldPanel.add(m_AttributeCombo);
JPanel m_targetTypeInputPanel = new JPanel(new GridLayout(1, 2, 2, 5));
JPanel m_targetDataTypeInputPanel = new JPanel( new GridLayout(1, 2, 2, 5));
targetInputFieldPanel.add(m_targetTypeInputPanel);
m_TargetTypeCombo.addActionListener(this);
m_targetTypeInputPanel.add(m_TargetTypeCombo);
m_AutoCheckbox.addChangeListener(this);
m_targetTypeInputPanel.add(m_AutoCheckbox );
m_targetDataTypeInputPanel.add(m_TargetDataTypeCombo);
m_targetDataTypeInputPanel.add(new JLabel(""));
targetInputFieldPanel.add(m_targetDataTypeInputPanel);
// set table default
m_MappingTable.setCellSelectionEnabled(false);
m_MappingTable.getTableHeader().setReorderingAllowed(false);
JScrollPane m_mappingScrollPane = new JScrollPane(m_MappingTable,JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED );
m_CenterPanel.setBorder( new EmptyBorder(0, 0, 7, 0));
m_CenterPanel.add(m_mappingScrollPane);
m_NorthPanel.add(targetLabelPanel, BorderLayout.WEST);
m_NorthPanel.add(targetInputFieldPanel, BorderLayout.CENTER);
m_ButtonReset.setText(Resource.srcStr("m_ButtonReset"));
m_ButtonApply.setText(Resource.srcStr("m_ButtonApply"));
m_ButtonClose.setSelected(false);
m_ButtonClose.setText(Resource.srcStr("m_ButtonClose"));
buttonPanel.add(m_ButtonApply);
buttonPanel.add(m_ButtonReset);
buttonPanel.add(m_ButtonClose);
//m_ButtonSelect.addActionListener(this);
m_ButtonReset.addActionListener(this);
m_ButtonApply.addActionListener(this);
m_ButtonClose.addActionListener(this);
this.getContentPane().add(m_NorthPanel, BorderLayout.NORTH);
this.getContentPane().add(m_CenterPanel, BorderLayout.CENTER);
this.getContentPane().add(buttonPanel, BorderLayout.SOUTH);
this.setSize(350, 300);
initContent();
getContent();
this.addInternalFrameListener(this);
}
protected void initContent() throws MiningException
{
if (m_ParentOperators.size()>0)
{
Operator parentOp = (Operator)m_ParentOperators.elementAt(0);
if (parentOp.getOutputBIObject()!=null && parentOp.getOutputBIObject().getBIData()!=null)
{
m_MetaData = parentOp.getOutputBIObject().getBIData().getMetaData();
}
if(m_MetaData==null){
throw new MiningException("Meta data of the node is null");
}
}
initMappingTable();
}
protected boolean getContent(){
/*
* set values that independent of the parent node
*/
String value = null;
int mode = INIT;
int index = -1;
int targetDataType = 0;
int targetType = 0;
//set target type combo box
setTargetTypeCombo();
//set target data type combo box
setTargetDataTypeCombo(INIT);
m_AutoCheckbox.setSelected(false);
value = (String) m_Node.getParameterValue("targetType");
if(value != null){
targetType = Integer.parseInt(value);
value = (String) m_Node.getParameterValue("targetDataType");
if(value != null ){
targetDataType = Integer.parseInt(value);
setTargetDataTypeCombo(targetType, targetDataType);
}else
setTargetDataTypeCombo(targetType);
}else {
setTargetDataTypeCombo(INIT);
}
value = (String) m_Node.getParameterValue("mode");
if(value!=null){
mode = Integer.parseInt(value);
switch (mode){
case CategoricalTransformationOperator.NUMERIZATION:
m_AutoCheckbox.setSelected(true);
setEnabledAutoCheckbox(true);
break;
case CategoricalTransformationOperator.CATEG_MAPPING:
if(targetType != CATEG){
m_TargetTypeCombo.setSelectedIndex(CATEG);
setTargetDataTypeCombo(CATEG);
}
break;
case CategoricalTransformationOperator.CATEG_NUM_MAPPING:
if(targetType != NUMERIC){
m_TargetTypeCombo.setSelectedIndex(NUMERIC);
setTargetDataTypeCombo(NUMERIC);
}
break;
}
m_MappingTable.setModel(new CatTransformationTableModel());
}
/*
* set values that dependent of the parent node
*/
if (m_MetaData==null || m_Node==null)
return false;
int m_Column = m_MetaData.getAttributesNumber();
if (m_Column==0)
return false;
//get target attribute
value = (String) m_Node.getParameterValue("target");
MiningAttribute[] miningAttributes = m_MetaData.getAttributesArray();
MiningAttribute attribute = null;
String name = null;
int attrIndex = 0;
String attrName = null;
MiningAttribute mAtt = null;
Vector targetCateg;
//set target attribute combo box and set the default value
m_AttributeCombo.removeAllItems();
m_AttributeCombo.addItem(DEFAULT);
index = 0;
for (int i=0; i<m_Column; i++)
{
attribute = miningAttributes[i];
name = attribute.getName();
if (attribute instanceof CategoricalAttribute){
m_AttributeCombo.addItem(name);
index ++;
if(value !=null && value.equalsIgnoreCase(name)){
attrIndex = index;
attrName = name;
mAtt = attribute;
}
}
}
m_AttributeCombo.setSelectedIndex(attrIndex);
//set jtable and target category values
if(mAtt !=null && mAtt instanceof CategoricalAttribute){
CatTransformationTableModel model = m_MappingTableModel.get(attrName);
value = (String) m_Node.getParameterValue("targetCateg");
if(value!=null){
targetCateg = ValueValidator.unescapeParam(value);
if(targetCateg.size() == ((CategoricalAttribute)mAtt).getCategoriesNumber()){
for(int i=0; i<targetCateg.size(); i++){
model.setValueAt((String)targetCateg.get(i), i);
}
m_MappingTable.setModel(model);
return true;
}else if (targetCateg.size()==0)
return false;
}
}
m_AttributeCombo.setSelectedIndex(0);
m_MappingTable.setModel(new CatTransformationTableModel());
// setTargetTypeCombo();
// setTargetDataTypeCombo(INIT);
return true;
}
protected boolean setContent(){
if (m_MappingTable.isEditing()) {
m_MappingTable.getCellEditor().stopCellEditing();
}
if (!validateProperty())
return false;
int x;
Vector<String> targetCat = new Vector<String>();
String attrName = null;
int mode = -1;
int targetDataType =-1;
int targetType = -1;
String targetCateg = null;
attrName = (String)m_AttributeCombo.getSelectedItem();
//get categorical mapping method
x = m_TargetTypeCombo.getSelectedIndex();
if(x ==CATEG){
mode = CategoricalTransformationOperator.CATEG_MAPPING;
targetType = CATEG;
//get the target data type
x = m_TargetDataTypeCombo.getSelectedIndex();
if(x>0)
targetDataType = CATEG_DATA_TYPE_VAL[x-1];
}else if (x==NUMERIC){
mode = CategoricalTransformationOperator.CATEG_NUM_MAPPING;
targetType = NUMERIC;
//get the target data type
x = m_TargetDataTypeCombo.getSelectedIndex();
if(x>0)
targetDataType = NUM_DATA_TYPE_VAL[x-1];
}
if(m_AutoCheckbox.isSelected())
mode = CategoricalTransformationOperator.NUMERIZATION;
//get target categories
CatTransformationTableModel model = (CatTransformationTableModel)m_MappingTable.getModel();
targetCat.clear();
// m_MappingTable.getCellEditor().stopCellEditing();
for (int i=0; i<model.getRowCount(); i++){
targetCat.add(model.getValueAt(i));
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -