diff options
| author | 2014-08-28 10:43:48 -0400 | |
|---|---|---|
| committer | 2014-08-28 10:43:48 -0400 | |
| commit | 3301d00ab1df7a0f88985d143787f9f3c2283e38 (patch) | |
| tree | 4d1cbdafb4918966073d673f9c1349004d0ae3ee /src | |
| parent | added checks to find buggy mappings (diff) | |
| download | enigma-fork-3301d00ab1df7a0f88985d143787f9f3c2283e38.tar.gz enigma-fork-3301d00ab1df7a0f88985d143787f9f3c2283e38.tar.xz enigma-fork-3301d00ab1df7a0f88985d143787f9f3c2283e38.zip | |
added crash reporter
Diffstat (limited to 'src')
| -rw-r--r-- | src/cuchaz/enigma/gui/CrashDialog.java | 107 | ||||
| -rw-r--r-- | src/cuchaz/enigma/gui/Gui.java | 22 |
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 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 | ******************************************************************************/ | ||
| 11 | package cuchaz.enigma.gui; | ||
| 12 | |||
| 13 | import java.awt.BorderLayout; | ||
| 14 | import java.awt.Container; | ||
| 15 | import java.awt.FlowLayout; | ||
| 16 | import java.awt.event.ActionEvent; | ||
| 17 | import java.awt.event.ActionListener; | ||
| 18 | import java.io.PrintWriter; | ||
| 19 | import java.io.StringWriter; | ||
| 20 | |||
| 21 | import javax.swing.BorderFactory; | ||
| 22 | import javax.swing.JButton; | ||
| 23 | import javax.swing.JFrame; | ||
| 24 | import javax.swing.JLabel; | ||
| 25 | import javax.swing.JPanel; | ||
| 26 | import javax.swing.JScrollPane; | ||
| 27 | import javax.swing.JTextArea; | ||
| 28 | import javax.swing.WindowConstants; | ||
| 29 | |||
| 30 | import cuchaz.enigma.Constants; | ||
| 31 | |||
| 32 | public 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 3dcb4e2..e357382 100644 --- a/src/cuchaz/enigma/gui/Gui.java +++ b/src/cuchaz/enigma/gui/Gui.java | |||
| @@ -28,6 +28,7 @@ import java.awt.event.WindowAdapter; | |||
| 28 | import java.awt.event.WindowEvent; | 28 | import java.awt.event.WindowEvent; |
| 29 | import java.io.File; | 29 | import java.io.File; |
| 30 | import java.io.IOException; | 30 | import java.io.IOException; |
| 31 | import java.lang.Thread.UncaughtExceptionHandler; | ||
| 31 | import java.util.Collection; | 32 | import java.util.Collection; |
| 32 | import java.util.Collections; | 33 | import java.util.Collections; |
| 33 | import java.util.Comparator; | 34 | import 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 ); |