KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > gjt > jclasslib > browser > detail > AttributeDetailPane


1 /*
2     This library is free software; you can redistribute it and/or
3     modify it under the terms of the GNU General Public
4     License as published by the Free Software Foundation; either
5     version 2 of the license, or (at your option) any later version.
6 */

7
8 package org.gjt.jclasslib.browser.detail;
9
10 import org.gjt.jclasslib.browser.AbstractDetailPane;
11 import org.gjt.jclasslib.browser.BrowserServices;
12 import org.gjt.jclasslib.browser.detail.attributes.*;
13 import org.gjt.jclasslib.structures.AttributeInfo;
14 import org.gjt.jclasslib.structures.attributes.*;
15
16 import javax.swing.*;
17 import javax.swing.border.Border JavaDoc;
18 import javax.swing.tree.TreePath JavaDoc;
19 import java.awt.*;
20 import java.util.HashMap JavaDoc;
21
22 /**
23  * Detail pane for an attribute of class <tt>org.gjt.jclasslib.structures.AttributeInfo</tt>.
24  * This class is a container for the classes defined in the <tt>attributes</tt>
25  * subpackage and switches between the contained panes as required.
26  *
27  * @author <a HREF="mailto:jclasslib@ej-technologies.com">Ingo Kegel</a>
28  * @version $Revision: 1.6 $ $Date: 2004/12/28 13:04:31 $
29  */

