Dialogue Cleanup

This commit is contained in:
Konloch 2021-07-01 16:08:56 -07:00
parent 9003b83e68
commit 1cf65954c5
5 changed files with 134 additions and 150 deletions

View file

@ -644,25 +644,20 @@ public class BytecodeViewer
if (System.currentTimeMillis() - Configuration.lastHotKeyExecuted <= (4000)) if (System.currentTimeMillis() - Configuration.lastHotKeyExecuted <= (4000))
return; return;
if ((e.getKeyCode() == KeyEvent.VK_O) && ((e.getModifiers() & KeyEvent.CTRL_MASK) != 0)) { if ((e.getKeyCode() == KeyEvent.VK_O) && ((e.getModifiers() & KeyEvent.CTRL_MASK) != 0))
{
Configuration.lastHotKeyExecuted = System.currentTimeMillis(); Configuration.lastHotKeyExecuted = System.currentTimeMillis();
JFileChooser fc = new FileChooser(Configuration.getLastDirectory(),
"Select File or Folder to open in BCV", final File file = DialogueUtils.fileChooser("Select File or Folder to open in BCV",
"APKs, DEX, Class Files or Zip/Jar/War Archives", "APKs, DEX, Class Files or Zip/Jar/War Archives",
Constants.SUPPORTED_FILE_EXTENSIONS); Constants.SUPPORTED_FILE_EXTENSIONS);
int returnVal = fc.showOpenDialog(BytecodeViewer.viewer); if(file == null)
if (returnVal == JFileChooser.APPROVE_OPTION) return;
{
try { BytecodeViewer.viewer.updateBusyStatus(true);
Configuration.lastDirectory = fc.getSelectedFile().getAbsolutePath(); BytecodeViewer.openFiles(new File[]{file}, true);
BytecodeViewer.viewer.updateBusyStatus(true); BytecodeViewer.viewer.updateBusyStatus(false);
BytecodeViewer.openFiles(new File[]{fc.getSelectedFile()}, true);
BytecodeViewer.viewer.updateBusyStatus(false);
} catch (Exception e1) {
new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e1);
}
}
} else if ((e.getKeyCode() == KeyEvent.VK_N) && ((e.getModifiers() & KeyEvent.CTRL_MASK) != 0)) { } else if ((e.getKeyCode() == KeyEvent.VK_N) && ((e.getModifiers() & KeyEvent.CTRL_MASK) != 0)) {
Configuration.lastHotKeyExecuted = System.currentTimeMillis(); Configuration.lastHotKeyExecuted = System.currentTimeMillis();
BytecodeViewer.resetWorkSpace(true); BytecodeViewer.resetWorkSpace(true);

View file

@ -847,150 +847,109 @@ public class MainViewerGUI extends JFrame
public void selectFile() public void selectFile()
{ {
final JFileChooser fc = new FileChooser(Configuration.getLastDirectory(), final File file = DialogueUtils.fileChooser("Select File or Folder to open in BCV",
"Select File or Folder to open in BCV",
"APKs, DEX, Class Files or Zip/Jar/War Archives", "APKs, DEX, Class Files or Zip/Jar/War Archives",
Constants.SUPPORTED_FILE_EXTENSIONS); Constants.SUPPORTED_FILE_EXTENSIONS);
if(file == null)
return;
int returnVal = fc.showOpenDialog(BytecodeViewer.viewer); BytecodeViewer.viewer.updateBusyStatus(true);
if (returnVal == JFileChooser.APPROVE_OPTION) BytecodeViewer.openFiles(new File[]{file}, true);
{ BytecodeViewer.viewer.updateBusyStatus(false);
try {
Configuration.lastDirectory = fc.getSelectedFile().getAbsolutePath();
BytecodeViewer.viewer.updateBusyStatus(true);
BytecodeViewer.openFiles(new File[]{fc.getSelectedFile()}, true);
BytecodeViewer.viewer.updateBusyStatus(false);
} catch (Exception e1) {
new ExceptionUI(e1);
}
}
} }
public void selectPythonC() { public void selectPythonC()
final JFileChooser fc = new FileChooser(Configuration.getLastDirectory(), {
"Select Python 2.7 Executable", final File file = DialogueUtils.fileChooser("Select Python 2.7 Executable",
"Python (Or PyPy for speed) 2.7 Executable", "Python (Or PyPy for speed) 2.7 Executable",
"everything"); "everything");
int returnVal = fc.showOpenDialog(BytecodeViewer.viewer); if(file == null)
if (returnVal == JFileChooser.APPROVE_OPTION) return;
try {
Configuration.lastDirectory = fc.getSelectedFile().getAbsolutePath(); Configuration.python = file.getAbsolutePath();
Configuration.python = fc.getSelectedFile().getAbsolutePath(); SettingsSerializer.saveSettingsAsync();
SettingsSerializer.saveSettingsAsync();
} catch (Exception e1) {
new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e1);
}
} }
public void selectJavac() { public void selectJavac()
final JFileChooser fc = new FileChooser(Configuration.getLastDirectory(), {
"Select Javac Executable", final File file = DialogueUtils.fileChooser("Select Javac Executable",
"Javac Executable (Requires JDK 'C:/programfiles/Java/JDK_xx/bin/javac.exe)", "Javac Executable (Requires JDK 'C:/programfiles/Java/JDK_xx/bin/javac.exe)",
"everything"); "everything");
if(file == null)
return;
int returnVal = fc.showOpenDialog(BytecodeViewer.viewer); Configuration.javac = file.getAbsolutePath();
if (returnVal == JFileChooser.APPROVE_OPTION) SettingsSerializer.saveSettingsAsync();
try {
Configuration.lastDirectory = fc.getSelectedFile().getAbsolutePath();
Configuration.javac = fc.getSelectedFile().getAbsolutePath();
SettingsSerializer.saveSettingsAsync();
} catch (Exception e1) {
new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e1);
}
} }
public void selectJava() { public void selectJava()
final JFileChooser fc = new FileChooser(Configuration.getLastDirectory(), {
"Select Java Executable", final File file = DialogueUtils.fileChooser("Select Java Executable",
"Java Executable (Inside Of JRE/JDK 'C:/programfiles/Java/JDK_xx/bin/java.exe')", "Java Executable (Inside Of JRE/JDK 'C:/programfiles/Java/JDK_xx/bin/java.exe')",
"everything"); "everything");
if(file == null)
return;
int returnVal = fc.showOpenDialog(BytecodeViewer.viewer); Configuration.java = file.getAbsolutePath();
if (returnVal == JFileChooser.APPROVE_OPTION) SettingsSerializer.saveSettingsAsync();
try {
Configuration.lastDirectory = fc.getSelectedFile().getAbsolutePath();
Configuration.java = fc.getSelectedFile().getAbsolutePath();
SettingsSerializer.saveSettingsAsync();
} catch (Exception e1) {
new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e1);
}
} }
public void selectPythonC3() { public void selectPythonC3()
final JFileChooser fc = new FileChooser(Configuration.getLastDirectory(), {
"Select Python 3.x Executable", final File file = DialogueUtils.fileChooser("Select Python 3.x Executable",
"Python (Or PyPy for speed) 3.x Executable", "Python (Or PyPy for speed) 3.x Executable",
"everything"); "everything");
int returnVal = fc.showOpenDialog(BytecodeViewer.viewer); if(file == null)
if (returnVal == JFileChooser.APPROVE_OPTION) return;
try {
Configuration.lastDirectory = fc.getSelectedFile().getAbsolutePath(); Configuration.python3 = file.getAbsolutePath();
Configuration.python3 = fc.getSelectedFile().getAbsolutePath(); SettingsSerializer.saveSettingsAsync();
SettingsSerializer.saveSettingsAsync();
} catch (Exception e1) {
new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e1);
}
} }
public void selectOpenalLibraryFolder() { public void selectOpenalLibraryFolder()
final JFileChooser fc = new FileChooser(Configuration.getLastDirectory(), {
"Select Library Folder", final File file = DialogueUtils.fileChooser("Select Library Folder",
"Optional Library Folder", "Optional Library Folder",
"everything"); "everything");
fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); if(file == null)
fc.setFileHidingEnabled(false); return;
fc.setAcceptAllFileFilterUsed(false);
Configuration.library = file.getAbsolutePath();
int returnVal = fc.showOpenDialog(BytecodeViewer.viewer); SettingsSerializer.saveSettingsAsync();
if (returnVal == JFileChooser.APPROVE_OPTION)
try {
Configuration.lastDirectory = fc.getSelectedFile().getAbsolutePath();
Configuration.library = fc.getSelectedFile().getAbsolutePath();
SettingsSerializer.saveSettingsAsync();
} catch (Exception e1) {
new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e1);
}
} }
public void selectJRERTLibrary() { public void selectJRERTLibrary() {
final JFileChooser fc = new FileChooser(Configuration.getLastDirectory(), final File file = DialogueUtils.fileChooser("Select JRE RT Jar",
"Select JRE RT Jar",
"JRE RT Library", "JRE RT Library",
"everything"); "everything");
int returnVal = fc.showOpenDialog(BytecodeViewer.viewer); if(file == null)
if (returnVal == JFileChooser.APPROVE_OPTION) return;
try {
Configuration.lastDirectory = fc.getSelectedFile().getAbsolutePath(); Configuration.rt = file.getAbsolutePath();
Configuration.rt = fc.getSelectedFile().getAbsolutePath(); SettingsSerializer.saveSettingsAsync();
SettingsSerializer.saveSettingsAsync();
} catch (Exception e1) {
new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e1);
}
} }
public void openExternalPlugin() public void openExternalPlugin()
{ {
JFileChooser fc = new FileChooser(Configuration.getLastDirectory(), final File file = DialogueUtils.fileChooser("Select External Plugin",
"Select External Plugin",
"External Plugin", "External Plugin",
PluginManager.fileFilter(),
"everything"); "everything");
fc.setFileFilter(PluginManager.fileFilter());
if(file == null)
int returnVal = fc.showOpenDialog(BytecodeViewer.viewer); return;
if (returnVal == JFileChooser.APPROVE_OPTION)
try { BytecodeViewer.viewer.updateBusyStatus(true);
Configuration.lastDirectory = fc.getSelectedFile().getAbsolutePath(); BytecodeViewer.startPlugin(file);
BytecodeViewer.viewer.updateBusyStatus(true); BytecodeViewer.viewer.updateBusyStatus(false);
BytecodeViewer.startPlugin(fc.getSelectedFile()); SettingsSerializer.saveSettingsAsync();
BytecodeViewer.viewer.updateBusyStatus(false);
SettingsSerializer.saveSettingsAsync();
} catch (Exception e1) {
new ExceptionUI(e1);
}
} }
public void askBeforeExiting() public void askBeforeExiting()

