Skip to main content

Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "GEF/GEF4/SwtFX"

< GEF‎ | GEF4
(Redirect page to GEF/GEF4/FX, because GEF4 SwtFX component was merged into GEF4 FX)
 
Line 1: Line 1:
''Note to non-wiki readers: This documentation is generated from the Eclipse wiki - if you have corrections or additions it would be awesome if you added them in [http://wiki.eclipse.org/GEF/GEF4/SwtFx the original wiki page]''.
+
#REDIRECT [[GEF/GEF4/FX]]
 
+
== Introduction ==
+
 
+
The GEF4 SwtFX component provides specific JavaFX Node implementations which embed SWT Controls in a JavaFX scene graph. The component is subdivided into different packages:
+
 
+
* '''org.eclipse.gef4.swtfx'''<br />Contains SWT specific sub-classes of JavaFX framework classes to make embedding SWT Controls in a JavaFX scene graph possible.
+
* '''org.eclipse.gef4.swtfx.controls'''<br />Contains a generic JavaFX adapter Node implementation to integrate SWT controls into a JavaFX scene.
+
 
+
== General ==
+
 
+
* '''package: org.eclipse.gef4.swtfx'''
+
 
+
In order to be able to embed SWT Controls in a JavaFX scene graph, we decided to sub-class two JavaFX framework classes: FXCanvas, and Scene. This is due to the API mismatch of SWT and JavaFX. To create an SWT Control, you need to know its parent (a Composite). But in JavaFX you can create all the nodes you need first, and then plug them together to the full scene graph. Therefore, a JavaFX Node for an SWT Control, which we will refer to as SwtFXControl, has to create the "peer" SWT Control not until it can acquire an SWT Composite. For the embedding of JavaFX in an SWT application, JavaFX provides the FXCanvas (which is a SWT Composite). Our SwtFXScene allows access to a corresponding SwtFXCanvas, so that a SwtFXControl can check for its Scene to determine if creating the peer is possible.
+
 
+
This is how you create the context for SwtFX:
+
<source lang="Java">
+
import org.eclipse.gef4.swtfx.SwtFXCanvas;
+
import org.eclipse.gef4.swtfx.SwtFXScene;
+
import org.eclipse.swt.SWT;
+
import org.eclipse.swt.layout.FillLayout;
+
import org.eclipse.swt.widgets.Display;
+
import org.eclipse.swt.widgets.Shell;
+
 
+
public abstract class SwtFXApplication {
+
public SwtFXApplication() {
+
Display display = new Display();
+
Shell shell = new Shell(display);
+
shell.setLayout(new FillLayout());
+
SwtFXCanvas canvas = new SwtFXCanvas(shell, SWT.NONE);
+
 
+
SwtFXScene scene = createScene();
+
canvas.setScene(scene);
+
 
+
shell.setSize((int) scene.getWidth(), (int) scene.getHeight());
+
shell.open();
+
 
+
while (!shell.isDisposed()) {
+
if (!display.readAndDispatch()) {
+
display.sleep();
+
}
+
}
+
display.dispose();
+
}
+
 
+
public abstract SwtFXScene createScene();
+
}
+
</source>
+

Latest revision as of 16:18, 11 August 2014

Redirect to:

Back to the top