⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 propertytable.java

📁 一个很好的LIBSVM的JAVA源码。对于要研究和改进SVM算法的学者。可以参考。来自数据挖掘工具YALE工具包。
💻 JAVA
字号:
/*
 *  YALE - Yet Another Learning Environment
 *  Copyright (C) 2001-2004
 *      Simon Fischer, Ralf Klinkenberg, Ingo Mierswa, 
 *          Katharina Morik, Oliver Ritthoff
 *      Artificial Intelligence Unit
 *      Computer Science Department
 *      University of Dortmund
 *      44221 Dortmund,  Germany
 *  email: yale-team@lists.sourceforge.net
 *  web:   http://yale.cs.uni-dortmund.de/
 *
 *  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., 59 Temple Place, Suite 330, Boston, MA 02111-1307
 *  USA.
 */
package edu.udo.cs.yale.gui;

import edu.udo.cs.yale.operator.Operator;
import edu.udo.cs.yale.operator.OperatorChain;
import edu.udo.cs.yale.operator.parameter.*;

import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableCellEditor;
import javax.swing.table.TableCellRenderer;
import java.awt.Font;
import java.util.Iterator;
import java.util.ArrayList;

/** A property table is a table for editing parameters of operators. Hence, it has two columns, one
 *  for the key and one for the value. This class does not do very much, but as we want such tables
 *  to appear at several places, we use this superclass for formatting and as a factory for
 *  CellEditors. */
public abstract class PropertyTable extends JTable {
    
    private DefaultTableModel model;

    private ArrayList editors    = new ArrayList();
    private ArrayList renderers  = new ArrayList();
    private String[] columnNames = new String[] { "Key", "Value" };
 
    public PropertyTable() {
	this(new String[] { "Key", "Value" });
    }

    public PropertyTable(String[] columnNames) {
	super();
	this.columnNames = columnNames;
	setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
	setRowHeight(getRowHeight()+SwingTools.TABLE_ROW_EXTRA_HEIGHT);
	getTableHeader().setReorderingAllowed(false);
    }

    public abstract ParameterType getParameterType(int row);
    public abstract Operator getOperator(int row);

    public DefaultTableModel getDefaultModel() {
	return model;
    }

    protected void updateEditorsAndRenderers() {
	editors.clear();
	renderers.clear();
	int numberOfRows = getDefaultModel().getRowCount();
	for (int i = 0; i < numberOfRows; i++) {
	    ParameterType type = getParameterType(i);
	    editors.add(createPropertyCellEditor(type, getOperator(i)));
	    renderers.add(new PropertyKeyRenderer(type));
	}
    }

    protected void updateTableData(int rows) {
	model = new DefaultTableModel(columnNames, rows);
	setModel(model);
    }

    public TableCellEditor getCellEditor(int row, int column) {
	if (column == 1) {
	    return (PropertyCellEditor)editors.get(row);
	} else {	    
	    return super.getCellEditor(row, column);
	}
    }
    
    public TableCellRenderer getCellRenderer(int row, int column) {
	if (column == 1) {
	    PropertyCellEditor editor = (PropertyCellEditor)editors.get(row);
	    if (!editor.useEditorAsRenderer()) {
		return super.getCellRenderer(row, column);
	    } else {
		return editor;
	    }		
	} else {
	    return (TableCellRenderer)renderers.get(row);
	}
    }
    
    private static PropertyCellEditor createPropertyCellEditor(ParameterType type, Operator operator) {
	if (type instanceof ParameterTypePassword) {
 	    return new SimplePropertyCellEditor((ParameterTypePassword)type);
	} else if (type instanceof ParameterTypeCategory) {
	    return new SimplePropertyCellEditor((ParameterTypeCategory)type);
 	} else if (type instanceof ParameterTypeStringCategory) {
	    return new SimplePropertyCellEditor((ParameterTypeStringCategory)type);
 	} else if (type instanceof ParameterTypeBoolean) {
 	    return new SimplePropertyCellEditor((ParameterTypeBoolean)type);
   	} else if (type instanceof ParameterTypeInt) {
   	    return new SimplePropertyCellEditor((ParameterTypeInt)type);
   	} else if (type instanceof ParameterTypeDouble) {
   	    return new SimplePropertyCellEditor((ParameterTypeDouble)type);
 	} else if (type instanceof ParameterTypeAttributeFile) {
 	    return new AttributeFileCellEditor((ParameterTypeAttributeFile)type, operator);
 	} else if (type instanceof ParameterTypeFile) {
 	    return new SimpleFileCellEditor((ParameterTypeFile)type);
 	} else if (type instanceof ParameterTypeParameterValue) {  // first PTPV, then PTV !!!
 	    return new ParameterValueCellEditor((ParameterTypeParameterValue)type, operator.getExperiment(), (OperatorChain)operator);
 	} else if (type instanceof ParameterTypeValue) {
 	    return new ValueCellEditor((ParameterTypeValue)type, operator.getExperiment());
 	} else if (type instanceof ParameterTypeList) {
 	    return new ListCellEditor((ParameterTypeList)type, operator);
 	} else {
	    return new SimplePropertyCellEditor(type);
	} 
    }
}






⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -