001: package org.swingml.tablebrowser.rowheader;
002:
003: import java.awt.*;
004:
005: import javax.swing.*;
006: import javax.swing.border.*;
007: import javax.swing.plaf.*;
008: import javax.swing.table.*;
009:
010: public class RowHeaderRenderer extends DefaultTableCellRenderer
011: implements ListCellRenderer {
012:
013: protected Border localNoFocusBorder, localFocusBorder;
014:
015: public RowHeaderRenderer() {
016: setOpaque(true);
017: setBorder(localNoFocusBorder);
018: }
019:
020: public Component getListCellRendererComponent(JList list,
021: Object value, int index, boolean selected, boolean focused) {
022: if (list != null) {
023: if (selected) {
024: setBackground(list.getSelectionBackground());
025: setForeground(list.getSelectionForeground());
026: } else {
027: setBackground(list.getBackground());
028: setForeground(list.getForeground());
029: }
030:
031: setFont(list.getFont());
032:
033: setEnabled(list.isEnabled());
034: } else {
035: setBackground(UIManager.getColor("TableHeader.background"));
036: setForeground(UIManager.getColor("TableHeader.foreground"));
037: setFont(UIManager.getFont("TableHeader.font"));
038: setEnabled(true);
039: }
040:
041: if (focused)
042: setBorder(localFocusBorder);
043: else
044: setBorder(localNoFocusBorder);
045:
046: setValue(value);
047:
048: return this ;
049: }
050:
051: public Component getTableCellRendererComponent(JTable table,
052: Object value, boolean selected, boolean focused, int row,
053: int column) {
054: if (table != null) {
055: if (selected) {
056: setBackground(table.getSelectionBackground());
057: setForeground(table.getSelectionForeground());
058: } else {
059: setBackground(table.getBackground());
060: setForeground(table.getForeground());
061: }
062:
063: setFont(table.getFont());
064:
065: setEnabled(table.isEnabled());
066: } else {
067: setBackground(UIManager.getColor("TableHeader.background"));
068: setForeground(UIManager.getColor("TableHeader.foreground"));
069: setFont(UIManager.getFont("TableHeader.font"));
070: setEnabled(true);
071: }
072:
073: if (focused)
074: setBorder(localFocusBorder);
075: else
076: setBorder(localNoFocusBorder);
077:
078: setValue(value);
079:
080: return this ;
081: }
082:
083: public void updateUI() {
084: super .updateUI();
085: Border cell = UIManager.getBorder("TableHeader.cellBorder");
086: Border focus = UIManager
087: .getBorder("Table.focusCellHighlightBorder");
088:
089: localFocusBorder = new BorderUIResource.CompoundBorderUIResource(
090: cell, focus);
091: Insets i = focus.getBorderInsets(this );
092: localNoFocusBorder = new BorderUIResource.CompoundBorderUIResource(
093: cell, BorderFactory.createEmptyBorder(i.top, i.left,
094: i.bottom, i.right));
095:
096: /*
097: * Alternatively, if focus shouldn't be supported:
098: *
099: * focusBorder = noFocusBorder = cell;
100: *
101: */
102: }
103: }
|