Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: jreversepro/gui/JPoolTable.java


1   /*
2    * @(#)JPoolTable.java
3    *
4    * JReversePro - Java Decompiler / Disassembler.
5    * Copyright (C) 2000 2001 Karthik Kumar.
6    * EMail: akkumar@users.sourceforge.net
7    *
8    * This program is free software; you can redistribute it and/or modify
9    * it , under the terms of the GNU General Public License as published
10   * by the Free Software Foundation; either version 2 of the License,
11   * or (at your option) any later version.
12   *
13   * This program is distributed in the hope that it will be useful,
14   * but WITHOUT ANY WARRANTY; without even the implied warranty of
15   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16   * See the GNU General Public License for more details.
17   * You should have received a copy of the GNU General Public License
18   * along with this program.If not, write to
19   *  The Free Software Foundation, Inc.,
20   *  59 Temple Place - Suite 330,
21   *  Boston, MA 02111-1307, USA.
22   */
23  package jreversepro.gui;
24  
25  import javax.swing.table.AbstractTableModel;
26  import javax.swing.JTable;
27  
28  import jreversepro.reflect.JConstantPool;
29  import jreversepro.reflect.JConstantPoolEntry;
30  
31  /**
32  *   Provides a reusable JPoolTable that uses JTablePoolModel
33  *   used to provide Constant Pool Entries.
34  *   Provides the TableModel for the ConstantPool Model.
35  */
36  public class JPoolTable extends JTable  {
37      public JPoolTable( JConstantPool RhsCpInfo ) {
38          super( new JPoolTableModel(RhsCpInfo) );
39      }
40  }
41  
42  /*
43  *   Has the JPoolTableModel for the JTable.
44  *
45  */
46  class JPoolTableModel extends AbstractTableModel
47  {
48      private int TotRows;
49      private static final int MAX_COLUMNS = 5;
50  
51      String [] ColName;
52      JConstantPool CpInfo;
53  
54      public JPoolTableModel(JConstantPool RhsCpInfo) {
55          TotRows = RhsCpInfo.getMaxCpEntry();
56  
57          CpInfo = RhsCpInfo;
58          initColumnNames();
59      }
60  
61      public int getColumnCount() {
62      return MAX_COLUMNS;
63      }
64  
65     public int getRowCount() {
66         return TotRows;
67     }
68  
69     public Object getValueAt(int row, int col) {
70      //Col : 0..4 index.
71          if( row == 0 ) {
72              return (Object)( new Integer(0) );
73          }
74          else {
75              switch (col ) {
76                  case 0:
77                      return String.valueOf(row);
78                  case 1:
79                      return fillTagByte(row);
80                  case 2:
81                     return fillValue(row);
82                  case 3:
83                     return fillPtr1(row);
84                  case 4:
85                     return fillPtr2(row);
86                  default:
87                     return new Integer(0); //Error
88              }
89          }
90      }
91  
92     // The default implementations of these methods in
93     // AbstractTableModel would work, but we can refine them.
94     public boolean isCellEditable(int row, int col) {
95              return false;
96      }
97  
98      public String getColumnName(int column ) {
99          return ColName[column];
100     }
101 
102     private void initColumnNames() {
103         ColName = new String[MAX_COLUMNS];
104 
105         ColName[0] = "Index";
106         ColName[1] = "Tag Type";
107         ColName[2] = "Tag Info";
108         ColName[3] = "Pointer I";
109         ColName[4] = "Pointer II";
110     }
111 
112     //Private Methods
113 
114     private Object fillPtr1( int Index ) {
115         int Ptr = CpInfo.getPtr1(Index);
116         if( Ptr == JConstantPool.PTR_INVALID ) {
117             return "PTR_INVALID";
118         }
119         else {
120             return new Integer(Ptr);
121         }
122     }
123 
124     private Object fillPtr2( int Index ) {
125         int Ptr = CpInfo.getPtr2(Index);
126         if( Ptr == JConstantPool.PTR_INVALID ) {
127             return "PTR_INVALID";
128         }
129         else {
130             return new Integer(Ptr);
131         }
132     }
133 
134     private Object fillTagByte( int Index ) {
135         switch( CpInfo.getTagByte(Index) ) {
136             case JConstantPool.TAG_UTF8:
137                 return ("TAG_UTF8");
138             case JConstantPool.TAG_INTEGER:
139                 return ("TAG_INTEGER");
140             case JConstantPool.TAG_FLOAT:
141                 return ("TAG_FLOAT");
142             case JConstantPool.TAG_LONG:
143                 return ("TAG_LONG");
144             case JConstantPool.TAG_DOUBLE:
145                 return ("TAG_DOUBLE");
146             case JConstantPool.TAG_CLASS:
147                 return ("TAG_CLASS");
148             case JConstantPool.TAG_STRING:
149                 return ("TAG_STRING");
150             case JConstantPool.TAG_FIELDREF:
151                 return ("TAG_FIELDREF");
152             case JConstantPool.TAG_METHODREF:
153                 return ("TAG_METHOREF");
154             case JConstantPool.TAG_INTERFACEREF:
155                 return ("TAG_INTERFACEREF");
156             case JConstantPool.TAG_NAMETYPE:
157                 return ("TAG_NAMETYPE");
158             case JConstantPool.TAG_NOTHING:
159                 return ("");
160             default:
161                 return ("Invalid Tag");
162         }
163     }
164 
165     private Object fillValue( int Index ) {
166         return (CpInfo.getCpValue(Index) );
167     }
168 
169 }