📄 inputfiledataoperatorproperty.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 Flat Files for Data Accessing
*/
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.io.File;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFileChooser;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import com.prudsys.pdm.Core.MiningDataSpecification;
import com.prudsys.pdm.Core.MiningException;
import com.prudsys.pdm.Input.Records.Excel.MiningExcelStream;
import com.prudsys.pdm.Transform.Filter.MiningFileFilter;
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.InputDataFileOperator;
import eti.bi.alphaminer.vo.BIData;
import eti.bi.exception.SysException;
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 InputFileDataOperatorProperty extends OperatorProperty implements
ChangeListener {
/**
*
*/
private static final long serialVersionUID = 1L;
// File type
private final String m_ARFF = "ARFF";
private final String m_CSV = "CSV";
private final String m_EXCEL = "EXCEL";
private final String m_IIS_LOG = "IIS_LOG";
private final String m_NCSA_COMMON_LOG = "NCSA_COMMON_LOG";
private final String m_NCSA_COMBINE_LOG = "NCSA_COMBINE_LOG";
private final String m_INTERSHOP_LOG = "INTERSHOP_LOG";
private final int ARFF = 1;
private final int CSV = 2;
private final int EXCEL = 3;
private final int IIS_LOG = 4;
private final int NCSA_COMMON_LOG = 5;
private final int NCSA_COMBINE_LOG = 6;
private final int INTERSHOP_LOG = 7;
// JComponents for arff source
private JComboBox m_fileTypeJCB;
private String m_Filename;
private JTextField m_FilePath;
private JButton m_ButtonSelect = new JButton();
private JLabel m_WorkSheetLabel = new JLabel(Resource.srcStr("m_WorkSheetLabel"));
private JComboBox m_worksheetCMB = new JComboBox();
private final Dimension m_defaultButtonSize = new Dimension(65, 25);
private JButton m_ButtonReset = new JButton();
private JButton m_ButtonApply = new JButton();
private JButton m_ButtonClose = new JButton();
private int m_WorkSheetIndex;
public InputFileDataOperatorProperty(String a_CaseID, String a_NodeID,String a_Name, INodeInfo a_NodeInfo, ICaseHandler a_CaseHandler) throws SysException {
super(a_CaseID, a_NodeID, a_Name, a_NodeInfo, a_CaseHandler);
createInputDataOperatorProperty();
String ls_name = "";
if (m_Node.getName() != null)
{
ls_name = m_Node.getName() + "_" + m_Node.getNodeID();
this.setTitle(Resource.srcStr("InputFileTitle")+"["+ ls_name + "]");
}
else{
this.setTitle(Resource.srcStr("InputFileTitle"));
}
}
private void createInputDataOperatorProperty() {
JPanel propertyFilePanel = new JPanel(new BorderLayout(10, 10));
JPanel buttonPanel = new JPanel();
// North panel
JPanel filePanel = new JPanel(new BorderLayout(10, 10));
filePanel.setBorder(BorderFactory.createEmptyBorder(5, 10, 0, 10));
JPanel fileLabelPanel = new JPanel(new GridLayout(2, 1, 2, 5));
//fileLabelPanel.setBorder(BorderFactory.createEmptyBorder(5,10,0,10));
JPanel fileFieldPanel = new JPanel(new GridLayout(2, 1, 2, 5));
//fileFieldPanel.setBorder(BorderFactory.createEmptyBorder(5,10,0,10));
JPanel fileFieldPane2 = new JPanel(new GridLayout(2, 1, 2, 5));
//fileFieldPane2.setBorder(BorderFactory.createEmptyBorder(5,10,0,10));
filePanel.add(fileLabelPanel, BorderLayout.WEST);
filePanel.add(fileFieldPanel, BorderLayout.CENTER);
filePanel.add(fileFieldPane2, BorderLayout.EAST);
filePanel.setPreferredSize(new Dimension(400, 50));
JLabel label1 = new JLabel(Resource.srcStr("FileTypeLabel"));
JLabel label2 = new JLabel(Resource.srcStr("FileNameLabel"));
fileLabelPanel.add(label1);
fileLabelPanel.add(label2);
String[] items = { Resource.srcStr("SelectItem"), "Attribute-Relation",
"Comma Separated Value", "Excel", "Ms IIS Log",
"NCSA Common Log", "NCSA Combined Log", "Intershop Log" };
m_fileTypeJCB = new JComboBox(items);
m_fileTypeJCB.addActionListener(this);
fileFieldPanel.add(m_fileTypeJCB);
JPanel fileNamePanel = new JPanel(new BorderLayout(10, 10));
m_FilePath = new JTextField(30);
m_FilePath.setText("");
//<< File Name field should be non-editable to avoid excel worksheet retrival problem
// -- Added by Joyce 2005/03/10
m_FilePath.setEditable(false);
//>>
fileNamePanel.add(m_FilePath, BorderLayout.CENTER);
m_ButtonSelect = new JButton(Resource.srcStr("m_ButtonSelect"));
fileNamePanel.add(m_ButtonSelect, BorderLayout.EAST);
fileFieldPanel.add(m_FilePath);
fileFieldPane2.add(new JLabel(""));
fileFieldPane2.add(m_ButtonSelect);
///
JPanel ExcelPanel = new JPanel(new BorderLayout(10, 10));
ExcelPanel.setBorder(BorderFactory.createTitledBorder(Resource.srcStr("ExcelOptionTitle")));
JPanel excelLabelPanel = new JPanel(new GridLayout(1, 1, 2, 5));
excelLabelPanel.setBorder(BorderFactory.createEmptyBorder(2, 5, 10, 0));
JPanel excelFieldPanel = new JPanel(new GridLayout(1, 1, 2, 5));
excelFieldPanel.setBorder(BorderFactory.createEmptyBorder(2, 0, 10, 5));
ExcelPanel.add(excelLabelPanel, BorderLayout.WEST);
ExcelPanel.add(excelFieldPanel, BorderLayout.CENTER);
ExcelPanel.setPreferredSize(new Dimension(350, 60));
excelLabelPanel.add(m_WorkSheetLabel);
m_WorkSheetLabel.setEnabled(false);
excelFieldPanel.add(m_worksheetCMB);
m_worksheetCMB.setEnabled(false);
m_worksheetCMB.addActionListener(this);
m_ButtonSelect.setText(Resource.srcStr("m_ButtonSelect"));
m_ButtonSelect.setSelected(true);
propertyFilePanel.add(filePanel, BorderLayout.NORTH);
propertyFilePanel.add(ExcelPanel, BorderLayout.CENTER);
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);
m_ButtonSelect.addActionListener(this);
m_ButtonApply.addActionListener(this);
m_ButtonReset.addActionListener(this);
m_ButtonClose.addActionListener(this);
this.getContentPane().add(propertyFilePanel, BorderLayout.NORTH);
this.getContentPane().add(buttonPanel, BorderLayout.SOUTH);
this.setSize(450, 200);
getContent();
}
public void stateChanged(ChangeEvent e) {
//setEnabledFile(m_RadioFile.isSelected());
}
public void openFileChooser() {
File directory = new File(System.getProperty("user.dir"));
if (m_Filename != null) {
File f = new File(m_Filename);
if (f.exists())
directory = f;
}
JFileChooser chooser = new JFileChooser(directory);
MiningFileFilter filter = new MiningFileFilter();
int m_fileType = m_fileTypeJCB.getSelectedIndex();
if (m_fileType ==ARFF )
filter.addExtension("arff");
if (m_fileType == CSV )
filter.addExtension("csv");
if (m_fileType == EXCEL )
filter.addExtension("xls");
if ((m_fileType ==IIS_LOG ) || (m_fileType == NCSA_COMMON_LOG ) || (m_fileType == NCSA_COMBINE_LOG )
|| (m_fileType == INTERSHOP_LOG )) {
filter.addExtension("log");
filter.addExtension("txt");
}
filter.setDescription("Mining input stream files");
chooser.setFileFilter(filter);
int returnVal = chooser.showOpenDialog(this);
if (returnVal == JFileChooser.APPROVE_OPTION) {
//<< added by Joyce - check if the file exit 2005/03/29
String ls_Filename =chooser.getSelectedFile().getPath();
File f = null;
if (ls_Filename != null && !ls_Filename.trim().equals(""))
f = new File(ls_Filename);
if (f == null || !f.exists()) {
m_MessageDialog.showWarning(Resource.srcStr("FileWarning") + ls_Filename
+ Resource.srcStr("NotExistMessage"), "Warning");
//<< set last visited path -- added by Joyce 2005/03/08
openFileChooser();
return;
}
//>>>
setFilePath(chooser.getSelectedFile().getPath());
//excel worksheet
if (m_fileTypeJCB.getSelectedIndex() == EXCEL ) {
m_worksheetCMB.removeAllItems();
try {
// put information to worksheet
m_worksheetCMB.addItem(Resource.srcStr("SelectItem"));
MiningExcelStream input = new MiningExcelStream(m_Filename,
null);
for (int i = 0; i < input.getNumberOfSheets(); i++) {
//System.out.println(input.getSheetName(i));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -