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

📄 simplepropertycelleditor.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.parameter.*;
import javax.swing.JTable;
import javax.swing.JPasswordField;
import javax.swing.DefaultCellEditor;
import javax.swing.JComboBox;
import javax.swing.JCheckBox;
import javax.swing.JTextField;
import javax.swing.table.TableCellRenderer;
import java.util.EventObject;
import java.awt.AWTEvent;
import java.awt.Component;

/** Editor for parameter values string, int, double, category, and boolean. */
public class SimplePropertyCellEditor extends DefaultCellEditor implements PropertyCellEditor {

    private boolean useEditorAsRenderer = false;

    public SimplePropertyCellEditor(ParameterTypeCategory type) {
	super(new JComboBox(type.getValues()));
	editorComponent.setToolTipText(type.getDescription());
	editorComponent.setBackground(javax.swing.UIManager.getColor("Table.cellBackground"));
	useEditorAsRenderer = true;
 	((JComboBox)editorComponent).removeItemListener(this.delegate);
 	this.delegate = new EditorDelegate() {
  		public void setValue(Object x) {
  		    super.setValue(x);
  		    ((JComboBox)editorComponent).setSelectedIndex(((Integer)x).intValue());
  		}		
  		public Object getCellEditorValue() {
  		    return new Integer(((JComboBox)editorComponent).getSelectedIndex());
  		}
	    };
 	((JComboBox)editorComponent).addItemListener(delegate);
    }

    public SimplePropertyCellEditor(ParameterTypeStringCategory type) {
	super(new JComboBox(type.getValues()));
	editorComponent.setToolTipText(type.getDescription());
	editorComponent.setBackground(javax.swing.UIManager.getColor("Table.cellBackground"));
	useEditorAsRenderer = true;
 	((JComboBox)editorComponent).removeItemListener(this.delegate);
	((JComboBox)editorComponent).setEditable(true);
 	this.delegate = new EditorDelegate() {
  		public void setValue(Object x) {
  		    super.setValue(x);
  		    ((JComboBox)editorComponent).setSelectedItem((String)x);
  		}		
  		public Object getCellEditorValue() {
		    String selected = (String)((JComboBox)editorComponent).getSelectedItem();
		    if (selected.trim().length() == 0) selected = null;
  		    return selected;
  		}
	    };
 	((JComboBox)editorComponent).addItemListener(delegate);
    }


    public SimplePropertyCellEditor(ParameterTypeBoolean type) {
	super(new JCheckBox());	
	editorComponent.setToolTipText(type.getDescription() + " ("+type.getRange()+")");
	((JCheckBox)editorComponent).setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
	editorComponent.setBackground(javax.swing.UIManager.getColor("Table.cellBackground"));
	useEditorAsRenderer = true;
    }

    public SimplePropertyCellEditor(final ParameterTypeInt type) {
	super(new JTextField());
	editorComponent.setToolTipText(type.getDescription() + " ("+type.getRange()+")");
	((JTextField)editorComponent).removeActionListener(delegate);
        this.delegate = new EditorDelegate() {
		public void setValue(Object x) {
		    super.setValue(x);
		    if (x != null) {
			if ((x instanceof Integer) || (x instanceof String))
			    ((JTextField)editorComponent).setText(x.toString());
			else throw new IllegalArgumentException("Illegal value class for integer parameter: " + 
								x.getClass().getName());
		    }
		}		
		public Object getCellEditorValue() {
		    try {
			int i = Integer.parseInt(((JTextField)editorComponent).getText());
			if (i < type.getMinValue()) i = (int)type.getMinValue();
			if (i > type.getMaxValue()) i = (int)type.getMaxValue();
			return new Integer(i);
		    } catch (NumberFormatException e) {
			return type.getDefaultValue();
		    }
		}		
	    };
	((JTextField)editorComponent).addActionListener(delegate);
    }

    public SimplePropertyCellEditor(final ParameterTypeDouble type) {
	super(new JTextField());
	editorComponent.setToolTipText(type.getDescription() + " ("+type.getRange()+")");
        this.delegate = new EditorDelegate() {
		public void setValue(Object x) {
		    super.setValue(x);
		    if (x != null) {
			if ((x instanceof Double) || (x instanceof String))
			    ((JTextField)editorComponent).setText(x.toString());
			else throw new IllegalArgumentException("Illegal value class for double parameter: " + 
								x.getClass().getName());
		    }
		}		
		public Object getCellEditorValue() {
		    try {
			double d = Double.parseDouble(((JTextField)editorComponent).getText());
			if (d < type.getMinValue()) d = type.getMinValue();
			if (d > type.getMaxValue()) d = type.getMaxValue();
			return new Double(d);
		    } catch (NumberFormatException e) {
			return type.getDefaultValue();
		    }
		}		
	    };
	((JTextField)editorComponent).addActionListener(delegate);
    }

    public SimplePropertyCellEditor(ParameterTypePassword type) {
	super(new JPasswordField());	
	editorComponent.setToolTipText(type.getDescription() + " ("+type.getRange()+")");
	useEditorAsRenderer = true;
    }

    public SimplePropertyCellEditor(ParameterType type) {
	super(new JTextField());	
	editorComponent.setToolTipText(type.getDescription() + " ("+type.getRange()+")");
    }

    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
	return getTableCellEditorComponent(table, value, isSelected, row, column);
    }

    public boolean useEditorAsRenderer() {
	return useEditorAsRenderer;
    }

}

⌨️ 快捷键说明

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