Changeset 12268 in josm for trunk/src/org/openstreetmap


Ignore:
Timestamp:
2017-05-28T19:24:09+02:00 (7 years ago)
Author:
Don-vip
Message:

see #11924 - fix macOS dock icon with Java 9

File:
1 edited

Legend:

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

    r12219 r12268  
    6060            Object proxy = Proxy.newProxyInstance(PlatformHookOsx.class.getClassLoader(), new Class<?>[] {
    6161                quitHandler, aboutHandler, openFilesHandler, preferencesHandler}, ivhandler);
    62             try {
    63                 Object appli = eawtApplication.getConstructor((Class[]) null).newInstance((Object[]) null);
     62            Object appli = eawtApplication.getConstructor((Class[]) null).newInstance((Object[]) null);
     63            if (Utils.getJavaVersion() >= 9) {
     64                setHandlers(Desktop.class, quitHandler, aboutHandler, openFilesHandler, preferencesHandler, proxy, Desktop.getDesktop());
     65            } else {
    6466                setHandlers(eawtApplication, quitHandler, aboutHandler, openFilesHandler, preferencesHandler, proxy, appli);
    65                 // this method has been deprecated, but without replacement ATM
     67                // this method has been deprecated, but without replacement. To remove with Java 9 migration
    6668                eawtApplication.getDeclaredMethod("setEnabledPreferencesMenu", boolean.class).invoke(appli, Boolean.TRUE);
    67                 // setup the dock icon. It is automatically set with application bundle and Web start but we need
    68                 // to do it manually if run with `java -jar``
    69                 eawtApplication.getDeclaredMethod("setDockIconImage", Image.class).invoke(appli, ImageProvider.get("logo").getImage());
    70                 // enable full screen
    71                 enableOSXFullscreen((Window) Main.parent);
    72             } catch (IllegalAccessException e) {
    73                 Main.debug(e);
    74                 // with Java 9, module java.desktop does not export com.apple.eawt, use new Desktop API instead
    75                 setHandlers(Desktop.class, quitHandler, aboutHandler, openFilesHandler, preferencesHandler, proxy, Desktop.getDesktop());
    7669            }
     70            // setup the dock icon. It is automatically set with application bundle and Web start but we need
     71            // to do it manually if run with `java -jar``
     72            eawtApplication.getDeclaredMethod("setDockIconImage", Image.class).invoke(appli, ImageProvider.get("logo").getImage());
     73            // enable full screen
     74            enableOSXFullscreen((Window) Main.parent);
    7775        } catch (ReflectiveOperationException | SecurityException | IllegalArgumentException ex) {
    7876            // We'll just ignore this for now. The user will still be able to close JOSM by closing all its windows.
     
    112110    protected Class<?> findHandlerClass(String className) throws ClassNotFoundException {
    113111        try {
     112            // Java 8 handlers
    114113            return Class.forName("com.apple.eawt."+className);
    115114        } catch (ClassNotFoundException e) {
    116115            Main.trace(e);
     116            // Java 9 handlers
    117117            return Class.forName("java.awt.desktop."+className);
    118118        }
Note: See TracChangeset for help on using the changeset viewer.