1 package org.wcb.gui.renderer;
2
3 import org.wcb.model.vo.TotalLogEntriesVO;
4
5 import javax.swing.*;
6 import javax.swing.table.TableCellRenderer;
7 import java.awt.*;
8 import java.text.DecimalFormat;
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37 public class ColorRowsTableCellRender extends JLabel implements TableCellRenderer {
38
39 final DecimalFormat formatter = new DecimalFormat("###,##0.0");
40
41 private Color focusColor = new Color(51,139,204);
42 private Color evenRowColor = new Color(200,223,240);
43 private Color totalRowColor = new Color(0xfff695);
44 private Color oddRowColor = Color.WHITE;
45
46 public ColorRowsTableCellRender()
47 {
48 this.setOpaque(true);
49 }
50
51
52
53
54
55
56 public void setFocusColor(Color color) {
57 focusColor = color;
58 }
59
60
61
62
63
64 public void setEvenRowColor(Color color) {
65 evenRowColor = color;
66 }
67
68
69
70
71
72 public void setOddRowColor(Color color) {
73 oddRowColor = color;
74 }
75
76 public Component getTableCellRendererComponent(
77 JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column)
78 {
79 if(isSelected || hasFocus) {
80 setBackground(focusColor);
81 } else {
82 if(value instanceof TotalLogEntriesVO)
83 {
84 this.setText(value.toString());
85 setBackground(totalRowColor);
86 return this;
87 }
88 if(row%2 == 0)
89 {
90 setBackground(evenRowColor);
91
92 }
93 else
94 {
95 setBackground(oddRowColor);
96 }
97 }
98 if(value != null) {
99
100 if (value instanceof Double) {
101 this.setText(formatter.format(value));
102 }
103 else {
104 this.setText(value.toString());
105 }
106 } else {
107 this.setText("-");
108 }
109 this.setFont(table.getFont());
110 return this;
111 }
112 }