View Javadoc

1   /*
2    * $Id: LocalTableModel.java,v 1.1 2005/10/17 01:28:18 weiju Exp $
3    * 
4    * Created on 15.10.2005
5    * Copyright 2005 by Wei-ju Wu
6    *
7    * This file is part of The Z-machine Preservation Project (ZMPP).
8    *
9    * ZMPP is free software; you can redistribute it and/or modify
10   * it under the terms of the GNU General Public License as published by
11   * the Free Software Foundation; either version 2 of the License, or
12   * (at your option) any later version.
13   *
14   * ZMPP is distributed in the hope that it will be useful,
15   * but WITHOUT ANY WARRANTY; without even the implied warranty of
16   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17   * GNU General Public License for more details.
18   *
19   * You should have received a copy of the GNU General Public License
20   * along with ZMPP; if not, write to the Free Software
21   * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
22   */
23  package org.zmpp.debug;
24  
25  import java.util.Formatter;
26  
27  import javax.swing.table.AbstractTableModel;
28  
29  import org.zmpp.vm.Machine3;
30  import org.zmpp.vm.RoutineContext;
31  
32  public class LocalTableModel extends AbstractTableModel {
33  
34    private static final long serialVersionUID = 1L;
35    private Machine3 machine;
36    
37    public LocalTableModel(Machine3 machine) { this.machine = machine; }
38    public int getRowCount() {
39      RoutineContext context = machine.getCurrentRoutineContext();
40      if (context != null) return context.getNumLocalVariables();
41      return 0;
42    }
43    public int getColumnCount() { return 2; }
44    public String getColumnName(int column) {
45      
46      if (column == 0) return "Name";
47      return "Value";
48    }
49    public Object getValueAt(int row, int column) {
50      
51      if (column == 0) return "L" + formatHex(row);
52      else {
53        RoutineContext context = machine.getCurrentRoutineContext();
54        if (context != null && row < context.getNumLocalVariables())
55          return formatHex(machine.getVariable(row + 1));
56      }
57      return "";
58    }
59    
60    public void update() {
61      super.fireTableDataChanged();
62    }
63  
64    private String formatHex(int number) {
65      
66      Formatter formatter = new Formatter();
67      formatter.format("%x", number);
68      return formatter.toString();
69    }
70  }