Refactor com.apple.* usages to JDK 9

(all windows are fullscreenable by default, so we don't need that anymore)
This commit is contained in:
Reinhard Pointner 2017-10-16 18:44:42 +02:00
parent a1457cc63a
commit 0dba9fe08a
4 changed files with 11 additions and 45 deletions

View File

@ -200,7 +200,6 @@ public class Main {
if (isMacApp()) { if (isMacApp()) {
// Mac specific configuration // Mac specific configuration
MacAppUtilities.initializeApplication(); MacAppUtilities.initializeApplication();
MacAppUtilities.setWindowCanFullScreen(frame);
MacAppUtilities.setDefaultMenuBar(FileBotMenuBar.createHelp()); MacAppUtilities.setDefaultMenuBar(FileBotMenuBar.createHelp());
MacAppUtilities.setOpenFileHandler(openFiles -> SwingEventBus.getInstance().post(new FileTransferable(openFiles))); MacAppUtilities.setOpenFileHandler(openFiles -> SwingEventBus.getInstance().post(new FileTransferable(openFiles)));
} else if (isUbuntuApp()) { } else if (isUbuntuApp()) {

View File

@ -12,6 +12,7 @@ import java.awt.BasicStroke;
import java.awt.Color; import java.awt.Color;
import java.awt.Component; import java.awt.Component;
import java.awt.Cursor; import java.awt.Cursor;
import java.awt.Desktop;
import java.awt.Dialog.ModalExclusionType; import java.awt.Dialog.ModalExclusionType;
import java.awt.Dimension; import java.awt.Dimension;
import java.awt.Font; import java.awt.Font;
@ -149,7 +150,7 @@ public class DropToUnlock extends JList<File> {
if (model.stream().allMatch(f -> !isLockedFolder(f))) { if (model.stream().allMatch(f -> !isLockedFolder(f))) {
dialogCancelled.set(false); dialogCancelled.set(false);
invokeLater(750, () -> dialog.setVisible(false)); // auto-close unlock dialog once all folders have been unlocked invokeLater(750, () -> dialog.setVisible(false)); // auto-close unlock dialog once all folders have been unlocked
invokeLater(1000, () -> requestForeground()); // bring application to foreground now that folders have been unlocked invokeLater(1000, () -> Desktop.getDesktop().requestForeground(true)); // bring application to foreground now that folders have been unlocked
} else { } else {
model.stream().filter(f -> isLockedFolder(f)).findFirst().ifPresent(f -> { model.stream().filter(f -> isLockedFolder(f)).findFirst().ifPresent(f -> {
invokeLater(250, () -> { invokeLater(250, () -> {

View File

@ -3,10 +3,12 @@ package net.filebot.platform.mac;
import static ca.weblite.objc.util.CocoaUtils.*; import static ca.weblite.objc.util.CocoaUtils.*;
import static net.filebot.Logging.*; import static net.filebot.Logging.*;
import java.awt.Desktop;
import java.awt.EventQueue; import java.awt.EventQueue;
import java.awt.SecondaryLoop; import java.awt.SecondaryLoop;
import java.awt.Toolkit; import java.awt.Toolkit;
import java.awt.Window; import java.awt.Window;
import java.awt.desktop.QuitStrategy;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
@ -17,10 +19,6 @@ import java.util.logging.Level;
import javax.swing.JMenuBar; import javax.swing.JMenuBar;
import javax.swing.UIManager; import javax.swing.UIManager;
import com.apple.eawt.Application;
import com.apple.eawt.FullScreenUtilities;
import com.apple.eawt.QuitStrategy;
import com.apple.eio.FileManager;
import com.sun.jna.Pointer; import com.sun.jna.Pointer;
import ca.weblite.objc.Client; import ca.weblite.objc.Client;
@ -96,41 +94,9 @@ public class MacAppUtilities {
return result; return result;
} }
public static void setWindowCanFullScreen(Window window) {
try {
FullScreenUtilities.setWindowCanFullScreen(window, true);
} catch (Throwable t) {
debug.log(Level.WARNING, t.getMessage(), t);
}
}
public static void requestForeground() {
try {
Application.getApplication().requestForeground(true);
} catch (Throwable t) {
debug.log(Level.WARNING, t.getMessage(), t);
}
}
public static void revealInFinder(File file) {
try {
FileManager.revealInFinder(file);
} catch (Throwable t) {
debug.log(Level.WARNING, t.getMessage(), t);
}
}
public static void moveToTrash(File file) {
try {
FileManager.moveToTrash(file);
} catch (Throwable t) {
debug.log(Level.WARNING, t.getMessage(), t);
}
}
public static void setDefaultMenuBar(JMenuBar menu) { public static void setDefaultMenuBar(JMenuBar menu) {
try { try {
Application.getApplication().setDefaultMenuBar(menu); Desktop.getDesktop().setDefaultMenuBar(menu);
} catch (Throwable t) { } catch (Throwable t) {
debug.log(Level.WARNING, t.getMessage(), t); debug.log(Level.WARNING, t.getMessage(), t);
} }
@ -138,7 +104,7 @@ public class MacAppUtilities {
public static void setQuitStrategyCloseAll() { public static void setQuitStrategyCloseAll() {
try { try {
Application.getApplication().setQuitStrategy(QuitStrategy.CLOSE_ALL_WINDOWS); Desktop.getDesktop().setQuitStrategy(QuitStrategy.CLOSE_ALL_WINDOWS);
} catch (Throwable t) { } catch (Throwable t) {
debug.log(Level.WARNING, t.getMessage(), t); debug.log(Level.WARNING, t.getMessage(), t);
} }
@ -146,7 +112,7 @@ public class MacAppUtilities {
public static void setOpenFileHandler(Consumer<List<File>> handler) { public static void setOpenFileHandler(Consumer<List<File>> handler) {
try { try {
Application.getApplication().setOpenFileHandler(evt -> { Desktop.getDesktop().setOpenFileHandler(evt -> {
List<File> files = evt.getFiles(); List<File> files = evt.getFiles();
if (files.size() > 0) { if (files.size() > 0) {
handler.accept(files); handler.accept(files);

View File

@ -12,6 +12,7 @@ import static net.filebot.Settings.*;
import static net.filebot.util.ui.SwingUI.*; import static net.filebot.util.ui.SwingUI.*;
import java.awt.Color; import java.awt.Color;
import java.awt.Desktop;
import java.awt.Dialog.ModalExclusionType; import java.awt.Dialog.ModalExclusionType;
import java.awt.Dimension; import java.awt.Dimension;
import java.awt.FlowLayout; import java.awt.FlowLayout;
@ -38,7 +39,6 @@ import com.google.common.eventbus.Subscribe;
import net.filebot.CacheManager; import net.filebot.CacheManager;
import net.filebot.Settings; import net.filebot.Settings;
import net.filebot.cli.GroovyPad; import net.filebot.cli.GroovyPad;
import net.filebot.platform.mac.MacAppUtilities;
import net.filebot.util.PreferencesMap.PreferencesEntry; import net.filebot.util.PreferencesMap.PreferencesEntry;
import net.filebot.util.ui.DefaultFancyListCellRenderer; import net.filebot.util.ui.DefaultFancyListCellRenderer;
import net.filebot.util.ui.ShadowBorder; import net.filebot.util.ui.ShadowBorder;
@ -208,9 +208,9 @@ public class MainFrame extends JFrame {
dragEnterTimer = invokeLater(SELECTDELAY_ON_DRAG_OVER, () -> { dragEnterTimer = invokeLater(SELECTDELAY_ON_DRAG_OVER, () -> {
selectEnabled = true; selectEnabled = true;
// bring window to front when on dnd // bring window to front when drag-and-drop operation is in progress
if (isMacApp()) { if (Desktop.getDesktop().isSupported(Desktop.Action.APP_REQUEST_FOREGROUND)) {
MacAppUtilities.requestForeground(); Desktop.getDesktop().requestForeground(true);
} else { } else {
SwingUtilities.getWindowAncestor(((DropTarget) dtde.getSource()).getComponent()).toFront(); SwingUtilities.getWindowAncestor(((DropTarget) dtde.getSource()).getComponent()).toFront();
} }