Changeset 7482 in josm


Ignore:
Timestamp:
2014-09-01T21:35:31+02:00 (10 years ago)
Author:
Don-vip
Message:

fix #7021 - enable fullscreen with OS X

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/tools/PlatformHookOsx.java

    r7480 r7482  
    44import static org.openstreetmap.josm.tools.I18n.tr;
    55
     6import java.awt.Window;
    67import java.awt.event.KeyEvent;
    78import java.io.File;
     
    4243        // Here we register callbacks for the menu entries in the system menu and file opening through double-click
    4344        try {
    44             Class<?> Ccom_apple_eawt_Application = Class.forName("com.apple.eawt.Application");
    45             Class<?> Ccom_apple_eawt_QuitHandler = Class.forName("com.apple.eawt.QuitHandler");
    46             Class<?> Ccom_apple_eawt_AboutHandler = Class.forName("com.apple.eawt.AboutHandler");
    47             Class<?> Ccom_apple_eawt_OpenFilesHandler = Class.forName("com.apple.eawt.OpenFilesHandler");
    48             Class<?> Ccom_apple_eawt_PreferencesHandler = Class.forName("com.apple.eawt.PreferencesHandler");
    49             Object Ocom_apple_eawt_Application = Ccom_apple_eawt_Application.getConstructor((Class[])null).newInstance((Object[])null);
    50             Object Oproxy = Proxy.newProxyInstance(PlatformHookOsx.class.getClassLoader(), new Class<?>[] {
    51                 Ccom_apple_eawt_QuitHandler, Ccom_apple_eawt_AboutHandler, Ccom_apple_eawt_OpenFilesHandler, Ccom_apple_eawt_PreferencesHandler}, ivhandler);
    52             Ccom_apple_eawt_Application.getDeclaredMethod("setQuitHandler", Ccom_apple_eawt_QuitHandler).invoke(Ocom_apple_eawt_Application, Oproxy);
    53             Ccom_apple_eawt_Application.getDeclaredMethod("setAboutHandler", Ccom_apple_eawt_AboutHandler).invoke(Ocom_apple_eawt_Application, Oproxy);
    54             Ccom_apple_eawt_Application.getDeclaredMethod("setOpenFileHandler", Ccom_apple_eawt_OpenFilesHandler).invoke(Ocom_apple_eawt_Application, Oproxy);
    55             Ccom_apple_eawt_Application.getDeclaredMethod("setPreferencesHandler", Ccom_apple_eawt_PreferencesHandler).invoke(Ocom_apple_eawt_Application, Oproxy);
     45            Class<?> eawtApplication = Class.forName("com.apple.eawt.Application");
     46            Class<?> eawtQuitHandler = Class.forName("com.apple.eawt.QuitHandler");
     47            Class<?> eawtAboutHandler = Class.forName("com.apple.eawt.AboutHandler");
     48            Class<?> eawtOpenFilesHandler = Class.forName("com.apple.eawt.OpenFilesHandler");
     49            Class<?> eawtPreferencesHandler = Class.forName("com.apple.eawt.PreferencesHandler");
     50            Object application = eawtApplication.getConstructor((Class[])null).newInstance((Object[])null);
     51            Object proxy = Proxy.newProxyInstance(PlatformHookOsx.class.getClassLoader(), new Class<?>[] {
     52                eawtQuitHandler, eawtAboutHandler, eawtOpenFilesHandler, eawtPreferencesHandler}, ivhandler);
     53            eawtApplication.getDeclaredMethod("setQuitHandler", eawtQuitHandler).invoke(application, proxy);
     54            eawtApplication.getDeclaredMethod("setAboutHandler", eawtAboutHandler).invoke(application, proxy);
     55            eawtApplication.getDeclaredMethod("setOpenFileHandler", eawtOpenFilesHandler).invoke(application, proxy);
     56            eawtApplication.getDeclaredMethod("setPreferencesHandler", eawtPreferencesHandler).invoke(application, proxy);
    5657            // this method has been deprecated, but without replacement ATM
    57             Ccom_apple_eawt_Application.getDeclaredMethod("setEnabledPreferencesMenu", boolean.class).invoke(Ocom_apple_eawt_Application, Boolean.TRUE);
     58            eawtApplication.getDeclaredMethod("setEnabledPreferencesMenu", boolean.class).invoke(application, Boolean.TRUE);
     59            // enable full screen
     60            enableOSXFullscreen((Window) Main.parent);
    5861        } catch (ReflectiveOperationException | SecurityException | IllegalArgumentException ex) {
    5962            // We'll just ignore this for now. The user will still be able to close JOSM by closing all its windows.
    6063            Main.warn("Failed to register with OSX: " + ex);
     64        }
     65    }
     66
     67    /**
     68     * Enables fullscreen support for the given window.
     69     * @param window The window for which full screen will be available
     70     * @since 7482
     71     */
     72    public static void enableOSXFullscreen(Window window) {
     73        CheckParameterUtil.ensureParameterNotNull(window, "window");
     74        try {
     75            // http://stackoverflow.com/a/8693890/2257172
     76            Class<?> eawtFullScreenUtilities = Class.forName("com.apple.eawt.FullScreenUtilities");
     77            eawtFullScreenUtilities.getDeclaredMethod("setWindowCanFullScreen",
     78                    new Class[]{Window.class, boolean.class}).invoke(eawtFullScreenUtilities, window, true);
     79        } catch (ReflectiveOperationException | SecurityException | IllegalArgumentException e) {
     80            Main.warn("Failed to register with OSX: " + e);
    6181        }
    6282    }
     
    291311    @Override
    292312    public boolean canFullscreen() {
     313        // OS X provides native full screen support registered at initialization, no need for custom action
    293314        return false;
    294315    }
Note: See TracChangeset for help on using the changeset viewer.