|
2 | 2 |
|
3 | 3 | import club.bytecode.the.jda.JDA; |
4 | 4 | import club.bytecode.the.jda.Resources; |
| 5 | +import club.bytecode.the.jda.settings.Settings; |
5 | 6 |
|
6 | 7 | import javax.swing.*; |
7 | 8 | import java.awt.*; |
|
13 | 14 | * |
14 | 15 | * @author Konloch |
15 | 16 | */ |
16 | | - |
17 | 17 | public class ExceptionUI extends JFrame { |
18 | 18 |
|
19 | 19 | private static final long serialVersionUID = -5230501978224926296L; |
20 | 20 |
|
21 | 21 | /** |
22 | 22 | * @param e The exception to be shown |
| 23 | + * @param context What JDA was doing when the exception occurred. Should be a gerund and lowercase |
23 | 24 | */ |
24 | | - public ExceptionUI(Throwable e) { |
25 | | - setup(e, JDA.ISSUE_TRACKER_URL); |
| 25 | + public ExceptionUI(Throwable e, String context) { |
| 26 | + StringWriter sw = new StringWriter(); |
| 27 | + e.printStackTrace(new PrintWriter(sw)); |
| 28 | + e.printStackTrace(); |
| 29 | + setup(sw.toString(), context); |
26 | 30 | } |
27 | 31 |
|
28 | 32 | /** |
29 | 33 | * @param e The exception to be shown |
| 34 | + * @param context What JDA was doing when the exception occurred. Should be a gerund and lowercase |
30 | 35 | */ |
31 | | - public ExceptionUI(String e) { |
32 | | - setup(e, JDA.ISSUE_TRACKER_URL); |
33 | | - } |
34 | | - |
35 | | - /** |
36 | | - * @param e The exception to be shown |
37 | | - * @param author the author of the plugin throwing this exception. |
38 | | - */ |
39 | | - public ExceptionUI(Throwable e, String author) { |
40 | | - setup(e, author); |
| 36 | + public ExceptionUI(String e, String context) { |
| 37 | + setup(e, context); |
41 | 38 | } |
42 | 39 |
|
43 | | - /** |
44 | | - * @param e The exception to be shown |
45 | | - * @param author the author of the plugin throwing this exception. |
46 | | - */ |
47 | | - public ExceptionUI(String e, String author) { |
48 | | - setup(e, author); |
49 | | - } |
50 | | - |
51 | | - private void setup(Throwable e, String author) { |
52 | | - this.setIconImages(Resources.iconList); |
53 | | - setSize(new Dimension(600, 400)); |
54 | | - setTitle("JDA v" + JDA.version + " - Stack Trace - Send this to " + author); |
55 | | - getContentPane().setLayout(new CardLayout(0, 0)); |
56 | | - |
57 | | - JTextArea txtrBytecodeViewerIs = new JTextArea(); |
58 | | - txtrBytecodeViewerIs.setDisabledTextColor(Color.BLACK); |
59 | | - txtrBytecodeViewerIs.setWrapStyleWord(true); |
60 | | - getContentPane().add(new JScrollPane(txtrBytecodeViewerIs), "name_140466576080695"); |
61 | | - StringWriter sw = new StringWriter(); |
62 | | - e.printStackTrace(new PrintWriter(sw)); |
63 | | - e.printStackTrace(); |
| 40 | + private void setup(String e, String context) { |
| 41 | + System.err.println("Error while " + context + ":"); |
| 42 | + System.err.println(e); |
64 | 43 |
|
65 | | - txtrBytecodeViewerIs.setText("JDA v" + JDA.version + JDA.nl + JDA.nl + sw.toString()); |
66 | | - this.setLocationRelativeTo(null); |
67 | | - this.setVisible(true); |
68 | | - } |
| 44 | + if (Settings.DONT_SHOW_EXCEPTIONS.getBool()) |
| 45 | + return; |
69 | 46 |
|
70 | | - private void setup(String e, String author) { |
71 | 47 | this.setIconImages(Resources.iconList); |
72 | | - setSize(new Dimension(600, 400)); |
73 | | - setTitle("JDA v" + JDA.version + " - Stack Trace - Send this to " + author); |
| 48 | + setSize(new Dimension(800, 400)); |
| 49 | + setTitle("JDA v" + JDA.version + " - Stack Trace - Send this to " + JDA.ISSUE_TRACKER_URL); |
74 | 50 | getContentPane().setLayout(new CardLayout(0, 0)); |
75 | 51 |
|
76 | 52 | JTextArea txtrBytecodeViewerIs = new JTextArea(); |
77 | 53 | txtrBytecodeViewerIs.setDisabledTextColor(Color.BLACK); |
78 | 54 | txtrBytecodeViewerIs.setWrapStyleWord(true); |
79 | 55 | getContentPane().add(new JScrollPane(txtrBytecodeViewerIs), "name_140466576080695"); |
80 | | - txtrBytecodeViewerIs.setText(e); |
81 | | - System.err.println(e); |
| 56 | + txtrBytecodeViewerIs.setFont(Settings.getCodeFont()); |
| 57 | + txtrBytecodeViewerIs.setText("Error while " + context + ":\n" + e); |
82 | 58 | this.setLocationRelativeTo(null); |
83 | 59 | this.setVisible(true); |
84 | 60 | } |
85 | | - |
86 | 61 | } |
0 commit comments