📄 regressionoperatorproperty.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/12
*
* $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.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
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.RegressionOperator;
import eti.bi.exception.SysException;
import eti.bi.util.ValueValidator;
import eti.bi.common.Locale.Resource;
/**
* RegressionOperatorProperty is a kind of OperatorProperty
*/
public class RegressionOperatorProperty extends OperatorProperty {
/**
*
*/
private static final long serialVersionUID = 1L;
/* UI controls */
private JButton m_ButtonReset = new JButton();
private JButton m_ButtonSave = new JButton();
private JButton m_ButtonCancel = new JButton();
private JTextField m_Ridge = new JTextField();
private JTextField m_NumIterations = new JTextField();
private JCheckBox m_CheckBoxConvergence = new JCheckBox(Resource.srcStr("m_CheckBoxConvergence"));
/**
* Constructs an RegressionOperatorProperty object.
* @param a_CaseID
* ID of the Case containing the Operator Node to be set by this
* RegressionOperatorProperty.
* @param a_NodeID
* ID of the Operator node to be set by this
* RegressionOperatorProperty.
* @throws SysException
*/
public RegressionOperatorProperty(String a_CaseID, String a_NodeID, String a_Name, INodeInfo a_NodeInfo, ICaseHandler a_CaseHandler) throws SysException {
super(a_CaseID, a_NodeID, Resource.srcStr("LogisticRegression")+" [" + a_NodeID + "]", a_NodeInfo, a_CaseHandler);
createRegressionOperatorProperty();
}
/**
* Create the UI for this RegressionOperatorProperty
*/
private void createRegressionOperatorProperty() {
JPanel propertyPanel = new JPanel();
JPanel buttonPanel = new JPanel();
propertyPanel.setBorder(BorderFactory.createCompoundBorder(
BorderFactory
.createTitledBorder(Resource.srcStr("RegressionTitledBorder")),
BorderFactory.createEmptyBorder(2, 4, 0, 6)));
JLabel ridge = new JLabel(Resource.srcStr("ridge"));
JLabel numOfIterations = new JLabel(Resource.srcStr("numOfIterations"));
propertyPanel.setLayout(new GridLayout(3, 2, 0, 5));
propertyPanel.add(ridge);
propertyPanel.add(m_Ridge);
propertyPanel.add(numOfIterations);
propertyPanel.add(m_NumIterations);
propertyPanel.add(new JPanel());
propertyPanel.add(m_CheckBoxConvergence);
m_CheckBoxConvergence.setBorder(BorderFactory.createEmptyBorder(0, 0,
0, 0));
m_CheckBoxConvergence.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent e) {
m_NumIterations.setEnabled(!m_CheckBoxConvergence.isSelected());
}
});
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, 180);
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 RegressionOperatorProperty 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_Ridge.getText().trim();
if (!ValueValidator.isDouble(num)) {
m_Ridge.requestFocus();
m_Ridge.selectAll();
message = Resource.srcStr("RidgeMessage");
m_MessageDialog.showWarning(message, Resource.srcStr("InvalidValueMessage"));
return false;
}
if (!m_CheckBoxConvergence.isSelected()) {
num = m_NumIterations.getText().trim();
if (ValueValidator.largerThan(num, Integer.MAX_VALUE, false)) {
m_NumIterations.requestFocus();
m_NumIterations.selectAll();
message = Resource.srcStr("MaxInterMessage")
+ Integer.MAX_VALUE;
m_MessageDialog.showWarning(message, Resource.srcStr("InvalidValueMessage"));
return false;
} else if (ValueValidator.smallerThan(num, 0, true)) {
m_NumIterations.requestFocus();
m_NumIterations.selectAll();
message = Resource.srcStr("MaxInterMessage1");
m_MessageDialog.showWarning(message, Resource.srcStr("InvalidValueMessage"));
return false;
} else if (!ValueValidator.isInteger(num)) {
m_NumIterations.requestFocus();
m_NumIterations.selectAll();
message = Resource.srcStr("MaxInterMessage2")
+ Integer.MAX_VALUE;
m_MessageDialog.showWarning(message, Resource.srcStr("InvalidValueMessage"));
return false;
}
}
return true;
}
/**
* Set values input in this RegressionOperatorProperty to the Operator Node.
*/
private boolean setContent() {
if (m_Node == null) {
return false;
}
if (m_CheckBoxConvergence.isSelected())
m_Node.setParameterValue(RegressionOperator.ITERATION_NUMBER, "-1");
else
m_Node.setParameterValue(RegressionOperator.ITERATION_NUMBER,
m_NumIterations.getText().trim());
m_Node.setParameterValue(RegressionOperator.RIDGE, m_Ridge.getText()
.trim());
//Operator op = m_ParentPanel.getOperator(m_NodeID);
//((RegressionOperator) op).clearResult();
clearOperatorTempResult();
//m_ParentPanel.getCaseWindow().setModified(true);
setPropertiesModified();
return true;
}
/**
* Retrieve information from Operator Node and display those values in this
* RegressionOperatorProperty.
*/
private void getContent() {
if (m_Node == null)
return;
String ridge = (String) m_Node.getParameterValue(RegressionOperator.RIDGE);
if (ridge == null)
ridge = "0.00000001";
m_Ridge.setText(ridge);
String itr = (String) m_Node
.getParameterValue(RegressionOperator.ITERATION_NUMBER);
if (itr == null || itr.equals("-1")) {
itr = "100";
m_CheckBoxConvergence.setSelected(true);
} else
m_CheckBoxConvergence.setSelected(false);
m_NumIterations.setText(itr);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -