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

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

/*
 * $Author$ 
 * $Date$
 * $Revision$
 *  UI for Missing Values Replacement
 */

package eti.bi.alphaminer.patch.standard.operation.property;

/**
 * @author jyung
 * 
 * TODO To change the template for this generated type comment go to Window -
 * Preferences - Java - Code Style - Code Templates
 */


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

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;


import com.prudsys.pdm.Core.CategoricalAttribute;
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.exception.SysException;
import eti.bi.util.ValueValidator;
import eti.bi.common.Locale.Resource;

public class ReplacementOperatorProperty extends OperatorProperty {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private final static String DEFAULT = Resource.srcStr("SelectItem");

	private final static String CATEG = Resource.srcStr("Categorical");

	private final static String NUM = Resource.srcStr("Numeric");

	private MiningDataSpecification m_MetaData;

	// JComponents
	private JComboBox m_AttributeJCB;

	private JLabel m_AttributeLabel = new JLabel(Resource.srcStr("m_AttributeLabel"));

	private JLabel m_RepValueLabel = new JLabel(Resource.srcStr("m_RepValueLabel"));

	private JTextField m_RepValueTF = new JTextField();

	private JButton m_ButtonReset = new JButton();

	private JButton m_ButtonApply = new JButton();

	private JButton m_ButtonClose = new JButton();

