1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 package ca.uhn.hl7v2.testpanel.ui.v2tree;
27
28 import java.awt.Component;
29
30 import javax.swing.JTable;
31 import javax.swing.table.DefaultTableCellRenderer;
32
33 import ca.uhn.hl7v2.testpanel.ui.v2tree.Hl7V2MessageTree.TreeNodeBase;
34 import ca.uhn.hl7v2.testpanel.ui.v2tree.Hl7V2MessageTree.TreeNodeGroupBase;
35 import ca.uhn.hl7v2.testpanel.ui.v2tree.Hl7V2MessageTree.TreeNodeSegment;
36 import ca.uhn.hl7v2.testpanel.ui.v2tree.Hl7V2MessageTree.TreeNodeType;
37 import ca.uhn.hl7v2.testpanel.util.FormatUtil;
38
39 class ValueCellRenderer extends DefaultTableCellRenderer {
40
41
42
43
44 private final Hl7V2MessageTree myTree;
45
46
47
48
49 ValueCellRenderer(Hl7V2MessageTree theHl7v2MessageTree) {
50 myTree = theHl7v2MessageTree;
51 }
52
53 @Override
54 public Component getTableCellRendererComponent(JTable theTable, Object theValue, boolean theIsSelected, boolean theHasFocus, int theRow, int theColumn) {
55 super.getTableCellRendererComponent(theTable, null, theIsSelected, theHasFocus, theRow, theColumn);
56
57 if (theValue == null) {
58
59 return this;
60
61 } else if (theValue instanceof TreeNodeGroupBase) {
62
63 TreeNodeGroupBase group = (TreeNodeGroupBase) theValue;
64 int segs = group.countPopulatedSegments();
65
66 switch (segs) {
67 case 0:
68 setText("<html><span style=\"color: #808080;\">(Empty)</span></html>");
69 break;
70 case 1:
71 setText("<html><span style=\"color: #808080;\">(" + segs + " populated segment)</span></html>");
72 break;
73 default:
74 setText("<html><span style=\"color: #808080;\">(" + segs + " populated segments)</span></html>");
75 break;
76 }
77
78 } else if (theValue instanceof TreeNodeType || theValue instanceof TreeNodeSegment) {
79 String value = ((TreeNodeBase) theValue).getPipeEncodedValue();
80
81 boolean isType = false;
82 if (theValue instanceof TreeNodeType) {
83 isType = true;
84 } else if (theValue instanceof TreeNodeSegment) {
85 if (!((TreeNodeSegment)theValue).isHasContent()) {
86 setText("<html><span style=\"color: #808080;\">" + value + "</span></html>");
87 setToolTipText(getText());
88 return this;
89 }
90 }
91
92 String html = FormatUtil.formatEr7(value, isType);
93 setText(html);
94
95 } else {
96
97 TreeNodeBase base = (TreeNodeBase) theValue;
98 setText(base.getPipeEncodedValue());
99
100 }
101
102 setToolTipText(getText());
103 return this;
104
105 }
106
107 }