Showing the changes to java/pkg/com/sun/tools/example/debug/gui/MonitorTool.java (1 of 18352 files). Show all
Unified · Split
| @@ -0,0 +1,125 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 1999, Oracle and/or its affiliates. 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. Oracle designates this | ||
| 8 | * particular file as subject to the "Classpath" exception as provided | ||
| 9 | * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | ||
| 22 | * or visit www.oracle.com if you need additional information or have any | ||
| 23 | * questions. | ||
| 24 | */ | ||
| 25 | |||
| 26 | package com.sun.tools.example.debug.gui; | ||
| 27 | |||
| 28 | import javax.swing.*; | ||
| 29 | import javax.swing.event.*; | ||
| 30 | import java.awt.*; | ||
| 31 | import com.sun.jdi.*; | ||
| 32 | import com.sun.tools.example.debug.bdi.*; | ||
| 33 | import com.sun.tools.example.debug.expr.ExpressionParser; | ||
| 34 | import com.sun.tools.example.debug.expr.ParseException; | ||
| 35 | |||
| 36 | public class MonitorTool extends JPanel { | ||
| 37 | |||
| 38 | private static final long serialVersionUID = -645235951031726647L; | ||
| 39 | private ExecutionManager runtime; | ||
| 40 | private ContextManager context; | ||
| 41 | |||
| 42 | private JList list; | ||
| 43 | |||
| 44 | public MonitorTool(Environment env) { | ||
| 45 | super(new BorderLayout()); | ||
| 46 | this.runtime = env.getExecutionManager(); | ||
| 47 | this.context = env.getContextManager(); | ||
| 48 | |||
| 49 | list = new JList(env.getMonitorListModel()); | ||
| 50 | list.setCellRenderer(new MonitorRenderer()); | ||
| 51 | |||
| 52 | JScrollPane listView = new JScrollPane(list); | ||
| 53 | add(listView); | ||
| 54 | |||
| 55 | // Create listener. | ||
| 56 | MonitorToolListener listener = new MonitorToolListener(); | ||
| 57 | list.addListSelectionListener(listener); | ||
| 58 | //### remove listeners on exit! | ||
| 59 | } | ||
| 60 | |||
| 61 | private class MonitorToolListener implements ListSelectionListener { | ||
| 62 | @Override | ||
| 63 | public void valueChanged(ListSelectionEvent e) { | ||
| 64 | int index = list.getSelectedIndex(); | ||
| 65 | if (index != -1) { | ||
| 66 | } | ||
| 67 | } | ||
| 68 | } | ||
| 69 | |||
| 70 | private Value evaluate(String expr) throws ParseException, | ||
| 71 | InvocationException, | ||
| 72 | InvalidTypeException, | ||
| 73 | ClassNotLoadedException, | ||
| 74 | IncompatibleThreadStateException { | ||
| 75 | ExpressionParser.GetFrame frameGetter = | ||
| 76 | new ExpressionParser.GetFrame() { | ||
| 77 | @Override | ||
| 78 | public StackFrame get() | ||
| 79 | throws IncompatibleThreadStateException | ||
| 80 | { | ||
| 81 | try { | ||
| 82 | return context.getCurrentFrame(); | ||
| 83 | } catch (VMNotInterruptedException exc) { | ||
| 84 | throw new IncompatibleThreadStateException(); | ||
| 85 | } | ||
| 86 | } | ||
| 87 | }; | ||
| 88 | return ExpressionParser.evaluate(expr, runtime.vm(), frameGetter); | ||
| 89 | } | ||
| 90 | |||
| 91 | private class MonitorRenderer extends DefaultListCellRenderer { | ||
| 92 | |||
| 93 | @Override | ||
| 94 | public Component getListCellRendererComponent(JList list, | ||
| 95 | Object value, | ||
| 96 | int index, | ||
| 97 | boolean isSelected, | ||
| 98 | boolean cellHasFocus) { | ||
| 99 | |||
| 100 | //### We should indicate the current thread independently of the | ||
| 101 | //### selection, e.g., with an icon, because the user may change | ||
| 102 | //### the selection graphically without affecting the current | ||
| 103 | //### thread. | ||
| 104 | |||
| 105 | super.getListCellRendererComponent(list, value, index, | ||
| 106 | isSelected, cellHasFocus); | ||
| 107 | if (value == null) { | ||
| 108 | this.setText("<unavailable>"); | ||
| 109 | } else { | ||
| 110 | String expr = (String)value; | ||
| 111 | try { | ||
| 112 | Value result = evaluate(expr); | ||
| 113 | this.setText(expr + " = " + result); | ||
| 114 | } catch (ParseException exc) { | ||
| 115 | this.setText(expr + " ? " + exc.getMessage()); | ||
| 116 | } catch (IncompatibleThreadStateException exc) { | ||
| 117 | this.setText(expr + " ..."); | ||
| 118 | } catch (Exception exc) { | ||
| 119 | this.setText(expr + " ? " + exc); | ||
| 120 | } | ||
| 121 | } | ||
| 122 | return this; | ||
| 123 | } | ||
| 124 | } | ||
| 125 | } | ||