1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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 }