View Javadoc

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;
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  }