< prev index next >
modules/javafx.graphics/src/main/java/com/sun/glass/ui/gtk/GtkPlatformFactory.java
Print this page
@@ -1,7 +1,7 @@
/*
- * 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
@@ -32,15 +32,73 @@
import com.sun.glass.ui.Window;
import com.sun.glass.ui.delegate.ClipboardDelegate;
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<Class<?>>) () -> {
+ 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<Method>) () -> {
+ 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) {
return new GtkMenuBarDelegate();
}
< prev index next >