📄 datacellrenderer.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 2005/3/30
*
* $Author$
* $Date$
* $Revision$
*
*/
package eti.bi.alphaminer.operation.result.renderer;
/**
* @author kelvinj
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
import java.awt.Component;
import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.border.Border;
import javax.swing.table.TableCellRenderer;
import eti.bi.common.data.MissingValue;
import eti.bi.util.NumberFormatter;
public class DataCellRenderer extends JLabel implements TableCellRenderer {
/**
*
*/
private static final long serialVersionUID = -754950250780323334L;
Border unselectedBorder = null;
Border selectedBorder = null;
boolean isBordered = true;
public DataCellRenderer(boolean isBordered) {
this.isBordered = isBordered;
setOpaque(true); //MUST do this for background to show up.
}
public Component getTableCellRendererComponent(
JTable table, Object value,
boolean isSelected, boolean hasFocus,
int row, int column)
{
// table.setSelectionForeground(Color.WHITE);
if (isBordered) {
if (isSelected) {
if (selectedBorder == null) {
selectedBorder = BorderFactory.createMatteBorder(2,5,2,5,
table.getSelectionBackground());
}
setBorder(selectedBorder);
setBackground(table.getSelectionBackground());
setForeground(table.getSelectionForeground());
} else {
if (unselectedBorder == null) {
unselectedBorder = BorderFactory.createMatteBorder(2,5,2,5,
table.getBackground());
}
setBorder(unselectedBorder);
setBackground(table.getBackground());
if (MissingValue.isMissingValue(value))
{
setForeground(MissingValue.DISPLAY_COLOR);
}else
{
setForeground(table.getForeground());
}
//setForeground(table.getForeground());
}
}
setFont(table.getFont());
setValue(value);
return this;
}
protected void setValue(Object a_Value)
{
if(MissingValue.isMissingValue(a_Value))
{
setText(MissingValue.DISPLAY_VALUE);
}else if (a_Value instanceof Double)
{
String formattedValue = NumberFormatter.format(((Double)a_Value).doubleValue());
setText(formattedValue);
}else
{
setText(a_Value.toString());
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -