Multiple Choice Dialogue Cleanup

This commit is contained in:
Konloch 2021-06-26 11:10:55 -07:00
parent c774bf441b
commit 3216b17389
3 changed files with 30 additions and 69 deletions

View file

@ -554,23 +554,16 @@ public class BytecodeViewer
* *
* @param ask if should require user input or not * @param ask if should require user input or not
*/ */
public static void resetWorkSpace(boolean ask) { public static void resetWorkSpace(boolean ask)
if (ask) { {
JOptionPane pane = new JOptionPane( if (ask)
"Are you sure you want to reset the workspace?\n\rIt will also reset your file navigator and " {
+ "search."); MultipleChoiceDialogue dialogue = new MultipleChoiceDialogue("Bytecode Viewer - Reset Workspace",
Object[] options = new String[]{"Yes", "No"}; "Are you sure you want to reset the workspace?" +
pane.setOptions(options); "\n\rIt will also reset your file navigator and search.",
JDialog dialog = pane.createDialog(viewer, new String[]{"Yes", "No"});
"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;
if (result != 0) if (dialogue.promptChoice() != 0)
return; return;
} }

View file

@ -11,10 +11,7 @@ import javax.swing.*;
import org.objectweb.asm.tree.ClassNode; import org.objectweb.asm.tree.ClassNode;
import the.bytecode.club.bytecodeviewer.*; import the.bytecode.club.bytecodeviewer.*;
import the.bytecode.club.bytecodeviewer.api.ExceptionUI; import the.bytecode.club.bytecodeviewer.api.ExceptionUI;
import the.bytecode.club.bytecodeviewer.gui.components.FileChooser; import the.bytecode.club.bytecodeviewer.gui.components.*;
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.plugins.MaliciousCodeScannerOptions; import the.bytecode.club.bytecodeviewer.gui.plugins.MaliciousCodeScannerOptions;
import the.bytecode.club.bytecodeviewer.gui.plugins.ReplaceStringsOptions; import the.bytecode.club.bytecodeviewer.gui.plugins.ReplaceStringsOptions;
import the.bytecode.club.bytecodeviewer.gui.resourcelist.ResourceListPane; import the.bytecode.club.bytecodeviewer.gui.resourcelist.ResourceListPane;
@ -765,18 +762,12 @@ public class MainViewerGUI extends JFrame
public void reloadResources() public void reloadResources()
{ {
JOptionPane pane = new JOptionPane("Are you sure you wish to reload the resources?"); MultipleChoiceDialogue dialogue = new MultipleChoiceDialogue("Bytecode Viewer - Reload Resources",
Object[] options = new String[]{"Yes", "No"}; "Are you sure you wish to reload the resources?",
pane.setOptions(options); new String[]{"Yes", "No"});
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;
if (result == 0) { if (dialogue.promptChoice() == 0)
{
LazyNameUtil.reset(); LazyNameUtil.reset();
ArrayList<File> reopen = new ArrayList<>(); ArrayList<File> reopen = new ArrayList<>();
@ -944,20 +935,11 @@ public class MainViewerGUI extends JFrame
public void askBeforeExiting() public void askBeforeExiting()
{ {
JOptionPane pane = new JOptionPane("Are you sure you want to exit?"); MultipleChoiceDialogue dialogue = new MultipleChoiceDialogue("Bytecode Viewer - Exit",
"Are you sure you want to exit?",
new String[]{"Yes", "No"});
Object[] options = new String[]{"Yes", "No"}; if (dialogue.promptChoice() == 0)
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;
if (result == 0)
{ {
Configuration.canExit = true; Configuration.canExit = true;
System.exit(0); System.exit(0);

View file

@ -5,6 +5,7 @@ import the.bytecode.club.bytecodeviewer.BytecodeViewer;
import the.bytecode.club.bytecodeviewer.Configuration; import the.bytecode.club.bytecodeviewer.Configuration;
import the.bytecode.club.bytecodeviewer.api.ExceptionUI; import the.bytecode.club.bytecodeviewer.api.ExceptionUI;
import the.bytecode.club.bytecodeviewer.gui.components.FileChooser; import the.bytecode.club.bytecodeviewer.gui.components.FileChooser;
import the.bytecode.club.bytecodeviewer.gui.components.MultipleChoiceDialogue;
import javax.swing.*; import javax.swing.*;
import javax.swing.filechooser.FileFilter; import javax.swing.filechooser.FileFilter;
@ -60,18 +61,12 @@ public class VersionChecker implements Runnable
if (!VERSION.equals(version)) if (!VERSION.equals(version))
{ {
JOptionPane pane = new JOptionPane( MultipleChoiceDialogue outdatedDialogue = new MultipleChoiceDialogue("Bytecode Viewer - Outdated Version",
"Your version: " + VERSION + ", latest version: " "Your version: " + VERSION + ", latest version: "
+ version + nl + "What would you like to do?"); + version + nl + "What would you like to do?",
Object[] options = new String[]{"Open The Download Page", "Download The Updated Jar", "Do Nothing"}; 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"); int result = outdatedDialogue.promptChoice();
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;
if (result == 0) if (result == 0)
{ {
@ -80,8 +75,7 @@ public class VersionChecker implements Runnable
else else
BytecodeViewer.showMessage("Cannot open the page, please manually type it." + nl + "https://github.com/Konloch/bytecode-viewer/releases"); BytecodeViewer.showMessage("Cannot open the page, please manually type it." + nl + "https://github.com/Konloch/bytecode-viewer/releases");
} }
else if (result == 1)
if (result == 1)
{ {
JFileChooser fc = new FileChooser(new File(Configuration.lastDirectory), JFileChooser fc = new FileChooser(new File(Configuration.lastDirectory),
"Select Save File", "Select Save File",
@ -104,19 +98,11 @@ public class VersionChecker implements Runnable
if (file.exists()) if (file.exists())
{ {
pane = new JOptionPane("The file " + file + " exists, would you like to overwrite it?"); MultipleChoiceDialogue overwriteDialogue = new MultipleChoiceDialogue("Bytecode Viewer - Overwrite File",
options = new String[]{"Yes", "No"}; "The file " + file + " exists, would you like to overwrite it?",
pane.setOptions(options); new String[]{"Yes", "No"});
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;
if (result != 0) if (overwriteDialogue.promptChoice() != 0)
return; return;
file.delete(); file.delete();