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 import java.awt.Font;
30
31 import javax.swing.DefaultCellEditor;
32 import javax.swing.JTable;
33 import javax.swing.JTextField;
34 import javax.swing.JTree;
35
36 import ca.uhn.hl7v2.testpanel.ui.v2tree.Hl7V2MessageTree.TreeNodeSegment;
37 import ca.uhn.hl7v2.testpanel.ui.v2tree.Hl7V2MessageTree.TreeNodeType;
38
39 public class ValueCellEditor extends DefaultCellEditor {
40
41 public ValueCellEditor(Font theFont) {
42 super(createTextField(theFont));
43 setClickCountToStart(1);
44 }
45
46
47
48
49
50
51
52
53 @Override
54 public Component getTreeCellEditorComponent(JTree theTree, Object theValue, boolean theIsSelected, boolean theExpanded, boolean theLeaf, int theRow) {
55 theValue = convertValue(theValue);
56 return super.getTreeCellEditorComponent(theTree, theValue, theIsSelected, theExpanded, theLeaf, theRow);
57 }
58
59 private Object convertValue(Object theValue) {
60
61 if (theValue instanceof TreeNodeSegment) {
62 theValue = ((TreeNodeSegment) theValue).getPipeEncodedValue();
63 } else if (theValue instanceof TreeNodeType) {
64 theValue = ((TreeNodeType) theValue).getPipeEncodedValue();
65 }
66
67 return theValue;
68 }
69
70
71
72
73
74
75
76
77 @Override
78 public Component getTableCellEditorComponent(JTable theTable, Object theValue, boolean theIsSelected, int theRow, int theColumn) {
79 theValue = convertValue(theValue);
80 return super.getTableCellEditorComponent(theTable, theValue, theIsSelected, theRow, theColumn);
81 }
82
83 private static JTextField createTextField(Font theFont) {
84 JTextField field = new JTextField();
85 field.setFont(theFont);
86 return field;
87 }
88
89 }