--- old/modules/javafx.graphics/src/main/java/com/sun/glass/ui/gtk/GtkPlatformFactory.java 2016-11-22 19:10:34.918503285 +0300 +++ new/modules/javafx.graphics/src/main/java/com/sun/glass/ui/gtk/GtkPlatformFactory.java 2016-11-22 19:10:34.834503288 +0300 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 2016, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -34,11 +34,69 @@ import com.sun.glass.ui.delegate.MenuBarDelegate; import com.sun.glass.ui.delegate.MenuDelegate; import com.sun.glass.ui.delegate.MenuItemDelegate; +import com.sun.javafx.util.Logging; +import sun.util.logging.PlatformLogger; + +import java.lang.reflect.Method; +import java.security.AccessController; +import java.security.PrivilegedAction; public final class GtkPlatformFactory extends PlatformFactory { + private static final String SWT_INTERNAL_CLASS = + "org.eclipse.swt.internal.gtk.OS"; + private static final int forcedGtkVersion; + + + static { + //check for SWT-GTK lib presence + Class OS = AccessController. + doPrivileged((PrivilegedAction>) () -> { + try { + return Class.forName(SWT_INTERNAL_CLASS, true, + ClassLoader.getSystemClassLoader()); + } catch (Exception e) {} + try { + return Class.forName(SWT_INTERNAL_CLASS, true, + Thread.currentThread().getContextClassLoader()); + } catch (Exception e) {} + return null; + }); + if (OS != null) { + PlatformLogger logger = Logging.getFocusLogger(); + logger.fine("SWT-GTK library found. Try to obtain GTK version."); + Method method = AccessController. + doPrivileged((PrivilegedAction) () -> { + try { + return OS.getMethod("gtk_major_version"); + } catch (Exception e) { + return null; + } + }); + int ver = 0; + if (method != null) { + try { + ver = ((Number)method.invoke(OS)).intValue(); + } catch (Exception e) { + logger.warning("Method gtk_major_version() of " + + "the org.eclipse.swt.internal.gtk.OS class " + + "returns error. SWT GTK version cannot be detected. " + + "GTK3 will be used as default."); + ver = 3; + } + } + if (ver < 2 && ver > 3) { + logger.warning("SWT-GTK uses unsupported major GTK version " + + ver + ". GTK3 will be used as default."); + ver = 3; + } + forcedGtkVersion = ver; + } else { + forcedGtkVersion = 0; + } + } @Override public Application createApplication(){ - return new GtkApplication(); + return new GtkApplication(forcedGtkVersion); } @Override public MenuBarDelegate createMenuBarDelegate(MenuBar menubar) {