View Javadoc

1   package ca.uhn.hl7v2.testpanel.ui.conf;
2   
3   import java.awt.Color;
4   import java.awt.Component;
5   
6   import javax.swing.JTree;
7   import javax.swing.tree.DefaultMutableTreeNode;
8   import javax.swing.tree.DefaultTreeCellRenderer;
9   
10  import ca.uhn.hl7v2.testpanel.model.conf.Table;
11  import ca.uhn.hl7v2.testpanel.model.conf.TableFile;
12  import ca.uhn.hl7v2.testpanel.ui.ImageFactory;
13  
14  public class TableTreeRenderer extends DefaultTreeCellRenderer {
15  
16  	@Override
17  	public Component getTreeCellRendererComponent(JTree theTree, Object theValue, boolean theSel, boolean theExpanded, boolean theLeaf, int theRow, boolean theHasFocus) {
18  		super.getTreeCellRendererComponent(theTree, theValue, theSel, theExpanded, theLeaf, theRow, theHasFocus);
19  		
20  		StringBuilder b = new StringBuilder();
21  		b.append("<html>");
22  		
23  		if (!theHasFocus) {
24  			setBackground(Color.white);
25  		}
26  		
27  		Object obj = ((DefaultMutableTreeNode)theValue).getUserObject();
28  		if (obj instanceof TableFile) {
29  			TableFile tf = (TableFile)obj;
30  			b.append("Table File: ");
31  			b.append(tf.getName());
32  			b.append(" (");
33  			b.append(tf.getFileName());
34  			b.append(")");
35  			setIcon(ImageFactory.getFile());
36  		} else if (obj instanceof Table) {
37  			Table t = (Table)obj;
38  			b.append(t.getCodeSystemName());
39  			b.append(" (");
40  			b.append(t.getCodeSystemId());
41  			b.append(") ");
42  			b.append(t.getCodes().size());
43  			b.append(" code");
44  			if (t.getCodes().size() != 1) {
45  				b.append('s');
46  			}
47  			setIcon(ImageFactory.getTable());
48  		} else {
49  			setIcon(null);
50  		}
51  		
52  		b.append("</html>");
53  		setText(b.toString());
54  		
55  		return this;
56  	}
57  
58  }