J. Duke | 319a3b9 | 2007-12-01 00:00:00 +0000 | [diff] [blame^] | 1 | /* |
| 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 | |
| 26 | package com.sun.tools.example.debug.gui; |
| 27 | |
| 28 | import java.io.*; |
| 29 | import java.util.*; |
| 30 | |
| 31 | import javax.swing.*; |
| 32 | import javax.swing.tree.*; |
| 33 | import javax.swing.event.*; |
| 34 | import java.awt.*; |
| 35 | import java.awt.event.*; |
| 36 | |
| 37 | import com.sun.jdi.*; |
| 38 | import com.sun.tools.example.debug.bdi.*; |
| 39 | import com.sun.tools.example.debug.expr.ExpressionParser; |
| 40 | import com.sun.tools.example.debug.expr.ParseException; |
| 41 | |
| 42 | public 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 | } |