1 package org.wcb.common;
2
3 import javax.swing.*;
4 import javax.swing.border.Border;
5 import javax.swing.table.TableCellRenderer;
6 import java.awt.*;
7
8 /***
9 * Copyright (C) 2003 Walter Bogaardt
10 *
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation; either
14 * version 2 of the License, or (at your option) any later version.
15 *
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
20 *
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with this library; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
24 *
25 * Project: Home Automation Interface
26 *
27 * Abstract: User Interface options dialog box
28 * Filename: $Id: ColorCellRender.java,v 1.2 2003/12/30 22:15:59 wbogaardt Exp $
29 *
30 * * $Log: ColorCellRender.java,v $
31 * * Revision 1.2 2003/12/30 22:15:59 wbogaardt
32 * * added javadoc comments
33 * *
34 */
35
36 public class ColorCellRender extends JLabel implements TableCellRenderer {
37 Border unselectedBorder = null;
38 Border selectedBorder = null;
39 boolean isBordered = true;
40
41 public ColorCellRender(boolean isBordered) {
42 super();
43 this.isBordered = isBordered;
44 setOpaque(true);
45 }
46
47 public Component getTableCellRendererComponent(
48 JTable table, Object color,
49 boolean isSelected, boolean hasFocus,
50 int row, int column) {
51 super.setBackground((Color)color);
52 if (isBordered)
53 {
54 if (isSelected)
55 {
56 if (selectedBorder == null)
57 {
58 selectedBorder = BorderFactory.createMatteBorder(2,5,2,5,
59 table.getSelectionBackground());
60 }
61 setBorder(selectedBorder);
62 }
63 else
64 {
65 if (unselectedBorder == null)
66 {
67 unselectedBorder = BorderFactory.createMatteBorder(2,5,2,5,
68 table.getBackground());
69 }
70 setBorder(unselectedBorder);
71 }
72 }
73 return this;
74 }
75 }