Skip to content

Commit 4192449

Browse files
committed
Rework menu placement to make it more like a certain other tool
1 parent 9679c5c commit 4192449

File tree

12 files changed

+103
-203
lines changed

12 files changed

+103
-203
lines changed

src/main/java/club/bytecode/the/jda/Boot.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public class Boot {
1515
try {
1616
screen = new InitialBootScreen();
1717
} catch (Exception e) {
18-
new ExceptionUI(e);
18+
new ExceptionUI(e, "displaying boot screen");
1919
}
2020
}
2121

src/main/java/club/bytecode/the/jda/FileDrop.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -330,12 +330,12 @@ public void drop(final java.awt.dnd.DropTargetDropEvent evt) {
330330
} // end try
331331
catch (final java.io.IOException io) {
332332
log(out, "FileDrop: IOException - abort:");
333-
new ExceptionUI(io);
333+
new ExceptionUI(io, "handling drag/drop");
334334
evt.rejectDrop();
335335
} // end catch IOException
336336
catch (final java.awt.datatransfer.UnsupportedFlavorException ufe) {
337337
log(out, "FileDrop: UnsupportedFlavorException - abort:");
338-
new ExceptionUI(ufe);
338+
new ExceptionUI(ufe, "handling drag/drop");
339339
evt.rejectDrop();
340340
} // end catch: UnsupportedFlavorException
341341
finally {
@@ -434,7 +434,7 @@ private void makeDropTarget(final java.io.PrintStream out, final java.awt.Compon
434434
dt.addDropTargetListener(dropListener);
435435
} // end try
436436
catch (final java.util.TooManyListenersException e) {
437-
new ExceptionUI(e);
437+
new ExceptionUI(e, "initializing drag/drop target");
438438
log(out, "FileDrop: Drop will not work due to previous error. Do you have another listener attached?");
439439
} // end catch
440440

src/main/java/club/bytecode/the/jda/JDA.java

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public static void main(String[] args) {
8686
Boot.boot();
8787
JDA.boot(args);
8888
} catch (Exception e) {
89-
new ExceptionUI(e);
89+
new ExceptionUI(e, "initializing");
9090
}
9191
}
9292

@@ -181,7 +181,7 @@ private static void onExit() {
181181
try {
182182
FileUtils.writeLines(recentsFile, recentFiles);
183183
} catch (IOException e) {
184-
new ExceptionUI(e);
184+
new ExceptionUI(e, "saving recent files");
185185
}
186186
if (!viewer.isMaximized)
187187
viewer.unmaximizedPos = viewer.getLocation();
@@ -320,7 +320,7 @@ public static void openFiles(final File[] files, boolean recentFiles, FileNaviga
320320
openFile(newContainer);
321321
fnp.addTreeElement(newContainer, parent);
322322
} catch (final Exception e) {
323-
new ExceptionUI(e);
323+
new ExceptionUI(e, "loading jar");
324324
}
325325
} else {
326326
HashMap<String, byte[]> files1 = new HashMap<>();
@@ -332,8 +332,8 @@ public static void openFiles(final File[] files, boolean recentFiles, FileNaviga
332332
fnp.addTreeElement(container, parent);
333333
}
334334
}
335-
} catch (final Exception e) {
336-
new ExceptionUI(e);
335+
} catch (Exception e) {
336+
new ExceptionUI(e, "loading file");
337337
} finally {
338338
JDA.setBusy(false);
339339
}
@@ -486,32 +486,23 @@ public static String getJDADirectory() {
486486
while (!dataDir.exists())
487487
dataDir.mkdirs();
488488

489-
if (!dataDir.isHidden() && isWindows())
490-
hideFile(dataDir);
489+
if (!dataDir.isHidden() && SystemUtils.IS_OS_WINDOWS)
490+
hideFileWindows(dataDir);
491491

492492
return dataDir.getAbsolutePath();
493493
}
494494

495-
/**
496-
* Checks if the OS contains 'win'
497-
*
498-
* @return true if the os.name property contains 'win'
499-
*/
500-
private static boolean isWindows() {
501-
return System.getProperty("os.name").toLowerCase().contains("win");
502-
}
503-
504495
/**
505496
* Runs the windows command to hide files
506497
*
507498
* @param f file you want hidden
508499
*/
509-
private static void hideFile(File f) {
500+
private static void hideFileWindows(File f) {
510501
try {
511502
// Hide file by running attrib system command (on Windows)
512503
Runtime.getRuntime().exec("attrib +H " + f.getAbsolutePath());
513504
} catch (Exception e) {
514-
new ExceptionUI(e);
505+
new ExceptionUI(e, "hiding file");
515506
}
516507
}
517508

@@ -568,7 +559,7 @@ public static void openFileChooser() {
568559
JDA.openFiles(new File[]{fc.getSelectedFile()}, true);
569560
JDA.setBusy(false);
570561
} catch (Exception e1) {
571-
new ExceptionUI(e1);
562+
new ExceptionUI(e1, "choosing file");
572563
}
573564
}
574565
}

