* support OSX Lion Full Screen Mode

* fix "To Front on Drag" feature that wasn't working on OSX
This commit is contained in:
Reinhard Pointner 2014-07-31 01:20:27 +00:00
parent d67e112c3b
commit f7848f52f3
6 changed files with 69 additions and 25 deletions

View File

@ -53,6 +53,7 @@ import net.filebot.cli.ArgumentProcessor;
import net.filebot.cli.CmdlineOperations;
import net.filebot.format.ExpressionFormat;
import net.filebot.gio.GVFS;
import net.filebot.mac.MacAppHelper;
import net.filebot.ui.MainFrame;
import net.filebot.ui.PanelBuilder;
import net.filebot.ui.SinglePanelFrame;
@ -266,7 +267,6 @@ public class Main {
// don't care, doesn't make a difference
}
frame.setLocationByPlatform(true);
frame.addWindowListener(new WindowAdapter() {
@Override
@ -282,6 +282,12 @@ public class Main {
}
});
// window settings
if (Settings.isMacSandbox()) {
MacAppHelper.setWindowCanFullScreen(frame);
}
frame.setLocationByPlatform(true);
// start application
frame.setVisible(true);
}

View File

@ -63,7 +63,7 @@ public final class Settings {
return !("mas".equals(getApplicationDeployment()) || "usc".equals(getApplicationDeployment()));
}
public static boolean isSandboxed() {
public static boolean isMacSandbox() {
return "mas".equals(getApplicationDeployment());
}

View File

@ -0,0 +1,54 @@
package net.filebot.mac;
import java.awt.Window;
import java.lang.reflect.Method;
import java.util.logging.Level;
import java.util.logging.Logger;
import net.filebot.Main;
import ca.weblite.objc.Client;
public class MacAppHelper {
private static Client _objc;
public static Client objc() {
if (_objc == null) {
_objc = new Client();
}
return _objc;
}
public static Object NSData_initWithBase64Encoding(String text) {
return objc().sendProxy("NSData", "data").send("initWithBase64Encoding:", text);
}
public static Object NSURL_bookmarkDataWithOptions(String path) {
return objc().sendProxy("NSURL", "fileURLWithPath:", path).sendProxy("bookmarkDataWithOptions:includingResourceValuesForKeys:relativeToURL:error:", 2048, null, null, null).sendString("base64Encoding");
}
public static Object NSURL_URLByResolvingBookmarkData_startAccessingSecurityScopedResource(String text) {
return objc().sendProxy("NSURL", "URLByResolvingBookmarkData:options:relativeToURL:bookmarkDataIsStale:error:", NSData_initWithBase64Encoding(text), 1024, null, false, null).send("startAccessingSecurityScopedResource");
}
public static void setWindowCanFullScreen(Window window) {
try {
Class<?> fullScreenUtilities = Class.forName("com.apple.eawt.FullScreenUtilities");
Method setWindowCanFullScreen = fullScreenUtilities.getMethod("setWindowCanFullScreen", new Class<?>[] { Window.class, boolean.class });
setWindowCanFullScreen.invoke(null, window, true);
} catch (Throwable t) {
Logger.getLogger(Main.class.getName()).log(Level.WARNING, "setWindowCanFullScreen not supported: " + t);
}
}
public static void requestForeground() {
try {
Class<?> application = Class.forName("com.apple.eawt.Application");
Object instance = application.getMethod("getApplication").invoke(null);
Method requestForeground = application.getMethod("requestForeground", new Class<?>[] { boolean.class });
requestForeground.invoke(instance, true);
} catch (Throwable t) {
Logger.getLogger(Main.class.getName()).log(Level.WARNING, "requestForeground not supported: " + t);
}
}
}

View File

@ -1,21 +0,0 @@
package net.filebot.mac.sandbox;
import ca.weblite.objc.Client;
public class SandBoxUtil {
private static final Client objc = new Client();
public static Object NSData_initWithBase64Encoding(String text) {
return objc.sendProxy("NSData", "data").send("initWithBase64Encoding:", text);
}
public static Object NSURL_bookmarkDataWithOptions(String path) {
return objc.sendProxy("NSURL", "fileURLWithPath:", path).sendProxy("bookmarkDataWithOptions:includingResourceValuesForKeys:relativeToURL:error:", 2048, null, null, null).sendString("base64Encoding");
}
public static Object NSURL_URLByResolvingBookmarkData_startAccessingSecurityScopedResource(String text) {
return objc.sendProxy("NSURL", "URLByResolvingBookmarkData:options:relativeToURL:bookmarkDataIsStale:error:", NSData_initWithBase64Encoding(text), 1024, null, false, null).send("startAccessingSecurityScopedResource");
}
}

View File

@ -43,6 +43,7 @@ import net.filebot.Analytics;
import net.filebot.ResourceManager;
import net.filebot.Settings;
import net.filebot.cli.GroovyPad;
import net.filebot.mac.MacAppHelper;
import net.filebot.ui.analyze.AnalyzePanelBuilder;
import net.filebot.ui.episodelist.EpisodeListPanelBuilder;
import net.filebot.ui.list.ListPanelBuilder;
@ -230,7 +231,11 @@ public class MainFrame extends JFrame {
selectEnabled = true;
// bring window to front when on dnd
SwingUtilities.getWindowAncestor(((DropTarget) dtde.getSource()).getComponent()).toFront();
if (Settings.isMacSandbox()) {
MacAppHelper.requestForeground();
} else {
SwingUtilities.getWindowAncestor(((DropTarget) dtde.getSource()).getComponent()).toFront();
}
}
});
}

View File

@ -303,7 +303,7 @@ class SubtitleDownloadComponent extends JComponent {
Charset selectedEncoding = Charset.forName("UTF-8");
// just use default values when we can't use a JFC with accessory component
if (Settings.isSandboxed()) {
if (Settings.isMacSandbox()) {
// AWT
selectedOutputFolder = showOpenDialogSelectFolder(null, "Export Subtitles", this);
} else {