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.Enumeration;
13: import java.util.Iterator;
14: import java.util.Map;
15: import java.util.TreeMap;
16: import javax.swing.JPanel;
17: import javax.swing.JScrollPane;
18: import javax.swing.JTable;
19: import javax.swing.table.DefaultTableModel;
20: import pnuts.lang.Context;
21: import pnuts.lang.Pnuts;
22: import pnuts.tools.ContextEvent;
23: import pnuts.tools.ContextListener;
24:
25: public class ContextLocalsView extends JPanel implements
26: ContextListener {
27: private final static Font monospaced = Font.getFont("monospaced");
28: JTable contextLocals;
29:
30: public ContextLocalsView() {
31: setLayout(new BorderLayout());
32: String[] columnNames = new String[] { "key", "value" };
33: this .contextLocals = new JTable(new DefaultTableModel(
34: columnNames, 0));
35: contextLocals.setRowSelectionAllowed(false);
36: JScrollPane p = new JScrollPane(contextLocals);
37: p.setPreferredSize(new Dimension(300, 70));
38: add(p);
39: }
40:
41: public void update(ContextEvent event) {
42: Context context = event.getContext();
43: DefaultTableModel dtm = (DefaultTableModel) contextLocals
44: .getModel();
45: TreeMap tmap = new TreeMap();
46: Enumeration keys = context.keys();
47: while (keys.hasMoreElements()) {
48: String name = (String) keys.nextElement();
49: tmap.put(name, context.get(name));
50: }
51: dtm.setRowCount(0);
52: for (Iterator it = tmap.entrySet().iterator(); it.hasNext();) {
53: Map.Entry entry = (Map.Entry) it.next();
54: dtm.addRow(new Object[] { entry.getKey(),
55: Pnuts.format(entry.getValue()) });
56: }
57: }
58: }
|