01: /*
02: * Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
03: *
04: * See the file "LICENSE.txt" for information on usage and redistribution of
05: * this file, and for a DISCLAIMER OF ALL WARRANTIES.
06: */
07: package org.pnuts.tools;
08:
09: import java.awt.BorderLayout;
10: import java.awt.Dimension;
11: import java.awt.Font;
12: import java.util.Iterator;
13: import java.util.Map;
14: import java.util.TreeMap;
15: import javax.swing.JPanel;
16: import javax.swing.JScrollPane;
17: import javax.swing.JTable;
18: import javax.swing.table.DefaultTableModel;
19: import pnuts.lang.Context;
20: import pnuts.lang.Pnuts;
21: import pnuts.tools.ContextEvent;
22: import pnuts.tools.ContextListener;
23: import pnuts.tools.StackFrameInspector;
24:
25: public class LocalsView extends JPanel implements ContextListener {
26: private final static Font monospaced = Font.getFont("monospaced");
27: JTable localsTable;
28:
29: public LocalsView() {
30: setLayout(new BorderLayout());
31: String[] columnNames = new String[] { "key", "value" };
32: this .localsTable = new JTable(new DefaultTableModel(
33: columnNames, 0));
34: localsTable.setRowSelectionAllowed(false);
35: JScrollPane p = new JScrollPane(localsTable);
36: p.setPreferredSize(new Dimension(300, 130));
37: add(p);
38: }
39:
40: public void update(ContextEvent event) {
41: DefaultTableModel dtm = (DefaultTableModel) localsTable
42: .getModel();
43: dtm.setRowCount(0);
44: TreeMap localSymbols = new TreeMap();
45: try {
46: Context context = event.getContext();
47: StackFrameInspector.localSymbols(context, localSymbols);
48: } catch (Exception e) {
49: }
50: for (Iterator it = localSymbols.entrySet().iterator(); it
51: .hasNext();) {
52: Map.Entry entry = (Map.Entry) it.next();
53: dtm.addRow(new Object[] { entry.getKey(),
54: Pnuts.format(entry.getValue()) });
55: }
56: }
57: }
|