blob: cf4ea6790755fd9196536a2147664634c1ea576f [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * Copyright 1999 Sun Microsystems, Inc. All Rights Reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Sun designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Sun in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22 * CA 95054 USA or visit www.sun.com if you need additional information or
23 * have any questions.
24 */
25
26package com.sun.tools.example.debug.gui;
27
28import java.io.*;
29import java.util.*;
30
31import javax.swing.*;
32import javax.swing.tree.*;
33import javax.swing.event.*;
34import java.awt.*;
35import java.awt.event.*;
36
37import com.sun.jdi.*;
38import com.sun.tools.example.debug.bdi.*;
39import com.sun.tools.example.debug.expr.ExpressionParser;
40import com.sun.tools.example.debug.expr.ParseException;
41
42public class MonitorTool extends JPanel {
43
44 private ExecutionManager runtime;
45 private ContextManager context;
46
47 private JList list;
48
49 public MonitorTool(Environment env) {
50 super(new BorderLayout());
51 this.runtime = env.getExecutionManager();
52 this.context = env.getContextManager();
53
54 list = new JList(env.getMonitorListModel());
55 list.setCellRenderer(new MonitorRenderer());
56
57 JScrollPane listView = new JScrollPane(list);
58 add(listView);
59
60 // Create listener.
61 MonitorToolListener listener = new MonitorToolListener();
62 list.addListSelectionListener(listener);
63 //### remove listeners on exit!
64 }
65
66 private class MonitorToolListener implements ListSelectionListener {
67 public void valueChanged(ListSelectionEvent e) {
68 int index = list.getSelectedIndex();
69 if (index != -1) {
70 }
71 }
72 }
73
74 private Value evaluate(String expr) throws ParseException,
75 InvocationException,
76 InvalidTypeException,
77 ClassNotLoadedException,
78 IncompatibleThreadStateException {
79 ExpressionParser.GetFrame frameGetter =
80 new ExpressionParser.GetFrame() {
81 public StackFrame get()
82 throws IncompatibleThreadStateException
83 {
84 try {
85 return context.getCurrentFrame();
86 } catch (VMNotInterruptedException exc) {
87 throw new IncompatibleThreadStateException();
88 }
89 }
90 };
91 return ExpressionParser.evaluate(expr, runtime.vm(), frameGetter);
92 }
93
94 private class MonitorRenderer extends DefaultListCellRenderer {
95
96 public Component getListCellRendererComponent(JList list,
97 Object value,
98 int index,
99 boolean isSelected,
100 boolean cellHasFocus) {
101
102 //### We should indicate the current thread independently of the
103 //### selection, e.g., with an icon, because the user may change
104 //### the selection graphically without affecting the current
105 //### thread.
106
107 super.getListCellRendererComponent(list, value, index,
108 isSelected, cellHasFocus);
109 if (value == null) {
110 this.setText("<unavailable>");
111 } else {
112 String expr = (String)value;
113 try {
114 Value result = evaluate(expr);
115 this.setText(expr + " = " + result);
116 } catch (ParseException exc) {
117 this.setText(expr + " ? " + exc.getMessage());
118 } catch (IncompatibleThreadStateException exc) {
119 this.setText(expr + " ...");
120 } catch (Exception exc) {
121 this.setText(expr + " ? " + exc);
122 }
123 }
124 return this;
125 }
126 }
127}