📄 sampleoperatorresult.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 Sep 1, 2004
*
* $Author$
* $Date$
* $Revision$
*
* To change the template for this generated file go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
package eti.bi.alphaminer.operation.result;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.JTable;
import javax.swing.event.InternalFrameEvent;
import javax.swing.table.JTableHeader;
import javax.swing.table.TableColumnModel;
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 com.prudsys.pdm.Core.OrdinalAttribute;
import com.prudsys.pdm.Input.MiningStoredData;
import com.prudsys.pdm.Input.MiningVector;
import eti.bi.alphaminer.core.handler.ICaseHandler;
import eti.bi.alphaminer.operation.operator.INodeInfo;
import eti.bi.alphaminer.operation.result.datamodel.DataTableModel;
import eti.bi.alphaminer.operation.result.datamodel.MetaDataTableModel;
import eti.bi.alphaminer.vo.IBIData;
import eti.bi.alphaminer.vo.IBIObject;
import eti.bi.exception.AppException;
import eti.bi.exception.SysException;
/**
* @author kjor
*
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
public class SampleOperatorResult extends OperatorResult
implements ActionListener
{
/**
*
*/
private static final long serialVersionUID = 1L;
String[] m_MetaDataTableHeader;
Object[][] m_MetaDataTableContent;
String[] m_DataTableHeader;
Object[][] m_DataTableContent;
Class[] m_DataTableType;
JScrollPane jScrollPane1;
JScrollPane jScrollPane2;
JTable jTable1;
JTable jTable2;
JTabbedPane jTabbedPane = new JTabbedPane();
JPanel jPanel1 = new JPanel();
JPanel jPanel2 = new JPanel();
JButton m_ButtonCancel = new JButton();
public SampleOperatorResult (
String a_CaseID,
String a_NodeID,
String a_Name,INodeInfo a_NodeInfo, ICaseHandler a_CaseHandler)
throws Exception{
super(a_Name + " result", a_CaseID, a_NodeID,a_NodeInfo, a_CaseHandler);
}
@Override
protected void init() throws Exception {
m_MetaDataTableHeader = new String[5];
m_MetaDataTableHeader[0] = "Attribute";
m_MetaDataTableHeader[1] = "Type";
m_MetaDataTableHeader[2] = "Value range";
m_MetaDataTableHeader[3] = "Data type";
m_MetaDataTableHeader[4] = "Description";
}
/* Get the operation result (opNode.getOutputBIObject()) from the Operator object and display on
* the user interface
*/
protected void getContent() throws SysException{
/* Get the Output BIOBject from the operator */
IBIObject aOutputBIObject = m_Operator.getOutputBIObject();
IBIData aOutputBIData = null;
MiningStoredData aMiningStoredData = null;
MiningDataSpecification aMetaData = null;
String target = null;
if (aOutputBIObject!=null)
{
aOutputBIData = aOutputBIObject.getBIData();
if (aOutputBIData!=null)
{
aMiningStoredData = aOutputBIData.getMiningStoredData();
aMetaData = aOutputBIData.getMetaData();
MiningAttribute aAttr = aOutputBIData.getTargetAttribute();
if (aAttr!=null)
{
target = aAttr.getName();
}
}
}
if (aMetaData==null || aMiningStoredData ==null)
{
System.out.println("No output data available.");
return;
}
/* Visualize the result */
int m_Column = aMetaData.getAttributesNumber();
if (m_Column==0)
return;
MiningAttribute[] miningAttributes = aMetaData.getAttributesArray();
MiningAttribute attribute = null;
m_DataTableType = new Class[m_Column];
m_DataTableHeader = new String[m_Column];
Object[][] content = new Object[m_Column][m_MetaDataTableHeader.length];
Object[] row = null;
for (int i=0; i<m_Column; i++)
{
row = new Object[m_MetaDataTableHeader.length];
attribute = miningAttributes[i];
m_DataTableHeader[i] = attribute.getName();
row[0] = attribute.getName();
if (target!=null && target.equals(row[0]))
row[0] = (String) row[0] + "[Target]";
m_DataTableType[i] = String.class;
if (attribute instanceof NumericAttribute)
{
row[1] = "Numeric";
row[2] = ((NumericAttribute) attribute).getInterval().toString();
int dataType = ((NumericAttribute) attribute).getDataType();
if (dataType == MiningAttribute.UNDEFINED) row[3] = "undefined";
else if (dataType == NumericAttribute.DOUBLE) {row[3] = "double"; m_DataTableType[i] = Double.class;}
else if (dataType == NumericAttribute.FLOAT) {row[3] = "float"; m_DataTableType[i] = Float.class;}
else if (dataType == NumericAttribute.INTEGER) {row[3] = "integer"; m_DataTableType[i] = Integer.class;}
else if (dataType == NumericAttribute.BOOLEAN) {row[3] = "boolean"; m_DataTableType[i] = Boolean.class;}
else if (dataType == NumericAttribute.DATETIME_PRUDSYS) row[3] = "datePrudsys";
String des = null;
if (((NumericAttribute) attribute).isCyclic())
des = "cyclic";
if (((NumericAttribute) attribute).isDiscrete())
des = (des==null?"":", ") + "discrete";
if (((NumericAttribute) attribute).isTime())
des = (des==null?"":", ") + "time";
row[4] = des;
}
else if (attribute instanceof CategoricalAttribute)
{
row[1] = "Categorical";
String cat = "";
ArrayList values = ((CategoricalAttribute) attribute).getValues();
for( int j = 0; j < values.size(); j++ )
{
cat += values.get( j );
if (j<values.size()-1)
cat += ", ";
}
row[2] = cat;
int dataType = ((CategoricalAttribute) attribute).getDataType();
if (dataType == MiningAttribute.UNDEFINED) row[3] = "undefined";
else if (dataType == CategoricalAttribute.STRING) row[3] = "string";
else if (dataType == CategoricalAttribute.BOOLEAN) {row[3] = "boolean"; m_DataTableType[i] = Boolean.class;}
String des = null;
if (attribute instanceof OrdinalAttribute)
{
row[1] = (String) row[1] + " ordinal";
if (((OrdinalAttribute) attribute).isCyclic())
des = "cyclic";
}
if (((CategoricalAttribute) attribute).getTaxonomy()!= null)
des = (des==null?"":", ") + "taxonomy";
if (((CategoricalAttribute) attribute).isUnboundedCategories())
des = (des==null?"":", ") + "unboundedCategories";
if (((CategoricalAttribute) attribute).isUnstoredCategories())
des = (des==null?"":", ") + "unstoredCategories";
row[4] = des;
}
content[i] = row;
}
m_MetaDataTableContent = content;
ArrayList list = aOutputBIData.getMiningStoredData().getMiningVectors();
content = new Object[list.size()][m_Column];
MiningVector vec = null;
for (int i=0; i<list.size(); i++)
{
vec = (MiningVector) list.get(i);
content[i] = vec.toVector().toArray();
}
m_DataTableContent = content;
System.out.print("meta data is transformed? Ans: ");
System.out.println(aMetaData.isTransformed());
}
/* Construct the user interface components for result display
* It is called by the constructor.
* Invoke getContent() at the end to visualize the result
* */
protected void createResult() throws MiningException {
jScrollPane1 = new JScrollPane();
jScrollPane2 = new JScrollPane();
jTable1 = new JTable();
jTable2 = new JTable();
this.setIconifiable(false);
this.setResizable(true);
this.setMaximizable(true);
this.setResizable(true);
this.setDefaultCloseOperation(
javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
this.getContentPane().setLayout(new BorderLayout());
m_ButtonCancel.setSelected(false);
m_ButtonCancel.setText("Close");
this.getContentPane().add(jTabbedPane, BorderLayout.CENTER);
jTabbedPane.add(jScrollPane1, "Variables");
jTabbedPane.add(jScrollPane2, "Data");
this.getContentPane().add(jPanel1, BorderLayout.SOUTH);
jPanel1.add(m_ButtonCancel, null);
jScrollPane1.getViewport().setBackground(Color.white);
jScrollPane1.getViewport().add(jTable1, null);
jScrollPane2.getViewport().setBackground(Color.white);
jScrollPane2.getViewport().add(jTable2, null);
m_ButtonCancel.addActionListener(this);
JTableHeader tableHeader = jTable1.getTableHeader();
tableHeader.setReorderingAllowed(false);
tableHeader = jTable2.getTableHeader();
tableHeader.setReorderingAllowed(false);
jTable1.setModel(new MetaDataTableModel(m_MetaDataTableContent, m_MetaDataTableHeader));
jTable2.setModel(new DataTableModel(m_DataTableContent, m_DataTableHeader, m_DataTableType));
this.setSize(450, 300);
//this.addInternalFrameListener(this);
}
/* (non-Javadoc)
* @see eti.bi.alphaminer.ui.operatorresult.IFileExportPanel#export()
*/
public void export() throws AppException, SysException {
// TODO Auto-generated method stub
}
/**
* @see java.awt.event.ActionListener#actionPerformed(ActionEvent)
*/
public void actionPerformed(ActionEvent e) {
close();
}
/**
* @see javax.swing.event.InternalFrameListener#internalFrameOpened(InternalFrameEvent)
*/
public void internalFrameOpened(InternalFrameEvent e) {
TableColumnModel tcm = jTable1.getColumnModel();
if (tcm.getColumn(0).getWidth()<60)
{
for (int i=0; i<tcm.getColumnCount(); i++)
tcm.getColumn(i).setMinWidth(60);
jTable1.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
}
tcm = jTable2.getColumnModel();
if (tcm.getColumn(0).getWidth()<60)
{
for (int i=0; i<tcm.getColumnCount(); i++)
tcm.getColumn(i).setMinWidth(60);
jTable2.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -