1 package vtk.rendering.swt;
3 import org.eclipse.swt.widgets.Composite;
5 import com.jogamp.opengl.swt.GLCanvas;
7 import vtk.vtkRenderWindow;
8 import vtk.rendering.vtkAbstractComponent;
11 * Provide SWT based vtk rendering component
13 * @author Joachim Pouderoux - joachim.pouderoux@kitware.com, Kitware SAS 2012
14 * @copyright This work was supported by CEA/CESTA
15 * Commissariat a l'Energie Atomique et aux Energies Alternatives,
16 * 15 avenue des Sablieres, CS 60001, 33116 Le Barp, France.
18 public class vtkSwtComponent extends vtkAbstractComponent<GLCanvas> {
20 protected vtkInternalSwtComponent uiComponent;
21 protected boolean isWindowCreated;
23 public vtkSwtComponent(Composite parentComposite) {
24 this(new vtkRenderWindow(), parentComposite);
27 public vtkSwtComponent(vtkRenderWindow renderWindowToUse, Composite parentComposite) {
28 super(renderWindowToUse);
29 this.eventForwarder = new vtkSwtInteractorForwarderDecorator(this, this.eventForwarder);
30 this.isWindowCreated = true;
31 this.uiComponent = new vtkInternalSwtComponent(this, parentComposite);
33 renderWindow.AddObserver("StartEvent", this, "startEvent");
34 renderWindow.AddObserver("EndEvent", this, "endEvent");
38 * Set the size of the VTK component
43 public void setSize(int x, int y) {
47 this.uiComponent.setSize(x, y);
48 this.uiComponent.redraw();
49 this.uiComponent.update();
53 * Render the VTK component. Should not be called externally.
54 * Call update() to refresh the window content.
57 public void Render() {
58 // Make sure we can render
59 if (inRenderCall || renderer == null || renderWindow == null) {
65 lock.lockInterruptibly();
67 // Trigger the real render
68 renderWindow.Render();
69 } catch (InterruptedException e) {
70 // Nothing that we can do except skipping execution
78 * Redraw the VTK component
80 public void update() {
81 this.uiComponent.redraw();
82 this.uiComponent.update();
86 * @return the encapsulated SWT component (a GLCanvas instance)
87 * @see vtk.rendering.vtkAbstractComponent#getComponent()
90 public GLCanvas getComponent() {
91 return this.uiComponent;
95 public void Delete() {
97 // We prevent any further rendering
98 this.inRenderCall = true;
99 this.renderWindow = null;
105 * @return true if the graphical component has been properly set and
106 * operation can be performed on it.
108 public boolean isWindowSet() {
109 return this.isWindowCreated;
113 * Just allow class in same package to affect inRenderCall boolean
117 protected void updateInRenderCall(boolean value) {
118 this.inRenderCall = value;
121 /** This method is called by the VTK JNI code. Do not remove. */
123 if (!getComponent().getContext().isCurrent()) {
124 getComponent().getContext().makeCurrent();
128 /** This method is called by the VTK JNI code. Do not remove. */
130 if (getComponent().getContext().isCurrent()) {
131 getComponent().swapBuffers();
132 getComponent().getContext().release();