KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > aspectj > ajde > ui > swing > SwingTreeViewNodeRenderer


1
2 /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
3  *
4  * This file is part of the IDE support for the AspectJ(tm)
5  * programming language; see http://aspectj.org
6  *
7  * The contents of this file are subject to the Mozilla Public License
8  * Version 1.1 (the "License"); you may not use this file except in
9  * compliance with the License. You may obtain a copy of the License at
10  * either http://www.mozilla.org/MPL/ or http://aspectj.org/MPL/.
11  *
12  * Software distributed under the License is distributed on an "AS IS" basis,
13  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
14  * for the specific language governing rights and limitations under the
15  * License.
16  *
17  * The Original Code is AspectJ.
18  *
19  * The Initial Developer of the Original Code is Xerox Corporation. Portions
20  * created by Xerox Corporation are Copyright (C) 1999-2002 Xerox Corporation.
21  * All Rights Reserved.
22  *
23  * Contributor(s):
24  */

25
26 package org.aspectj.ajde.ui.swing;
27
28 import java.awt.*;
29 import java.util.*;
30 import javax.swing.*;
31 import javax.swing.tree.*;
32 import org.aspectj.asm.*;
33 import org.aspectj.ajde.*;
34 import org.aspectj.ajde.ui.*;
35
36 /**
37  * @author Mik Kersten
38  */

39 class SwingTreeViewNodeRenderer extends DefaultTreeCellRenderer {
40
41     public Component getTreeCellRendererComponent(JTree tree,
42                                                     Object JavaDoc treeNode,
43                                                     boolean sel,
44                                                     boolean expanded,
45                                                     boolean leaf,
46                                                     int row,
47                                                     boolean hasFocus) {
48         if (treeNode == null) return null;
49         SwingTreeViewNode viewNode = (SwingTreeViewNode)treeNode;
50         StructureNode node = viewNode.getStructureNode();
51
52         if (node instanceof LinkNode) {
53             if (((LinkNode)node).getProgramElementNode().getSourceLocation().getSourceFilePath() == null) {
54                 setTextNonSelectionColor(AjdeWidgetStyles.LINK_NODE_NO_SOURCE_COLOR);
55             } else {
56                 setTextNonSelectionColor(AjdeWidgetStyles.LINK_NODE_COLOR);
57             }
58         } else {
59             setTextNonSelectionColor(new Color(0, 0, 0));
60         }
61         
62         super.getTreeCellRendererComponent(tree, treeNode, sel, expanded, leaf, row, hasFocus);
63         this.setFont(StructureTree.DEFAULT_FONT);
64         
65         if (viewNode.getIcon() != null && viewNode.getIcon().getIconResource() != null) {
66             setIcon((Icon)viewNode.getIcon().getIconResource());
67         } else {
68             setIcon(null);
69         }
70         
71         if (node instanceof ProgramElementNode) {
72             ProgramElementNode pNode = (ProgramElementNode)node;
73             if (pNode.isRunnable()) {
74                 //setIcon(AjdeUIManager.getDefault().getIconRegistry().getExecuteIcon());
75
}
76             if (pNode.isImplementor()) {
77                 //this.setText("<implementor>");
78
}
79             if (pNode.isOverrider()) {
80                 //this.setText("<overrider>");
81
}
82         } else if (node instanceof RelationNode) {
83             this.setFont(new Font(this.getFont().getName(), Font.ITALIC, this.getFont().getSize()));
84         }
85
86         if (node.getMessage() != null) {
87             if (node.getMessage().getKind().equals(StructureMessage.Kind.WARNING)) {
88                 setIcon(AjdeUIManager.getDefault().getIconRegistry().getWarningIcon());
89             } else if (node.getMessage().getKind().equals(StructureMessage.Kind.ERROR)) {
90                 setIcon(AjdeUIManager.getDefault().getIconRegistry().getErrorIcon());
91             } else {
92                 setIcon(AjdeUIManager.getDefault().getIconRegistry().getInfoIcon());
93             }
94         }
95         
96         return this;
97     }
98 }
99
100
Popular Tags