View Javadoc

1   /*
2    * Copyright 2008 Eric Caspole
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
5    * file except in compliance with the License. You may obtain a copy of the License at
6    * 
7    * http://www.apache.org/licenses/LICENSE-2.0
8    * 
9    * Unless required by applicable law or agreed to in writing, software distributed under
10   * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
11   * KIND, either express or implied. See the License for the specific language governing
12   * permissions and limitations under the License.
13   */
14  
15  package net.sf.madmap;
16  
17  import java.io.*;
18  import java.util.*;
19  import java.awt.*;
20  import java.awt.event.*;
21  import javax.swing.*;
22  import javax.swing.filechooser.*;
23  
24  
25  public class ThreadTableModel extends javax.swing.table.AbstractTableModel {
26    TreeSet     threads;
27    
28    private String[] columnNames = {
29      "Object Address",
30      "Thread Name",
31      "Hprof ID"
32    };
33    
34    private Class[] columnType = {
35      (java.lang.Class)((new String("")).getClass()),
36      (java.lang.Class)((new String("")).getClass()),
37      (java.lang.Class)((new Long(0)).getClass())
38    };
39      
40    public ThreadTableModel( TreeSet thdTable ) {
41      threads = thdTable;
42    }
43  
44    public Class getColumnClass(int c) {
45      return columnType[c];
46    }
47    
48    public String getColumnName(int col) {
49        return columnNames[col];
50    }
51  
52    public int getColumnCount() { return columnNames.length; }
53    public int getRowCount() { return threads.size(); }
54    
55    public Object getValueAt(int row, int col) { 
56      Iterator<HprofThreadData>   ihoc3 = threads.iterator();
57      int i = 0;
58  
59      while( ihoc3.hasNext() ) {
60        HprofThreadData hk = ihoc3.next();
61        
62        if ( i == row ) {
63          if ( col == 0 ) {
64            return Long.toHexString(hk.addr());
65          } else if ( col == 1 ) {
66            return hk.name();
67          } else if ( col == 2 ) {
68            return new Long(hk.id());
69          }
70        }
71        
72        i += 1;
73      }
74      
75      assert  true == false : "Should not reach here!" ;
76      return null;
77    }    
78  };