summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/cuchaz/enigma/gui/CrashDialog.java107
-rw-r--r--src/cuchaz/enigma/gui/Gui.java22
2 files changed, 124 insertions, 5 deletions
diff --git a/src/cuchaz/enigma/gui/CrashDialog.java b/src/cuchaz/enigma/gui/CrashDialog.java
new file mode 100644
index 00000000..501080ec
--- /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}
diff --git a/src/cuchaz/enigma/gui/Gui.java b/src/cuchaz/enigma/gui/Gui.java
index 3dcb4e24..e357382a 100644
--- a/src/cuchaz/enigma/gui/Gui.java
+++ b/src/cuchaz/enigma/gui/Gui.java
@@ -28,6 +28,7 @@ import java.awt.event.WindowAdapter;
28import java.awt.event.WindowEvent; 28import java.awt.event.WindowEvent;
29import java.io.File; 29import java.io.File;
30import java.io.IOException; 30import java.io.IOException;
31import java.lang.Thread.UncaughtExceptionHandler;
31import java.util.Collection; 32import java.util.Collection;
32import java.util.Collections; 33import java.util.Collections;
33import java.util.Comparator; 34import java.util.Comparator;
@@ -176,6 +177,22 @@ public class Gui
176 177
177 public Gui( ) 178 public Gui( )
178 { 179 {
180 // init frame
181 m_frame = new JFrame( Constants.Name );
182 final Container pane = m_frame.getContentPane();
183 pane.setLayout( new BorderLayout() );
184
185 // install a global exception handler to the event thread
186 CrashDialog.init( m_frame );
187 Thread.setDefaultUncaughtExceptionHandler( new UncaughtExceptionHandler( )
188 {
189 @Override
190 public void uncaughtException( Thread thread, Throwable ex )
191 {
192 CrashDialog.show( ex );
193 }
194 } );
195
179 m_controller = new GuiController( this ); 196 m_controller = new GuiController( this );
180 197
181 // init file choosers 198 // init file choosers
@@ -184,11 +201,6 @@ public class Gui
184 m_exportFileChooser = new JFileChooser(); 201 m_exportFileChooser = new JFileChooser();
185 m_exportFileChooser.setFileSelectionMode( JFileChooser.DIRECTORIES_ONLY ); 202 m_exportFileChooser.setFileSelectionMode( JFileChooser.DIRECTORIES_ONLY );
186 203
187 // init frame
188 m_frame = new JFrame( Constants.Name );
189 final Container pane = m_frame.getContentPane();
190 pane.setLayout( new BorderLayout() );
191
192 // init obfuscated classes list 204 // init obfuscated classes list
193 m_obfClasses = new JList<String>(); 205 m_obfClasses = new JList<String>();
194 m_obfClasses.setSelectionMode( ListSelectionModel.SINGLE_SELECTION ); 206 m_obfClasses.setSelectionMode( ListSelectionModel.SINGLE_SELECTION );