01: /* Copyright (C) 2003 Finalist IT Group
02: *
03: * This file is part of JAG - the Java J2EE Application Generator
04: *
05: * JAG is free software; you can redistribute it and/or modify
06: * it under the terms of the GNU General Public License as published by
07: * the Free Software Foundation; either version 2 of the License, or
08: * (at your option) any later version.
09: * 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;
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 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(
46: "../images/associationEntity.png");
47: sessionIcon = new ImageIcon("../images/session.png");
48: configIcon = new ImageIcon("../images/config.png");
49: rootIcon = new ImageIcon("../images/root.png");
50: businessMethodIcon = new ImageIcon("../images/business.png");
51: fieldIcon = new ImageIcon("../images/field.png");
52: pkFieldIcon = new ImageIcon("../images/pkfield.png");
53: }
54:
55: public Component getTreeCellRendererComponent(JTree tree,
56: Object value, boolean sel, boolean expanded, boolean leaf,
57: int row, boolean hasFocus) {
58: super .getTreeCellRendererComponent(tree, value, sel, expanded,
59: leaf, row, hasFocus);
60: super .setIcon(rootIcon);
61:
62: if (leaf && value instanceof Relation) {
63: setIcon(relationIcon);
64: }
65: if (leaf && value instanceof BusinessMethod) {
66: setIcon(businessMethodIcon);
67: } else if (value instanceof Entity) {
68: if ("true"
69: .equals(((Entity) value).getIsAssociationEntity())) {
70: setIcon(associationEntityIcon);
71: } else {
72: setIcon(entityIcon);
73: }
74: } else if (value instanceof Session) {
75: setIcon(sessionIcon);
76: } else if (leaf && value instanceof Config) {
77: setIcon(configIcon);
78: } else if (leaf && value instanceof App) {
79: setIcon(configIcon);
80: } else if (leaf && value instanceof Datasource) {
81: setIcon(configIcon);
82: } else if (leaf && value instanceof Paths) {
83: setIcon(configIcon);
84: } else if (leaf && value instanceof Field) {
85: if (((Field) value).isPrimaryKey()) {
86: setIcon(pkFieldIcon);
87: } else {
88: setIcon(fieldIcon);
89: }
90: }
91: return this;
92: }
93:
94: }
|