Skip to content

Commit

Permalink
Rework menu placement to make it more like a certain other tool
Browse files Browse the repository at this point in the history
  • Loading branch information
rcx committed Aug 28, 2018
1 parent 9679c5c commit 4192449
Show file tree
Hide file tree
Showing 12 changed files with 103 additions and 203 deletions.
2 changes: 1 addition & 1 deletion src/main/java/club/bytecode/the/jda/Boot.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class Boot {
try {
screen = new InitialBootScreen();
} catch (Exception e) {
new ExceptionUI(e);
new ExceptionUI(e, "displaying boot screen");
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/club/bytecode/the/jda/FileDrop.java
Original file line number Diff line number Diff line change
Expand Up @@ -330,12 +330,12 @@ public void drop(final java.awt.dnd.DropTargetDropEvent evt) {
} // end try
catch (final java.io.IOException io) {
log(out, "FileDrop: IOException - abort:");
new ExceptionUI(io);
new ExceptionUI(io, "handling drag/drop");
evt.rejectDrop();
} // end catch IOException
catch (final java.awt.datatransfer.UnsupportedFlavorException ufe) {
log(out, "FileDrop: UnsupportedFlavorException - abort:");
new ExceptionUI(ufe);
new ExceptionUI(ufe, "handling drag/drop");
evt.rejectDrop();
} // end catch: UnsupportedFlavorException
finally {
Expand Down Expand Up @@ -434,7 +434,7 @@ private void makeDropTarget(final java.io.PrintStream out, final java.awt.Compon
dt.addDropTargetListener(dropListener);
} // end try
catch (final java.util.TooManyListenersException e) {
new ExceptionUI(e);
new ExceptionUI(e, "initializing drag/drop target");
log(out, "FileDrop: Drop will not work due to previous error. Do you have another listener attached?");
} // end catch

Expand Down
29 changes: 10 additions & 19 deletions src/main/java/club/bytecode/the/jda/JDA.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public static void main(String[] args) {
Boot.boot();
JDA.boot(args);
} catch (Exception e) {
new ExceptionUI(e);
new ExceptionUI(e, "initializing");
}
}

Expand Down Expand Up @@ -181,7 +181,7 @@ private static void onExit() {
try {
FileUtils.writeLines(recentsFile, recentFiles);
} catch (IOException e) {
new ExceptionUI(e);
new ExceptionUI(e, "saving recent files");
}
if (!viewer.isMaximized)
viewer.unmaximizedPos = viewer.getLocation();
Expand Down Expand Up @@ -320,7 +320,7 @@ public static void openFiles(final File[] files, boolean recentFiles, FileNaviga
openFile(newContainer);
fnp.addTreeElement(newContainer, parent);
} catch (final Exception e) {
new ExceptionUI(e);
new ExceptionUI(e, "loading jar");
}
} else {
HashMap<String, byte[]> files1 = new HashMap<>();
Expand All @@ -332,8 +332,8 @@ public static void openFiles(final File[] files, boolean recentFiles, FileNaviga
fnp.addTreeElement(container, parent);
}
}
} catch (final Exception e) {
new ExceptionUI(e);
} catch (Exception e) {
new ExceptionUI(e, "loading file");
} finally {
JDA.setBusy(false);
}
Expand Down Expand Up @@ -486,32 +486,23 @@ public static String getJDADirectory() {
while (!dataDir.exists())
dataDir.mkdirs();

if (!dataDir.isHidden() && isWindows())
hideFile(dataDir);
if (!dataDir.isHidden() && SystemUtils.IS_OS_WINDOWS)
hideFileWindows(dataDir);

return dataDir.getAbsolutePath();
}

/**
* Checks if the OS contains 'win'
*
* @return true if the os.name property contains 'win'
*/
private static boolean isWindows() {
return System.getProperty("os.name").toLowerCase().contains("win");
}

/**
* Runs the windows command to hide files
*
* @param f file you want hidden
*/
private static void hideFile(File f) {
private static void hideFileWindows(File f) {
try {
// Hide file by running attrib system command (on Windows)
Runtime.getRuntime().exec("attrib +H " + f.getAbsolutePath());
} catch (Exception e) {
new ExceptionUI(e);
new ExceptionUI(e, "hiding file");
}
}

Expand Down Expand Up @@ -568,7 +559,7 @@ public static void openFileChooser() {
JDA.openFiles(new File[]{fc.getSelectedFile()}, true);
JDA.setBusy(false);
} catch (Exception e1) {
new ExceptionUI(e1);
new ExceptionUI(e1, "choosing file");
}
}
}
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/club/bytecode/the/jda/JarUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public static FileContainer load(final File jarFile) throws IOException {
}
}
} catch (Exception e) {
new ExceptionUI(e);
new ExceptionUI(e, "loading jar");
} finally {
jis.closeEntry();
}
Expand Down Expand Up @@ -75,7 +75,7 @@ public static ArrayList<ClassNode> loadClasses(final File jarFile) throws IOExce
}

} catch (Exception e) {
new ExceptionUI(e);
new ExceptionUI(e, "loading classes from jarfile");
} finally {
jis.closeEntry();
}
Expand Down Expand Up @@ -109,7 +109,7 @@ public static HashMap<String, byte[]> loadResources(final File zipFile) throws I
continue;
}
} catch (Exception e) {
new ExceptionUI(e);
new ExceptionUI(e, "loading resources from file");
} finally {
jis.closeEntry();
}
Expand Down Expand Up @@ -196,7 +196,7 @@ public static void saveAsJar(ArrayList<ClassNode> nodeList, String path, String

out.close();
} catch (IOException e) {
new ExceptionUI(e);
new ExceptionUI(e, "saving as jar");
}
}

