Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTom Schindl2015-08-17 05:00:20 +0000
committerTom Schindl2015-08-17 05:01:43 +0000
commit1fa30090e5d3cda32200cce15b84629a17b03183 (patch)
tree7da12e421c59e8ee3421b938560bc92013f514ce
parent18c1d101d630ed6952048bafd65a8de617753199 (diff)
downloadorg.eclipse.efxclipse-1fa30090e5d3cda32200cce15b84629a17b03183.tar.gz
org.eclipse.efxclipse-1fa30090e5d3cda32200cce15b84629a17b03183.tar.xz
org.eclipse.efxclipse-1fa30090e5d3cda32200cce15b84629a17b03183.zip
util lib to launch swt in javafx and native compat way
-rw-r--r--experimental/swt/org.eclipse.fx.runtime.swtutil/.classpath7
-rw-r--r--experimental/swt/org.eclipse.fx.runtime.swtutil/.gitignore1
-rw-r--r--experimental/swt/org.eclipse.fx.runtime.swtutil/.project28
-rw-r--r--experimental/swt/org.eclipse.fx.runtime.swtutil/.settings/org.eclipse.jdt.core.prefs7
-rw-r--r--experimental/swt/org.eclipse.fx.runtime.swtutil/META-INF/MANIFEST.MF9
-rw-r--r--experimental/swt/org.eclipse.fx.runtime.swtutil/build.properties4
-rw-r--r--experimental/swt/org.eclipse.fx.runtime.swtutil/src/org/eclipse/fx/runtime/swtutil/SWTFXUtil.java139
-rw-r--r--experimental/swt/org.eclipse.fx.runtime.swtutil/src/org/eclipse/fx/runtime/swtutil/SWTNativeUtil.java64
-rw-r--r--experimental/swt/org.eclipse.fx.runtime.swtutil/src/org/eclipse/fx/runtime/swtutil/SWTUtil.java38
9 files changed, 297 insertions, 0 deletions
diff --git a/experimental/swt/org.eclipse.fx.runtime.swtutil/.classpath b/experimental/swt/org.eclipse.fx.runtime.swtutil/.classpath
new file mode 100644
index 000000000..eca7bdba8
--- /dev/null
+++ b/experimental/swt/org.eclipse.fx.runtime.swtutil/.classpath
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/experimental/swt/org.eclipse.fx.runtime.swtutil/.gitignore b/experimental/swt/org.eclipse.fx.runtime.swtutil/.gitignore
new file mode 100644
index 000000000..ae3c17260
--- /dev/null
+++ b/experimental/swt/org.eclipse.fx.runtime.swtutil/.gitignore
@@ -0,0 +1 @@
+/bin/
diff --git a/experimental/swt/org.eclipse.fx.runtime.swtutil/.project b/experimental/swt/org.eclipse.fx.runtime.swtutil/.project
new file mode 100644
index 000000000..a41003ab2
--- /dev/null
+++ b/experimental/swt/org.eclipse.fx.runtime.swtutil/.project
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.fx.runtime.swtutil</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
diff --git a/experimental/swt/org.eclipse.fx.runtime.swtutil/.settings/org.eclipse.jdt.core.prefs b/experimental/swt/org.eclipse.fx.runtime.swtutil/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 000000000..0c68a61dc
--- /dev/null
+++ b/experimental/swt/org.eclipse.fx.runtime.swtutil/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,7 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
+org.eclipse.jdt.core.compiler.compliance=1.8
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.8
diff --git a/experimental/swt/org.eclipse.fx.runtime.swtutil/META-INF/MANIFEST.MF b/experimental/swt/org.eclipse.fx.runtime.swtutil/META-INF/MANIFEST.MF
new file mode 100644
index 000000000..ff99a5de2
--- /dev/null
+++ b/experimental/swt/org.eclipse.fx.runtime.swtutil/META-INF/MANIFEST.MF
@@ -0,0 +1,9 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Swtutil
+Bundle-SymbolicName: org.eclipse.fx.runtime.swtutil
+Bundle-Version: 1.0.0.qualifier
+Bundle-RequiredExecutionEnvironment: JavaSE-1.8
+Require-Bundle: org.eclipse.fx.runtime.swt;bundle-version="1.0.0";resolution:=optional,
+ org.eclipse.swt;resolution:=optional
+Export-Package: org.eclipse.fx.runtime.swtutil
diff --git a/experimental/swt/org.eclipse.fx.runtime.swtutil/build.properties b/experimental/swt/org.eclipse.fx.runtime.swtutil/build.properties
new file mode 100644
index 000000000..34d2e4d2d
--- /dev/null
+++ b/experimental/swt/org.eclipse.fx.runtime.swtutil/build.properties
@@ -0,0 +1,4 @@
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .
diff --git a/experimental/swt/org.eclipse.fx.runtime.swtutil/src/org/eclipse/fx/runtime/swtutil/SWTFXUtil.java b/experimental/swt/org.eclipse.fx.runtime.swtutil/src/org/eclipse/fx/runtime/swtutil/SWTFXUtil.java
new file mode 100644
index 000000000..2183a21fd
--- /dev/null
+++ b/experimental/swt/org.eclipse.fx.runtime.swtutil/src/org/eclipse/fx/runtime/swtutil/SWTFXUtil.java
@@ -0,0 +1,139 @@
+package org.eclipse.fx.runtime.swtutil;
+
+import javafx.application.Application;
+import javafx.application.Platform;
+import javafx.stage.Stage;
+
+import org.eclipse.swt.events.DisposeEvent;
+import org.eclipse.swt.events.DisposeListener;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+
+import com.sun.javafx.tk.Toolkit;
+
+final class SWTFXUtil extends SWTUtil {
+
+ private static SWTAppStart runnable;
+
+ public void bootstrap(SWTAppStart runnable) {
+ SWTFXUtil.runnable = runnable;
+ Application.launch(FXApp.class);
+ }
+
+ public static class FXApp extends Application {
+
+ @Override
+ public void start(Stage primaryStage) throws Exception {
+ final Display d = new Display();
+ BlockCondition condition = runnable.createApp(d);
+ if( condition != null ) {
+ if( condition instanceof ShellBlockCondition ) {
+ ShellBlockCondition c = (ShellBlockCondition) condition;
+ c.closeRunnable = new Runnable() {
+
+ @Override
+ public void run() {
+ d.dispose();
+ }
+ };
+ } else {
+ SWTUtil.getInstance().block(d, condition);
+ d.dispose();
+ }
+ } else {
+ d.dispose();
+ }
+ }
+ }
+
+ public void openBlocking(Shell shell) {
+ Stage s = (Stage) shell.internal_getWindow();
+ s.showAndWait();
+ }
+
+ public void block(Display d, BlockCondition condition) {
+ final DefaultBlockCondition fCondition = (DefaultBlockCondition) condition;
+ Thread t = new Thread() {
+ @Override
+ public void run() {
+ fCondition.cleanLoop();
+ }
+ };
+ t.setDaemon(true);
+ t.start();
+ Toolkit.getToolkit().enterNestedEventLoop(condition);
+ }
+
+ @Override
+ public BlockCondition createShellBlockCondition(Shell shell) {
+ return new ShellBlockCondition(shell);
+ }
+
+ @Override
+ public BlockCondition createSimpleBlockCondition() {
+ return new DefaultBlockCondition();
+ }
+
+ public static class ShellBlockCondition extends DefaultBlockCondition {
+ private Shell shell;
+ private Runnable closeRunnable;
+
+ public ShellBlockCondition(Shell shell) {
+ this.shell = shell;
+ this.shell.addDisposeListener(new DisposeListener() {
+
+ @Override
+ public void widgetDisposed(DisposeEvent e) {
+ unblock();
+ }
+ });
+ }
+
+ @Override
+ public synchronized void unblock() {
+ super.unblock();
+ if( closeRunnable != null ) {
+ closeRunnable.run();
+ }
+ }
+
+ @Override
+ public boolean isBlocked() {
+ return super.isBlocked() && ! shell.isDisposed();
+ }
+ }
+
+ public static class DefaultBlockCondition extends BlockCondition {
+ private boolean blocked = true;
+
+ public synchronized void unblock() {
+ this.blocked = false;
+ notifyAll();
+ }
+
+ public synchronized boolean isBlocked() {
+ return blocked;
+ }
+
+ @SuppressWarnings("restriction")
+ synchronized void cleanLoop() {
+ if( ! isBlocked() ) {
+ Toolkit.getToolkit().exitNestedEventLoop(this, null);
+ return;
+ }
+ try {
+ wait();
+ } catch (InterruptedException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ Platform.runLater(new Runnable() {
+
+ @Override
+ public void run() {
+ Toolkit.getToolkit().exitNestedEventLoop(DefaultBlockCondition.this, null);
+ }
+ });
+ }
+ }
+} \ No newline at end of file
diff --git a/experimental/swt/org.eclipse.fx.runtime.swtutil/src/org/eclipse/fx/runtime/swtutil/SWTNativeUtil.java b/experimental/swt/org.eclipse.fx.runtime.swtutil/src/org/eclipse/fx/runtime/swtutil/SWTNativeUtil.java
new file mode 100644
index 000000000..1771b679d
--- /dev/null
+++ b/experimental/swt/org.eclipse.fx.runtime.swtutil/src/org/eclipse/fx/runtime/swtutil/SWTNativeUtil.java
@@ -0,0 +1,64 @@
+package org.eclipse.fx.runtime.swtutil;
+
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+
+final class SWTNativeUtil extends SWTUtil {
+ public void bootstrap(SWTAppStart runnable) {
+ Display d = new Display();
+ BlockCondition condition = runnable.createApp(d);
+ if( condition != null ) {
+ block(d, condition);
+ }
+ d.dispose();
+ }
+
+ public void openBlocking(Shell shell) {
+ shell.open();
+ block(shell.getDisplay(), new ShellBlockCondition(shell));
+ }
+
+ public void block(Display d, BlockCondition condition) {
+ DefaultBlockCondition fCondition = (DefaultBlockCondition) condition;
+ while( fCondition.isBlocked() ) {
+ if( !d.readAndDispatch() ) {
+ d.sleep();
+ }
+ }
+ }
+
+ @Override
+ public BlockCondition createShellBlockCondition(Shell shell) {
+ return new ShellBlockCondition(shell);
+ }
+
+ @Override
+ public BlockCondition createSimpleBlockCondition() {
+ return new DefaultBlockCondition();
+ }
+
+ public static class ShellBlockCondition extends DefaultBlockCondition {
+ private Shell shell;
+
+ public ShellBlockCondition(Shell shell) {
+ this.shell = shell;
+ }
+
+ @Override
+ public boolean isBlocked() {
+ return super.isBlocked() && ! shell.isDisposed();
+ }
+ }
+
+ public static class DefaultBlockCondition extends BlockCondition {
+ private boolean blocked = true;
+
+ public final synchronized void unblock() {
+ this.blocked = false;
+ }
+
+ public synchronized boolean isBlocked() {
+ return blocked;
+ }
+ }
+} \ No newline at end of file
diff --git a/experimental/swt/org.eclipse.fx.runtime.swtutil/src/org/eclipse/fx/runtime/swtutil/SWTUtil.java b/experimental/swt/org.eclipse.fx.runtime.swtutil/src/org/eclipse/fx/runtime/swtutil/SWTUtil.java
new file mode 100644
index 000000000..3f1aa005f
--- /dev/null
+++ b/experimental/swt/org.eclipse.fx.runtime.swtutil/src/org/eclipse/fx/runtime/swtutil/SWTUtil.java
@@ -0,0 +1,38 @@
+package org.eclipse.fx.runtime.swtutil;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+
+public abstract class SWTUtil {
+ private static SWTUtil INSTANCE;
+
+ public static SWTUtil getInstance() {
+ if( INSTANCE == null ) {
+ if( SWT.getPlatform().equals("javafx") ) {
+ INSTANCE = new SWTFXUtil();
+ } else {
+ INSTANCE = new SWTNativeUtil();
+ }
+ }
+
+ return INSTANCE;
+ }
+
+ public interface SWTAppStart {
+ public BlockCondition createApp(Display display);
+ }
+
+ public abstract void bootstrap(SWTAppStart runnable);
+ public abstract void openBlocking(Shell shell);
+ public abstract void block(final Display d, final BlockCondition condition);
+ public abstract BlockCondition createSimpleBlockCondition();
+ public abstract BlockCondition createShellBlockCondition(Shell shell);
+
+
+ public static abstract class BlockCondition {
+ BlockCondition() {
+ }
+ public abstract void unblock();
+ }
+} \ No newline at end of file

Back to the top