Skip to content

Commit

Permalink
Make FallbackException's manual jar file choosing use JFXFileChooser
Browse files Browse the repository at this point in the history
  • Loading branch information
Janmm14 committed Nov 21, 2022
1 parent 96fe38c commit 8ed76b9
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 16 deletions.
27 changes: 16 additions & 11 deletions src/java/com/javadeobfuscator/deobfuscator/ui/SwingWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,17 +98,7 @@ public void run()
@Override
public void run()
{
try
{
SynchronousJFXCaller.init();
} catch (NoClassDefFoundError e)
{
e.printStackTrace();
ensureSwingLafLoaded();
ExceptionUtil.showFatalError("You need a JVM with JavaFX (non-headless installation).\n\n" +
"Could not find class " + e.getMessage());
System.exit(1);
}
initJFX();
}
};
GuiConfig.read();
Expand Down Expand Up @@ -1232,6 +1222,21 @@ public void windowClosing(WindowEvent e)
frame.setVisible(true);
}

public static void initJFX()
{
try
{
SynchronousJFXCaller.init();
} catch (NoClassDefFoundError e)
{
e.printStackTrace();
ensureSwingLafLoaded();
ExceptionUtil.showFatalError("You need a JVM with JavaFX (non-headless installation).\n\n" +
"Could not find class " + e.getMessage());
System.exit(1);
}
}

public static synchronized void ensureSwingLafLoaded()
{
if (!swingLafLoaded)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.io.File;

import javax.swing.JButton;
import javax.swing.JFileChooser;
Expand All @@ -13,6 +14,8 @@
import javax.swing.JTextField;

import com.javadeobfuscator.deobfuscator.ui.SwingWindow;
import com.javadeobfuscator.deobfuscator.ui.component.SynchronousJFXFileChooser;
import javafx.stage.FileChooser;

public class FallbackException extends Exception
{
Expand All @@ -23,6 +26,7 @@ public FallbackException(String title, String msg, Throwable cause)
super(msg, cause);
this.printStackTrace();
SwingWindow.ensureSwingLafLoaded();
SwingWindow.initJFX();
JPanel fallback = new JPanel();
fallback.setLayout(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();
Expand All @@ -46,12 +50,21 @@ public FallbackException(String title, String msg, Throwable cause)
JButton button = new JButton("Select");
button.addActionListener(e ->
{
JFileChooser inputFile = new JFileChooser();
int action = inputFile.showOpenDialog(null);
if (action == JFileChooser.APPROVE_OPTION)
SynchronousJFXFileChooser chooser = new SynchronousJFXFileChooser(() -> {
FileChooser ch = new FileChooser();
ch.setTitle("Select deobfuscator jar");
ch.setInitialDirectory(new File("abc").getAbsoluteFile().getParentFile());
ch.getExtensionFilters().addAll(
new FileChooser.ExtensionFilter("Jar files", "*.jar"),
new FileChooser.ExtensionFilter("Jar and Zip files", "*.jar", "*.zip"),
new FileChooser.ExtensionFilter("Zip files", "*.zip"),
new FileChooser.ExtensionFilter("All Files", "*.*"));
return ch;
});
File file = chooser.showOpenDialog();
if (file != null)
{
String path = inputFile.getSelectedFile().toString();
textField.setText(path);
textField.setText(file.getAbsolutePath());
}
});
GridBagConstraints gbc_Button = new GridBagConstraints();
Expand Down

0 comments on commit 8ed76b9

Please # to comment.