Expand Down Expand Up @@ -227,7 +227,7 @@ public static void saveAsJarClassesOnly(ArrayList<ClassNode> nodeList, String pa
noDupe.clear();
out.close();
} catch (IOException e) {
new ExceptionUI(e);
new ExceptionUI(e, "saving as jar");
}
}

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

Expand Down Expand Up @@ -282,7 +282,7 @@ public static void saveAsJar(Map<String, byte[]> nodeList, String path) {
noDupe.clear();
out.close();
} catch (IOException e) {
new ExceptionUI(e);
new ExceptionUI(e, "saving as jar");
}
}
}
63 changes: 19 additions & 44 deletions src/main/java/club/bytecode/the/jda/api/ExceptionUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import club.bytecode.the.jda.JDA;
import club.bytecode.the.jda.Resources;
import club.bytecode.the.jda.settings.Settings;

import javax.swing.*;
import java.awt.*;
Expand All @@ -13,74 +14,48 @@
*
* @author Konloch
*/

public class ExceptionUI extends JFrame {

private static final long serialVersionUID = -5230501978224926296L;

/**
* @param e The exception to be shown
* @param context What JDA was doing when the exception occurred. Should be a gerund and lowercase
*/
public ExceptionUI(Throwable e) {
setup(e, JDA.ISSUE_TRACKER_URL);
public ExceptionUI(Throwable e, String context) {
StringWriter sw = new StringWriter();
e.printStackTrace(new PrintWriter(sw));
e.printStackTrace();
setup(sw.toString(), context);
}

/**
* @param e The exception to be shown
* @param context What JDA was doing when the exception occurred. Should be a gerund and lowercase
*/
public ExceptionUI(String e) {
setup(e, JDA.ISSUE_TRACKER_URL);
}

/**
* @param e The exception to be shown
* @param author the author of the plugin throwing this exception.
*/
public ExceptionUI(Throwable e, String author) {
setup(e, author);
public ExceptionUI(String e, String context) {
setup(e, context);
}

/**
* @param e The exception to be shown
* @param author the author of the plugin throwing this exception.
*/
public ExceptionUI(String e, String author) {
setup(e, author);
}

private void setup(Throwable e, String author) {
this.setIconImages(Resources.iconList);
setSize(new Dimension(600, 400));
setTitle("JDA v" + JDA.version + " - Stack Trace - Send this to " + author);
getContentPane().setLayout(new CardLayout(0, 0));

JTextArea txtrBytecodeViewerIs = new JTextArea();
txtrBytecodeViewerIs.setDisabledTextColor(Color.BLACK);
txtrBytecodeViewerIs.setWrapStyleWord(true);
getContentPane().add(new JScrollPane(txtrBytecodeViewerIs), "name_140466576080695");
StringWriter sw = new StringWriter();
e.printStackTrace(new PrintWriter(sw));
e.printStackTrace();
private void setup(String e, String context) {
System.err.println("Error while " + context + ":");
System.err.println(e);

txtrBytecodeViewerIs.setText("JDA v" + JDA.version + JDA.nl + JDA.nl + sw.toString());
this.setLocationRelativeTo(null);
this.setVisible(true);
}
if (Settings.DONT_SHOW_EXCEPTIONS.getBool())
return;

private void setup(String e, String author) {
this.setIconImages(Resources.iconList);
setSize(new Dimension(600, 400));
setTitle("JDA v" + JDA.version + " - Stack Trace - Send this to " + author);
setSize(new Dimension(800, 400));
setTitle("JDA v" + JDA.version + " - Stack Trace - Send this to " + JDA.ISSUE_TRACKER_URL);
getContentPane().setLayout(new CardLayout(0, 0));

JTextArea txtrBytecodeViewerIs = new JTextArea();
txtrBytecodeViewerIs.setDisabledTextColor(Color.BLACK);
txtrBytecodeViewerIs.setWrapStyleWord(true);
getContentPane().add(new JScrollPane(txtrBytecodeViewerIs), "name_140466576080695");
txtrBytecodeViewerIs.setText(e);
System.err.println(e);
txtrBytecodeViewerIs.setFont(Settings.getCodeFont());
txtrBytecodeViewerIs.setText("Error while " + context + ":\n" + e);
this.setLocationRelativeTo(null);
this.setVisible(true);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ protected String printTypeInsnNode(TypeInsnNode tin) {
}
return nameOpcode(tin.opcode()) + " " + desc;
} catch (Exception e) {
new ExceptionUI(e);
new ExceptionUI(e, "printing instruction");
}
return "// error";
}
Expand Down Expand Up @@ -344,17 +344,4 @@ protected int resolveLabel(LabelNode label) {
return newLabelIndex;
}
}

public static void saveTo(File file, InstructionPrinter printer) {
try {
BufferedWriter bw = new BufferedWriter(new FileWriter(file));
for (String s : printer.createPrint()) {
bw.write(s);
bw.newLine();
}
bw.close();
} catch (IOException e) {
new ExceptionUI(e);
}
}
}
Loading

0 comments on commit 4192449

Please sign in to comment.