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))
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();
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",
Constants.SUPPORTED_FILE_EXTENSIONS);
int returnVal = fc.showOpenDialog(BytecodeViewer.viewer);
if (returnVal == JFileChooser.APPROVE_OPTION)
{
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 the.bytecode.club.bytecodeviewer.api.ExceptionUI(e1);
}
}
if(file == null)
return;
BytecodeViewer.viewer.updateBusyStatus(true);
BytecodeViewer.openFiles(new File[]{file}, true);
BytecodeViewer.viewer.updateBusyStatus(false);
} else if ((e.getKeyCode() == KeyEvent.VK_N) && ((e.getModifiers() & KeyEvent.CTRL_MASK) != 0)) {
Configuration.lastHotKeyExecuted = System.currentTimeMillis();
BytecodeViewer.resetWorkSpace(true);

View file

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

View file

@ -27,39 +27,30 @@ public class WorkPaneRefresh implements Runnable
try {
if (!BytecodeViewer.compile(false))
return;
} catch (NullPointerException ignored) {
}
} catch (NullPointerException ignored) { }
JButton src = null;
if(event != null && event.getSource() instanceof JButton)
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();
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);
}
JButton finalSrc = src;
SwingUtilities.invokeLater(()-> finalSrc.setEnabled(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)
return;
JViewport viewport = updateUpdaterTextArea.getScrollPane().getViewport();
SwingUtilities.invokeLater(()->
{
JViewport viewport = updateUpdaterTextArea.getScrollPane().getViewport();
viewport.addChangeListener(viewportListener);
updateUpdaterTextArea.addCaretListener(caretListener);
});

View file

@ -1,7 +1,12 @@
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 javax.swing.*;
import javax.swing.filechooser.FileFilter;
import java.io.File;
/**
@ -39,4 +44,38 @@ public class DialogueUtils
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;
}
}