KickJava   Java API By Example, From Geeks To Geeks.

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


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.BrowserServices;
11 import org.gjt.jclasslib.structures.*;
12 import org.gjt.jclasslib.util.ExtendedJLabel;
13
14 import javax.swing.tree.TreePath JavaDoc;
15
16 /**
17     Detail pane showing class members (methods or fields).
18  
19     @author <a HREF="mailto:jclasslib@ej-technologies.com">Ingo Kegel</a>
20     @version $Revision: 1.6 $ $Date: 2003/08/18 08:13:21 $
21 */

22 public class ClassMemberDetailPane extends FixedListDetailPane {
23
24     /** Constant which indicates that a <tt>ClassMemberDetailPane</tt> shows fields. */
25     public static final int FIELDS = 1;
26     /** Constant which indicates that a <tt>ClassMemberDetailPane</tt> shows methods. */
27     public static final int METHODS = 2;
28     
29     private int mode;
30     
31     // Visual components
32

33     private ExtendedJLabel lblName;
34     private ExtendedJLabel lblNameVerbose;
35
36     private ExtendedJLabel lblDescriptor;
37     private ExtendedJLabel lblDescriptorVerbose;
38
39     private ExtendedJLabel lblAccessFlags;
40     private ExtendedJLabel lblAccessFlagsVerbose;
41
42     /**
43         Construct a <tt>ClassMemberDetailPane</tt> with a specified mode which is
44         either <tt>FIELDS</tt> or <tt>METHODS</tt>.
45         @param services browser services
46         @param mode the mode
47      */

48     public ClassMemberDetailPane(BrowserServices services, int mode) {
49         super(services);
50         this.mode = mode;
51     }
52     
53     protected void setupLabels() {
54         
55         addDetailPaneEntry(normalLabel("Name:"),
56                            lblName = linkLabel(),
57                            lblNameVerbose = highlightLabel());
58
59         addDetailPaneEntry(normalLabel("Descriptor:"),
60                            lblDescriptor = linkLabel(),
61                            lblDescriptorVerbose = highlightLabel());
62
63         addDetailPaneEntry(normalLabel("Access flags:"),
64                            lblAccessFlags = highlightLabel(),
65                            lblAccessFlagsVerbose = highlightLabel());
66     }
67
68     public void show(TreePath JavaDoc treePath) {
69         
70         int index = getIndex(treePath);
71         ClassMember classMember;
72         if (mode == FIELDS) {
73             FieldInfo[] fields = services.getClassFile().getFields();
74             if (index >= fields.length) {
75                 return;
76             }
77             classMember = fields[index];
78         } else {
79             MethodInfo[] methods = services.getClassFile().getMethods();
80             if (index >= methods.length) {
81                 return;
82             }
83             classMember = methods[index];
84         }
85         
86         constantPoolHyperlink(lblName,
87                               lblNameVerbose,
88                               classMember.getNameIndex());
89         
90         constantPoolHyperlink(lblDescriptor,
91                               lblDescriptorVerbose,
92                               classMember.getDescriptorIndex());
93         
94         lblAccessFlags.setText(classMember.getFormattedAccessFlags());
95         lblAccessFlagsVerbose.setText("[" + classMember.getAccessFlagsVerbose() + "]");
96
97         super.show(treePath);
98         
99     }
100     
101 }
102
103
Popular Tags