1/*
2 * Copyright (c) 2002, 2004, 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.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25package sun.jvm.hotspot.ui;
26
27import java.awt.*;
28import javax.swing.*;
29import javax.swing.event.*;
30
31import sun.jvm.hotspot.runtime.*;
32import sun.jvm.hotspot.ui.classbrowser.*;
33
34/** Provides Java stack trace of a Java Thread */
35
36public class JavaStackTracePanel extends JPanel {
37    private JSplitPane          splitPane;
38    private SAEditorPane        stackTraceEditor;
39    private SAEditorPane        contentEditor;
40    private HTMLGenerator htmlGen = new HTMLGenerator();
41
42    public JavaStackTracePanel() {
43        initUI();
44    }
45
46    private void initUI() {
47        setLayout(new BorderLayout());
48        HyperlinkListener hyperListener = new HyperlinkListener() {
49                         public void hyperlinkUpdate(HyperlinkEvent e) {
50                            if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
51                               setContentText(htmlGen.genHTMLForHyperlink(e.getDescription()));
52                            }
53                         }
54                      };
55
56        stackTraceEditor = new SAEditorPane();
57        stackTraceEditor.addHyperlinkListener(hyperListener);
58
59        contentEditor = new SAEditorPane();
60        contentEditor.addHyperlinkListener(hyperListener);
61
62        JPanel topPanel = new JPanel();
63        topPanel.setLayout(new BorderLayout());
64        topPanel.add(new JScrollPane(stackTraceEditor), BorderLayout.CENTER);
65
66        JPanel bottomPanel = new JPanel();
67        bottomPanel.setLayout(new BorderLayout());
68        bottomPanel.add(new JScrollPane(contentEditor), BorderLayout.CENTER);
69
70        splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, topPanel, bottomPanel);
71        splitPane.setDividerLocation(0.4);
72
73        setLayout(new BorderLayout());
74        add(splitPane, BorderLayout.CENTER);
75    }
76
77    public void setJavaThread(final JavaThread thread) {
78        setStackTraceText(htmlGen.genHTMLForJavaStackTrace(thread));
79    }
80
81    private void setStackTraceText(String text) {
82        stackTraceEditor.setText(text);
83    }
84
85    private void setContentText(String text) {
86        contentEditor.setText(text);
87    }
88}
89