From 8ed76b9d2a36bc8400980d6b16daa0bb56b1f0bf Mon Sep 17 00:00:00 2001 From: Janmm14 Date: Mon, 21 Nov 2022 16:52:51 +0100 Subject: [PATCH] Make FallbackException's manual jar file choosing use JFXFileChooser --- .../deobfuscator/ui/SwingWindow.java | 27 +++++++++++-------- .../ui/util/FallbackException.java | 23 ++++++++++++---- 2 files changed, 34 insertions(+), 16 deletions(-) diff --git a/src/java/com/javadeobfuscator/deobfuscator/ui/SwingWindow.java b/src/java/com/javadeobfuscator/deobfuscator/ui/SwingWindow.java index 2f04315..6cb4cf7 100644 --- a/src/java/com/javadeobfuscator/deobfuscator/ui/SwingWindow.java +++ b/src/java/com/javadeobfuscator/deobfuscator/ui/SwingWindow.java @@ -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(); @@ -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) diff --git a/src/java/com/javadeobfuscator/deobfuscator/ui/util/FallbackException.java b/src/java/com/javadeobfuscator/deobfuscator/ui/util/FallbackException.java index 4b335b1..8808075 100644 --- a/src/java/com/javadeobfuscator/deobfuscator/ui/util/FallbackException.java +++ b/src/java/com/javadeobfuscator/deobfuscator/ui/util/FallbackException.java @@ -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; @@ -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 { @@ -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(); @@ -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();