001: // The contents of this file are subject to the Mozilla Public License Version
002: // 1.1
003: //(the "License"); you may not use this file except in compliance with the
004: //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
005: //
006: //Software distributed under the License is distributed on an "AS IS" basis,
007: //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
008: //for the specific language governing rights and
009: //limitations under the License.
010: //
011: //The Original Code is "The Columba Project"
012: //
013: //The Initial Developers of the Original Code are Frederik Dietz and Timo
014: // Stich.
015: //Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
016: //
017: //All Rights Reserved.
018: package org.columba.addressbook.gui.table.renderer;
019:
020: import java.awt.Color;
021: import java.awt.Component;
022:
023: import javax.swing.BorderFactory;
024: import javax.swing.JLabel;
025: import javax.swing.JTable;
026: import javax.swing.border.Border;
027: import javax.swing.table.TableCellRenderer;
028:
029: /**
030: * @author fdietz
031: */
032:
033: public class DefaultLabelRenderer extends JLabel implements
034: TableCellRenderer {
035: private Border unselectedBorder = null;
036: private Border selectedBorder = null;
037: private Color background;
038: private Color foreground;
039: private boolean isBordered = true;
040:
041: /**
042: * Constructor for DefaultLabelRenderer.
043: */
044: public DefaultLabelRenderer() {
045: super ();
046: }
047:
048: /**
049: * @see javax.swing.table.TableCellRenderer#getTableCellRendererComponent(javax.swing.JTable,
050: * java.lang.Object, boolean, boolean, int, int)
051: */
052: public Component getTableCellRendererComponent(JTable table,
053: Object value, boolean isSelected, boolean hasFocus,
054: int row, int column) {
055: if (isBordered) {
056: if (isSelected) {
057: if (selectedBorder == null) {
058: selectedBorder = BorderFactory.createMatteBorder(2,
059: 5, 2, 5, table.getSelectionBackground());
060: }
061:
062: //setBorder(selectedBorder);
063: setBackground(table.getSelectionBackground());
064: setForeground(table.getSelectionForeground());
065: } else {
066: if (unselectedBorder == null) {
067: unselectedBorder = BorderFactory.createMatteBorder(
068: 2, 5, 2, 5, table.getBackground());
069: }
070:
071: setBackground(table.getBackground());
072:
073: //setBorder(unselectedBorder);
074: setForeground(table.getForeground());
075: }
076: }
077:
078: return this ;
079: }
080:
081: public boolean isOpaque() {
082: return (background != null);
083: }
084:
085: /**
086: * Returns the background.
087: *
088: * @return Color
089: */
090: public Color getBackground() {
091: return background;
092: }
093:
094: /**
095: * Returns the foreground.
096: *
097: * @return Color
098: */
099: public Color getForeground() {
100: return foreground;
101: }
102:
103: /**
104: * Sets the background.
105: *
106: * @param background
107: * The background to set
108: */
109: public void setBackground(Color background) {
110: this .background = background;
111: }
112:
113: /**
114: * Sets the foreground.
115: *
116: * @param foreground
117: * The foreground to set
118: */
119: public void setForeground(Color foreground) {
120: this.foreground = foreground;
121: }
122: }
|