KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > gjt > jclasslib > browser > detail > attributes > code > ExceptionTableDetailPane


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.attributes.code;
9
10 import org.gjt.jclasslib.browser.BrowserServices;
11 import org.gjt.jclasslib.browser.ConstantPoolHyperlinkListener;
12 import org.gjt.jclasslib.browser.detail.ListDetailPane;
13 import org.gjt.jclasslib.browser.detail.attributes.AbstractAttributeListDetailPane;
14 import org.gjt.jclasslib.browser.detail.attributes.AbstractAttributeTableModel;
15 import org.gjt.jclasslib.structures.AttributeInfo;
16 import org.gjt.jclasslib.structures.attributes.CodeAttribute;
17 import org.gjt.jclasslib.structures.attributes.ExceptionTableEntry;
18
19 /**
20     Detail pane showing the exception table about a <tt>Code</tt> attribute.
21  
22     @author <a HREF="mailto:jclasslib@ej-technologies.com">Ingo Kegel</a>
23     @version $Revision: 1.1 $ $Date: 2003/08/18 08:19:37 $
24 */

25 public class ExceptionTableDetailPane extends AbstractAttributeListDetailPane {
26
27     /**
28         Constructor.
29         @param services the associated browser services.
30      */

31     public ExceptionTableDetailPane(BrowserServices services) {
32         super(services);
33     }
34     
35     protected AbstractAttributeTableModel createTableModel(AttributeInfo attribute) {
36         return new AttributeTableModel(attribute);
37     }
38     
39     private class AttributeTableModel extends AbstractAttributeTableModel {
40         
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 END_PC_COLUMN_INDEX = BASE_COLUMN_COUNT + 1;
45         private static final int HANDLER_PC_COLUMN_INDEX = BASE_COLUMN_COUNT + 2;
46         private static final int CATCH_TYPE_COLUMN_INDEX = BASE_COLUMN_COUNT + 3;
47         private static final int CATCH_TYPE_VERBOSE_COLUMN_INDEX = BASE_COLUMN_COUNT + 4;
48         
49         private static final int HANDLER_PC_COLUMN_WIDTH = 70;
50         
51         private ExceptionTableEntry[] exceptionTable;
52         
53         private AttributeTableModel(AttributeInfo attribute) {
54             super(attribute);
55             exceptionTable = ((CodeAttribute)attribute).getExceptionTable();
56         }
57
58         public int getColumnWidth(int column) {
59             switch (column) {
60                 case START_PC_COLUMN_INDEX:
61                 case END_PC_COLUMN_INDEX:
62                    return NUMBER_COLUMN_WIDTH;
63
64                 case HANDLER_PC_COLUMN_INDEX:
65                    return HANDLER_PC_COLUMN_WIDTH;
66                    
67                 case CATCH_TYPE_COLUMN_INDEX:
68                    return LINK_COLUMN_WIDTH;
69                     
70                 case CATCH_TYPE_VERBOSE_COLUMN_INDEX:
71                 default:
72                    return VERBOSE_COLUMN_WIDTH;
73             }
74         }
75         
76         public void link(int row, int column) {
77             
78             if (column == CATCH_TYPE_COLUMN_INDEX) {
79                 int constantPoolIndex = exceptionTable[row].getCatchType();
80                 ConstantPoolHyperlinkListener.link(services, constantPoolIndex);
81             }
82         }
83         
84         public int getRowCount() {
85             return exceptionTable.length;
86         }
87         
88         public int getColumnCount() {
89             return COLUMN_COUNT;
90         }
91         
92         protected String JavaDoc doGetColumnName(int column) {
93             switch (column) {
94                 case START_PC_COLUMN_INDEX:
95                    return "start_pc";
96                 case END_PC_COLUMN_INDEX:
97                    return "end_pc";
98                 case HANDLER_PC_COLUMN_INDEX:
99                    return "handler_pc";
100                 case CATCH_TYPE_COLUMN_INDEX:
101                    return "catch_type";
102                 case CATCH_TYPE_VERBOSE_COLUMN_INDEX:
103                    return "verbose";
104                 default:
105                    return "";
106             }
107         }
108         
109         protected Class JavaDoc doGetColumnClass(int column) {
110             switch (column) {
111                 case START_PC_COLUMN_INDEX:
112                 case END_PC_COLUMN_INDEX:
113                 case HANDLER_PC_COLUMN_INDEX:
114                    return Number JavaDoc.class;
115                 case CATCH_TYPE_COLUMN_INDEX:
116                    return ListDetailPane.Link.class;
117                 case CATCH_TYPE_VERBOSE_COLUMN_INDEX:
118                 default:
119                    return String JavaDoc.class;
120             }
121         }
122         
123         protected Object JavaDoc doGetValueAt(int row, int column) {
124
125             ExceptionTableEntry exceptionTableEntry = exceptionTable[row];
126             int catchType = exceptionTableEntry.getCatchType();
127             
128             switch (column) {
129                 case START_PC_COLUMN_INDEX:
130                     return String.valueOf(exceptionTableEntry.getStartPc());
131                 case END_PC_COLUMN_INDEX:
132                     return String.valueOf(exceptionTableEntry.getEndPc());
133                 case HANDLER_PC_COLUMN_INDEX:
134                     return String.valueOf(exceptionTableEntry.getHandlerPc());
135                 case CATCH_TYPE_COLUMN_INDEX:
136                     if (catchType == 0) {
137                         return "";
138                     } else {
139                         return CPINFO_LINK_TEXT + String.valueOf(catchType);
140                     }
141                 case CATCH_TYPE_VERBOSE_COLUMN_INDEX:
142                     if (catchType == 0) {
143                         return "any";
144                     } else {
145                         return getConstantPoolEntryName(exceptionTableEntry.getCatchType());
146                     }
147                 default:
148                     return "";
149             }
150         }
151     }
152 }
153
Popular Tags