30 public class AttributeDetailPane extends AbstractDetailPane {
31
32     private static final String JavaDoc SCREEN_UNKNOWN = "Unknown";
33     private static final String JavaDoc SCREEN_CONSTANT_VALUE = "ConstantValue";
34     private static final String JavaDoc SCREEN_CODE = "Code";
35     private static final String JavaDoc SCREEN_EXCEPTIONS = "Exceptions";
36     private static final String JavaDoc SCREEN_INNER_CLASSES = "InnerClasses";
37     private static final String JavaDoc SCREEN_SOURCE_FILE = "SourceFile";
38     private static final String JavaDoc SCREEN_LINE_NUMBER_TABLE = "LineNumberTable";
39     private static final String JavaDoc SCREEN_LOCAL_VARIABLE_TABLE = "LocalVariableTable";
40     private static final String JavaDoc SCREEN_ENCLOSING_METHOD = "EnclosingMethod";
41     private static final String JavaDoc SCREEN_SIGNATURE = "Signature";
42     private static final String JavaDoc SCREEN_LOCAL_VARIABLE_TYPE_TABLE = "LocalVariableTypeTable";
43     private static final String JavaDoc SCREEN_RUNTIME_ANNOTATIONS = "RuntimeAnnotations";
44     private static final String JavaDoc SCREEN_ANNOTATION_DEFAULT = "AnnotationDefault";
45
46     private HashMap JavaDoc attributeTypeToDetailPane;
47     
48     // Visual components
49

50     private JPanel specificInfoPane;
51     private GenericAttributeDetailPane genericInfoPane;
52
53     /**
54      * Constructor.
55      *
56      * @param services the associated browser services.
57      */

58     public AttributeDetailPane(BrowserServices services) {
59         super(services);
60     }
61
62     protected void setupComponent() {
63
64         buildGenericInfoPane();
65         buildSpecificInfoPane();
66
67         setLayout(new BorderLayout());
68
69         add(genericInfoPane, BorderLayout.NORTH);
70         add(specificInfoPane, BorderLayout.CENTER);
71
72     }
73
74     public void show(TreePath JavaDoc treePath) {
75
76         AttributeInfo attribute = findAttribute(treePath);
77
78         String JavaDoc paneName = null;
79         if (attribute instanceof ConstantValueAttribute) {
80             paneName = SCREEN_CONSTANT_VALUE;
81         } else if (attribute instanceof CodeAttribute) {
82             paneName = SCREEN_CODE;
83         } else if (attribute instanceof ExceptionsAttribute) {
84             paneName = SCREEN_EXCEPTIONS;
85         } else if (attribute instanceof InnerClassesAttribute) {
86             paneName = SCREEN_INNER_CLASSES;
87         } else if (attribute instanceof SourceFileAttribute) {
88             paneName = SCREEN_SOURCE_FILE;
89         } else if (attribute instanceof LineNumberTableAttribute) {
90             paneName = SCREEN_LINE_NUMBER_TABLE;
91         } else if (attribute instanceof LocalVariableTableAttribute) {
92             paneName = SCREEN_LOCAL_VARIABLE_TABLE;
93         } else if (attribute instanceof EnclosingMethodAttribute) {
94             paneName = SCREEN_ENCLOSING_METHOD;
95         } else if (attribute instanceof SignatureAttribute) {
96             paneName = SCREEN_SIGNATURE;
97         } else if (attribute instanceof LocalVariableTypeTableAttribute) {
98             paneName = SCREEN_LOCAL_VARIABLE_TYPE_TABLE;
99         } else if (attribute instanceof RuntimeAnnotationsAttribute) {
100             paneName = SCREEN_RUNTIME_ANNOTATIONS;
101         } else if (attribute instanceof AnnotationDefaultAttribute) {
102             paneName = SCREEN_ANNOTATION_DEFAULT;
103         }
104
105         CardLayout layout = (CardLayout)specificInfoPane.getLayout();
106         if (paneName == null) {
107             layout.show(specificInfoPane, SCREEN_UNKNOWN);
108         } else {
109             AbstractDetailPane pane = (AbstractDetailPane)attributeTypeToDetailPane.get(paneName);
110             pane.show(treePath);
111             layout.show(specificInfoPane, paneName);
112         }
113
114         genericInfoPane.show(treePath);
115     }
116
117     /**
118      * Get the <tt>CodeAttributeDetailPane</tt> showing the details of a
119      * <tt>Code</tt> attribute.
120      *
121      * @return the <tt>CodeAttributeDetailPane</tt>
122      */

123     public CodeAttributeDetailPane getCodeAttributeDetailPane() {
124         return (CodeAttributeDetailPane)attributeTypeToDetailPane.get(SCREEN_CODE);
125     }
126
127     private void buildGenericInfoPane() {
128
129         genericInfoPane = new GenericAttributeDetailPane(services);
130         genericInfoPane.setBorder(createTitledBorder("Generic info:"));
131     }
132
133     private void buildSpecificInfoPane() {
134
135         specificInfoPane = new JPanel();
136         specificInfoPane.setBorder(createTitledBorder("Specific info:"));
137
138         specificInfoPane.setLayout(new CardLayout());
139         attributeTypeToDetailPane = new HashMap JavaDoc();
140         JPanel pane;
141
142         pane = new JPanel();
143         specificInfoPane.add(pane, SCREEN_UNKNOWN);
144
145         addScreen(new ConstantValueAttributeDetailPane(services),
146                 SCREEN_CONSTANT_VALUE);
147
148         addScreen(new CodeAttributeDetailPane(services),
149                 SCREEN_CODE);
150
151         addScreen(new ExceptionsAttributeDetailPane(services),
152                 SCREEN_EXCEPTIONS);
153
154         addScreen(new InnerClassesAttributeDetailPane(services),
155                 SCREEN_INNER_CLASSES);
156
157         addScreen(new SourceFileAttributeDetailPane(services),
158                 SCREEN_SOURCE_FILE);
159
160         addScreen(new LineNumberTableAttributeDetailPane(services),
161                 SCREEN_LINE_NUMBER_TABLE);
162
163         addScreen(new LocalVariableTableAttributeDetailPane(services),
164                 SCREEN_LOCAL_VARIABLE_TABLE);
165
166         addScreen(new EnclosingMethodAttributeDetailPane(services),
167                 SCREEN_ENCLOSING_METHOD);
168
169         addScreen(new SignatureAttributeDetailPane(services),
170                 SCREEN_SIGNATURE);
171
172         addScreen(new LocalVariableTypeTableAttributeDetailPane(services),
173                 SCREEN_LOCAL_VARIABLE_TYPE_TABLE);
174
175         addScreen(new RuntimeAnnotationsAttributeDetailPane(services),
176                 SCREEN_RUNTIME_ANNOTATIONS);
177
178         addScreen(new AnnotationDefaultAttributeDetailPane(services),
179                 SCREEN_ANNOTATION_DEFAULT);
180     }
181
182     private void addScreen(AbstractDetailPane detailPane, String JavaDoc name) {
183
184         if (detailPane instanceof FixedListDetailPane) {
185             specificInfoPane.add(((FixedListDetailPane)detailPane).getScrollPane(), name);
186         } else {
187             specificInfoPane.add(detailPane, name);
188         }
189         attributeTypeToDetailPane.put(name, detailPane);
190     }
191
192     private Border JavaDoc createTitledBorder(String JavaDoc title) {
193         Border JavaDoc simpleBorder = BorderFactory.createEtchedBorder();
194         Border JavaDoc titledBorder = BorderFactory.createTitledBorder(simpleBorder, title);
195
196         return titledBorder;
197     }
198 }
199
200
Popular Tags