1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 package org.apache.log4j.chainsaw;
25
26 import javax.swing.*;
27 import javax.swing.table.TableCellEditor;
28 import java.awt.*;
29 import java.awt.event.ActionEvent;
30 import java.awt.event.ActionListener;
31
32
33
34
35
36
37
38
39 class ThrowableRenderPanel extends AbstractCellEditor
40 implements TableCellEditor {
41 private final SmallButton btn = new SmallButton();
42 private final JLabel lbl = new JLabel("");
43 private final JPanel panel = new JPanel();
44 private Color background = new Color(255, 255, 254);
45 private final Color COLOR_ODD = new Color(230, 230, 230);
46 private final Action showStackTraceAction;
47
48 ThrowableRenderPanel() {
49 panel.setLayout(new BorderLayout());
50 panel.add(lbl, BorderLayout.CENTER);
51 panel.add(btn, BorderLayout.EAST);
52 lbl.setOpaque(false);
53
54 showStackTraceAction =
55 new AbstractAction("...") {
56 public void actionPerformed(ActionEvent e) {
57 }
58 };
59 showStackTraceAction.putValue(
60 Action.SHORT_DESCRIPTION, "Display the full stack trace in a popup");
61 btn.setAction(showStackTraceAction);
62 }
63
64 void addActionListener(ActionListener l) {
65 btn.addActionListener(l);
66 }
67
68
69
70
71 public Component getTableCellEditorComponent(
72 JTable table, Object value, boolean isSelected, int row, int column) {
73 if (value instanceof String[] && ((String[]) value).length > 0) {
74 lbl.setText(((String[]) value)[0]);
75 } else {
76 lbl.setText("");
77 }
78
79 if (isSelected) {
80 panel.setBackground(table.getSelectionBackground());
81 panel.setForeground(table.getSelectionForeground());
82 } else if ((row % 2) != 0) {
83 panel.setBackground(COLOR_ODD);
84 panel.setForeground(table.getSelectionForeground());
85 } else {
86 panel.setBackground(background);
87 panel.setForeground(table.getSelectionForeground());
88 }
89
90 return panel;
91 }
92
93
94
95
96 public Object getCellEditorValue() {
97 return lbl.getText();
98 }
99 }