src/main/java/club/bytecode/the/jda/JarUtils.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public static FileContainer load(final File jarFile) throws IOException {
4141
}
4242
}
4343
} catch (Exception e) {
44-
new ExceptionUI(e);
44+
new ExceptionUI(e, "loading jar");
4545
} finally {
4646
jis.closeEntry();
4747
}
@@ -75,7 +75,7 @@ public static ArrayList<ClassNode> loadClasses(final File jarFile) throws IOExce
7575
}
7676

7777
} catch (Exception e) {
78-
new ExceptionUI(e);
78+
new ExceptionUI(e, "loading classes from jarfile");
7979
} finally {
8080
jis.closeEntry();
8181
}
@@ -109,7 +109,7 @@ public static HashMap<String, byte[]> loadResources(final File zipFile) throws I
109109
continue;
110110
}
111111
} catch (Exception e) {
112-
new ExceptionUI(e);
112+
new ExceptionUI(e, "loading resources from file");
113113
} finally {
114114
jis.closeEntry();
115115
}
@@ -196,7 +196,7 @@ public static void saveAsJar(ArrayList<ClassNode> nodeList, String path, String
196196

197197
out.close();
198198
} catch (IOException e) {
199-
new ExceptionUI(e);
199+
new ExceptionUI(e, "saving as jar");
200200
}
201201
}
202202

@@ -227,7 +227,7 @@ public static void saveAsJarClassesOnly(ArrayList<ClassNode> nodeList, String pa
227227
noDupe.clear();
228228
out.close();
229229
} catch (IOException e) {
230-
new ExceptionUI(e);
230+
new ExceptionUI(e, "saving as jar");
231231
}
232232
}
233233

@@ -248,7 +248,7 @@ public static void saveAsJarClassesOnly(Map<String, byte[]> nodeList, String pat
248248
noDupe.clear();
249249
out.close();
250250
} catch (IOException e) {
251-
new ExceptionUI(e);
251+
new ExceptionUI(e, "saving as jar");
252252
}
253253
}
254254

@@ -282,7 +282,7 @@ public static void saveAsJar(Map<String, byte[]> nodeList, String path) {
282282
noDupe.clear();
283283
out.close();
284284
} catch (IOException e) {
285-
new ExceptionUI(e);
285+
new ExceptionUI(e, "saving as jar");
286286
}
287287
}
288288
}

src/main/java/club/bytecode/the/jda/api/ExceptionUI.java

Lines changed: 19 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import club.bytecode.the.jda.JDA;
44
import club.bytecode.the.jda.Resources;
5+
import club.bytecode.the.jda.settings.Settings;
56

67
import javax.swing.*;
78
import java.awt.*;
@@ -13,74 +14,48 @@
1314
*
1415
* @author Konloch
1516
*/
16-
1717
public class ExceptionUI extends JFrame {
1818

1919
private static final long serialVersionUID = -5230501978224926296L;
2020

2121
/**
2222
* @param e The exception to be shown
23+
* @param context What JDA was doing when the exception occurred. Should be a gerund and lowercase
2324
*/
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);
2630
}
2731

2832
/**
2933
* @param e The exception to be shown
34+
* @param context What JDA was doing when the exception occurred. Should be a gerund and lowercase
3035
*/
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);
4138
}
4239

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);
6443

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;
6946

70-
private void setup(String e, String author) {
7147
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);
7450
getContentPane().setLayout(new CardLayout(0, 0));
7551

7652
JTextArea txtrBytecodeViewerIs = new JTextArea();
7753
txtrBytecodeViewerIs.setDisabledTextColor(Color.BLACK);
7854
txtrBytecodeViewerIs.setWrapStyleWord(true);
7955
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);
8258
this.setLocationRelativeTo(null);
8359
this.setVisible(true);
8460
}
85-
8661
}

src/main/java/club/bytecode/the/jda/decompilers/bytecode/InstructionPrinter.java

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ protected String printTypeInsnNode(TypeInsnNode tin) {
247247
}
248248
return nameOpcode(tin.opcode()) + " " + desc;
249249
} catch (Exception e) {
250-
new ExceptionUI(e);
250+
new ExceptionUI(e, "printing instruction");
251251
}
252252
return "// error";
253253
}
@@ -344,17 +344,4 @@ protected int resolveLabel(LabelNode label) {
344344
return newLabelIndex;
345345
}
346346
}
347-
348-
public static void saveTo(File file, InstructionPrinter printer) {
349-
try {
350-
BufferedWriter bw = new BufferedWriter(new FileWriter(file));
351-
for (String s : printer.createPrint()) {
352-
bw.write(s);
353-
bw.newLine();
354-
}
355-
bw.close();
356-
} catch (IOException e) {
357-
new ExceptionUI(e);
358-
}
359-
}
360347
}

0 commit comments

Comments
 (0)