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  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  	 * (non-Javadoc)
48  	 * 
49  	 * @see
50  	 * javax.swing.DefaultCellEditor#getTreeCellEditorComponent(javax.swing.
51  	 * JTree, java.lang.Object, boolean, boolean, boolean, int)
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  	 * (non-Javadoc)
72  	 * 
73  	 * @see
74  	 * javax.swing.DefaultCellEditor#getTableCellEditorComponent(javax.swing
75  	 * .JTable, java.lang.Object, boolean, int, int)
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  }