KickJava   Java API By Example, From Geeks To Geeks.

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


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.ConstantUtf8Info;
13 import org.gjt.jclasslib.util.ExtendedJLabel;
14
15 import javax.swing.tree.TreePath JavaDoc;
16
17 /**
18     Detail pane showing a <tt>CONSTANT_Utf8</tt> constant pool entry.
19
20     @author <a HREF="mailto:jclasslib@ej-technologies.com">Ingo Kegel</a>
21     @version $Revision: 1.5 $ $Date: 2003/08/18 08:16:34 $
22 */

23 public class ConstantUtf8InfoDetailPane extends AbstractConstantInfoDetailPane {
24
25     // Visual components
26

27     private ExtendedJLabel lblByteLength;
28     private ExtendedJLabel lblByteLengthComment;
29     private ExtendedJLabel lblStringLength;
30     private ExtendedJLabel lblString;
31     
32     /**
33         Constructor.
34         @param services the associated browser services.
35      */

36     public ConstantUtf8InfoDetailPane(BrowserServices services) {
37         super(services);
38     }
39     
40     protected void setupLabels() {
41         
42         addDetailPaneEntry(normalLabel("Length of byte array:"),
43                            lblByteLength = highlightLabel(),
44                            lblByteLengthComment = highlightLabel());
45
46         addDetailPaneEntry(normalLabel("Length of string:"),
47                            lblStringLength = highlightLabel());
48         
49         addDetailPaneEntry(normalLabel("String:"),
50                            null,
51                            lblString = highlightLabel());
52
53     }
54
55     public void show(TreePath JavaDoc treePath) {
56         
57         int constantPoolIndex = constantPoolIndex(treePath);
58
59         try {
60             ConstantUtf8Info entry = services.getClassFile().getConstantPoolUtf8Entry(constantPoolIndex);
61             lblByteLength.setText(entry.getBytes().length);
62             lblStringLength.setText(entry.getString().length());
63             lblString.setText(getConstantPoolEntryName(constantPoolIndex));
64         } catch (InvalidByteCodeException ex) {
65             lblByteLength.setText(-1);
66             lblStringLength.setText(-1);
67             lblByteLengthComment.setText(MESSAGE_INVALID_CONSTANT_POOL_ENTRY);
68         }
69         
70         super.show(treePath);
71     }
72     
73 }
74
75
Popular Tags