From 6cc4851fab1fd04113c50c91bba674a81eb872e5 Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Mon, 16 Oct 2017 21:35:36 +0200 Subject: [PATCH] Refactor com.apple.* usages to JDK 9 --- source/net/filebot/Main.java | 4 +- .../filebot/platform/mac/MacAppUtilities.java | 46 ++++++------------- 2 files changed, 14 insertions(+), 36 deletions(-) diff --git a/source/net/filebot/Main.java b/source/net/filebot/Main.java index 5b30e08a..e64ea59c 100644 --- a/source/net/filebot/Main.java +++ b/source/net/filebot/Main.java @@ -199,9 +199,7 @@ public class Main { // configure main window if (isMacApp()) { // Mac specific configuration - MacAppUtilities.initializeApplication(); - MacAppUtilities.setDefaultMenuBar(FileBotMenuBar.createHelp()); - MacAppUtilities.setOpenFileHandler(openFiles -> SwingEventBus.getInstance().post(new FileTransferable(openFiles))); + MacAppUtilities.initializeApplication(FileBotMenuBar.createHelp(), files -> SwingEventBus.getInstance().post(new FileTransferable(files))); } else if (isUbuntuApp()) { // Ubuntu/Debian specific configuration frame.setIconImages(ResourceManager.getApplicationIcons()); diff --git a/source/net/filebot/platform/mac/MacAppUtilities.java b/source/net/filebot/platform/mac/MacAppUtilities.java index 6ee6fc9d..5fb4de64 100644 --- a/source/net/filebot/platform/mac/MacAppUtilities.java +++ b/source/net/filebot/platform/mac/MacAppUtilities.java @@ -1,7 +1,6 @@ package net.filebot.platform.mac; import static ca.weblite.objc.util.CocoaUtils.*; -import static net.filebot.Logging.*; import java.awt.Desktop; import java.awt.EventQueue; @@ -14,7 +13,6 @@ import java.util.ArrayList; import java.util.Collection; import java.util.List; import java.util.function.Consumer; -import java.util.logging.Level; import javax.swing.JMenuBar; import javax.swing.UIManager; @@ -94,41 +92,23 @@ public class MacAppUtilities { return result; } - public static void setDefaultMenuBar(JMenuBar menu) { - try { - Desktop.getDesktop().setDefaultMenuBar(menu); - } catch (Throwable t) { - debug.log(Level.WARNING, t.getMessage(), t); - } - } - - public static void setQuitStrategyCloseAll() { - try { - Desktop.getDesktop().setQuitStrategy(QuitStrategy.CLOSE_ALL_WINDOWS); - } catch (Throwable t) { - debug.log(Level.WARNING, t.getMessage(), t); - } - } - - public static void setOpenFileHandler(Consumer> handler) { - try { - Desktop.getDesktop().setOpenFileHandler(evt -> { - List files = evt.getFiles(); - if (files.size() > 0) { - handler.accept(files); - } - }); - } catch (Throwable t) { - debug.log(Level.WARNING, t.getMessage(), t); - } - } - - public static void initializeApplication() { + public static void initializeApplication(JMenuBar appMenuBar, Consumer> openFileHandler) { // improved UI defaults UIManager.put("TitledBorder.border", UIManager.getBorder("InsetBorder.aquaVariant")); // make sure Application Quit Events get forwarded to normal Window Listeners - setQuitStrategyCloseAll(); + Desktop.getDesktop().setQuitStrategy(QuitStrategy.CLOSE_ALL_WINDOWS); + + // set global menu bar + Desktop.getDesktop().setDefaultMenuBar(appMenuBar); + + // set open file handler + Desktop.getDesktop().setOpenFileHandler(evt -> { + List files = evt.getFiles(); + if (files.size() > 0) { + openFileHandler.accept(files); + } + }); } public static boolean isLockedFolder(File folder) {