KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > gjt > jclasslib > browser > detail > attributes > LocalVariableCommonAttributeDetailPane


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 package org.gjt.jclasslib.browser.detail.attributes;
8
9 import org.gjt.jclasslib.browser.BrowserServices;
10 import org.gjt.jclasslib.browser.ConstantPoolHyperlinkListener;
11 import org.gjt.jclasslib.structures.AttributeInfo;
12 import org.gjt.jclasslib.structures.attributes.LocalVariableCommonAttribute;
13 import org.gjt.jclasslib.structures.attributes.LocalVariableCommonEntry;
14
15 /**
16  * Contains common attributes to a local variable detail pane.
17  *
18  * @author <a HREF="mailto:vitor.carreira@gmail.com">Vitor Carreira</a>
19  * @version $Revision: 1.1 $ $Date: 2004/12/28 13:04:30 $
20  */

21 public abstract class LocalVariableCommonAttributeDetailPane extends AbstractAttributeListDetailPane {
22
23     /**
24      * Constructor.
25      *
26      * @param services the associated browser services.
27      */

28     public LocalVariableCommonAttributeDetailPane(BrowserServices services) {
29         super(services);
30     }
31
32     protected AbstractAttributeTableModel createTableModel(AttributeInfo attribute, String JavaDoc descriptorOrSignatureDescription) {
33         return new AttributeTableModel(attribute, descriptorOrSignatureDescription);
34     }
35
36     protected float getRowHeightFactor() {
37         return 2f;
38     }
39
40     private class AttributeTableModel extends AbstractAttributeTableModel {
41         private static final int COLUMN_COUNT = BASE_COLUMN_COUNT + 5;
42
43         private static final int START_PC_COLUMN_INDEX = BASE_COLUMN_COUNT;
44         private static final int LENGTH_COLUMN_INDEX = BASE_COLUMN_COUNT + 1;
45         private static final int INDEX_COLUMN_INDEX = BASE_COLUMN_COUNT + 2;
46         private static final int NAME_COLUMN_INDEX = BASE_COLUMN_COUNT + 3;
47         private static final int DESCRIPTOR_OR_SIGNATURE_COLUMN_INDEX = BASE_COLUMN_COUNT + 4;
48
49         private final String JavaDoc descriptorOrSignatureVerbose;
50
51         private static final int COMMENT_LINK_COLUMN_WIDTH = 200;
52
53         private LocalVariableCommonEntry[] localVariableEntries;
54
55         private AttributeTableModel(AttributeInfo attribute,
56                                     String JavaDoc descriptorOrSignatureVerbose) {
57
58             super(attribute);
59             localVariableEntries = ((LocalVariableCommonAttribute)attribute).getLocalVariableEntries();
60             this.descriptorOrSignatureVerbose = descriptorOrSignatureVerbose;
61         }
62
63         public int getColumnWidth(int column) {
64             switch (column) {
65                 case START_PC_COLUMN_INDEX:
66                 case LENGTH_COLUMN_INDEX:
67                 case INDEX_COLUMN_INDEX:
68                     return NUMBER_COLUMN_WIDTH;
69
70                 case NAME_COLUMN_INDEX:
71                 case DESCRIPTOR_OR_SIGNATURE_COLUMN_INDEX:
72                     return COMMENT_LINK_COLUMN_WIDTH;
73
74                 default:
75                     return LINK_COLUMN_WIDTH;
76             }
77         }
78
79         public void link(int row, int column) {
80             int constantPoolIndex;
81             switch (column) {
82                 case NAME_COLUMN_INDEX:
83                     constantPoolIndex = localVariableEntries[row].getNameIndex();
84                     break;
85                 case DESCRIPTOR_OR_SIGNATURE_COLUMN_INDEX:
86                     constantPoolIndex = localVariableEntries[row].getDescriptorOrSignatureIndex();
87                     break;
88                 default:
89                     return;
90             }
91             ConstantPoolHyperlinkListener.link(services, constantPoolIndex);
92         }
93
94         public int getRowCount() {
95             return localVariableEntries.length;
96         }
97
98         public int getColumnCount() {
99             return COLUMN_COUNT;
100         }
101
102         protected String JavaDoc doGetColumnName(int column) {
103             switch (column) {
104                 case START_PC_COLUMN_INDEX:
105                     return "start_pc";
106                 case LENGTH_COLUMN_INDEX:
107                     return "length";
108                 case INDEX_COLUMN_INDEX:
109                     return "index";
110                 case NAME_COLUMN_INDEX:
111                     return "name";
112                 case DESCRIPTOR_OR_SIGNATURE_COLUMN_INDEX:
113                     return descriptorOrSignatureVerbose;
114                 default:
115                     return "";
116             }
117         }
118
119         protected Class JavaDoc doGetColumnClass(int column) {
120             switch (column) {
121                 case START_PC_COLUMN_INDEX:
122                 case LENGTH_COLUMN_INDEX:
123                 case INDEX_COLUMN_INDEX:
124                     return Number JavaDoc.class;
125                 case NAME_COLUMN_INDEX:
126                 case DESCRIPTOR_OR_SIGNATURE_COLUMN_INDEX:
127                     return Link.class;
128                 default:
129                     return String JavaDoc.class;
130             }
131         }
132
133         protected Object JavaDoc doGetValueAt(int row, int column) {
134             LocalVariableCommonEntry localVariableEntry = localVariableEntries[row];
135
136             switch (column) {
137                 case START_PC_COLUMN_INDEX:
138                     return String.valueOf(localVariableEntry.getStartPc());
139                 case LENGTH_COLUMN_INDEX:
140                     return String.valueOf(localVariableEntry.getLength());
141                 case INDEX_COLUMN_INDEX:
142                     return String.valueOf(localVariableEntry.getIndex());
143                 case NAME_COLUMN_INDEX:
144                     return createCommentLink(localVariableEntry.getNameIndex());
145                 case DESCRIPTOR_OR_SIGNATURE_COLUMN_INDEX:
146                     return createCommentLink(localVariableEntry.getDescriptorOrSignatureIndex());
147                 default:
148                     return "";
149             }
150         }
151     }
152 }
153
Popular Tags