01: package org.gui4j.core.swing;
02:
03: /**
04: * MultiLineCellRenderer.java
05: *
06: * Created: Mon May 17 09:41:53 1999
07: *
08: * @author Thomas Wernitz, Da Vinci Communications Ltd <thomas_wernitz@clear.net.nz>
09: *
10: * credit to Zafir Anjum for JTableEx and thanks to SUN for their source code ;)
11: */
12:
13: import javax.swing.*;
14: import javax.swing.table.TableCellRenderer;
15: import javax.swing.border.*;
16:
17: import java.awt.Component;
18: import java.awt.Color;
19:
20: import java.io.Serializable;
21:
22: public class MultiLineCellRenderer extends JTextArea implements
23: TableCellRenderer, Serializable {
24:
25: protected static Border noFocusBorder;
26:
27: private Color unselectedForeground;
28: private Color unselectedBackground;
29:
30: public MultiLineCellRenderer() {
31: super ();
32: noFocusBorder = new EmptyBorder(1, 2, 1, 2);
33: setLineWrap(true);
34: setWrapStyleWord(true);
35: setOpaque(true);
36: setBorder(noFocusBorder);
37: }
38:
39: public void setForeground(Color c) {
40: super .setForeground(c);
41: unselectedForeground = c;
42: }
43:
44: public void setBackground(Color c) {
45: super .setBackground(c);
46: unselectedBackground = c;
47: }
48:
49: public void updateUI() {
50: super .updateUI();
51: setForeground(null);
52: setBackground(null);
53: }
54:
55: public Component getTableCellRendererComponent(JTable table,
56: Object value, boolean isSelected, boolean hasFocus,
57: int row, int column) {
58:
59: if (isSelected) {
60: super .setForeground(table.getSelectionForeground());
61: super .setBackground(table.getSelectionBackground());
62: } else {
63: super
64: .setForeground((unselectedForeground != null) ? unselectedForeground
65: : table.getForeground());
66: super
67: .setBackground((unselectedBackground != null) ? unselectedBackground
68: : table.getBackground());
69: }
70:
71: setFont(table.getFont());
72:
73: if (hasFocus) {
74: setBorder(UIManager
75: .getBorder("Table.focusCellHighlightBorder"));
76: if (table.isCellEditable(row, column)) {
77: super .setForeground(UIManager
78: .getColor("Table.focusCellForeground"));
79: super .setBackground(UIManager
80: .getColor("Table.focusCellBackground"));
81: }
82: } else {
83: setBorder(noFocusBorder);
84: }
85:
86: setValue(value);
87:
88: return this ;
89: }
90:
91: protected void setValue(Object value) {
92: setText((value == null) ? "" : value.toString());
93: }
94:
95: public static class UIResource extends MultiLineCellRenderer
96: implements javax.swing.plaf.UIResource {
97: }
98:
99: }
|