📄 addexpressionoperatorproperty.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/20
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
/**
* @author kclai
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
package eti.bi.alphaminer.patch.standard.operation.property;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.JToolTip;
import javax.swing.border.TitledBorder;
import com.prudsys.pdm.Core.MiningAttribute;
import com.prudsys.pdm.Core.MiningDataSpecification;
import com.prudsys.pdm.Core.MiningException;
import com.prudsys.pdm.Input.MiningStoredData;
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.common.Locale.Resource;
public class AddExpressionOperatorProperty extends OperatorProperty
implements ActionListener {
/**
*
*/
private static final long serialVersionUID = 2976482112652931140L;
private static String DEFAULT = Resource.srcStr("VariableListItem");
private MiningDataSpecification m_MetaData;
@SuppressWarnings("unused")
private MiningStoredData m_msd;
// Constants
private static final String OPERATOR_PLUS = "+";
private static final String OPERATOR_MINUS = "-";
private static final String OPERATOR_MULTIPLY = "*";
private static final String OPERATOR_DIVIDE = "/";
private static final String OPERATOR_LOG = "log";
private static final String OPERATOR_ABS = "abs";
private static final String OPERATOR_EXP = "exp";
private static final String OPERATOR_SQRT = "sqrt";
private static final String OPERATOR_FLOOR = "floor";
private static final String OPERATOR_CEIL = "ceil";
private static final String OPERATOR_INT = "rint";
private static final String OPERATOR_TAN = "tan";
private static final String OPERATOR_SIN = "sin";
private static final String OPERATOR_COS = "cos";
private static final String OPERATOR_AGE = "age";
private static final String OPERATOR_EQ = "eq";
private static final String OPERATOR_NE = "ne";
private static final String OPERATOR_GE = "ge";
private static final String OPERATOR_GT = "gt";
private static final String OPERATOR_LE = "le";
private static final String OPERATOR_LT = "lt";
private static final String OPERATOR_EQ_SYMBOL = "==0";
private static final String OPERATOR_NE_SYMBOL = "!=0";
private static final String OPERATOR_GE_SYMBOL = ">=0";
private static final String OPERATOR_GT_SYMBOL = ">0";
private static final String OPERATOR_LE_SYMBOL = "<=0";
private static final String OPERATOR_LT_SYMBOL = "<0";
// JComponents
private JLabel m_NewAttributeLabel = new JLabel(Resource.srcStr("m_NewAttributeLabel"));
private JTextField m_NewAttribute = new JTextField();
private JTextArea m_Expression = new JTextArea(4, 35);
private JComboBox m_AttributeVarJCB;
private JComboBox [] m_OperatorJCB;
private JButton m_ButtonReset = new JButton();
private JButton m_ButtonApply = new JButton();
private JButton m_ButtonClose = new JButton();
private JPanel operatorLeftOuterPanel;
private JPanel attributeVarOuterPanel;
private final Dimension m_defaultButtonSize = new Dimension(65, 25);
// variables
private String [] m_AttributeVarSymbol;
private int m_counter = 1; //variable to indicate if we should append it
public AddExpressionOperatorProperty(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);
createAddExpressionOperatorProperty();
this.setResizable(true);
this.setTitle(Resource.srcStr("AddExpressionTitle")+"["+a_NodeID+"]") ; // Added title menu by Joyce 2005/02/17
}
private void createAddExpressionOperatorProperty() throws MiningException{
/*
* create attribute group panel, including new attribute row and
* attribute variable row
*/
/* new attribute row */
JPanel newAttributePanel = new JPanel();
newAttributePanel.setLayout(new BoxLayout(newAttributePanel,
BoxLayout.LINE_AXIS));
newAttributePanel.add(Box.createRigidArea(new Dimension(4, 0)));
newAttributePanel.add(m_NewAttributeLabel);
newAttributePanel.add(Box.createRigidArea(new Dimension(10, 0)));
m_NewAttribute.setPreferredSize(new Dimension(10, 20));
newAttributePanel.add(m_NewAttribute);
newAttributePanel.add(Box.createRigidArea(new Dimension(3, 0)));
/* attribute variable row */
attributeVarOuterPanel = new JPanel();
attributeVarOuterPanel.setBorder(BorderFactory.
createTitledBorder(Resource.srcStr("AttributeVariable")));
JPanel attributeVarInnerPanel = new JPanel(
new GridLayout(1, 1, 0, 5));
attributeVarInnerPanel.setBorder(BorderFactory.
createEmptyBorder(0, 0, 5, 0));
m_AttributeVarJCB = new JComboBox();
m_AttributeVarJCB.setPreferredSize(new Dimension(10, 20));
m_AttributeVarJCB.addActionListener(this);
attributeVarInnerPanel.add(m_AttributeVarJCB);
attributeVarInnerPanel.setPreferredSize(new Dimension(300, 25));
attributeVarOuterPanel.setPreferredSize(new Dimension(300, 60));
attributeVarOuterPanel.add(attributeVarInnerPanel);
/* combine the 2 rows into a single panel */
JPanel attributeGroupPanel = new JPanel(new BorderLayout(0,5));
attributeGroupPanel.add(newAttributePanel, BorderLayout.NORTH);
attributeGroupPanel.add(attributeVarOuterPanel, BorderLayout.SOUTH);
/*
* create operator group panel
*/
/* operator left panel */
operatorLeftOuterPanel = new JPanel();
JPanel operatorLeftInnerPanel = new JPanel(new GridLayout(3, 1, 0, 0));
operatorLeftOuterPanel.setBorder(
BorderFactory.createTitledBorder(Resource.srcStr("Operator")));
String[][] operators = {
{OPERATOR_PLUS, OPERATOR_MINUS,
OPERATOR_MULTIPLY, OPERATOR_DIVIDE},
{OPERATOR_LOG, OPERATOR_ABS, OPERATOR_EXP,
OPERATOR_SQRT, OPERATOR_FLOOR, OPERATOR_CEIL,
OPERATOR_INT, OPERATOR_TAN, OPERATOR_SIN,
OPERATOR_COS,OPERATOR_AGE },
{OPERATOR_EQ + " (" + OPERATOR_EQ_SYMBOL + ")",
OPERATOR_NE + " (" + OPERATOR_NE_SYMBOL + ")",
OPERATOR_GE + " (" + OPERATOR_GE_SYMBOL + ")",
OPERATOR_GT + " (" + OPERATOR_GT_SYMBOL + ")",
OPERATOR_LE + " (" + OPERATOR_LE_SYMBOL + ")",
OPERATOR_LT + " (" + OPERATOR_LT_SYMBOL + ")"}
};
// add a space prior to every item in operators array
// in order to have a better layout for comboboxes
for (int i=0; i<operators.length; i++) {
for (int j=0; j<operators[i].length; j++) {
operators[i][j] = " " + operators[i][j];
}
}
m_OperatorJCB = new JComboBox[3];
for (int i=0; i<3; i++) {
m_OperatorJCB[i] = new JComboBox(operators[i]);
m_OperatorJCB[i].setPreferredSize(new Dimension(70, 20));
m_OperatorJCB[i].addActionListener(this);
operatorLeftInnerPanel.add(m_OperatorJCB[i]);
}
operatorLeftOuterPanel.add(operatorLeftInnerPanel);
/* operator right panel */
JPanel operatorRightOuterPanel = new JPanel(new GridLayout(1, 1, 0, 0));
JPanel operatorRightInnerPanel1 = new JPanel();
operatorRightInnerPanel1.setLayout(new BoxLayout(operatorRightInnerPanel1,
BoxLayout.PAGE_AXIS));
JPanel operatorRightInnerPanel2 = new JPanel();
operatorRightInnerPanel2.setLayout(new BoxLayout(operatorRightInnerPanel2,
BoxLayout.LINE_AXIS));
m_Expression.setEditable(true);
m_Expression.setLineWrap(true);
m_Expression.setWrapStyleWord(true);
m_Expression.setFont( m_AttributeVarJCB.getFont() );
JScrollPane scrollPane = new JScrollPane(m_Expression,
JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
operatorRightInnerPanel1.add(Box.createRigidArea(new Dimension(0, 8)));
operatorRightInnerPanel1.add(scrollPane);
operatorRightInnerPanel1.add(Box.createRigidArea(new Dimension(0, 2)));
operatorRightInnerPanel2.add(operatorRightInnerPanel1);
operatorRightInnerPanel2.add(Box.createRigidArea(new Dimension(2, 0)));
operatorRightOuterPanel.add(operatorRightInnerPanel2);
/* combine the 2 panels into a single group panel */
JPanel operatorGroupPanel = new JPanel();
operatorGroupPanel.setLayout(new BoxLayout(operatorGroupPanel,
BoxLayout.LINE_AXIS));
operatorGroupPanel.add(operatorLeftOuterPanel);
operatorGroupPanel.add(Box.createRigidArea(new Dimension(8, 0)));
operatorGroupPanel.add(operatorRightOuterPanel);
/*
* create button panel
*/
JPanel buttonPanel = new JPanel();
m_ButtonApply.setText(Resource.srcStr("m_ButtonApply"));
m_ButtonApply.setPreferredSize(m_defaultButtonSize);
m_ButtonReset.setSelected(false);
m_ButtonReset.setText(Resource.srcStr("m_ButtonReset"));
m_ButtonReset.setPreferredSize(m_defaultButtonSize);
m_ButtonClose.setSelected(false);
m_ButtonClose.setText(Resource.srcStr("m_ButtonClose"));
m_ButtonClose.setPreferredSize(m_defaultButtonSize);
buttonPanel.add(m_ButtonApply);
buttonPanel.add(m_ButtonReset);
buttonPanel.add(m_ButtonClose);
/*
* add all the panels to the content pane
* and set the layout
*/
JPanel nonButtonPanel = new JPanel(new BorderLayout());
nonButtonPanel.setBorder(BorderFactory.createEmptyBorder(5, 0, 0, 0));
@SuppressWarnings("unused") JPanel filledPanel = new JPanel(new BorderLayout(0, 5));
nonButtonPanel.add(attributeGroupPanel, BorderLayout.NORTH);
nonButtonPanel.add(operatorGroupPanel, BorderLayout.SOUTH);
this.getContentPane().add(nonButtonPanel, BorderLayout.NORTH);
this.getContentPane().add(buttonPanel, BorderLayout.SOUTH);
this.setContentPane(this.getContentPane());
this.setSize(350, 275);
//this.setVisible(true); remarked by Joyce
//Added by Joyce 2005/01/24
m_ButtonReset.addActionListener(this);
m_ButtonApply.addActionListener(this);
m_ButtonClose.addActionListener(this);
initContent();
getContent();
}
public void actionPerformed(ActionEvent e) {
if (e.getSource() == m_AttributeVarJCB) {
int index = m_AttributeVarJCB.getSelectedIndex();
if(index >0 && m_counter > 2){
m_Expression.append(m_AttributeVarSymbol[index-1]);
}
m_counter ++;
} else if (e.getSource() == m_OperatorJCB[0]) {
switch ( m_OperatorJCB[0].getSelectedIndex() ) {
case 0 : m_Expression.append(OPERATOR_PLUS);
break;
case 1 : m_Expression.append(OPERATOR_MINUS);
break;
case 2 : m_Expression.append(OPERATOR_MULTIPLY);
break;
case 3 : m_Expression.append(OPERATOR_DIVIDE);
break;
default: break;
}
} else if (e.getSource() == m_OperatorJCB[1]) {
//<< add tooltips>>
if (m_OperatorJCB[1].getSelectedIndex() == 10 ){
//<< Modified by Franky Chan 23/03/2005
// To fix serious indentation problems
// m_OperatorJCB[1].setToolTipText("<html>"
// +"Letter Description"
// +"<br>"+"y Year"
// +"<br>"+"M Month in year"
// +"<br>"+"d Day in month"
// +"<br>"+"E Day in week"
// +"<br>"+"a Am/pm marker"
// +"<br>"+"H Hour in day(0-23)"
// +"<br>"+"k Hour in day(1-24)"
// +"<br>"+"K Hour in am/pm(0-11)"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -