From f99010a02615548269c50108e36d73a4ebf1d514 Mon Sep 17 00:00:00 2001 From: "jianhua.fengjh" Date: Mon, 28 Nov 2016 00:24:17 +0800 Subject: [PATCH 1/5] add native open, save dlg in macOS --- .../org/jd/gui/util/io/FileUtils.groovy | 20 +++++ .../org/jd/gui/util/sys/SystemUtils.groovy | 20 +++++ .../groovy/org/jd/gui/view/MainView.groovy | 5 +- .../jd/gui/view/component/FileChooser.groovy | 87 +++++++++++++++++++ 4 files changed, 130 insertions(+), 2 deletions(-) create mode 100644 app/src/main/groovy/org/jd/gui/util/io/FileUtils.groovy create mode 100644 app/src/main/groovy/org/jd/gui/util/sys/SystemUtils.groovy create mode 100644 app/src/main/groovy/org/jd/gui/view/component/FileChooser.groovy diff --git a/app/src/main/groovy/org/jd/gui/util/io/FileUtils.groovy b/app/src/main/groovy/org/jd/gui/util/io/FileUtils.groovy new file mode 100644 index 00000000..94f51e7f --- /dev/null +++ b/app/src/main/groovy/org/jd/gui/util/io/FileUtils.groovy @@ -0,0 +1,20 @@ +package org.jd.gui.util.io + +/** + * Created by jianhua.fengjh on 27/11/2015. + */ +class FileUtils { + + 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(); + } +} diff --git a/app/src/main/groovy/org/jd/gui/util/sys/SystemUtils.groovy b/app/src/main/groovy/org/jd/gui/util/sys/SystemUtils.groovy new file mode 100644 index 00000000..c5905fcb --- /dev/null +++ b/app/src/main/groovy/org/jd/gui/util/sys/SystemUtils.groovy @@ -0,0 +1,20 @@ +package org.jd.gui.util.sys + +/** + * Created by jianhua.fengjh on 27/11/2015. + */ +final class SystemUtils { + + static boolean isLinux() { + return System.getProperty("os.name").startsWith("Linux"); + } + + static boolean isMacOS() { + return System.getProperty("os.name").startsWith("Mac"); + } + + static boolean isWindows() { + return System.getProperty("os.name").startsWith("Windows"); + } + +} diff --git a/app/src/main/groovy/org/jd/gui/view/MainView.groovy b/app/src/main/groovy/org/jd/gui/view/MainView.groovy index 36367b6b..c063bb6b 100644 --- a/app/src/main/groovy/org/jd/gui/view/MainView.groovy +++ b/app/src/main/groovy/org/jd/gui/view/MainView.groovy @@ -23,6 +23,7 @@ import org.jd.gui.api.feature.UriOpenable import org.jd.gui.model.configuration.Configuration import org.jd.gui.model.history.History import org.jd.gui.spi.FileLoader +import org.jd.gui.view.component.FileChooser import javax.swing.Icon import javax.swing.JComponent @@ -199,7 +200,7 @@ class MainView implements UriOpenable, PreferencesChangeListener { } JFileChooser createOpenFileChooser() { - JFileChooser chooser = new JFileChooser() { + FileChooser chooser = new FileChooser() { void addFileFilters(Map loaders) { removeChoosableFileFilter(getFileFilter()) @@ -223,7 +224,7 @@ class MainView implements UriOpenable, PreferencesChangeListener { } JFileChooser createSaveFileChooser() { - JFileChooser chooser = new JFileChooser() { + FileChooser chooser = new FileChooser() { void show(Closure okClosure) { if (showSaveDialog(swing.mainFrame) == JFileChooser.APPROVE_OPTION) { if (selectedFile.exists()) { diff --git a/app/src/main/groovy/org/jd/gui/view/component/FileChooser.groovy b/app/src/main/groovy/org/jd/gui/view/component/FileChooser.groovy new file mode 100644 index 00000000..0bf14379 --- /dev/null +++ b/app/src/main/groovy/org/jd/gui/view/component/FileChooser.groovy @@ -0,0 +1,87 @@ +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.* + +/** + * Created by jianhua.fengjh on 27/11/2015. + */ +class FileChooser extends JFileChooser { + + int showOpenDialog(Component parent) { + if (!SystemUtils.isMacOS()) { + return super.showOpenDialog(parent); + } else { + setDialogType(JFileChooser.OPEN_DIALOG); + return showNativeFileDialog(this); + } + } + + 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() { + + 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; + } + +} From 5492bf869f629c1f8d92ad8fbeb126c230ea3955 Mon Sep 17 00:00:00 2001 From: Lothar Haeger Date: Mon, 30 Dec 2019 21:24:04 +0100 Subject: [PATCH 2/5] Use native file dialogs in macOS This is a Java port of Jianhua Feng's earlier Groovy-PR (https://github.com/java-decompiler/jd-gui/pull/180) --- .../org/jd/gui/controller/MainController.java | 15 +-- .../java/org/jd/gui/util/io/FileUtils.java | 23 +++++ .../java/org/jd/gui/util/sys/SystemUtils.java | 20 ++++ .../jd/gui/view/component/FileChooser.java | 94 +++++++++++++++++++ 4 files changed, 145 insertions(+), 7 deletions(-) create mode 100644 app/src/main/java/org/jd/gui/util/io/FileUtils.java create mode 100644 app/src/main/java/org/jd/gui/util/sys/SystemUtils.java create mode 100644 app/src/main/java/org/jd/gui/view/component/FileChooser.java diff --git a/app/src/main/java/org/jd/gui/controller/MainController.java b/app/src/main/java/org/jd/gui/controller/MainController.java index 94b0e881..e607408f 100644 --- a/app/src/main/java/org/jd/gui/controller/MainController.java +++ b/app/src/main/java/org/jd/gui/controller/MainController.java @@ -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 @@ public void show(List files) { // 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 @@ protected void onOpen() { 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 @@ protected void onOpen() { 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 onClose() { 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 @@ protected void onSaveAllSources() { 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()); diff --git a/app/src/main/java/org/jd/gui/util/io/FileUtils.java b/app/src/main/java/org/jd/gui/util/io/FileUtils.java new file mode 100644 index 00000000..a4548178 --- /dev/null +++ b/app/src/main/java/org/jd/gui/util/io/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(); + } +} diff --git a/app/src/main/java/org/jd/gui/util/sys/SystemUtils.java b/app/src/main/java/org/jd/gui/util/sys/SystemUtils.java new file mode 100644 index 00000000..6a75c591 --- /dev/null +++ b/app/src/main/java/org/jd/gui/util/sys/SystemUtils.java @@ -0,0 +1,20 @@ +package org.jd.gui.util.sys; + +/** + * Created by jianhua.fengjh on 27/11/2015. + */ +public final class SystemUtils { + + public 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"); + } + +} diff --git a/app/src/main/java/org/jd/gui/view/component/FileChooser.java b/app/src/main/java/org/jd/gui/view/component/FileChooser.java new file mode 100644 index 00000000..ba477ce3 --- /dev/null +++ b/app/src/main/java/org/jd/gui/view/component/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; + } + +} From a783adede5e227b57dffff0ba4fbbd2387dbdab9 Mon Sep 17 00:00:00 2001 From: John Feng Date: Wed, 10 Nov 2021 20:11:51 +0800 Subject: [PATCH 3/5] support jdk8-17, by java -jar xxx --- src/osx/resources/universalJavaApplicationStub.sh | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/osx/resources/universalJavaApplicationStub.sh b/src/osx/resources/universalJavaApplicationStub.sh index 686db22d..c7ed84ea 100644 --- a/src/osx/resources/universalJavaApplicationStub.sh +++ b/src/osx/resources/universalJavaApplicationStub.sh @@ -286,13 +286,12 @@ elif [ -f "$JAVACMD" ] && [ -x "$JAVACMD" ] ; then # - main class # - JVM arguments exec "$JAVACMD" \ - -cp "${JVMClassPath}" \ -Xdock:icon="${ResourcesFolder}/${CFBundleIconFile}" \ -Xdock:name="${CFBundleName}" \ ${JVMOptions:+$JVMOptions }\ ${JVMDefaultOptions:+$JVMDefaultOptions }\ - ${JVMMainClass}\ - ${JVMArguments:+ $JVMArguments} + ${JVMArguments:+ $JVMArguments}\ + -jar "${JVMClassPath}" \ else From ba0a05d79576c867e9e354ada14c21a0bdf62540 Mon Sep 17 00:00:00 2001 From: john Date: Sun, 14 Nov 2021 21:18:47 +0800 Subject: [PATCH 4/5] issue: Unsupported class file major version jdk8-17, command: gradle assembleOsxDist --- build.gradle | 9 ++++++--- gradle/wrapper/gradle-wrapper.properties | 2 +- services/build.gradle | 8 ++++---- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/build.gradle b/build.gradle index 51633402..e4285216 100644 --- a/build.gradle +++ b/build.gradle @@ -1,11 +1,14 @@ buildscript { repositories { jcenter() + maven { + url "https://plugins.gradle.org/m2/" + } } dependencies { - classpath 'com.netflix.nebula:gradle-ospackage-plugin:5.3.0' // RPM & DEB support - classpath 'edu.sc.seis.gradle:launch4j:2.4.4' - classpath 'net.sf.proguard:proguard-gradle:6.1.0' + classpath 'com.netflix.nebula:gradle-ospackage-plugin:9.0.0' // RPM & DEB support + classpath 'edu.sc.seis.launch4j:launch4j:2.5.1' + classpath 'net.sf.proguard:proguard-gradle:6.2.2' } } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 9a6bf73b..7de2580f 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-5.2.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-6.9.1-bin.zip diff --git a/services/build.gradle b/services/build.gradle index 6ed884b9..07964299 100644 --- a/services/build.gradle +++ b/services/build.gradle @@ -1,8 +1,8 @@ apply plugin: 'java' dependencies { - compile 'com.fifesoft:rsyntaxtextarea:3.0.4' - compile 'org.ow2.asm:asm:7.1' + compile 'com.fifesoft:rsyntaxtextarea:3.1.3' + compile 'org.ow2.asm:asm:9.2' compile 'org.jd:jd-core:' + parent.jdCoreVersion compile project(':api') testCompile 'junit:junit:4.12' @@ -24,8 +24,8 @@ configurations { } dependencies { - compile 'org.antlr:antlr4-runtime:4.5' - antlr4 'org.antlr:antlr4:4.5' + compile 'org.antlr:antlr4-runtime:4.9.3' + antlr4 'org.antlr:antlr4:4.9.3' } task antlr4OutputDir() { From 3e983c28f6665b850de1a53038eab866812d4b58 Mon Sep 17 00:00:00 2001 From: john Date: Sun, 14 Nov 2021 21:34:12 +0800 Subject: [PATCH 5/5] modify app version 1.6.7 --- app/src/main/java/org/jd/gui/view/AboutView.java | 2 +- build.gradle | 2 +- src/osx/resources/Info.plist | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/org/jd/gui/view/AboutView.java b/app/src/main/java/org/jd/gui/view/AboutView.java index f7cfa84a..c97c33ee 100644 --- a/app/src/main/java/org/jd/gui/view/AboutView.java +++ b/app/src/main/java/org/jd/gui/view/AboutView.java @@ -97,7 +97,7 @@ public AboutView(JFrame mainFrame) { hbox.add(Box.createHorizontalGlue()); hbox = Box.createHorizontalBox(); - hbox.add(new JLabel("Copyright © 2008, 2019 Emmanuel Dupuy")); + hbox.add(new JLabel("Copyright © 2008, 2021 Emmanuel Dupuy")); hbox.add(Box.createHorizontalGlue()); subvbox.add(hbox); diff --git a/build.gradle b/build.gradle index e4285216..842ec1d0 100644 --- a/build.gradle +++ b/build.gradle @@ -18,7 +18,7 @@ apply plugin: 'edu.sc.seis.launch4j' apply plugin: 'nebula.ospackage' // Common configuration // -rootProject.version='1.6.6' +rootProject.version='1.6.7' rootProject.ext.set('jdCoreVersion', '1.1.3') targetCompatibility = '1.8' diff --git a/src/osx/resources/Info.plist b/src/osx/resources/Info.plist index 264b3fd3..5e5f27c6 100644 --- a/src/osx/resources/Info.plist +++ b/src/osx/resources/Info.plist @@ -5,16 +5,16 @@ CFBundleDevelopmentRegion English CFBundleExecutable universalJavaApplicationStub.sh CFBundleName JD-GUI - CFBundleGetInfoString JD-GUI version ${VERSION}, Copyright 2008, 2019 Emmanuel Dupuy + CFBundleGetInfoString JD-GUI version ${VERSION}, Copyright 2008, 2021 Emmanuel Dupuy CFBundleIconFile jd-gui.icns CFBundleIdentifier jd.jd-gui CFBundleInfoDictionaryVersion 6.0 CFBundlePackageType APPL - CFBundleLongVersionString ${VERSION}, Copyright 2008, 2019 Emmanuel Dupuy + CFBundleLongVersionString ${VERSION}, Copyright 2008, 2021 Emmanuel Dupuy CFBundleShortVersionString ${VERSION} CSResourcesFileMapped LSRequiresCarbon - NSHumanReadableCopyright Copyright 2008, 2019 Emmanuel Dupuy + NSHumanReadableCopyright Copyright 2008, 2021 Emmanuel Dupuy NSPrincipalClass NSApplication NSHighResolutionCapable CFBundleDocumentTypes