📄 attributeweightcelleditor.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 java.awt.*;
import java.awt.event.*;
import javax.swing.*;
/** Editor for attribute weights. A text field for numeric values and three buttons. The first button sets the
* weight to zero, the second button to 1, and the third resets the value to the old weight. */
public class AttributeWeightCellEditor extends AbstractCellEditor implements PropertyCellEditor {
private JPanel panel = new JPanel();
private JTextField textField = new JTextField(12);
private GridBagLayout gridBagLayout = new GridBagLayout();
private double oldValue;
public AttributeWeightCellEditor(double oldValue) {
super();
this.oldValue = oldValue;
panel.setLayout(gridBagLayout);
panel.setToolTipText("The weight for this attribute.");
textField.setToolTipText("The weight for this attribute.");
GridBagConstraints c = new GridBagConstraints();
c.fill = c.BOTH;
c.weightx = 1;
gridBagLayout.setConstraints(textField, c);
panel.add(textField);
c.weightx = 0;
addButton(createValueButton("Zero", "0.0"), 1);
addButton(createValueButton("One", "1.0"), GridBagConstraints.RELATIVE);
addButton(createValueButton("Reset", oldValue+""), GridBagConstraints.REMAINDER);
}
protected JButton createValueButton(String name, final String newValue) {
JButton button = new JButton(name);
button.setMargin(new Insets(0,0,0,0));
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
textField.setText(newValue);
fireEditingStopped();
}
});
button.setToolTipText("Sets the weight of this attribute to " + newValue + ".");
return button;
}
protected void addButton(JButton button, int gridwidth) {
GridBagConstraints c = new GridBagConstraints();
c.gridwidth = gridwidth;
c.weightx = 0;
c.fill = c.BOTH;
gridBagLayout.setConstraints(button, c);
panel.add(button);
}
public Object getCellEditorValue() {
return (textField.getText().trim().length() == 0) ? null : textField.getText().trim();
}
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int col) {
textField.setText((value == null) ? "" : value.toString());
return panel;
}
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 true;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -