KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > gjt > jclasslib > browser > detail > constants > ConstantReferenceDetailPane


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.constants;
9
10 import org.gjt.jclasslib.browser.BrowserServices;
11 import org.gjt.jclasslib.structures.InvalidByteCodeException;
12 import org.gjt.jclasslib.structures.constants.ConstantReference;
13 import org.gjt.jclasslib.util.ExtendedJLabel;
14
15 import javax.swing.tree.TreePath JavaDoc;
16
17 /**
18     Detail pane showing a <tt>CONSTANT_Fieldref</tt>, <tt>CONSTANT_Methodref</tt>,
19     or a <tt>CONSTANT_InterfaceMethodref</tt> constant pool entry.
20  
21     @author <a HREF="mailto:jclasslib@ej-technologies.com">Ingo Kegel</a>
22     @version $Revision: 1.6 $ $Date: 2004/02/10 16:06:56 $
23 */

24 public class ConstantReferenceDetailPane extends AbstractConstantInfoDetailPane {
25
26     // Visual components
27

28     private ExtendedJLabel lblClass;
29     private ExtendedJLabel lblClassVerbose;
30     private ExtendedJLabel lblNameAndType;
31     private ExtendedJLabel lblNameAndTypeVerbose;
32
33     private ClassElementOpener classElementOpener;
34
35     /**
36         Constructor.
37         @param services the associated browser services.
38      */

39     public ConstantReferenceDetailPane(BrowserServices services) {
40         super(services);
41     }
42     
43     protected void setupLabels() {
44         
45         addDetailPaneEntry(normalLabel("Class name:"),
46                            lblClass = linkLabel(),
47                            lblClassVerbose = highlightLabel());
48
49         addDetailPaneEntry(normalLabel("Name and type:"),
50                            lblNameAndType = linkLabel(),
51                            lblNameAndTypeVerbose = highlightLabel());
52     }
53
54     protected int addSpecial(int gridy) {
55
56         classElementOpener = new ClassElementOpener(this);
57         if (getBrowserServices().canOpenClassFiles()) {
58             return classElementOpener.addSpecial(this, gridy);
59         } else {
60             return 0;
61         }
62     }
63
64     public void show(TreePath JavaDoc treePath) {
65         
66         int constantPoolIndex = constantPoolIndex(treePath);
67
68         try {
69             ConstantReference entry = (ConstantReference)services.getClassFile().getConstantPoolEntry(constantPoolIndex, ConstantReference.class);
70             classElementOpener.setCPInfo(entry);
71
72             constantPoolHyperlink(lblClass,
73                                   lblClassVerbose,
74                                   entry.getClassIndex());
75         
76             constantPoolHyperlink(lblNameAndType,
77                                   lblNameAndTypeVerbose,
78                                   entry.getNameAndTypeIndex());
79         
80         } catch (InvalidByteCodeException ex) {
81             lblClassVerbose.setText(MESSAGE_INVALID_CONSTANT_POOL_ENTRY);
82         }
83         
84         super.show(treePath);
85     }
86     
87 }
88
89
Popular Tags