1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package com.finalist.jaggenerator;
19
20 import com.finalist.jaggenerator.modules.*;
21
22 import javax.swing.tree.DefaultTreeCellRenderer;
23 import javax.swing.*;
24 import java.awt.*;
25
26 /***
27 * A custom TreeCellRenderer that uses a different icons for the various JAG objects.
28 *
29 * @author Michael O'Connor - Finalist IT Group
30 */
31 public class JagTreeCellRenderer extends DefaultTreeCellRenderer {
32 ImageIcon relationIcon;
33 ImageIcon entityIcon;
34 ImageIcon sessionIcon;
35 ImageIcon configIcon;
36 ImageIcon rootIcon;
37 ImageIcon businessMethodIcon;
38 ImageIcon fieldIcon;
39 ImageIcon pkFieldIcon;
40
41 public JagTreeCellRenderer() {
42 relationIcon = new ImageIcon("../images/relation.png");
43 entityIcon = new ImageIcon("../images/entity.png");
44 sessionIcon = new ImageIcon("../images/session.png");
45 configIcon = new ImageIcon("../images/config.png");
46 rootIcon = new ImageIcon("../images/root.png");
47 businessMethodIcon = new ImageIcon("../images/business.png");
48 fieldIcon = new ImageIcon("../images/field.png");
49 pkFieldIcon = new ImageIcon("../images/pkfield.png");
50 }
51
52 public Component getTreeCellRendererComponent(JTree tree,
53 Object value,
54 boolean sel,
55 boolean expanded,
56 boolean leaf,
57 int row,
58 boolean hasFocus) {
59 super.getTreeCellRendererComponent(tree, value, sel,
60 expanded, leaf, row,
61 hasFocus);
62 super.setIcon(rootIcon);
63
64 if (leaf && value instanceof Relation) {
65 setIcon(relationIcon);
66 }
67 if (leaf && value instanceof BusinessMethod) {
68 setIcon(businessMethodIcon);
69 }
70 else if (value instanceof Entity) {
71 setIcon(entityIcon);
72 }
73 else if (value instanceof Session) {
74 setIcon(sessionIcon);
75 }
76 else if (leaf && value instanceof Config) {
77 setIcon(configIcon);
78 }
79 else if (leaf && value instanceof App) {
80 setIcon(configIcon);
81 }
82 else if (leaf && value instanceof Datasource) {
83 setIcon(configIcon);
84 }
85 else if (leaf && value instanceof Paths) {
86 setIcon(configIcon);
87 }
88 else if (leaf && value instanceof Field) {
89 if ( ((Field) value).isPrimaryKey() ) {
90 setIcon(pkFieldIcon);
91 } else {
92 setIcon(fieldIcon);
93 }
94 }
95 return this;
96 }
97
98 }