01: /*
02: ** $Id: ExceptionDialog.java,v 1.4 2000/10/26 08:34:15 mrw Exp $
03: **
04: ** Mike Wilson, July 2000, mrw@whisperingwind.co.uk
05: **
06: ** This program is free software; you can redistribute it and/or modify
07: ** it under the terms of the GNU General Public License as published by
08: ** the Free Software Foundation; either version 2 of the License, or
09: ** (at your option) any later version.
10: **
11: ** This program is distributed in the hope that it will be useful,
12: ** but WITHOUT ANY WARRANTY; without even the implied warranty of
13: ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14: ** GNU General Public License for more details.
15: **
16: ** You should have received a copy of the GNU Library General
17: ** Public License along with this library; if not, write to the
18: ** Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19: ** Boston, MA 02111-1307 USA.
20: */
21:
22: package uk.co.whisperingwind.framework;
23:
24: import java.io.ByteArrayOutputStream;
25: import java.io.PrintStream;
26: import java.awt.BorderLayout;
27: import java.awt.Dimension;
28: import java.awt.event.WindowAdapter;
29: import java.awt.event.WindowEvent;
30: import javax.swing.JScrollPane;
31: import javax.swing.JTextArea;
32: import javax.swing.JDialog;
33:
34: /**
35: ** Dialog to display the full details of an exception.
36: */
37:
38: public class ExceptionDialog extends JDialog {
39: private JTextArea textArea = new JTextArea();
40:
41: public ExceptionDialog(Throwable ex, boolean quitOnExit) {
42: createComponents();
43: showTrace(ex);
44:
45: if (quitOnExit)
46: addWindowListener(new DeadlyWindowListener());
47: }
48:
49: public ExceptionDialog(Throwable ex) {
50: this (ex, false);
51: }
52:
53: private void createComponents() {
54: JScrollPane textScroller = new JScrollPane(textArea);
55: getContentPane().add(textScroller, BorderLayout.CENTER);
56: textArea.setEditable(false);
57: pack();
58: setSize(new Dimension(600, 400));
59: setVisible(true);
60: }
61:
62: private void showTrace(Throwable ex) {
63: ByteArrayOutputStream os = new ByteArrayOutputStream();
64: PrintStream ps = new PrintStream(os);
65: ex.printStackTrace(ps);
66: textArea.setText(os.toString());
67: ps.close();
68: setTitle("Serious error");
69: }
70:
71: private class DeadlyWindowListener extends WindowAdapter {
72: public void windowClosing(WindowEvent evt) {
73: System.exit(0);
74: }
75: }
76: }
|