📄 categorynamecellrenderer.java
字号:
/*
* 08/10/2005
*
* CategoryNameCellRenderer.java - Renderer for a category name row.
* Copyright (C) 2005 Robert Futrell
* email@address.com
* www.website.com
*
* 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 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 org.fife.ui.propertysheet.renderers;
import java.awt.Component;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.geom.Rectangle2D;
import javax.swing.JTable;
import javax.swing.UIManager;
import javax.swing.border.Border;
import javax.swing.table.DefaultTableCellRenderer;
import org.fife.ui.propertysheet.PropertySheetUtilities;
/**
* Renderer for category rows.
*
* @author Robert Futrell
* @version 1.0
*/
public class CategoryNameCellRenderer extends DefaultTableCellRenderer {
/**
*
*/
private static final long serialVersionUID = 2185075561403410267L;
private Font cachedTableFont;
private Font cachedBoldFont;
private boolean paintBottomLine;
/*****************************************************************************/
/**
* Returns the component with which to renderer category rows.
*/
public Component getTableCellRendererComponent(JTable table, Object value,
boolean isSelected, boolean hasFocus, int row, int column) {
setBackground(PropertySheetUtilities.getBorderColor());
setForeground(table.getForeground());
// We must jump through hoops for the font as super's implementation
// sets the font too. We want to keep it bold, but try to prevent
// from making the deriveFont() call unless we have to.
Font tableFont = table.getFont();
if (!tableFont.equals(cachedTableFont)) {
cachedTableFont = tableFont;
cachedBoldFont = cachedTableFont.deriveFont(Font.BOLD);
}
setFont(cachedBoldFont);
// Don't set a value (text) for column 1 as it contains a Boolean
// specifying our collapsed/expanded state.
if (column==0) {
setValue(value);
setBorder(hasFocus ?
UIManager.getBorder("Table.focusCellHighlightBorder") :
noFocusBorder);
}
else { // column==1.
setValue(null);
setBorder(null);
}
setForeground(PropertySheetUtilities.getBorderColor().darker());
Object bool = table.getValueAt(row,1);
if (bool instanceof Boolean)
paintBottomLine = ((Boolean)bool).booleanValue() &&
row<table.getRowCount()-1;
else
paintBottomLine = false;
return this;
}
/*****************************************************************************/
/**
* Paints the border for this renderer. This method is overridden so that
* the border is painted to be only the width of the text of the cell,
* to mimic property sheets found in Visual Studio.
*
* @param g The graphics context.
*/
protected void paintBorder(Graphics g) {
if (paintBottomLine) {
java.awt.Rectangle bounds = getBounds();
g.setColor(UIManager.getColor("Panel.background"));
int y = bounds.height - 1;
g.drawLine(0,y, bounds.width,y);
}
Border border = getBorder();
if (border!=null) {
String text = getText();
Rectangle2D bounds = this.getFontMetrics(cachedBoldFont).
getStringBounds(text, g);
int width = (int)bounds.getWidth() + 2; // Fudge factor.
border.paintBorder(this, g, 0,0, width,getHeight());
}
}
/*****************************************************************************/
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -