KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > gjt > jclasslib > browser > BrowserDetailPane


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;
9
10 import org.gjt.jclasslib.browser.detail.*;
11
12 import javax.swing.*;
13 import javax.swing.tree.TreePath JavaDoc;
14 import java.awt.*;
15 import java.util.HashMap JavaDoc;
16
17 /**
18  * The right half of a child window of the class file browser application
19  * showing detailed information for the specific tree node selected in
20  * <tt>BrowserTreePane</tt>.
21  *
22  * @author <a HREF="mailto:jclasslib@ej-technologies.com">Ingo Kegel</a>, <a HREF="mailto:vitor.carreira@gmail.com">Vitor Carreira</a>
23  * @version $Revision: 1.7 $ $Date: 2004/12/28 13:04:31 $
24  */

25 public class BrowserDetailPane extends JPanel {
26
27     private static final Dimension detailMinimumSize = new Dimension(150, 150);
28     private static final Dimension detailPreferredSize = new Dimension(150, 150);
29
30     private BrowserServices services;
31     private HashMap JavaDoc nodeTypeToDetailPane = new HashMap JavaDoc();
32
33     /**
34      * Constructor.
35      *
36      * @param services the associated browser services.
37      */

38     public BrowserDetailPane(BrowserServices services) {
39         this.services = services;
40         setupComponent();
41     }
42
43     /**
44      * Show details for the specific tree node selected in
45      * <tt>BrowserTreePane</tt>.
46      *
47      * @param nodeType the type of the node as defined in the <tt>NODE_</tt>
48      * constants in <tt>BrowserTreeNode</tt>
49      * @param treePath the tree path of the selected node
50      */

51     public void showPane(String JavaDoc nodeType, TreePath JavaDoc treePath) {
52         if (services.getClassFile() == null) {
53             return;
54         }
55         CardLayout layout = (CardLayout)getLayout();
56         AbstractDetailPane detailPane = (AbstractDetailPane)nodeTypeToDetailPane.get(nodeType);
57         if (detailPane != null) {
58             detailPane.show(treePath);
59         }
60
61         layout.show(this, nodeType);
62     }
63
64     /**
65      * Get the <tt>AttributeDetailPane</tt> detail pane associated with the
66      * node type <tt>BrowserTreeNode.NODE_ATTRIBUTE</tt>. This is necessary for
67      * hyperlinks within <tt>Code</tt> attributes.
68      *
69      * @return the <tt>AttributeDetailPane</tt>
70      */

71     public AttributeDetailPane getAttributeDetailPane() {
72         return (AttributeDetailPane)nodeTypeToDetailPane.get(BrowserTreeNode.NODE_ATTRIBUTE);
73     }
74
75     private void setupComponent() {
76
77         setLayout(new CardLayout());
78
79         add(new JPanel(), BrowserTreeNode.NODE_NO_CONTENT);
80
81         addScreen(new GeneralDetailPane(services),
82                 BrowserTreeNode.NODE_GENERAL);
83         addScreen(new ConstantPoolDetailPane(services),
84                 BrowserTreeNode.NODE_CONSTANT_POOL);
85         addScreen(new InterfaceDetailPane(services),
86                 BrowserTreeNode.NODE_INTERFACE);
87         addScreen(new ClassMemberDetailPane(services, ClassMemberDetailPane.FIELDS),
88                 BrowserTreeNode.NODE_FIELD);
89         addScreen(new ClassMemberDetailPane(services, ClassMemberDetailPane.METHODS),
90                 BrowserTreeNode.NODE_METHOD);
91         addScreen(new AttributeDetailPane(services),
92                 BrowserTreeNode.NODE_ATTRIBUTE);
93         addScreen(new AnnotationDetailPane(services),
94                 BrowserTreeNode.NODE_ANNOTATION);
95         addScreen(new ElementValueDetailPane(services),
96                 BrowserTreeNode.NODE_ELEMENTVALUE);
97         addScreen(new ElementValuePairDetailPane(services),
98                 BrowserTreeNode.NODE_ELEMENTVALUEPAIR);
99         addScreen(new ArrayElementValueDetailPane(services),
100                 BrowserTreeNode.NODE_ARRAYELEMENTVALUE);
101
102         setMinimumSize(detailMinimumSize);
103         setPreferredSize(detailPreferredSize);
104
105     }
106
107     private void addScreen(AbstractDetailPane detailPane, String JavaDoc nodeType) {
108
109         if (detailPane instanceof FixedListDetailPane) {
110             add(((FixedListDetailPane)detailPane).getScrollPane(), nodeType);
111         } else {
112             add(detailPane, nodeType);
113         }
114         nodeTypeToDetailPane.put(nodeType, detailPane);
115     }
116
117 }
118
Popular Tags