summaryrefslogtreecommitdiff
path: root/src/cuchaz/enigma/gui/CrashDialog.java
diff options
context:
space:
mode:
authorGravatar jeff2014-08-28 10:43:48 -0400
committerGravatar jeff2014-08-28 10:43:48 -0400
commit3301d00ab1df7a0f88985d143787f9f3c2283e38 (patch)
tree4d1cbdafb4918966073d673f9c1349004d0ae3ee /src/cuchaz/enigma/gui/CrashDialog.java
parentadded checks to find buggy mappings (diff)
downloadenigma-fork-3301d00ab1df7a0f88985d143787f9f3c2283e38.tar.gz
enigma-fork-3301d00ab1df7a0f88985d143787f9f3c2283e38.tar.xz
enigma-fork-3301d00ab1df7a0f88985d143787f9f3c2283e38.zip
added crash reporter
Diffstat (limited to 'src/cuchaz/enigma/gui/CrashDialog.java')
-rw-r--r--src/cuchaz/enigma/gui/CrashDialog.java107
1 files changed, 107 insertions, 0 deletions
diff --git a/src/cuchaz/enigma/gui/CrashDialog.java b/src/cuchaz/enigma/gui/CrashDialog.java
new file mode 100644
index 0000000..501080e
--- /dev/null
+++ b/src/cuchaz/enigma/gui/CrashDialog.java
@@ -0,0 +1,107 @@
1/*******************************************************************************
2 * Copyright (c) 2014 Jeff Martin.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the GNU Public License v3.0
5 * which accompanies this distribution, and is available at
6 * http://www.gnu.org/licenses/gpl.html
7 *
8 * Contributors:
9 * Jeff Martin - initial API and implementation
10 ******************************************************************************/
11package cuchaz.enigma.gui;
12
13import java.awt.BorderLayout;
14import java.awt.Container;
15import java.awt.FlowLayout;
16import java.awt.event.ActionEvent;
17import java.awt.event.ActionListener;
18import java.io.PrintWriter;
19import java.io.StringWriter;
20
21import javax.swing.BorderFactory;
22import javax.swing.JButton;
23import javax.swing.JFrame;
24import javax.swing.JLabel;
25import javax.swing.JPanel;
26import javax.swing.JScrollPane;
27import javax.swing.JTextArea;
28import javax.swing.WindowConstants;
29
30import cuchaz.enigma.Constants;
31
32public class CrashDialog
33{
34 private static CrashDialog m_instance = null;
35
36 private JFrame m_frame;
37 private JTextArea m_text;
38
39 private CrashDialog( JFrame parent )
40 {
41 // init frame
42 m_frame = new JFrame( Constants.Name + " - Crash Report" );
43 final Container pane = m_frame.getContentPane();
44 pane.setLayout( new BorderLayout() );
45
46 JLabel label = new JLabel( Constants.Name + " has crashed! =(" );
47 label.setBorder( BorderFactory.createEmptyBorder( 10, 10, 10, 10 ) );
48 pane.add( label, BorderLayout.NORTH );
49
50 // report panel
51 m_text = new JTextArea();
52 m_text.setTabSize( 2 );
53 pane.add( new JScrollPane( m_text ), BorderLayout.CENTER );
54
55 // buttons panel
56 JPanel buttonsPanel = new JPanel();
57 FlowLayout buttonsLayout = new FlowLayout();
58 buttonsLayout.setAlignment( FlowLayout.RIGHT );
59 buttonsPanel.setLayout( buttonsLayout );
60 JButton ignoreButton = new JButton( "Ignore" );
61 ignoreButton.addActionListener( new ActionListener( )
62 {
63 @Override
64 public void actionPerformed( ActionEvent event )
65 {
66 // close (hide) the dialog
67 m_frame.setVisible( false );
68 }
69 } );
70 buttonsPanel.add( ignoreButton );
71 JButton exitButton = new JButton( "Exit" );
72 exitButton.addActionListener( new ActionListener( )
73 {
74 @Override
75 public void actionPerformed( ActionEvent event )
76 {
77 // exit enigma
78 System.exit( 1 );
79 }
80 } );
81 buttonsPanel.add( exitButton );
82 pane.add( buttonsPanel, BorderLayout.SOUTH );
83
84 // show the frame
85 m_frame.setSize( 600, 400 );
86 m_frame.setLocationRelativeTo( parent );
87 m_frame.setDefaultCloseOperation( WindowConstants.DO_NOTHING_ON_CLOSE );
88 }
89
90 public static void init( JFrame parent )
91 {
92 m_instance = new CrashDialog( parent );
93 }
94
95 public static void show( Throwable ex )
96 {
97 // get the error report
98 StringWriter buf = new StringWriter();
99 ex.printStackTrace( new PrintWriter( buf ) );
100 String report = buf.toString();
101
102 // show it!
103 m_instance.m_text.setText( report );
104 m_instance.m_frame.doLayout();
105 m_instance.m_frame.setVisible( true );
106 }
107}