1 package sk.stuba.fiit.foo07.genex.gui;
2
3 import java.awt.Color;
4 import java.awt.Component;
5
6 import javax.swing.JProgressBar;
7 import javax.swing.JTable;
8 import javax.swing.table.TableCellRenderer;
9
10 public class ProgressCellRenderer extends JProgressBar implements
11 TableCellRenderer {
12
13
14
15
16 private static final long serialVersionUID = -3016786372481872199L;
17
18 private static Color[] colors = { Color.WHITE, Color.GREEN, Color.YELLOW,
19 Color.BLUE, Color.MAGENTA, Color.RED };
20
21 public ProgressCellRenderer() {
22 super(0, 5);
23 setIntegerValue(1);
24 setStringPainted(true);
25 setBackground(new Color(255, 255, 240));
26 setBorderPainted(false);
27 }
28
29 public void setIntegerValue(Integer value) {
30 super.setValue(value);
31
32 if (value == -1)
33 setString("KAT");
34 else {
35 setString(value.toString());
36 setForeground(colors[value]);
37 }
38 }
39
40 public Component getTableCellRendererComponent(JTable table, Object value,
41 boolean isSelected, boolean hasFocus, int row, int column) {
42 Integer val = (Integer) value;
43 setIntegerValue(val);
44
45 return this;
46 }
47 }