diff options
| author | 2016-07-03 00:05:04 +1000 | |
|---|---|---|
| committer | 2016-07-03 00:05:04 +1000 | |
| commit | 9a3e5a9d132735f818c379ba72c554362650690d (patch) | |
| tree | 2a454f96d99bdcfc5bdf0f6814a2ea7857698d1b /src/main/java/cuchaz/enigma/gui/CrashDialog.java | |
| parent | Fixed #4 (diff) | |
| download | enigma-fork-9a3e5a9d132735f818c379ba72c554362650690d.tar.gz enigma-fork-9a3e5a9d132735f818c379ba72c554362650690d.tar.xz enigma-fork-9a3e5a9d132735f818c379ba72c554362650690d.zip | |
Started Gui Refactor
Diffstat (limited to 'src/main/java/cuchaz/enigma/gui/CrashDialog.java')
| -rw-r--r-- | src/main/java/cuchaz/enigma/gui/CrashDialog.java | 86 |
1 files changed, 0 insertions, 86 deletions
diff --git a/src/main/java/cuchaz/enigma/gui/CrashDialog.java b/src/main/java/cuchaz/enigma/gui/CrashDialog.java deleted file mode 100644 index 3806f54..0000000 --- a/src/main/java/cuchaz/enigma/gui/CrashDialog.java +++ /dev/null | |||
| @@ -1,86 +0,0 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2015 Jeff Martin. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the GNU Lesser General Public | ||
| 5 | * License v3.0 which accompanies this distribution, and is available at | ||
| 6 | * http://www.gnu.org/licenses/lgpl.html | ||
| 7 | * <p> | ||
| 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.io.PrintWriter; | ||
| 17 | import java.io.StringWriter; | ||
| 18 | |||
| 19 | import javax.swing.*; | ||
| 20 | |||
| 21 | import cuchaz.enigma.Constants; | ||
| 22 | |||
| 23 | public class CrashDialog { | ||
| 24 | |||
| 25 | private static CrashDialog m_instance = null; | ||
| 26 | |||
| 27 | private JFrame m_frame; | ||
| 28 | private JTextArea m_text; | ||
| 29 | |||
| 30 | private CrashDialog(JFrame parent) { | ||
| 31 | // init frame | ||
| 32 | m_frame = new JFrame(Constants.NAME + " - Crash Report"); | ||
| 33 | final Container pane = m_frame.getContentPane(); | ||
| 34 | pane.setLayout(new BorderLayout()); | ||
| 35 | |||
| 36 | JLabel label = new JLabel(Constants.NAME + " has crashed! =("); | ||
| 37 | label.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); | ||
| 38 | pane.add(label, BorderLayout.NORTH); | ||
| 39 | |||
| 40 | // report panel | ||
| 41 | m_text = new JTextArea(); | ||
| 42 | m_text.setTabSize(2); | ||
| 43 | pane.add(new JScrollPane(m_text), BorderLayout.CENTER); | ||
| 44 | |||
| 45 | // buttons panel | ||
| 46 | JPanel buttonsPanel = new JPanel(); | ||
| 47 | FlowLayout buttonsLayout = new FlowLayout(); | ||
| 48 | buttonsLayout.setAlignment(FlowLayout.RIGHT); | ||
| 49 | buttonsPanel.setLayout(buttonsLayout); | ||
| 50 | buttonsPanel.add(GuiTricks.unboldLabel(new JLabel("If you choose exit, you will lose any unsaved work."))); | ||
| 51 | JButton ignoreButton = new JButton("Ignore"); | ||
| 52 | ignoreButton.addActionListener(event -> { | ||
| 53 | // close (hide) the dialog | ||
| 54 | m_frame.setVisible(false); | ||
| 55 | }); | ||
| 56 | buttonsPanel.add(ignoreButton); | ||
| 57 | JButton exitButton = new JButton("Exit"); | ||
| 58 | exitButton.addActionListener(event -> { | ||
| 59 | // exit enigma | ||
| 60 | System.exit(1); | ||
| 61 | }); | ||
| 62 | buttonsPanel.add(exitButton); | ||
| 63 | pane.add(buttonsPanel, BorderLayout.SOUTH); | ||
| 64 | |||
| 65 | // show the frame | ||
| 66 | m_frame.setSize(600, 400); | ||
| 67 | m_frame.setLocationRelativeTo(parent); | ||
| 68 | m_frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); | ||
| 69 | } | ||
| 70 | |||
| 71 | public static void init(JFrame parent) { | ||
| 72 | m_instance = new CrashDialog(parent); | ||
| 73 | } | ||
| 74 | |||
| 75 | public static void show(Throwable ex) { | ||
| 76 | // get the error report | ||
| 77 | StringWriter buf = new StringWriter(); | ||
| 78 | ex.printStackTrace(new PrintWriter(buf)); | ||
| 79 | String report = buf.toString(); | ||
| 80 | |||
| 81 | // show it! | ||
| 82 | m_instance.m_text.setText(report); | ||
| 83 | m_instance.m_frame.doLayout(); | ||
| 84 | m_instance.m_frame.setVisible(true); | ||
| 85 | } | ||
| 86 | } | ||