📄 binerizationoperatorproperty.java
字号:
return false;
String attrName = ((String)m_AttributeJCB.getSelectedItem()).trim();
if(attrName ==null || attrName.trim().length()<=0 )
return false;
BinerizationTableModel model = (BinerizationTableModel)m_Table.getModel();
Boolean[] selection = new Boolean[model.getRowCount()];
for(int i=0; i<selection.length; i++){
selection[i] = model.getValueAt(i);
}
//<< added by Joyce 2005/03/17 to clear result
//Operator op = m_ParentPanel.getOperator(m_NodeID);
//((BinerizationOperator) m_Operator).clearResult();
clearOperatorTempResult();
//>>
m_Node.getParameters().remove("target");
m_Node.getParameters().remove("selection");
m_Node.setParameterValue("target", attrName);
m_Node.setParameterValue("selection", parseSelected(selection));
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("AttributeMessage");
m_MessageDialog.showWarning(message, Resource.srcStr("InvalidValueMessage"));
return false;
}
// if(message.equals(""))
return true;
// else {
// MessageDialog.showWarning(message, "Invalid input values");
// 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();
}
if(m_MetaData==null){
throw new MiningException("Meta data of the node is null");
}
}
initMappingTable();
}
private void getContent(){
if (m_MetaData==null || m_Node==null)
return;
int m_Column = m_MetaData.getAttributesNumber();
if (m_Column==0)
return;
String value = null;
String name = null;
MiningAttribute[] miningAttributes = m_MetaData.getAttributesArray();
MiningAttribute attribute = null;
MiningAttribute mAtt = null;
int index = 0;
int attrIndex = 0;
String attrName = null;
Boolean [] selection = null;
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();
if (attribute instanceof CategoricalAttribute){
m_AttributeJCB.addItem(name);
index ++;
if(value!=null && value.equalsIgnoreCase(name)){
attrIndex = index;
mAtt = attribute;
attrName = name;
}
}
}
m_AttributeJCB.setSelectedIndex(attrIndex);
// set jtable and target category values
if(mAtt != null && mAtt instanceof CategoricalAttribute){
BinerizationTableModel model = (BinerizationTableModel)m_TableModel.get(attrName);
value = (String) m_Node.getParameterValue("selection");
if(value!=null){
selection = parseSelected(value);
if(selection.length == ((CategoricalAttribute)mAtt).getCategoriesNumber()){
for(int i=0; i<selection.length; i++){
model.setValueAt(selection[i], i);
}
m_Table.setModel(model);
return;
}
}
}
m_AttributeJCB.setSelectedIndex(0);
m_Table.setModel(new BinerizationTableModel());
}
private String parseSelected(Boolean [] a_Selection){
String parsed = "";
for(int i=0; i<a_Selection.length; i++){
if(a_Selection[i].booleanValue()){
parsed+="1";
}else{
parsed+="0";
}
}
return parsed;
}
private Boolean [] parseSelected(String a_Selection){
Boolean [] selection = new Boolean[a_Selection.length()];
for(int i=0; i<a_Selection.length(); i++){
if(a_Selection.charAt(i)=='0'){
selection[i]= Boolean.FALSE;
}else {
selection[i]= Boolean.TRUE;
}
}
return selection;
}
@SuppressWarnings("unchecked")
private void initMappingTable(){
if (m_MetaData==null || m_Node==null)
return;
int numAttr = m_MetaData.getAttributesNumber();
if (numAttr==0)
return;
MiningAttribute[] miningAttributes = m_MetaData.getAttributesArray();
m_TableModel = new Hashtable();
for (int i=0; i<numAttr; i++){
if (miningAttributes[i] instanceof CategoricalAttribute){
CategoricalAttribute attr = (CategoricalAttribute)miningAttributes[i];
String attrName = miningAttributes[i].getName();
int numCat = attr.getCategoriesNumber();
Object[][] content = new Object[numCat][m_MetaDataTableHeader.length];
Object[] row = null;
ArrayList catValues = attr.getValues();
for (int j=0; j<catValues.size(); j++){
row = new Object [2];
row[0] = ((Category)catValues.get(j)).getValue().toString();
row[1] = new Boolean(false);
content[j] = row;
}
BinerizationTableModel model = new BinerizationTableModel(content, m_MetaDataTableHeader, i);
m_TableModel.put(attrName, model);
}
}
}
public void resetLocale() {
String title = getTitle();
int index = title.indexOf('[');
title = Resource.srcStr("BinerizationTitle")+title.substring(index);
setTitle(title);
DEFAULT = Resource.srcStr("SelectItem");
m_AttributeLabel.setText(Resource.srcStr("m_AttributeLabel"));
//for table
m_MetaDataTableHeader[0] = Resource.srcStr("Category");
m_MetaDataTableHeader[1] = Resource.srcStr("Use");
Collection values = m_TableModel.values();
Iterator iterator = values.iterator();
while(iterator.hasNext()) {
((BinerizationTableModel)iterator.next()).setColumnIdentifiers(m_MetaDataTableHeader);
}
m_MenuItemClear.setText(Resource.srcStr("m_MenuItemClear"));
m_MenuItemSelect.setText(Resource.srcStr("m_MenuItemSelect"));
m_ButtonApply.setText(Resource.srcStr("m_ButtonApply"));
m_ButtonReset.setText(Resource.srcStr("m_ButtonReset"));
m_ButtonClose.setText(Resource.srcStr("m_ButtonClose"));
}
}
class BinerizationTableModel extends DefaultTableModel
implements TableModelListener {
/**
*
*/
private static final long serialVersionUID = 3052672643137411513L;
Class[] types;
boolean[] canEdit;
Object[][] m_TableContent;
int m_Target = -1;
boolean m_Modified = false;
public BinerizationTableModel(){
super();
}
/**
* Constructs a TableMode.
* @param a_TableContent an Object array storing table content.
* @param a_TableHeader an Object array storing header names.
*/
public BinerizationTableModel(Object[][] a_TableContent,
Object[] a_TableHeader, int a_Target) {
super(a_TableContent, a_TableHeader);
m_Target = a_Target;
types = new Class[a_TableHeader.length];
canEdit = new boolean[a_TableHeader.length];
types[0]=String.class;
types[1]=Boolean.class;
canEdit[0] = false;
canEdit[1] = true;
m_TableContent = a_TableContent;
addTableModelListener(this);
}
/**
* Gets content of a row.
* @param rowIndex index of the row.
* @return String[] a String array of size 2 with the first element stores
* text of (rowIndex, 0) cell the table content; the second element stores
* text of (rowIndex, 1) cell in the table content.
*/
public Boolean getValueAt(int rowIndex) {
return (Boolean) super.getValueAt(rowIndex, 1);
}
public void setValueAt(Boolean value, int rowIndex) {
super.setValueAt(value, rowIndex, 1);
m_Modified = true;
}
public void setValue(Boolean value){
for(int i=0; i<getRowCount(); i++){
setValueAt(value, i, 1);
}
}
/**
* @see javax.swing.event.TableModelListener#tableChanged(TableModelEvent)
*/
public void tableChanged(TableModelEvent e) {
int row = e.getFirstRow();
int column = e.getColumn();
BinerizationTableModel model = (BinerizationTableModel) e.getSource();
@SuppressWarnings("unused") String columnName = model.getColumnName(column);
Boolean data = model.getValueAt(row);
m_TableContent[row][1] = data;
}
/**
* @see javax.swing.table.TableModel#getColumnClass(int)
*/
@SuppressWarnings("unchecked")
public Class getColumnClass(int columnIndex) {
return types[columnIndex];
}
/**
* @see javax.swing.table.TableModel#isCellEditable(int, int)
*/
public boolean isCellEditable(int rowIndex, int columnIndex) {
return canEdit[columnIndex];
}
public boolean isModified()
{
return m_Modified;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -