The system tray and GTK backend no longer have a hard-dependency on SWT/JavaFX modules. They now use a "plugin" type of system to provide a "renderer", which is used for various determination and dispatch tasks.

This repository only serves now as an EXAMPLE of a correct provider.
master
Robinson 2021-05-02 12:51:52 +02:00
parent 46500e8b26
commit 0edf0a688b
14 changed files with 684 additions and 451 deletions

292
LICENSE
View File

@ -17,8 +17,300 @@
Copyright 2021
Oracle and/or its affiliates
- Utilities - Utilities for use within Java projects
[The Apache Software License, Version 2.0]
https://git.dorkbox.com/dorkbox/Utilities
Copyright 2021
Dorkbox LLC
Extra license information
- MersenneTwisterFast -
[BSD 3-Clause License]
https://git.dorkbox.com/dorkbox/Utilities
Copyright 2003
Sean Luke
Michael Lecuyer (portions Copyright 1993
- FileUtil (code from FilenameUtils.java for normalize + dependencies) -
[The Apache Software License, Version 2.0]
https://git.dorkbox.com/dorkbox/Utilities
http://commons.apache.org/proper/commons-io/
Copyright 2013
The Apache Software Foundation
Kevin A. Burton
Scott Sanders
Daniel Rall
Christoph.Reck
Peter Donald
Jeff Turner
Matthew Hawthorne
Martin Cooper
Jeremias Maerki
Stephen Colebourne
- FastThreadLocal -
[BSD 3-Clause License]
https://git.dorkbox.com/dorkbox/Utilities
https://github.com/LWJGL/lwjgl3/blob/5819c9123222f6ce51f208e022cb907091dd8023/modules/core/src/main/java/org/lwjgl/system/FastThreadLocal.java
https://github.com/riven8192/LibStruct/blob/master/src/net/indiespot/struct/runtime/FastThreadLocal.java
Copyright 2014
Lightweight Java Game Library Project
Riven
- Base64Fast -
[BSD 3-Clause License]
https://git.dorkbox.com/dorkbox/Utilities
http://migbase64.sourceforge.net/
Copyright 2004
Mikael Grev, MiG InfoCom AB. (base64@miginfocom.com)
- BCrypt -
[BSD 2-Clause "Simplified" or "FreeBSD" license]
https://git.dorkbox.com/dorkbox/Utilities
http://www.mindrot.org/projects/jBCrypt
Copyright 2006
Damien Miller (djm@mindrot.org)
GWT modified version
- Bias, BinarySearch -
[MIT License]
https://git.dorkbox.com/dorkbox/Utilities
https://github.com/timboudreau/util
Copyright 2013
Tim Boudreau
- ConcurrentEntry -
[The Apache Software License, Version 2.0]
https://git.dorkbox.com/dorkbox/Utilities
Copyright 2016
bennidi
dorkbox
- Collection Utilities (Array, ArrayMap, BooleanArray, ByteArray, CharArray, FloatArray, IdentityMap, IntArray, IntFloatMap, IntIntMap, IntMap, IntSet, LongArray, LongMap, ObjectFloatMap, ObjectIntMap, ObjectMap, ObjectSet, OrderedMap, OrderedSet) -
[The Apache Software License, Version 2.0]
https://git.dorkbox.com/dorkbox/Utilities
https://github.com/libgdx/libgdx/blob/master/gdx/src/com/badlogic/gdx/utils
Copyright 2011
LibGDX
Mario Zechner (badlogicgames@gmail.com)
Nathan Sweet (nathan.sweet@gmail.com)
- Predicate -
[The Apache Software License, Version 2.0]
https://git.dorkbox.com/dorkbox/Utilities
https://github.com/libgdx/libgdx/blob/master/gdx/src/com/badlogic/gdx/utils
Copyright 2011
LibGDX
Mario Zechner (badlogicgames@gmail.com)
Nathan Sweet (nathan.sweet@gmail.com)
xoppa
- Select, QuickSelect -
[The Apache Software License, Version 2.0]
https://git.dorkbox.com/dorkbox/Utilities
https://github.com/libgdx/libgdx/blob/master/gdx/src/com/badlogic/gdx/utils
Copyright 2011
LibGDX
Mario Zechner (badlogicgames@gmail.com)
Nathan Sweet (nathan.sweet@gmail.com)
Jon Renner
- TimSort, ComparableTimSort -
[The Apache Software License, Version 2.0]
https://git.dorkbox.com/dorkbox/Utilities
https://github.com/libgdx/libgdx/blob/master/gdx/src/com/badlogic/gdx/utils
Copyright 2008
The Android Open Source Project
- Modified hex conversion utility methods -
[The Apache Software License, Version 2.0]
https://git.dorkbox.com/dorkbox/Utilities
https://netty.io
Copyright 2014
The Netty Project
- Retrofit - A type-safe HTTP client for Android and Java
[The Apache Software License, Version 2.0]
https://github.com/square/retrofit
Copyright 2020
Square, Inc
- Kotlin -
[The Apache Software License, Version 2.0]
https://github.com/JetBrains/kotlin
Copyright 2020
JetBrains s.r.o. and Kotlin Programming Language contributors
Kotlin Compiler, Test Data+Libraries, and Tools repository contain third-party code, to which different licenses may apply
See: https://github.com/JetBrains/kotlin/blob/master/license/README.md
- JNA - Simplified native library access for Java.
[The Apache Software License, Version 2.0]
https://github.com/twall/jna
Copyright 2021
Timothy Wall
- JNA-Platform - Mappings for a number of commonly used platform functions
[The Apache Software License, Version 2.0]
https://github.com/twall/jna
Copyright 2021
Timothy Wall
- Java Uuid Generator - A set of Java classes for working with UUIDs
[The Apache Software License, Version 2.0]
https://github.com/cowtowncoder/java-uuid-generator
Copyright 2021
Tatu Saloranta (tatu.saloranta@iki.fi)
Contributors. See source release-notes/CREDITS
- Netty - An event-driven asynchronous network application framework
[The Apache Software License, Version 2.0]
https://netty.io
Copyright 2021
The Netty Project
Contributors. See source NOTICE
- Bouncy Castle Crypto - Lightweight cryptography API and JCE Extension
[The Apache Software License, Version 2.0]
http://www.bouncycastle.org
Copyright 2021
The Legion of the Bouncy Castle Inc
- Lightweight Java Game Library - Java library that enables cross-platform access to popular native APIs
[BSD 3-Clause License]
https://github.com/LWJGL/lwjgl3
Copyright 2021
Lightweight Java Game Library
- TypeTools - A simple, zero-dependency library for working with types. Supports Java 1.6+ and Android.
[The Apache Software License, Version 2.0]
https://github.com/jhalterman/typetools
Copyright 2021
Jonathan Halterman and friends
- kotlinx.coroutines - Library support for Kotlin coroutines with multiplatform support
[The Apache Software License, Version 2.0]
https://github.com/Kotlin/kotlinx.coroutines
Copyright 2021
JetBrains s.r.o.
- SLF4J - Simple facade or abstraction for various logging frameworks
[MIT License]
http://www.slf4j.org
Copyright 2021
QOS.ch
- XZ for Java - Complete implementation of XZ data compression in pure Java
[Public Domain, per Creative Commons CC0]
https://tukaani.org/xz/java.html
Copyright 2021
Lasse Collin
Igor Pavlov
- Executor - Shell, JVM, and SSH command execution on Linux, MacOS, or Windows for Java 8+
[The Apache Software License, Version 2.0]
https://git.dorkbox.com/dorkbox/Executor
Copyright 2021
Dorkbox LLC
Extra license information
- ZT Process Executor -
[The Apache Software License, Version 2.0]
https://github.com/zeroturnaround/zt-exec
Copyright 2014
ZeroTurnaround LLC
- Apache Commons Exec -
[The Apache Software License, Version 2.0]
https://commons.apache.org/proper/commons-exec/
Copyright 2014
The Apache Software Foundation
- Kotlin -
[The Apache Software License, Version 2.0]
https://github.com/JetBrains/kotlin
Copyright 2020
JetBrains s.r.o. and Kotlin Programming Language contributors
Kotlin Compiler, Test Data+Libraries, and Tools repository contain third-party code, to which different licenses may apply
See: https://github.com/JetBrains/kotlin/blob/master/license/README.md
- Logback - Logback is a logging framework for Java applications
[The Apache Software License, Version 2.0]
http://logback.qos.ch
Copyright 2021
QOS.ch
- SSHJ - SSHv2 library for Java
[The Apache Software License, Version 2.0]
https://github.com/hierynomus/sshj
Copyright 2021
Jeroen van Erp
SSHJ Contributors
Extra license information
- Apache MINA -
[The Apache Software License, Version 2.0]
https://mina.apache.org/sshd-project/
The Apache Software Foundation
- Apache Commons-Net -
[The Apache Software License, Version 2.0]
https://commons.apache.org/proper/commons-net/
The Apache Software Foundation
- JZlib -
[The Apache Software License, Version 2.0]
http://www.jcraft.com/jzlib
Atsuhiko Yamanaka
JCraft, Inc.
- Bouncy Castle Crypto -
[The Apache Software License, Version 2.0]
http://www.bouncycastle.org
The Legion of the Bouncy Castle Inc
- ed25519-java -
[Public Domain, per Creative Commons CC0]
https://github.com/str4d/ed25519-java
https://github.com/str4d
- kotlinx.coroutines - Library support for Kotlin coroutines with multiplatform support
[The Apache Software License, Version 2.0]
https://github.com/Kotlin/kotlinx.coroutines
Copyright 2021
JetBrains s.r.o.
- SLF4J - Simple facade or abstraction for various logging frameworks
[MIT License]
http://www.slf4j.org
Copyright 2021
QOS.ch
- Updates - Software Update Management
[The Apache Software License, Version 2.0]
https://git.dorkbox.com/dorkbox/Updates
Copyright 2021
Dorkbox LLC
Extra license information
- Kotlin -
[The Apache Software License, Version 2.0]
https://github.com/JetBrains/kotlin
Copyright 2020
JetBrains s.r.o. and Kotlin Programming Language contributors
Kotlin Compiler, Test Data+Libraries, and Tools repository contain third-party code, to which different licenses may apply
See: https://github.com/JetBrains/kotlin/blob/master/license/README.md
- Updates - Software Update Management
[The Apache Software License, Version 2.0]
https://git.dorkbox.com/dorkbox/Updates
Copyright 2021
Dorkbox LLC
Extra license information
- Kotlin -
[The Apache Software License, Version 2.0]
https://github.com/JetBrains/kotlin
Copyright 2020
JetBrains s.r.o. and Kotlin Programming Language contributors
Kotlin Compiler, Test Data+Libraries, and Tools repository contain third-party code, to which different licenses may apply
See: https://github.com/JetBrains/kotlin/blob/master/license/README.md

22
LICENSE.BSD2 Normal file
View File

@ -0,0 +1,22 @@
BSD License
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL <ORGANIZATION> BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

26
LICENSE.BSD3 Normal file
View File

@ -0,0 +1,26 @@
BSD License
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the <ORGANIZATION> nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL <ORGANIZATION> BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

121
LICENSE.CC0 Normal file
View File

@ -0,0 +1,121 @@
Creative Commons Legal Code
CC0 1.0 Universal
CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE
LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN
ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS
INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES
REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS
PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM
THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED
HEREUNDER.
Statement of Purpose
The laws of most jurisdictions throughout the world automatically confer
exclusive Copyright and Related Rights (defined below) upon the creator
and subsequent owner(s) (each and all, an "owner") of an original work of
authorship and/or a database (each, a "Work").
Certain owners wish to permanently relinquish those rights to a Work for
the purpose of contributing to a commons of creative, cultural and
scientific works ("Commons") that the public can reliably and without fear
of later claims of infringement build upon, modify, incorporate in other
works, reuse and redistribute as freely as possible in any form whatsoever
and for any purposes, including without limitation commercial purposes.
These owners may contribute to the Commons to promote the ideal of a free
culture and the further production of creative, cultural and scientific
works, or to gain reputation or greater distribution for their Work in
part through the use and efforts of others.
For these and/or other purposes and motivations, and without any
expectation of additional consideration or compensation, the person
associating CC0 with a Work (the "Affirmer"), to the extent that he or she
is an owner of Copyright and Related Rights in the Work, voluntarily
elects to apply CC0 to the Work and publicly distribute the Work under its
terms, with knowledge of his or her Copyright and Related Rights in the
Work and the meaning and intended legal effect of CC0 on those rights.
1. Copyright and Related Rights. A Work made available under CC0 may be
protected by copyright and related or neighboring rights ("Copyright and
Related Rights"). Copyright and Related Rights include, but are not
limited to, the following:
i. the right to reproduce, adapt, distribute, perform, display,
communicate, and translate a Work;
ii. moral rights retained by the original author(s) and/or performer(s);
iii. publicity and privacy rights pertaining to a person's image or
likeness depicted in a Work;
iv. rights protecting against unfair competition in regards to a Work,
subject to the limitations in paragraph 4(a), below;
v. rights protecting the extraction, dissemination, use and reuse of data
in a Work;
vi. database rights (such as those arising under Directive 96/9/EC of the
European Parliament and of the Council of 11 March 1996 on the legal
protection of databases, and under any national implementation
thereof, including any amended or successor version of such
directive); and
vii. other similar, equivalent or corresponding rights throughout the
world based on applicable law or treaty, and any national
implementations thereof.
2. Waiver. To the greatest extent permitted by, but not in contravention
of, applicable law, Affirmer hereby overtly, fully, permanently,
irrevocably and unconditionally waives, abandons, and surrenders all of
Affirmer's Copyright and Related Rights and associated claims and causes
of action, whether now known or unknown (including existing as well as
future claims and causes of action), in the Work (i) in all territories
worldwide, (ii) for the maximum duration provided by applicable law or
treaty (including future time extensions), (iii) in any current or future
medium and for any number of copies, and (iv) for any purpose whatsoever,
including without limitation commercial, advertising or promotional
purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each
member of the public at large and to the detriment of Affirmer's heirs and
successors, fully intending that such Waiver shall not be subject to
revocation, rescission, cancellation, termination, or any other legal or
equitable action to disrupt the quiet enjoyment of the Work by the public
as contemplated by Affirmer's express Statement of Purpose.
3. Public License Fallback. Should any part of the Waiver for any reason
be judged legally invalid or ineffective under applicable law, then the
Waiver shall be preserved to the maximum extent permitted taking into
account Affirmer's express Statement of Purpose. In addition, to the
extent the Waiver is so judged Affirmer hereby grants to each affected
person a royalty-free, non transferable, non sublicensable, non exclusive,
irrevocable and unconditional license to exercise Affirmer's Copyright and
Related Rights in the Work (i) in all territories worldwide, (ii) for the
maximum duration provided by applicable law or treaty (including future
time extensions), (iii) in any current or future medium and for any number
of copies, and (iv) for any purpose whatsoever, including without
limitation commercial, advertising or promotional purposes (the
"License"). The License shall be deemed effective as of the date CC0 was
applied by Affirmer to the Work. Should any part of the License for any
reason be judged legally invalid or ineffective under applicable law, such
partial invalidity or ineffectiveness shall not invalidate the remainder
of the License, and in such case Affirmer hereby affirms that he or she
will not (i) exercise any of his or her remaining Copyright and Related
Rights in the Work or (ii) assert any associated claims and causes of
action with respect to the Work, in either case contrary to Affirmer's
express Statement of Purpose.
4. Limitations and Disclaimers.
a. No trademark or patent rights held by Affirmer are waived, abandoned,
surrendered, licensed or otherwise affected by this document.
b. Affirmer offers the Work as-is and makes no representations or
warranties of any kind concerning the Work, express, implied,
statutory or otherwise, including without limitation warranties of
title, merchantability, fitness for a particular purpose, non
infringement, or the absence of latent or other defects, accuracy, or
the present or absence of errors, whether or not discoverable, all to
the greatest extent permissible under applicable law.
c. Affirmer disclaims responsibility for clearing rights of other persons
that may apply to the Work or any use thereof, including without
limitation any person's Copyright and Related Rights in the Work.
Further, Affirmer disclaims responsibility for obtaining any necessary
consents, permissions or other rights required for any use of the
Work.
d. Affirmer understands and acknowledges that Creative Commons is not a
party to this document and has no duty or obligation with respect to
this CC0 or use of the Work.

View File

@ -26,7 +26,7 @@ gradle.startParameter.showStacktrace = ShowStacktrace.ALWAYS // always show th
plugins {
id("com.dorkbox.GradleUtils") version "2.6"
id("com.dorkbox.Licensing") version "2.6"
id("com.dorkbox.Licensing") version "2.7"
id("com.dorkbox.VersionUpdate") version "2.3"
id("com.dorkbox.GradlePublish") version "1.11"
}
@ -35,7 +35,7 @@ object Extras {
// set for the project
const val description = "Swt and JavaFx Utilities"
const val group = "com.dorkbox"
const val version = "1.2"
const val version = "1.3"
// set as project.ext
const val name = "SwtJavaFx"
@ -57,8 +57,7 @@ object Extras {
///////////////////////////////
GradleUtils.load("$projectDir/../../gradle.properties", Extras)
GradleUtils.defaults()
GradleUtils.compileConfiguration(JavaVersion.VERSION_1_8)
//GradleUtils.jpms(JavaVersion.VERSION_1_9)
GradleUtils.compileConfiguration(JavaVersion.VERSION_11)
licensing {
license(License.APACHE_2) {
@ -84,7 +83,7 @@ tasks.jar.get().apply {
}
dependencies {
implementation("org.slf4j:slf4j-api:1.8.0-beta4")
implementation("com.dorkbox:Utilities:1.11")
// This is explicitly linux because we access GTK internals (and it's only available on the linux GTK version of SWT)
// we use ALL of the swt dependencies, this way any implementation will work

View File

@ -1,148 +0,0 @@
/*
* Copyright 2016 dorkbox, llc
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package dorkbox.javaFx;
import java.lang.reflect.Method;
import java.security.AccessController;
import java.security.PrivilegedAction;
import org.slf4j.LoggerFactory;
import dorkbox.swt.Swt;
/**
* Utility methods for JavaFX.
*/
public
class JavaFx {
public final static boolean isLoaded;
public final static boolean isGtk3;
static {
// There is a silly amount of redirection, simply because we have to be able to access JavaFX, but only if it's in use.
// Since this class is the place other code interacts with, we can use JavaFX stuff if necessary without loading/linking
// the JavaFX classes by accident
// We cannot use getToolkit(), because if JavaFX is not being used, calling getToolkit() will initialize it...
// see: https://bugs.openjdk.java.net/browse/JDK-8090933
String fullJavaVersion = System.getProperty("java.version", "");
boolean isJava8 = fullJavaVersion.startsWith("1.") && fullJavaVersion.charAt(2) == '8';
Class<?> javaFxLoggerClass = AccessController.doPrivileged(new PrivilegedAction<Class<?>>() {
@Override
public
Class<?> run() {
try {
return Class.forName("com.sun.javafx.logging.PlatformLogger", true, ClassLoader.getSystemClassLoader());
} catch (Exception ignored) {
}
try {
return Class.forName("com.sun.javafx.logging.PlatformLogger", true, Thread.currentThread().getContextClassLoader());
} catch (Exception ignored) {
}
return null;
}
});
boolean isJavaFxLoaded_ = false;
try {
if (javaFxLoggerClass != null) {
// try to avoid using reflection!
// first, walk the stack to see if any JavaFX classes are used (which indicate that we are running with JavaFX)
StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
for (int i = 0; i < stackTrace.length; i++) {
if (stackTrace[i].getClassName().contains("javafx")) {
isJavaFxLoaded_ = true;
break;
}
}
// this is important to use reflection, because if JavaFX is not being used, calling getToolkit() will initialize it...
if (!isJavaFxLoaded_) {
// stack walking failed, resort to using a property (emit a warning)
String usingJavFx = System.getProperty("usingJavaFx", "false");
if (!usingJavFx.equals("false")) {
// if it is set to ANYTHING other than exactly "false", then we are using javaFX. Skip reflection testing
isJavaFxLoaded_ = true;
} else {
// stack walking and property check failed, resort to using reflection.
// WE DON'T always want to do this BECAUSE Java9+ really doesn't like reflection!
LoggerFactory.getLogger(JavaFx.class).debug("Using reflection to detect if JavaFX is loaded.\n" +
"To avoid using reflection, set the system property \"usingJavaFx\" to \"true\" before your application starts. " +
"For example: System.setProperty(\"usingJavaFx\", \"true\");");
Method m = ClassLoader.class.getDeclaredMethod("findLoadedClass", String.class);
m.setAccessible(true);
ClassLoader cl = ClassLoader.getSystemClassLoader();
isJavaFxLoaded_ = (null != m.invoke(cl, "com.sun.javafx.tk.Toolkit")) || (null != m.invoke(cl, "javafx.application.Application"));
}
}
}
} catch (Throwable e) {
LoggerFactory.getLogger(JavaFx.class).debug("Error detecting if JavaFX is loaded", e);
}
boolean isJavaFxGtk3_ = false;
if (isJavaFxLoaded_) {
// JavaFX Java7,8 is GTK2 only. Java9 can MAYBE have it be GTK3 if `-Djdk.gtk.version=3` is specified
// see
// http://mail.openjdk.java.net/pipermail/openjfx-dev/2016-May/019100.html
// https://docs.oracle.com/javafx/2/system_requirements_2-2-3/jfxpub-system_requirements_2-2-3.htm
// from the page: JavaFX 2.2.3 for Linux requires gtk2 2.18+.
// HILARIOUSLY enough, you can use JavaFX + SWT..... And the javaFX GTK version info SHOULD
// be based on what SWT has loaded
// https://github.com/teamfx/openjfx-9-dev-rt/blob/master/modules/javafx.graphics/src/main/java/com/sun/glass/ui/gtk/GtkApplication.java
if (isJava8) {
// JavaFX from Oracle Java 8 is GTK2 only. Java9 can have it be GTK3 if -Djdk.gtk.version=3 is specified
// see http://mail.openjdk.java.net/pipermail/openjfx-dev/2016-May/019100.html
isJavaFxGtk3_ = false;
} else {
// Only possible Java9+ (so our case, Java11+ since 9 is no longer available, 11 is officially LTS)
if (Swt.isLoaded && !Swt.isGtk3) {
isJavaFxGtk3_ = AccessController.doPrivileged(new PrivilegedAction<Boolean>() {
@Override
public
Boolean run() {
String version = System.getProperty("jdk.gtk.version", "2");
return "3".equals(version) || version.startsWith("3.");
}
});
}
}
}
isLoaded = isJavaFxLoaded_;
isGtk3 = isJavaFxGtk3_;
}
public static
void dispatch(final Runnable runnable) {
JavaFxAccess.dispatch(runnable);
}
public static
boolean isEventThread() {
return JavaFxAccess.isEventThread();
}
}

View File

@ -1,33 +0,0 @@
/*
* Copyright 2016 dorkbox, llc
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package dorkbox.javaFx;
/**
* Utility methods for JavaFX.
*/
public
class JavaFxAccess {
static
void dispatch(final Runnable runnable) {
javafx.application.Platform.runLater(runnable);
}
static
boolean isEventThread() {
// JAVA 8
return com.sun.javafx.tk.Toolkit.getToolkit().isFxUserThread();
}
}

View File

@ -0,0 +1,101 @@
/*
* Copyright 2021 dorkbox, llc
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package dorkbox.javaFx;
import dorkbox.jna.rendering.ProviderType;
import dorkbox.jna.rendering.Renderer;
import dorkbox.os.OS;
public
class JavaFxProvider implements Renderer {
@Override
public
boolean isSupported() {
return true;
}
@Override
public
ProviderType getType() {
return ProviderType.JAVAFX;
}
@Override
public
boolean alreadyRunning() {
// this is only true for SWT. JavaFX running detection is elsewhere
return false;
}
@Override
public
boolean isEventThread() {
return javafx.application.Platform.isFxApplicationThread();
}
@Override
public
int getGtkVersion() {
if (!OS.isLinux()) {
return 0;
}
// JavaFX Java7,8 is GTK2 only. Java9 can MAYBE have it be GTK3 if `-Djdk.gtk.version=3` is specified
// see
// http://mail.openjdk.java.net/pipermail/openjfx-dev/2016-May/019100.html
// https://docs.oracle.com/javafx/2/system_requirements_2-2-3/jfxpub-system_requirements_2-2-3.htm
// from the page: JavaFX 2.2.3 for Linux requires gtk2 2.18+.
// HILARIOUSLY enough, you can use JavaFX + SWT..... And the javaFX GTK version info SHOULD
// be based on what SWT has loaded
// https://github.com/teamfx/openjfx-9-dev-rt/blob/master/modules/javafx.graphics/src/main/java/com/sun/glass/ui/gtk/GtkApplication.java
if (OS.javaVersion < 9) {
// JavaFX from Oracle Java 8 is GTK2 only. Java9 can have it be GTK3 if -Djdk.gtk.version=3 is specified
// see http://mail.openjdk.java.net/pipermail/openjfx-dev/2016-May/019100.html
return 2;
}
// Only possible Java9+ (so our case, Java11+ since 9 is no longer available, 11 is officially LTS)
String version = OS.getProperty("jdk.gtk.version", "2");
if ("3".equals(version) || version.startsWith("3.")) {
return 3;
}
else {
return 2;
}
}
@Override
public
boolean dispatch(final Runnable runnable) {
// JavaFX only
if (isEventThread()) {
// Run directly on the JavaFX event thread
runnable.run();
}
else {
javafx.application.Platform.runLater(runnable);
}
// javaFX always manages the runnable
return true;
}
}

View File

@ -1,82 +0,0 @@
/*
* Copyright 2016 dorkbox, llc
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package dorkbox.swt;
import java.security.AccessController;
import java.security.PrivilegedAction;
/**
* Utility methods for SWT. SWT is always available for compiling, so it is not necessary to use reflection to compile it.
* <p>
* SWT system tray types are GtkStatusIcon trays (so we don't want to use them)
*/
public
class Swt {
public final static boolean isLoaded;
public final static boolean isGtk3;
private static final int version;
// NOTE: This class cannot have SWT **ANYTHING** in it
static {
// There is a silly amount of redirection, simply because we have to be able to access SWT, but only if it's in use.
// Since this class is the place other code interacts with, we can use SWT stuff if necessary without loading/linking
// the SWT classes by accident
Class<?> swtErrorClass = AccessController.doPrivileged(new PrivilegedAction<Class<?>>() {
@Override
public
Class<?> run() {
try {
return Class.forName("org.eclipse.swt.SWTError", true, ClassLoader.getSystemClassLoader());
} catch (Exception ignored) {
}
try {
return Class.forName("org.eclipse.swt.SWTError", true, Thread.currentThread().getContextClassLoader());
} catch (Exception ignored) {
}
return null;
}
});
if (swtErrorClass != null && SwtAccess.isLoadable()) {
// this means that SWT is available in the system at runtime. We use the error class because that DOES NOT initialize anything
version = SwtAccess.getVersion();
isLoaded = true;
isGtk3 = SwtAccess.isGtk3();
SwtAccess.init();
} else {
version = 0;
isLoaded = false;
isGtk3 = false;
}
}
public static
int getVersion() {
return version;
}
public static
void dispatch(final Runnable runnable) {
SwtAccess.dispatch(runnable);
}
public static
boolean isEventThread() {
return SwtAccess.isEventThread();
}
}

View File

@ -1,122 +0,0 @@
package dorkbox.swt;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.Locale;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Display;
public
class SwtAccess {
private static Display currentDisplay = null;
private static Thread currentDisplayThread = null;
public static
void init() {
// we MUST save this on init, otherwise it is "null" when methods are run from the swing EDT.
currentDisplay = org.eclipse.swt.widgets.Display.getCurrent();
currentDisplayThread = currentDisplay.getThread();
}
static
boolean isLoadable() {
return org.eclipse.swt.SWT.isLoadable();
}
static
void onShutdown(final org.eclipse.swt.widgets.Display currentDisplay, final Runnable runnable) {
// currentDisplay.getShells() must only be called inside the event thread!
org.eclipse.swt.widgets.Shell shell = currentDisplay.getShells()[0];
shell.addListener(org.eclipse.swt.SWT.Close, new org.eclipse.swt.widgets.Listener() {
@Override
public
void handleEvent(final org.eclipse.swt.widgets.Event event) {
runnable.run();
}
});
}
static
int getVersion() {
return SWT.getVersion();
}
private static
int getViaReflection(String clazz) throws InvocationTargetException, IllegalAccessException {
final Class<?> osClass = AccessController.doPrivileged(new PrivilegedAction<Class<?>>() {
@Override
public
Class<?> run() {
try {
return Class.forName(clazz, true, ClassLoader.getSystemClassLoader());
} catch (Exception ignored) {
}
try {
return Class.forName(clazz, true, Thread.currentThread().getContextClassLoader());
} catch (Exception ignored) {
}
return null;
}
});
Method method = AccessController.doPrivileged(new PrivilegedAction<Method>() {
@Override
public
Method run() {
try {
return osClass.getMethod("gtk_major_version");
} catch (Exception e) {
return null;
}
}
});
// might throw an exception!
return ((Number)method.invoke(osClass)).intValue();
}
/**
* This is only necessary for linux.
*
* @return true if SWT is GTK3. False if SWT is GTK2 or unknown.
*/
static boolean isGtk3() {
boolean isLinux = System.getProperty("os.name", "").toLowerCase(Locale.US).startsWith("linux");
if (!isLinux) {
return false;
}
try {
return org.eclipse.swt.internal.gtk.GTK.gtk_get_major_version() == 3;
} catch (Exception e) {
// this might be an older/different version of SWT! Try reflection.
try {
return getViaReflection("org.eclipse.swt.internal.gtk.GTK") == 3;
} catch (Exception e1) {
try {
return getViaReflection("org.eclipse.swt.internal.gtk.OS") == 3;
} catch (Exception ignored) {
}
}
}
return false;
}
static
void dispatch(final Runnable runnable) {
currentDisplay.syncExec(runnable);
}
static
boolean isEventThread() {
return Thread.currentThread() == currentDisplayThread;
}
}

View File

@ -0,0 +1,98 @@
/*
* Copyright 2021 dorkbox, llc
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package dorkbox.swt;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Display;
import dorkbox.jna.rendering.ProviderType;
import dorkbox.jna.rendering.Renderer;
import dorkbox.os.OS;
public class SwtProvider implements Renderer {
private static Display currentDisplay = null;
private static Thread currentDisplayThread = null;
static {
// we MUST save this on init, otherwise it is "null" when methods are run from the swing EDT.
currentDisplay = org.eclipse.swt.widgets.Display.getCurrent();
currentDisplayThread = currentDisplay.getThread();
}
@Override
public
boolean isSupported() {
// versions of SWT older than v4.4, are INCOMPATIBLE with us.
// Of note, v4.3 is the "last released" version of SWT by eclipse AND IT WILL NOT WORK!!
// for NEWER versions of SWT via maven, use http://maven-eclipse.github.io/maven
return SWT.getVersion() > 4430;
}
@Override
public
ProviderType getType() {
return ProviderType.SWT;
}
@Override
public
boolean alreadyRunning() {
// ONLY true for SWT. JavaFX/etc are checked elsewhere
return true;
}
@Override
public
boolean isEventThread() {
return Thread.currentThread() == currentDisplayThread;
}
@Override
public
int getGtkVersion() {
if (!OS.isLinux()) {
return 0;
}
// Swt has a property that tells us the version information
// "org.eclipse.swt.internal.gtk.version=3.12.2"
// Only possible Java9+ (so our case, Java11+ since 9 is no longer available, 11 is officially LTS)
String version = OS.getProperty("org.eclipse.swt.internal.gtk.version", "2");
if ("3".equals(version) || version.startsWith("3.")) {
return 3;
} else {
return 2;
}
}
@Override
public
boolean dispatch(final Runnable runnable) {
if (isEventThread()) {
// Run directly on the SWT event thread. If it's not on the dispatch thread, we will use the DEFAULT GTK to put it there.
// We do not need to dispatch manually onto swt??
runnable.run();
// we only directly run if we are SWT, and in SWTs event thread
return true;
}
// let the default handler manage it
return false;
}
}

16
src/module-info.java Normal file
View File

@ -0,0 +1,16 @@
module dorkbox.swtjavafx {
exports dorkbox.javaFx;
exports dorkbox.swt;
requires dorkbox.utilities;
requires javafx.graphics;
// 32-bit support was dropped by eclipse since 4.10 (3.108.0 is the oldest that is 32 bit)
// this must match what your release target and SWT dependency is
requires org.eclipse.swt.gtk.linux.x86_64;
// requires static org.eclipse.swt.win32.win32.x86_64;
// requires static org.eclipse.swt.cocoa.macosx.x86_64;
requires java.base;
}

View File

@ -1,33 +0,0 @@
/*
* Copyright 2016 dorkbox, llc
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package dorkbox.javaFx;
/**
* Utility methods for JavaFX.
*/
public
class JavaFxAccess {
static
void dispatch(final Runnable runnable) {
javafx.application.Platform.runLater(runnable);
}
static
boolean isEventThread() {
// JAVA 9+
return javafx.application.Platform.isFxApplicationThread();
}
}

View File

@ -1,24 +0,0 @@
/*
* Copyright 2021 dorkbox, llc
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package dorkbox.swt;
/**
* Required for intellij to not complain regarding `module-info` for a multi-release jar.
* This file is completely ignored by the gradle build process
*/
public
class EmptyClass {}