Path: blob/master/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/ui/FindPanel.java
41161 views
/*1* Copyright (c) 2000, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324package sun.jvm.hotspot.ui;2526import java.io.*;27import java.awt.*;28import java.awt.event.*;29import javax.swing.*;30import javax.swing.text.*;3132import sun.jvm.hotspot.debugger.*;33import sun.jvm.hotspot.runtime.*;34import sun.jvm.hotspot.utilities.*;3536/** Uses {@link sun.jvm.hotspot.utilities.PointerFinder} to provide a37graphical user interface to the VM's debugging utility "find". */3839public class FindPanel extends JPanel {40// UI widgets we need permanent handles to41private JTextField addressField;42private JTextArea textArea;43private JLabel statusLabel;4445public FindPanel() {46super();4748setLayout(new BorderLayout());49Box hbox = Box.createHorizontalBox();50hbox.add(new JLabel("Address: "));51addressField = new JTextField(20);52hbox.add(addressField);53statusLabel = new JLabel();54hbox.add(statusLabel);55add(hbox, BorderLayout.NORTH);5657JScrollPane scroller = new JScrollPane();58textArea = new JTextArea();59textArea.setEditable(false);60textArea.setLineWrap(true);61textArea.setWrapStyleWord(true);62scroller.getViewport().add(textArea);63add(scroller, BorderLayout.CENTER);6465addressField.addActionListener(new ActionListener() {66public void actionPerformed(ActionEvent e) {67try {68Address a = VM.getVM().getDebugger().parseAddress(addressField.getText());69PointerLocation loc = PointerFinder.find(a);70ByteArrayOutputStream bos = new ByteArrayOutputStream();71loc.printOn(new PrintStream(bos));72clear();73textArea.append(bos.toString());74statusLabel.setText("");75}76catch (NumberFormatException ex) {77statusLabel.setText("<parse error>");78}79catch (AddressException ex) {80statusLabel.setText("<bad address>");81}82catch (Exception ex) {83ex.printStackTrace();84statusLabel.setText("<error during find>");85}86}87});88}8990private void clear() {91Document doc = textArea.getDocument();92if (doc.getLength() > 0) {93try {94doc.remove(0, doc.getLength());95}96catch (BadLocationException e) {97}98}99}100}101102103