-public class vtkCanvas extends vtkPanel implements MouseListener, MouseMotionListener, KeyListener {
- private static final long serialVersionUID = 1L;
- protected vtkGenericRenderWindowInteractor iren = new vtkGenericRenderWindowInteractor();
- protected Timer timer = new Timer(10, new DelayAction());
- protected int ctrlPressed = 0;
- protected int shiftPressed = 0;
- protected vtkPlaneWidget pw = new vtkPlaneWidget();
- protected vtkBoxWidget bw = new vtkBoxWidget();
-
- static {
- // load up hybrid for 3d widgets
- vtkNativeLibrary.HYBRID.LoadLibrary();
- vtkNativeLibrary.WIDGETS.LoadLibrary();
+public class vtkCanvas extends vtkPanel implements MouseListener, MouseMotionListener, MouseWheelListener, KeyListener {
+ private static final long serialVersionUID = 1L;
+ protected vtkGenericRenderWindowInteractor iren = new vtkGenericRenderWindowInteractor();
+ protected Timer timer = new Timer(10, new DelayAction());
+ protected int ctrlPressed = 0;
+ protected int shiftPressed = 0;
+ protected vtkPlaneWidget pw = new vtkPlaneWidget();
+ protected vtkBoxWidget bw = new vtkBoxWidget();
+
+ public void Delete() {
+ iren = null;
+ pw = null;
+ bw = null;
+ super.Delete();
+ }
+
+ public vtkCanvas() {
+ super();
+ Initialize();
+ }
+
+ public vtkCanvas(vtkRenderWindow renwin) {
+ super(renwin);
+ Initialize();
+ }
+
+ protected void Initialize() {
+ iren.SetRenderWindow(rw);
+ iren.TimerEventResetsTimerOff();
+ iren.AddObserver("CreateTimerEvent", this, "StartTimer");
+ iren.AddObserver("DestroyTimerEvent", this, "DestroyTimer");
+ iren.SetSize(200, 200);
+ iren.ConfigureEvent();
+ pw.AddObserver("EnableEvent", this, "BeginPlaneInteraction");
+ bw.AddObserver("EnableEvent", this, "BeginBoxInteraction");
+ pw.SetKeyPressActivationValue('l');
+ bw.SetKeyPressActivationValue('b');
+ pw.SetInteractor(iren);
+ bw.SetInteractor(iren);
+
+ addComponentListener(new ComponentAdapter() {
+ public void componentResized(ComponentEvent event) {
+ // The Canvas is being resized, get the new size
+ int width = getWidth();
+ int height = getHeight();
+ setSize(width, height);
+ }
+ });
+
+ ren.SetBackground(0.0, 0.0, 0.0);
+
+ // Setup same interactor style than vtkPanel
+ vtkInteractorStyleTrackballCamera style = new vtkInteractorStyleTrackballCamera();
+ iren.SetInteractorStyle(style);
+ }
+
+ public void StartTimer() {
+ if (timer.isRunning())
+ timer.stop();
+
+ timer.setRepeats(true);
+ timer.start();
+ }
+
+ public void DestroyTimer() {
+ if (timer.isRunning())
+ timer.stop();
+ }
+
+ /**
+ * Replace by getRenderWindowInteractor()
+ */
+ @Deprecated
+ public vtkGenericRenderWindowInteractor getIren() {
+ return this.iren;
+ }
+
+ public vtkGenericRenderWindowInteractor getRenderWindowInteractor() {
+ return this.iren;
+ }
+
+ public void setInteractorStyle(vtkInteractorStyle style) {
+ iren.SetInteractorStyle(style);
+ }
+
+ public void addToPlaneWidget(vtkProp3D prop) {
+ pw.SetProp3D(prop);
+ pw.PlaceWidget();
+ }
+
+ public void addToBoxWidget(vtkProp3D prop) {
+ bw.SetProp3D(prop);
+ bw.PlaceWidget();
+ }
+
+ public void BeginPlaneInteraction() {
+ System.out.println("Plane widget begin interaction");
+ }
+
+ public void BeginBoxInteraction() {
+ System.out.println("Box widget begin interaction");
+ }
+
+ public void setSize(int x, int y) {
+ super.setSize(x, y);
+ if (windowset == 1) {
+ Lock();
+ rw.SetSize(x, y);
+ iren.SetSize(x, y);
+ iren.ConfigureEvent();
+ UnLock();