From 3216b173898ee84e8a9acdd02c7b99219bc63a1e Mon Sep 17 00:00:00 2001 From: Konloch Date: Sat, 26 Jun 2021 11:10:55 -0700 Subject: [PATCH] Multiple Choice Dialogue Cleanup --- .../club/bytecodeviewer/BytecodeViewer.java | 25 +++++------- .../bytecodeviewer/gui/MainViewerGUI.java | 38 +++++-------------- .../bytecodeviewer/util/VersionChecker.java | 36 ++++++------------ 3 files changed, 30 insertions(+), 69 deletions(-) diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/BytecodeViewer.java b/src/main/java/the/bytecode/club/bytecodeviewer/BytecodeViewer.java index 917fc892..dd271bc8 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/BytecodeViewer.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/BytecodeViewer.java @@ -554,23 +554,16 @@ public class BytecodeViewer * * @param ask if should require user input or not */ - public static void resetWorkSpace(boolean ask) { - if (ask) { - JOptionPane pane = new JOptionPane( - "Are you sure you want to reset the workspace?\n\rIt will also reset your file navigator and " - + "search."); - Object[] options = new String[]{"Yes", "No"}; - pane.setOptions(options); - JDialog dialog = pane.createDialog(viewer, - "Bytecode Viewer - Reset Workspace"); - dialog.setVisible(true); - Object obj = pane.getValue(); - int result = -1; - for (int k = 0; k < options.length; k++) - if (options[k].equals(obj)) - result = k; + public static void resetWorkSpace(boolean ask) + { + if (ask) + { + MultipleChoiceDialogue dialogue = new MultipleChoiceDialogue("Bytecode Viewer - Reset Workspace", + "Are you sure you want to reset the workspace?" + + "\n\rIt will also reset your file navigator and search.", + new String[]{"Yes", "No"}); - if (result != 0) + if (dialogue.promptChoice() != 0) return; } diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/gui/MainViewerGUI.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/MainViewerGUI.java index 0f8bb374..ade18005 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/gui/MainViewerGUI.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/MainViewerGUI.java @@ -11,10 +11,7 @@ import javax.swing.*; import org.objectweb.asm.tree.ClassNode; import the.bytecode.club.bytecodeviewer.*; import the.bytecode.club.bytecodeviewer.api.ExceptionUI; -import the.bytecode.club.bytecodeviewer.gui.components.FileChooser; -import the.bytecode.club.bytecodeviewer.gui.components.VisibleComponent; -import the.bytecode.club.bytecodeviewer.gui.components.AboutWindow; -import the.bytecode.club.bytecodeviewer.gui.components.RunOptions; +import the.bytecode.club.bytecodeviewer.gui.components.*; import the.bytecode.club.bytecodeviewer.gui.plugins.MaliciousCodeScannerOptions; import the.bytecode.club.bytecodeviewer.gui.plugins.ReplaceStringsOptions; import the.bytecode.club.bytecodeviewer.gui.resourcelist.ResourceListPane; @@ -765,18 +762,12 @@ public class MainViewerGUI extends JFrame public void reloadResources() { - JOptionPane pane = new JOptionPane("Are you sure you wish to reload the resources?"); - Object[] options = new String[]{"Yes", "No"}; - pane.setOptions(options); - JDialog dialog = pane.createDialog(BytecodeViewer.viewer, "Bytecode Viewer - Reload Resources"); - dialog.setVisible(true); - Object obj = pane.getValue(); - int result = -1; - for (int k = 0; k < options.length; k++) - if (options[k].equals(obj)) - result = k; + MultipleChoiceDialogue dialogue = new MultipleChoiceDialogue("Bytecode Viewer - Reload Resources", + "Are you sure you wish to reload the resources?", + new String[]{"Yes", "No"}); - if (result == 0) { + if (dialogue.promptChoice() == 0) + { LazyNameUtil.reset(); ArrayList reopen = new ArrayList<>(); @@ -944,20 +935,11 @@ public class MainViewerGUI extends JFrame public void askBeforeExiting() { - JOptionPane pane = new JOptionPane("Are you sure you want to exit?"); - - Object[] options = new String[]{"Yes", "No"}; - - pane.setOptions(options); - JDialog dialog = pane.createDialog(BytecodeViewer.viewer, "Bytecode Viewer - Exit"); - dialog.setVisible(true); - Object obj = pane.getValue(); - int result = -1; - for (int k = 0; k < options.length; k++) - if (options[k].equals(obj)) - result = k; + MultipleChoiceDialogue dialogue = new MultipleChoiceDialogue("Bytecode Viewer - Exit", + "Are you sure you want to exit?", + new String[]{"Yes", "No"}); - if (result == 0) + if (dialogue.promptChoice() == 0) { Configuration.canExit = true; System.exit(0); diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/util/VersionChecker.java b/src/main/java/the/bytecode/club/bytecodeviewer/util/VersionChecker.java index a68e6527..620cee88 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/util/VersionChecker.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/util/VersionChecker.java @@ -5,6 +5,7 @@ import the.bytecode.club.bytecodeviewer.BytecodeViewer; import the.bytecode.club.bytecodeviewer.Configuration; import the.bytecode.club.bytecodeviewer.api.ExceptionUI; import the.bytecode.club.bytecodeviewer.gui.components.FileChooser; +import the.bytecode.club.bytecodeviewer.gui.components.MultipleChoiceDialogue; import javax.swing.*; import javax.swing.filechooser.FileFilter; @@ -60,18 +61,12 @@ public class VersionChecker implements Runnable if (!VERSION.equals(version)) { - JOptionPane pane = new JOptionPane( + MultipleChoiceDialogue outdatedDialogue = new MultipleChoiceDialogue("Bytecode Viewer - Outdated Version", "Your version: " + VERSION + ", latest version: " - + version + nl + "What would you like to do?"); - Object[] options = new String[]{"Open The Download Page", "Download The Updated Jar", "Do Nothing"}; - pane.setOptions(options); - JDialog dialog = pane.createDialog(BytecodeViewer.viewer, "Bytecode Viewer - Outdated Version"); - dialog.setVisible(true); - Object obj = pane.getValue(); - int result = -1; - for (int k = 0; k < options.length; k++) - if (options[k].equals(obj)) - result = k; + + version + nl + "What would you like to do?", + new String[]{"Open The Download Page", "Download The Updated Jar", "Do Nothing"}); + + int result = outdatedDialogue.promptChoice(); if (result == 0) { @@ -80,8 +75,7 @@ public class VersionChecker implements Runnable else BytecodeViewer.showMessage("Cannot open the page, please manually type it." + nl + "https://github.com/Konloch/bytecode-viewer/releases"); } - - if (result == 1) + else if (result == 1) { JFileChooser fc = new FileChooser(new File(Configuration.lastDirectory), "Select Save File", @@ -104,19 +98,11 @@ public class VersionChecker implements Runnable if (file.exists()) { - pane = new JOptionPane("The file " + file + " exists, would you like to overwrite it?"); - options = new String[]{"Yes", "No"}; - pane.setOptions(options); - dialog = pane.createDialog(BytecodeViewer.viewer, - "Bytecode Viewer - Overwrite File"); - dialog.setVisible(true); - obj = pane.getValue(); - result = -1; - for (int k = 0; k < options.length; k++) - if (options[k].equals(obj)) - result = k; + MultipleChoiceDialogue overwriteDialogue = new MultipleChoiceDialogue("Bytecode Viewer - Overwrite File", + "The file " + file + " exists, would you like to overwrite it?", + new String[]{"Yes", "No"}); - if (result != 0) + if (overwriteDialogue.promptChoice() != 0) return; file.delete();