View file

@ -27,39 +27,30 @@ public class WorkPaneRefresh implements Runnable
try { try {
if (!BytecodeViewer.compile(false)) if (!BytecodeViewer.compile(false))
return; return;
} catch (NullPointerException ignored) { } catch (NullPointerException ignored) { }
}
JButton src = null; JButton src = null;
if(event != null && event.getSource() instanceof JButton) if(event != null && event.getSource() instanceof JButton)
src = (JButton) event.getSource(); src = (JButton) event.getSource();
//if (src == BytecodeViewer.viewer.workPane.refreshClass) final Component tabComp = BytecodeViewer.viewer.workPane.tabs.getSelectedComponent();
if(tabComp == null)
return;
if(src != null)
{ {
final Component tabComp = BytecodeViewer.viewer.workPane.tabs.getSelectedComponent(); JButton finalSrc = src;
SwingUtilities.invokeLater(()-> finalSrc.setEnabled(false));
if(tabComp == null)
return;
if (tabComp instanceof ClassViewer)
{
if(src != null)
src.setEnabled(false);
BytecodeViewer.viewer.updateBusyStatus(true);
((ClassViewer) tabComp).startPaneUpdater(src);
BytecodeViewer.viewer.updateBusyStatus(false);
}
else if (tabComp instanceof FileViewer)
{
if(src != null)
src.setEnabled(false);
BytecodeViewer.viewer.updateBusyStatus(true);
((FileViewer) tabComp).refresh(src);
BytecodeViewer.viewer.updateBusyStatus(false);
}
} }
BytecodeViewer.viewer.updateBusyStatus(true);
if (tabComp instanceof ClassViewer)
((ClassViewer) tabComp).startPaneUpdater(src);
else if (tabComp instanceof FileViewer)
((FileViewer) tabComp).refresh(src);
BytecodeViewer.viewer.updateBusyStatus(false);
} }
} }

