KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > finalist > jaggenerator > JagTreeCellRenderer


1 /* Copyright (C) 2003 Finalist IT Group
2  *
3  * This file is part of JAG - the Java J2EE Application Generator
4  *
5  * JAG is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  * JAG is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  * You should have received a copy of the GNU General Public License
14  * along with JAG; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16  */

17
18 package com.finalist.jaggenerator;
19
20 import com.finalist.jaggenerator.modules.*;
21
22 import javax.swing.tree.DefaultTreeCellRenderer JavaDoc;
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 JavaDoc {
32    ImageIcon relationIcon;
33    ImageIcon entityIcon;
34    ImageIcon associationEntityIcon;
35    ImageIcon sessionIcon;
36    ImageIcon configIcon;
37    ImageIcon rootIcon;
38    ImageIcon businessMethodIcon;
39    ImageIcon fieldIcon;
40    ImageIcon pkFieldIcon;
41
42    public JagTreeCellRenderer() {
43       relationIcon = new ImageIcon("../images/relation.png");
44       entityIcon = new ImageIcon("../images/entity.png");
45       associationEntityIcon = new ImageIcon("../images/associationEntity.png");
46       sessionIcon = new ImageIcon("../images/session.png");
47       configIcon = new ImageIcon("../images/config.png");
48       rootIcon = new ImageIcon("../images/root.png");
49       businessMethodIcon = new ImageIcon("../images/business.png");
50       fieldIcon = new ImageIcon("../images/field.png");
51       pkFieldIcon = new ImageIcon("../images/pkfield.png");
52    }
53
54    public Component getTreeCellRendererComponent(JTree tree,
55                                                  Object JavaDoc value,
56                                                  boolean sel,
57                                                  boolean expanded,
58                                                  boolean leaf,
59                                                  int row,
60                                                  boolean hasFocus) {
61       super.getTreeCellRendererComponent(tree, value, sel,
62                                          expanded, leaf, row,
63                                          hasFocus);
64       super.setIcon(rootIcon);
65
66       if (leaf && value instanceof Relation) {
67          setIcon(relationIcon);
68       }
69        if (leaf && value instanceof BusinessMethod) {
70           setIcon(businessMethodIcon);
71        }
72       else if (value instanceof Entity) {
73          if ("true".equals(((Entity) value).getIsAssociationEntity())) {
74             setIcon(associationEntityIcon);
75          } else {
76             setIcon(entityIcon);
77          }
78       }
79       else if (value instanceof Session) {
80          setIcon(sessionIcon);
81       }
82       else if (leaf && value instanceof Config) {
83          setIcon(configIcon);
84       }
85       else if (leaf && value instanceof App) {
86          setIcon(configIcon);
87       }
88       else if (leaf && value instanceof Datasource) {
89          setIcon(configIcon);
90       }
91       else if (leaf && value instanceof Paths) {
92          setIcon(configIcon);
93       }
94       else if (leaf && value instanceof Field) {
95          if ( ((Field) value).isPrimaryKey() ) {
96             setIcon(pkFieldIcon);
97          } else {
98             setIcon(fieldIcon);
99          }
100       }
101       return this;
102    }
103
104 }
105
Popular Tags