]> gerrit.simantics Code Review - simantics/3d.git/blob - vtk/src/vtk/vtkRenderWindowPanel.java
Add back explicit loading of jawt.dll.
[simantics/3d.git] / vtk / src / vtk / vtkRenderWindowPanel.java
1 package vtk;
2
3 import java.awt.event.InputEvent;
4 import java.awt.event.KeyEvent;
5 import java.awt.event.MouseEvent;
6 import java.awt.event.MouseWheelEvent;
7
8 /**
9  * vtkRenderWindowPanel is a vtkCanvas which allows additional vtkRenderers to
10  * be added. vtkPanel and vtkCanvas force you to add actors to the internal
11  * vtkRenderer. vtkRenderWindowPanel always renders, even if the internal
12  * renderer has no visible actors.
13  *
14  * @author Kitware
15  */
16 public class vtkRenderWindowPanel extends vtkCanvas {
17   private static final long serialVersionUID = 1L;
18
19   public vtkRenderWindowPanel() {
20     cam = new vtkCamera();
21     lgt = new vtkLight();
22   }
23
24   public vtkRenderWindowPanel(vtkRenderWindow win) {
25     super(win);
26     cam = new vtkCamera();
27     lgt = new vtkLight();
28   }
29
30   public synchronized void Render() {
31     if (!rendering) {
32       rendering = true;
33       if (rw != null) {
34         if (windowset == 0) {
35           // set the window id and the active camera
36           RenderCreate(rw);
37           Lock();
38           rw.SetSize(getWidth(), getHeight());
39           UnLock();
40           windowset = 1;
41           // notify observers that we have a renderwindow created
42           // windowSetObservable.notifyObservers();
43         }
44         Lock();
45         rw.Render();
46         UnLock();
47       }
48       rendering = false;
49     }
50   }
51
52   public void mousePressed(MouseEvent e) {
53     Lock();
54     rw.SetDesiredUpdateRate(5.0);
55     lastX = e.getX();
56     lastY = e.getY();
57
58     ctrlPressed = (e.getModifiers() & InputEvent.CTRL_MASK) == InputEvent.CTRL_MASK ? 1 : 0;
59     shiftPressed = (e.getModifiers() & InputEvent.SHIFT_MASK) == InputEvent.SHIFT_MASK ? 1 : 0;
60
61     iren.SetEventInformationFlipY(e.getX(), e.getY(), ctrlPressed, shiftPressed, '0', 0, "0");
62
63     if ((e.getModifiers() & InputEvent.BUTTON1_MASK) == InputEvent.BUTTON1_MASK) {
64       iren.LeftButtonPressEvent();
65     }
66
67     else if ((e.getModifiers() & InputEvent.BUTTON2_MASK) == InputEvent.BUTTON2_MASK) {
68       iren.MiddleButtonPressEvent();
69     }
70
71     else if ((e.getModifiers() & InputEvent.BUTTON3_MASK) == InputEvent.BUTTON3_MASK) {
72       iren.RightButtonPressEvent();
73     }
74
75     UnLock();
76   }
77
78   public void mouseDragged(MouseEvent e) {
79     ctrlPressed = (e.getModifiers() & InputEvent.CTRL_MASK) == InputEvent.CTRL_MASK ? 1 : 0;
80     shiftPressed = (e.getModifiers() & InputEvent.SHIFT_MASK) == InputEvent.SHIFT_MASK ? 1 : 0;
81
82     iren.SetEventInformationFlipY(e.getX(), e.getY(), ctrlPressed, shiftPressed, '0', 0, "0");
83
84     Lock();
85     iren.MouseMoveEvent();
86     UnLock();
87   }
88
89   public void mouseWheelMoved(MouseWheelEvent e) {
90     ctrlPressed = (e.getModifiers() & InputEvent.CTRL_MASK) == InputEvent.CTRL_MASK ? 1 : 0;
91     shiftPressed = (e.getModifiers() & InputEvent.SHIFT_MASK) == InputEvent.SHIFT_MASK ? 1 : 0;
92
93     Lock();
94     if (e.getWheelRotation() > 0) {
95       iren.SetEventInformationFlipY(e.getX(), e.getY(), ctrlPressed, shiftPressed, '0', 0, "0");
96       iren.MouseWheelBackwardEvent();
97     }
98     else if (e.getWheelRotation() < 0) {
99       iren.SetEventInformationFlipY(e.getX(), e.getY(), ctrlPressed, shiftPressed, '0', 0, "0");
100       iren.MouseWheelForwardEvent();
101     }
102     UnLock();
103   }
104
105   public void keyPressed(KeyEvent e) {
106     char keyChar = e.getKeyChar();
107
108     ctrlPressed = (e.getModifiers() & InputEvent.CTRL_MASK) == InputEvent.CTRL_MASK ? 1 : 0;
109     shiftPressed = (e.getModifiers() & InputEvent.SHIFT_MASK) == InputEvent.SHIFT_MASK ? 1 : 0;
110
111     iren.SetEventInformationFlipY(lastX, lastY, ctrlPressed, shiftPressed, keyChar, 0, String.valueOf(keyChar));
112
113     Lock();
114     iren.KeyPressEvent();
115     iren.CharEvent();
116     UnLock();
117   }
118 }