/* * 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 * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package com.sun.glass.ui.gtk; import com.sun.glass.ui.Application; import com.sun.glass.ui.Menu; import com.sun.glass.ui.MenuBar; import com.sun.glass.ui.MenuItem; import com.sun.glass.ui.PlatformFactory; 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>) () -> { 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(forcedGtkVersion); } @Override public MenuBarDelegate createMenuBarDelegate(MenuBar menubar) { return new GtkMenuBarDelegate(); } @Override public MenuDelegate createMenuDelegate(Menu menu) { return new GtkMenuDelegate(); } @Override public MenuItemDelegate createMenuItemDelegate(MenuItem item) { return new GtkMenuItemDelegate(); } public ClipboardDelegate createClipboardDelegate() { return new GtkClipboardDelegate(); } }