1 package com.melloware.jukes.gui.view.component;
2
3 import java.awt.Component;
4
5 import javax.swing.Icon;
6 import javax.swing.JLabel;
7 import javax.swing.JList;
8 import javax.swing.ListCellRenderer;
9
10 import com.jgoodies.validation.Severity;
11 import com.jgoodies.validation.view.ValidationResultViewFactory;
12 import com.melloware.jukes.util.JukesValidationMessage;
13
14
15
16
17
18
19
20
21
22 public final class MessageCellRenderer
23 extends JLabel
24 implements ListCellRenderer {
25
26
27
28
29 public MessageCellRenderer() {
30 super();
31 }
32
33
34
35
36
37
38 public MessageCellRenderer(final String aText) {
39 super(aText);
40 }
41
42
43
44
45
46
47
48 public MessageCellRenderer(final String aText, final Icon aIcon) {
49 super(aText);
50 this.setIcon(aIcon);
51 }
52
53
54
55
56
57
58
59
60
61 public static Icon getIcon(final Severity severity) {
62 if (severity == Severity.ERROR) {
63 return ValidationResultViewFactory.getErrorIcon();
64 } else if (severity == Severity.WARNING) {
65 return ValidationResultViewFactory.getWarningIcon();
66 } else if (severity == Severity.OK) {
67 return ValidationResultViewFactory.getCheckIcon();
68 } else {
69 return null;
70 }
71 }
72
73
74
75
76
77 public Component getListCellRendererComponent(final JList list,
78 final Object value,
79 final int index,
80 final boolean isSelected,
81 final boolean cellHasFocus) {
82
83 final JukesValidationMessage message = (JukesValidationMessage)value;
84 this.setIcon(MessageCellRenderer.getIcon(message.severity()));
85 this.setText(message.formattedText());
86 this.setToolTipText(message.getToolTip());
87 if (isSelected) {
88 setBackground(list.getSelectionBackground());
89 setForeground(list.getSelectionForeground());
90 } else {
91 setBackground(list.getBackground());
92 setForeground(list.getForeground());
93 }
94 setEnabled(list.isEnabled());
95 setFont(list.getFont());
96 setOpaque(true);
97 return this;
98 }
99
100 }