View file

@ -215,9 +215,9 @@ public abstract class PaneUpdaterThread implements Runnable
if(decompilerViewIndex == 5 || decompilerViewIndex < 0) if(decompilerViewIndex == 5 || decompilerViewIndex < 0)
return; return;
JViewport viewport = updateUpdaterTextArea.getScrollPane().getViewport();
SwingUtilities.invokeLater(()-> SwingUtilities.invokeLater(()->
{ {
JViewport viewport = updateUpdaterTextArea.getScrollPane().getViewport();
viewport.addChangeListener(viewportListener); viewport.addChangeListener(viewportListener);
updateUpdaterTextArea.addCaretListener(caretListener); updateUpdaterTextArea.addCaretListener(caretListener);
}); });

View file

@ -1,7 +1,12 @@
package the.bytecode.club.bytecodeviewer.util; package the.bytecode.club.bytecodeviewer.util;
import the.bytecode.club.bytecodeviewer.BytecodeViewer;
import the.bytecode.club.bytecodeviewer.Configuration;
import the.bytecode.club.bytecodeviewer.gui.components.FileChooser;
import the.bytecode.club.bytecodeviewer.gui.components.MultipleChoiceDialogue; import the.bytecode.club.bytecodeviewer.gui.components.MultipleChoiceDialogue;
import javax.swing.*;
import javax.swing.filechooser.FileFilter;
import java.io.File; import java.io.File;
/** /**
@ -39,4 +44,38 @@ public class DialogueUtils
return true; return true;
} }
/**
* Prompts a File Chooser dilogue
*/
public static File fileChooser(String title, String description, String... extensions)
{
return fileChooser(title, description, null, extensions);
}
/**
* Prompts a File Chooser dilogue
*/
public static File fileChooser(String title, String description, FileFilter filter, String... extensions)
{
final JFileChooser fc = new FileChooser(Configuration.getLastDirectory(),
title,
description,
extensions);
if(filter != null)
fc.setFileFilter(filter);
int returnVal = fc.showOpenDialog(BytecodeViewer.viewer);
if (returnVal == JFileChooser.APPROVE_OPTION)
try {
File file = fc.getSelectedFile();
Configuration.lastDirectory = file.getAbsolutePath();
return file;
} catch (Exception e1) {
new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e1);
}
return null;
}
} }