View Javadoc

1   /**
2    * The contents of this file are subject to the Mozilla Public License Version 1.1
3    * (the "License"); you may not use this file except in compliance with the License.
4    * You may obtain a copy of the License at http://www.mozilla.org/MPL/
5    * Software distributed under the License is distributed on an "AS IS" basis,
6    * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the
7    * specific language governing rights and limitations under the License.
8    *
9    * The Original Code is ""  Description:
10   * ""
11   *
12   * The Initial Developer of the Original Code is University Health Network. Copyright (C)
13   * 2001.  All Rights Reserved.
14   *
15   * Contributor(s): ______________________________________.
16   *
17   * Alternatively, the contents of this file may be used under the terms of the
18   * GNU General Public License (the  "GPL"), in which case the provisions of the GPL are
19   * applicable instead of those above.  If you wish to allow use of your version of this
20   * file only under the terms of the GPL and not to allow others to use your version
21   * of this file under the MPL, indicate your decision by deleting  the provisions above
22   * and replace  them with the notice and other provisions required by the GPL License.
23   * If you do not delete the provisions above, a recipient may use your version of
24   * this file under either the MPL or the GPL.
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  	 * @param theHl7v2MessageTree
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 }