Jump to: navigation, search

GEF/GEF4/SwtFX

< GEF‎ | GEF4
Revision as of 17:59, 20 November 2013 by Matthias.wienand.itemis.de (Talk | contribs)

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 the original wiki page.

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
    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
    Contains JavaFX Node implementations for the individual SWT Controls, i.e. SwtFXButton, SwtFXLabel, etc.

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:

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();
}

SwtFXScene

SwtFXCanvas

AbstractSwtFXControl

Controls

  • package: org.eclipse.gef4.swtfx.controls

Although you are able to create specific SwtFXControls yourself by sub-classing AbstractSwtFXControl, we provide implementations for a set of SWT Controls, already.

SwtFXButton

The SwtFXButton is used to embed SWT Button controls in a JavaFX scene graph.

In order to be able to correctly embed multiple radio button groups, you have to group the buttons together by using the SwtFXButton#groupRadios() method. The standard SWT way does not work, because you would have to create all radio buttons of one group in one Composite. But as we only have access to one single Composite, which serves as the parent for all SWT peers, we cannot use the standard behavior.

SwtFXStyledText

The SwtFXStyledText is used to embed SWT StyledText controls in a JavaFX scene graph.