From 59572b871cffdf2d037e8c46394dbf5fa39ff639 Mon Sep 17 00:00:00 2001 From: Lothar Haeger Date: Mon, 30 Dec 2019 19:22:39 +0100 Subject: [PATCH 1/2] jd-gui: update to 1.6.6 --- java/jd-gui/Portfile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/java/jd-gui/Portfile b/java/jd-gui/Portfile index e8b3e581bbbc1..be479dd4643b3 100644 --- a/java/jd-gui/Portfile +++ b/java/jd-gui/Portfile @@ -4,7 +4,7 @@ PortSystem 1.0 PortGroup java 1.0 PortGroup github 1.0 -github.setup java-decompiler jd-gui 1.6.5 v +github.setup java-decompiler jd-gui 1.6.6 v categories java devel platforms darwin @@ -19,9 +19,9 @@ long_description JD-GUI is a standalone graphical utility that displays J homepage http://java-decompiler.github.io/ -checksums rmd160 87b932d25b9fec0fdde1362aa55c2e28d3d5d1d7 \ - sha256 bbaf602d4542effaf80ce24cd6d91c3aaa6c7f73a38332f81ec3c73868c04936 \ - size 365596 +checksums rmd160 dd396d140545793cb1c166f7206252b7085499d3 \ + sha256 606fd8e2c339faaa0cec72c855a550fd2131445c9a884fc9f2fed96071b5aa97 \ + size 365626 java.version 1.8+ java.fallback openjdk11 From f066c33db17b4c12bfc18fd1ff561158690b719f Mon Sep 17 00:00:00 2001 From: Lothar Haeger Date: Mon, 30 Dec 2019 21:33:33 +0100 Subject: [PATCH 2/2] jd-gui: add nativedialogs variant --- java/jd-gui/Portfile | 11 ++++ java/jd-gui/files/FileChooser.java | 94 +++++++++++++++++++++++++++ java/jd-gui/files/FileUtils.java | 23 +++++++ java/jd-gui/files/SystemUtils.java | 20 ++++++ java/jd-gui/files/native-dialogs.diff | 67 +++++++++++++++++++ 5 files changed, 215 insertions(+) create mode 100644 java/jd-gui/files/FileChooser.java create mode 100644 java/jd-gui/files/FileUtils.java create mode 100644 java/jd-gui/files/SystemUtils.java create mode 100644 java/jd-gui/files/native-dialogs.diff diff --git a/java/jd-gui/Portfile b/java/jd-gui/Portfile index be479dd4643b3..d4908d45ab2ad 100644 --- a/java/jd-gui/Portfile +++ b/java/jd-gui/Portfile @@ -32,6 +32,17 @@ universal_variant no patchfiles macos-only.diff \ jdk13-compat.diff +variant nativedialogs description {Enable experimental support for macOS native dialogs} { + pre-patch { + file mkdir ${worksrcpath}/app/src/main/java/org/jd/gui/util/io/ + file mkdir ${worksrcpath}/app/src/main/java/org/jd/gui/util/sys/ + file copy ${filespath}/FileUtils.java ${worksrcpath}/app/src/main/java/org/jd/gui/util/io/ + file copy ${filespath}/SystemUtils.java ${worksrcpath}/app/src/main/java/org/jd/gui/util/sys/ + file copy ${filespath}/FileChooser.java ${worksrcpath}/app/src/main/java/org/jd/gui/view/component/ + } + patchfiles-append native-dialogs.diff +} + depends_build-append port:gradle \ port:proguard diff --git a/java/jd-gui/files/FileChooser.java b/java/jd-gui/files/FileChooser.java new file mode 100644 index 0000000000000..aa542de54599f --- /dev/null +++ b/java/jd-gui/files/FileChooser.java @@ -0,0 +1,94 @@ +package org.jd.gui.view.component; + +import org.jd.gui.util.io.FileUtils; +import org.jd.gui.util.sys.SystemUtils; + +import javax.swing.*; +import java.awt.*; +import java.io.File; +import java.io.FilenameFilter; + +/** + * Created by jianhua.fengjh on 27/11/2015. + */ +public class FileChooser extends JFileChooser { + + /** + * + */ + private static final long serialVersionUID = 1L; + + public int showOpenDialog(Component parent) { + if (!SystemUtils.isMacOS()) { + return super.showOpenDialog(parent); + } else { + setDialogType(JFileChooser.OPEN_DIALOG); + return showNativeFileDialog(this); + } + } + + public int showSaveDialog(Component parent) { + + if (!SystemUtils.isMacOS()) { + return super.showSaveDialog(parent); + } else { + setDialogType(JFileChooser.SAVE_DIALOG); + return showNativeFileDialog(this); + } + } + + private static int showNativeFileDialog(final JFileChooser chooser) { + if (chooser != null) { + + FileDialog fileDialog = new FileDialog((Frame) chooser.getParent()); + fileDialog.setDirectory(chooser.getCurrentDirectory().getPath()); + File file = chooser.getSelectedFile(); + + if (chooser.getDialogType() == JFileChooser.SAVE_DIALOG) { + fileDialog.setFile(file != null ? file.getName() : ""); //save only need name + } else { + fileDialog.setFile(file != null ? file.getPath() : ""); + } + + fileDialog.setFilenameFilter(new FilenameFilter() { + + public boolean accept(File dir, String name) { + String path = dir.getPath(); + String pathSeparator = File.pathSeparator; + return chooser.getFileFilter().accept(new File(0 + path.length() + pathSeparator.length() + name.length() + path + pathSeparator + name)); + } + + }); + + if (chooser.getDialogType() == JFileChooser.SAVE_DIALOG) { + fileDialog.setMode(FileDialog.SAVE); + } else { + fileDialog.setMode(FileDialog.LOAD); + } + + if (chooser.getFileSelectionMode() == JFileChooser.DIRECTORIES_ONLY) { + System.setProperty("apple.awt.fileDialogForDirectories", "true"); + } else { + System.setProperty("apple.awt.fileDialogForDirectories", "false"); + } + + fileDialog.setVisible(true); + + //reset fileDialogForDirectories property + System.setProperty("apple.awt.fileDialogForDirectories", "false"); + if (fileDialog.getFile() == null) { + return JFileChooser.CANCEL_OPTION; + } + + String dir = fileDialog.getDirectory(); + String trailingSlash = FileUtils.ensureTrailingSlash(dir); + String strFile = fileDialog.getFile(); + chooser.setSelectedFile(new File(strFile.length() != 0 ? trailingSlash.concat(strFile) : trailingSlash)); + + return JFileChooser.APPROVE_OPTION; + } + + return JFileChooser.ERROR_OPTION; + } + +} \ No newline at end of file diff --git a/java/jd-gui/files/FileUtils.java b/java/jd-gui/files/FileUtils.java new file mode 100644 index 0000000000000..ee10bb6056a98 --- /dev/null +++ b/java/jd-gui/files/FileUtils.java @@ -0,0 +1,23 @@ +package org.jd.gui.util.io; + +import java.io.File; + + +/** + * Created by jianhua.fengjh on 27/11/2015. + */ +public class FileUtils { + + public static String ensureTrailingSlash(final String path) { + if ((path == null) || "".equals(path)) { + return ""; + } + + StringBuilder buf = new StringBuilder(path); + while (buf.charAt(buf.length() - 1) == File.separatorChar) { + buf.deleteCharAt(buf.length() - 1); + } + + return buf.append(File.separatorChar).toString(); + } +} \ No newline at end of file diff --git a/java/jd-gui/files/SystemUtils.java b/java/jd-gui/files/SystemUtils.java new file mode 100644 index 0000000000000..7e3a77b423c5f --- /dev/null +++ b/java/jd-gui/files/SystemUtils.java @@ -0,0 +1,20 @@ +package org.jd.gui.util.sys; + +/** + * Created by jianhua.fengjh on 27/11/2015. + */ +public final class SystemUtils { + + static boolean isLinux() { + return System.getProperty("os.name").startsWith("Linux"); + } + + public static boolean isMacOS() { + return System.getProperty("os.name").startsWith("Mac"); + } + + public static boolean isWindows() { + return System.getProperty("os.name").startsWith("Windows"); + } + +} \ No newline at end of file diff --git a/java/jd-gui/files/native-dialogs.diff b/java/jd-gui/files/native-dialogs.diff new file mode 100644 index 0000000000000..7bb832b905752 --- /dev/null +++ b/java/jd-gui/files/native-dialogs.diff @@ -0,0 +1,67 @@ +--- app/src/main/java/org/jd/gui/controller/MainController.java.orig 2019-12-30 20:20:31.000000000 +0100 ++++ app/src/main/java/org/jd/gui/controller/MainController.java 2019-12-30 20:09:49.000000000 +0100 +@@ -35,6 +35,7 @@ + import javax.swing.*; + import javax.swing.filechooser.FileNameExtensionFilter; + import javax.swing.filechooser.FileSystemView; ++import org.jd.gui.view.component.FileChooser; + import java.awt.*; + import java.awt.datatransfer.DataFlavor; + import java.awt.datatransfer.Transferable; +@@ -155,7 +156,7 @@ + // Set drop files transfer handler + mainFrame.setTransferHandler(new FilesTransferHandler()); + // Background class loading +- new JFileChooser().addChoosableFileFilter(new FileNameExtensionFilter("", "dummy")); ++ new FileChooser().addChoosableFileFilter(new FileNameExtensionFilter("", "dummy")); + FileSystemView.getFileSystemView().isFileSystemRoot(new File("dummy")); + new JLayer(); + }); +@@ -183,7 +184,7 @@ + + String description = sb.toString(); + String[] array = extensions.toArray(new String[0]); +- JFileChooser chooser = new JFileChooser(); ++ FileChooser chooser = new FileChooser(); + + chooser.removeChoosableFileFilter(chooser.getFileFilter()); + chooser.addChoosableFileFilter(new FileNameExtensionFilter("All files (" + description + ")", array)); +@@ -195,7 +196,7 @@ + + chooser.setCurrentDirectory(configuration.getRecentLoadDirectory()); + +- if (chooser.showOpenDialog(mainView.getMainFrame()) == JFileChooser.APPROVE_OPTION) { ++ if (chooser.showOpenDialog(mainView.getMainFrame()) == FileChooser.APPROVE_OPTION) { + configuration.setRecentLoadDirectory(chooser.getCurrentDirectory()); + openFile(chooser.getSelectedFile()); + } +@@ -207,12 +208,12 @@ + + protected void onSaveSource() { + if (currentPage instanceof ContentSavable) { +- JFileChooser chooser = new JFileChooser(); ++ FileChooser chooser = new FileChooser(); + JFrame mainFrame = mainView.getMainFrame(); + + chooser.setSelectedFile(new File(configuration.getRecentSaveDirectory(), ((ContentSavable)currentPage).getFileName())); + +- if (chooser.showSaveDialog(mainFrame) == JFileChooser.APPROVE_OPTION) { ++ if (chooser.showSaveDialog(mainFrame) == FileChooser.APPROVE_OPTION) { + File selectedFile = chooser.getSelectedFile(); + + configuration.setRecentSaveDirectory(chooser.getCurrentDirectory()); +@@ -245,12 +246,12 @@ + + if (currentPanel instanceof SourcesSavable) { + SourcesSavable sourcesSavable = (SourcesSavable)currentPanel; +- JFileChooser chooser = new JFileChooser(); ++ FileChooser chooser = new FileChooser(); + JFrame mainFrame = mainView.getMainFrame(); + + chooser.setSelectedFile(new File(configuration.getRecentSaveDirectory(), sourcesSavable.getSourceFileName())); + +- if (chooser.showSaveDialog(mainFrame) == JFileChooser.APPROVE_OPTION) { ++ if (chooser.showSaveDialog(mainFrame) == FileChooser.APPROVE_OPTION) { + File selectedFile = chooser.getSelectedFile(); + + configuration.setRecentSaveDirectory(chooser.getCurrentDirectory());