	public ReplacementOperatorProperty(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);
		createReplacementOperatorProperty();
		this.setTitle(Resource.srcStr("MissingValues")+" [" + a_NodeID + "]"); // Added title menu
															// by Joyce
															// 2005/02/17

	}

	private void createReplacementOperatorProperty() throws MiningException {

		// Top panel - Attribute row
		JPanel attributePanel = new JPanel();
		BorderLayout attributeLayout = new BorderLayout();
		attributeLayout.setHgap(30);
		attributePanel.setLayout(attributeLayout);

		m_AttributeJCB = new JComboBox();
		m_AttributeJCB.addActionListener(this);
		m_AttributeJCB.setPreferredSize(new Dimension(10, 20));
		m_AttributeLabel.setPreferredSize(new Dimension(45, 20));
		attributePanel.add(m_AttributeLabel, BorderLayout.LINE_START);
		attributePanel.add(m_AttributeJCB, BorderLayout.CENTER);

		// Middle panel - replacement value row
		JPanel replcValuePanel = new JPanel(new BorderLayout());
		m_RepValueLabel.setPreferredSize(new Dimension(120, 20));
		m_RepValueTF.setPreferredSize(new Dimension(40, 20));
		replcValuePanel.add(m_RepValueLabel, BorderLayout.LINE_START);
		replcValuePanel.add(m_RepValueTF, BorderLayout.CENTER);

		// Bottom (button) panel
		JPanel buttonPanel = new JPanel();
		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_ButtonReset.addActionListener(this);
		m_ButtonApply.addActionListener(this);
		m_ButtonClose.addActionListener(this);

		JPanel upperPanel = new JPanel(new GridLayout(2, 1, 0, 8));
		upperPanel.setBorder(BorderFactory.createEmptyBorder(5, 0, 0, 0));
		upperPanel.add(attributePanel);
		upperPanel.add(replcValuePanel);

		this.getContentPane().add(upperPanel, BorderLayout.NORTH);
		this.getContentPane().add(buttonPanel, BorderLayout.SOUTH);
		this.setContentPane(this.getContentPane());
		this.setSize(280, 140);
		//this.setVisible(true); remarked by Joyce

		initContent();
		getContent();
	}

	/**
	 * @see java.awt.event.ActionListener#actionPerformed(ActionEvent)
	 */
	public void actionPerformed(ActionEvent e) {
		if (e.getSource() == m_ButtonApply) {
			if (setContent()) {
				m_ParameterChanged = true;
				//m_ParentPanel.getCaseWindow().setModified(true);
				setPropertiesModified();
			}
		} else if (e.getSource() == m_ButtonReset) {
			getContent();
		} else if (e.getSource() == m_ButtonClose) {
			close();
		} else if (e.getSource() == m_AttributeJCB) {
			// add codes here
		}
	}

	public boolean setContent() {
		if (!validateProperty())
			return false;

		//<< added by Joyce 2005/03/17 to clear result
		//Operator op = m_ParentPanel.getOperator(m_NodeID);
		//((MissingValuesOperator) op).clearResult();
		clearOperatorTempResult();
		//>>

		String value = null;
		String attrName = null;
		String targetType = null;
		MiningAttribute mAtt = null;

		attrName = ((String) m_AttributeJCB.getSelectedItem()).trim();
		value = m_RepValueTF.getText();

		mAtt = m_MetaData.getMiningAttribute(attrName);
		if (mAtt instanceof CategoricalAttribute) {
			targetType = CATEG;
		} else {
			targetType = NUM;
		}

		m_Node.getParameters().remove("target");
		m_Node.getParameters().remove("targetType");
		m_Node.getParameters().remove("repValue");

		m_Node.setParameterValue("target", attrName);
		m_Node.setParameterValue("repValue", value);
		m_Node.setParameterValue("targetType", targetType);
		
		setPropertiesModified();
		return true;

	}

	private boolean validateProperty() {
		String message = "";
		boolean setFocus = false;

		if (m_AttributeJCB.getSelectedIndex() <= 0) {
			if (!setFocus) {
				m_AttributeJCB.requestFocus();
				setFocus = true;
			}
			message += Resource.srcStr("SelectAttribute");
			m_MessageDialog.showWarning(message, Resource.srcStr("InvalidValueMessage"));
			return false;
		}

		String attrName = ((String) m_AttributeJCB.getSelectedItem()).trim();
		MiningAttribute mAtt = m_MetaData.getMiningAttribute(attrName);
		String TF = m_RepValueTF.getText().trim();

		if (mAtt instanceof NumericAttribute && !ValueValidator.isDouble(TF)) {
			if (!setFocus) {
				m_RepValueTF.requestFocus();
				setFocus = true;
			}
			m_RepValueTF.setText(null);
			message += Resource.srcStr("ReplacementMessage");
			m_MessageDialog.showWarning(message, Resource.srcStr("InvalidValueMessage"));
			return false;
		} else if (TF.equals("")) {
			if (!setFocus) {
				m_RepValueTF.requestFocus();
				setFocus = true;
			}
			message += Resource.srcStr("ReplacementMessage1");
			m_MessageDialog.showWarning(message, Resource.srcStr("InvalidValueMessage"));
			return false;
		}

		//		if (message.equals(")
		return true;
		//		else{
		//		    MessageDialog.showWarning(message, Resource.srcStr("InvalidValueMessage"));
		//			return false;
		//		}
	}

	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();
			}
		}
	}

	public void getContent() {
		/*
		 * set values independent of parent
		 */
		String value = null;

		value = (String) m_Node.getParameterValue("repValue");
		if (value != null)
			m_RepValueTF.setText(value);
		else
			m_RepValueTF.setText("");

		/*
		 * set values dependent of parent
		 */
		if (m_MetaData == null || m_Node == null)
			return;
		int m_Column = m_MetaData.getAttributesNumber();
		if (m_Column == 0)
			return;

		MiningAttribute[] miningAttributes = m_MetaData.getAttributesArray();
		MiningAttribute attribute = null;
		String name;
		MiningAttribute mAtt = null;
		int index = 0;
		int attrIndex = 0;

		m_AttributeJCB.removeAllItems();
		m_AttributeJCB.addItem(DEFAULT);
		for (int i = 0; i < m_Column; i++) {
			value = (String) m_Node.getParameterValue("target");
			attribute = miningAttributes[i];
			name = attribute.getName();

			m_AttributeJCB.addItem(name);
			index++;
			if (value != null && value.equalsIgnoreCase(name)) {
				attrIndex = index;
				mAtt = attribute;
			}
		}
		m_AttributeJCB.setSelectedIndex(attrIndex);

		if (mAtt == null) {
			m_AttributeJCB.setSelectedIndex(0);
			//		    m_RepValueTF.setText("");
		} else {
			value = (String) m_Node.getParameterValue("targetType");
			if (mAtt instanceof CategoricalAttribute) {
				if (value == null || value.equals(NUM)) {
					m_AttributeJCB.setSelectedIndex(0);
					//				    m_RepValueTF.setText("");
				}
			} else {
				if (value == null || value.equals(CATEG)) {
					m_AttributeJCB.setSelectedIndex(0);
					//				    m_RepValueTF.setText("");
				}
			}
		}
	}
}

⌨️ 快捷键说明

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