diff options
Diffstat (limited to 'src/cuchaz/enigma/gui/CrashDialog.java')
| -rw-r--r-- | src/cuchaz/enigma/gui/CrashDialog.java | 77 |
1 files changed, 35 insertions, 42 deletions
diff --git a/src/cuchaz/enigma/gui/CrashDialog.java b/src/cuchaz/enigma/gui/CrashDialog.java index 0eb9830..360091a 100644 --- a/src/cuchaz/enigma/gui/CrashDialog.java +++ b/src/cuchaz/enigma/gui/CrashDialog.java | |||
| @@ -29,80 +29,73 @@ import javax.swing.WindowConstants; | |||
| 29 | 29 | ||
| 30 | import cuchaz.enigma.Constants; | 30 | import cuchaz.enigma.Constants; |
| 31 | 31 | ||
| 32 | public class CrashDialog | 32 | public class CrashDialog { |
| 33 | { | 33 | |
| 34 | private static CrashDialog m_instance = null; | 34 | private static CrashDialog m_instance = null; |
| 35 | 35 | ||
| 36 | private JFrame m_frame; | 36 | private JFrame m_frame; |
| 37 | private JTextArea m_text; | 37 | private JTextArea m_text; |
| 38 | 38 | ||
| 39 | private CrashDialog( JFrame parent ) | 39 | private CrashDialog(JFrame parent) { |
| 40 | { | ||
| 41 | // init frame | 40 | // init frame |
| 42 | m_frame = new JFrame( Constants.Name + " - Crash Report" ); | 41 | m_frame = new JFrame(Constants.Name + " - Crash Report"); |
| 43 | final Container pane = m_frame.getContentPane(); | 42 | final Container pane = m_frame.getContentPane(); |
| 44 | pane.setLayout( new BorderLayout() ); | 43 | pane.setLayout(new BorderLayout()); |
| 45 | 44 | ||
| 46 | JLabel label = new JLabel( Constants.Name + " has crashed! =(" ); | 45 | JLabel label = new JLabel(Constants.Name + " has crashed! =("); |
| 47 | label.setBorder( BorderFactory.createEmptyBorder( 10, 10, 10, 10 ) ); | 46 | label.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); |
| 48 | pane.add( label, BorderLayout.NORTH ); | 47 | pane.add(label, BorderLayout.NORTH); |
| 49 | 48 | ||
| 50 | // report panel | 49 | // report panel |
| 51 | m_text = new JTextArea(); | 50 | m_text = new JTextArea(); |
| 52 | m_text.setTabSize( 2 ); | 51 | m_text.setTabSize(2); |
| 53 | pane.add( new JScrollPane( m_text ), BorderLayout.CENTER ); | 52 | pane.add(new JScrollPane(m_text), BorderLayout.CENTER); |
| 54 | 53 | ||
| 55 | // buttons panel | 54 | // buttons panel |
| 56 | JPanel buttonsPanel = new JPanel(); | 55 | JPanel buttonsPanel = new JPanel(); |
| 57 | FlowLayout buttonsLayout = new FlowLayout(); | 56 | FlowLayout buttonsLayout = new FlowLayout(); |
| 58 | buttonsLayout.setAlignment( FlowLayout.RIGHT ); | 57 | buttonsLayout.setAlignment(FlowLayout.RIGHT); |
| 59 | buttonsPanel.setLayout( buttonsLayout ); | 58 | buttonsPanel.setLayout(buttonsLayout); |
| 60 | buttonsPanel.add( GuiTricks.unboldLabel( new JLabel( "If you choose exit, you will lose any unsaved work." ) ) ); | 59 | buttonsPanel.add(GuiTricks.unboldLabel(new JLabel("If you choose exit, you will lose any unsaved work."))); |
| 61 | JButton ignoreButton = new JButton( "Ignore" ); | 60 | JButton ignoreButton = new JButton("Ignore"); |
| 62 | ignoreButton.addActionListener( new ActionListener( ) | 61 | ignoreButton.addActionListener(new ActionListener() { |
| 63 | { | ||
| 64 | @Override | 62 | @Override |
| 65 | public void actionPerformed( ActionEvent event ) | 63 | public void actionPerformed(ActionEvent event) { |
| 66 | { | ||
| 67 | // close (hide) the dialog | 64 | // close (hide) the dialog |
| 68 | m_frame.setVisible( false ); | 65 | m_frame.setVisible(false); |
| 69 | } | 66 | } |
| 70 | } ); | 67 | }); |
| 71 | buttonsPanel.add( ignoreButton ); | 68 | buttonsPanel.add(ignoreButton); |
| 72 | JButton exitButton = new JButton( "Exit" ); | 69 | JButton exitButton = new JButton("Exit"); |
| 73 | exitButton.addActionListener( new ActionListener( ) | 70 | exitButton.addActionListener(new ActionListener() { |
| 74 | { | ||
| 75 | @Override | 71 | @Override |
| 76 | public void actionPerformed( ActionEvent event ) | 72 | public void actionPerformed(ActionEvent event) { |
| 77 | { | ||
| 78 | // exit enigma | 73 | // exit enigma |
| 79 | System.exit( 1 ); | 74 | System.exit(1); |
| 80 | } | 75 | } |
| 81 | } ); | 76 | }); |
| 82 | buttonsPanel.add( exitButton ); | 77 | buttonsPanel.add(exitButton); |
| 83 | pane.add( buttonsPanel, BorderLayout.SOUTH ); | 78 | pane.add(buttonsPanel, BorderLayout.SOUTH); |
| 84 | 79 | ||
| 85 | // show the frame | 80 | // show the frame |
| 86 | m_frame.setSize( 600, 400 ); | 81 | m_frame.setSize(600, 400); |
| 87 | m_frame.setLocationRelativeTo( parent ); | 82 | m_frame.setLocationRelativeTo(parent); |
| 88 | m_frame.setDefaultCloseOperation( WindowConstants.DO_NOTHING_ON_CLOSE ); | 83 | m_frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); |
| 89 | } | 84 | } |
| 90 | 85 | ||
| 91 | public static void init( JFrame parent ) | 86 | public static void init(JFrame parent) { |
| 92 | { | 87 | m_instance = new CrashDialog(parent); |
| 93 | m_instance = new CrashDialog( parent ); | ||
| 94 | } | 88 | } |
| 95 | 89 | ||
| 96 | public static void show( Throwable ex ) | 90 | public static void show(Throwable ex) { |
| 97 | { | ||
| 98 | // get the error report | 91 | // get the error report |
| 99 | StringWriter buf = new StringWriter(); | 92 | StringWriter buf = new StringWriter(); |
| 100 | ex.printStackTrace( new PrintWriter( buf ) ); | 93 | ex.printStackTrace(new PrintWriter(buf)); |
| 101 | String report = buf.toString(); | 94 | String report = buf.toString(); |
| 102 | 95 | ||
| 103 | // show it! | 96 | // show it! |
| 104 | m_instance.m_text.setText( report ); | 97 | m_instance.m_text.setText(report); |
| 105 | m_instance.m_frame.doLayout(); | 98 | m_instance.m_frame.doLayout(); |
| 106 | m_instance.m_frame.setVisible( true ); | 99 | m_instance.m_frame.setVisible(true); |
| 107 | } | 100 | } |
| 108 | } | 101 | } |