14
14
* not expected to create instances of this class directly or call its methods. To use it, specify it as the
15
15
* gov.nasa.worldwind.avkey.InputHandlerClassName in the WorldWind configuration file.
16
16
*/
17
- public class ZebraInputHandler extends AWTInputHandler {
18
-
19
- /**
20
- * All instantiations of this class are stored for internal retrieval.
21
- */
17
+ public class ZebraInputHandler extends AWTInputHandler
18
+ {
19
+ /** All instantiations of this class are stored for internal retrieval. */
22
20
private static List <ZebraInputHandler > instances = new ArrayList <ZebraInputHandler >();
23
21
private static Timer repaintContextsTimer = null ;
24
-
25
- final static TimerTask repaintContextsTask = new TimerTask () {
26
- public void run () {
27
- Iterator <ZebraInputHandler > itr = instances .iterator ();
28
- while (itr .hasNext ()) {
29
- ZebraInputHandler h = itr .next ();
30
- if (h .NeedsRefresh () == true ) {
31
- h .SetRefresh (false );
32
- h .getWorldWindow ().redraw ();
33
- }
34
- }
35
- }
36
- };
37
-
38
- private long hwnd = 0 ;
39
- private boolean arGL2Present = false ;
22
+
23
+ final static TimerTask repaintContextsTask = new TimerTask ()
24
+ {
25
+ public void run ()
26
+ {
27
+ Iterator <ZebraInputHandler > itr = instances .iterator ();
28
+ while (itr .hasNext ())
29
+ {
30
+ ZebraInputHandler h = itr .next ();
31
+ if (h .NeedsRefresh () == true )
32
+ {
33
+ h .SetRefresh (false );
34
+ h .getWorldWindow ().redraw ();
35
+ }
36
+ }
37
+ }
38
+ };
39
+
40
+ private long hwnd = 0 ;
41
+ private boolean arGL2Present = false ;
40
42
private boolean refresh = false ;
41
-
42
- public ZebraInputHandler () {
43
+
44
+ public ZebraInputHandler ()
45
+ {
43
46
/**
44
- * Attempt to load zebraIntegrator. If it's not found, assume we're either: (a) Not connected to the Zebra UPSD
45
- * Dynamic Display. (b) Not using the Zebra integration tools.
47
+ * Attempt to load zebraIntegrator. If it's not found, assume we're either:
48
+ * (a) Not connected to the Zebra UPSD Dynamic Display.
49
+ * (b) Not using the Zebra integration tools.
46
50
*/
47
- try {
51
+ try
52
+ {
48
53
System .loadLibrary ("arGL2Integrator" );
49
54
arGL2Present = true ;
50
55
instances .add (this );
51
56
System .out .println ("Loaded arGL2Integrator successfully" );
52
- } catch (UnsatisfiedLinkError e ) {
57
+ }
58
+ catch (UnsatisfiedLinkError e )
59
+ {
53
60
System .out .println ("FAILED to load arGL2Integrator.dll" );
54
61
}
55
-
56
- if (repaintContextsTimer == null ) {
57
- repaintContextsTimer = new Timer ();
58
- repaintContextsTimer .scheduleAtFixedRate (repaintContextsTask , 0 , 10 );
62
+
63
+ if (repaintContextsTimer == null )
64
+ {
65
+ repaintContextsTimer = new Timer ();
66
+ repaintContextsTimer .scheduleAtFixedRate (repaintContextsTask , 0 , 10 );
59
67
}
60
68
}
61
69
62
- private synchronized void SetRefresh (boolean value ) {
63
- refresh = value ;
70
+ private synchronized void SetRefresh (boolean value )
71
+ {
72
+ refresh = value ;
64
73
}
65
-
66
- private synchronized boolean NeedsRefresh () {
67
- return refresh ;
68
- }
69
-
70
- public void keyPressed (KeyEvent e ) {
74
+
75
+ private synchronized boolean NeedsRefresh ()
76
+ {
77
+ return refresh ;
78
+ }
79
+
80
+ public void keyPressed (KeyEvent e )
81
+ {
71
82
boolean consumed = false ;
72
- if (arGL2Present ) {
83
+ if (arGL2Present )
73
84
consumed = zebraKeyPressed (getGLCanvasHandle (), e .getKeyCode ());
74
- }
75
- if (consumed == true ) {
85
+ if (consumed == true )
76
86
e .consume ();
77
- } else {
87
+ else
78
88
super .keyPressed (e );
79
- }
80
89
}
81
90
82
- public void keyReleased (KeyEvent e ) {
91
+ public void keyReleased (KeyEvent e )
92
+ {
83
93
boolean consumed = false ;
84
- if (arGL2Present ) {
94
+ if (arGL2Present )
85
95
consumed = zebraKeyReleased (getGLCanvasHandle (), e .getKeyCode ());
86
- }
87
- if (consumed == true ) {
96
+ if (consumed == true )
88
97
e .consume ();
89
- } else {
98
+ else
90
99
super .keyReleased (e );
91
- }
92
100
}
93
101
94
- public void mouseClicked (MouseEvent e ) {
102
+ public void mouseClicked (MouseEvent e )
103
+ {
95
104
boolean consumed = false ;
96
- if (arGL2Present ) {
105
+ if (arGL2Present )
97
106
consumed = zebraMouseReleased (getGLCanvasHandle (), e .getButton (), e .getX (), e .getY ());
98
- }
99
- if (consumed == true ) {
107
+ if (consumed == true )
100
108
e .consume ();
101
- } else {
109
+ else
102
110
super .mouseClicked (e );
103
- }
104
111
}
105
112
106
- public void mousePressed (MouseEvent e ) {
113
+ public void mousePressed (MouseEvent e )
114
+ {
107
115
boolean consumed = false ;
108
- if (arGL2Present ) {
116
+ if (arGL2Present )
109
117
consumed = zebraMousePressed (getGLCanvasHandle (), e .getButton (), e .getX (), e .getY ());
110
- }
111
- if (consumed == true ) {
118
+ if (consumed == true )
112
119
e .consume ();
113
- } else {
120
+ else
114
121
super .mousePressed (e );
115
- }
116
122
}
117
123
118
- public void mouseReleased (MouseEvent e ) {
124
+ public void mouseReleased (MouseEvent e )
125
+ {
119
126
boolean consumed = false ;
120
- if (arGL2Present ) {
127
+ if (arGL2Present )
121
128
consumed = zebraMouseReleased (getGLCanvasHandle (), e .getButton (), e .getX (), e .getY ());
122
- }
123
- if (consumed == true ) {
129
+ if (consumed == true )
124
130
e .consume ();
125
- } else {
131
+ else
126
132
super .mouseReleased (e );
127
- }
128
133
}
129
134
130
- public void mouseDragged (MouseEvent e ) {
131
- /**
132
- * The mouseDragged event does not populate the button field of MouseEvent. Therefore it must be done manually.
133
- */
135
+ public void mouseDragged (MouseEvent e )
136
+ {
137
+ /** The mouseDragged event does not populate the button field of MouseEvent. Therefore it must be done manually. */
134
138
int button = 0 ;
135
139
button = (e .getModifiersEx () & InputEvent .BUTTON1_DOWN_MASK ) == InputEvent .BUTTON1_DOWN_MASK ? 1 : button ;
136
140
button = (e .getModifiersEx () & InputEvent .BUTTON2_DOWN_MASK ) == InputEvent .BUTTON2_DOWN_MASK ? 2 : button ;
137
141
button = (e .getModifiersEx () & InputEvent .BUTTON3_DOWN_MASK ) == InputEvent .BUTTON3_DOWN_MASK ? 3 : button ;
138
142
139
143
boolean consumed = false ;
140
- if (arGL2Present ) {
144
+ if (arGL2Present )
141
145
consumed = zebraMouseMoved (getGLCanvasHandle (), button , e .getX (), e .getY ());
142
- }
143
- if (consumed == true ) {
146
+ if (consumed == true )
144
147
e .consume ();
145
- } else {
148
+ else
146
149
super .mouseDragged (e );
147
- }
148
150
}
149
151
150
- public void mouseWheelMoved (MouseWheelEvent e ) {
152
+ public void mouseWheelMoved (MouseWheelEvent e )
153
+ {
151
154
boolean consumed = false ;
152
- if (arGL2Present ) {
155
+ if (arGL2Present )
153
156
consumed = zebraMouseWheel (getGLCanvasHandle (), e .getWheelRotation ());
154
- }
155
- if (consumed == true ) {
157
+ if (consumed == true )
156
158
e .consume ();
157
- } else {
159
+ else
158
160
super .mouseWheelMoved (e );
159
- }
160
161
}
161
162
162
- private long getGLCanvasHandle () {
163
+ private long getGLCanvasHandle ()
164
+ {
163
165
/**
164
- * Returns the win32 HWND handle of the GLCanvas component by calling native C++ code in arGL2Integrator.
166
+ * Returns the win32 HWND handle of the GLCanvas component by calling native
167
+ * C++ code in arGL2Integrator.
165
168
*/
166
- if (hwnd == 0 ) {
169
+ if (hwnd == 0 )
170
+ {
167
171
WorldWindow ww = this .getWorldWindow ();
168
- if (ww != null ) {
172
+ if (ww != null )
173
+ {
169
174
WorldWindowGLCanvas wwgl = (WorldWindowGLCanvas ) ww ;
170
175
GLCanvas glc = wwgl ;
171
176
Canvas cv = glc ;
@@ -177,53 +182,60 @@ private long getGLCanvasHandle() {
177
182
return hwnd ;
178
183
}
179
184
180
- private static ZebraInputHandler getInstance (long hwnd ) {
185
+ private static ZebraInputHandler getInstance (long hwnd )
186
+ {
181
187
Iterator <ZebraInputHandler > itr = instances .iterator ();
182
- while (itr .hasNext ()) {
188
+ while (itr .hasNext ())
189
+ {
183
190
ZebraInputHandler h = itr .next ();
184
- if (h .hwnd == hwnd ) {
191
+ if (h .hwnd == hwnd )
185
192
return h ;
186
- }
187
193
}
188
194
189
195
return null ;
190
196
}
191
197
192
198
// Java static methods executed by arGL2Integrator.dll via JNI
193
- public static void forceRepaint ( long hwnd ) {
194
- /**
195
- * Force the instance of the ZebraViewInputHandler class to redraw it's associated OpenGL window.
196
- */
199
+
200
+ public static void forceRepaint ( long hwnd )
201
+ {
202
+ /** Force the instance of the ZebraViewInputHandler class to redraw it's associated OpenGL window. */
197
203
ZebraInputHandler h = getInstance (hwnd );
198
- if (h != null ) {
199
- h .SetRefresh (true );
200
- //h.refresh = true;
204
+ if (h != null )
205
+ {
206
+ h .SetRefresh (true );
207
+ //h.refresh = true;
201
208
}
202
209
}
203
210
204
- public static double [] getModelviewMatrix (long hwnd ) {
211
+ public static double [] getModelviewMatrix (long hwnd )
212
+ {
205
213
double [] matrix = new double [16 ];
206
214
207
215
ZebraInputHandler h = getInstance (hwnd );
208
- if (h != null ) {
216
+ if (h != null )
217
+ {
209
218
h .getWorldWindow ().getView ().getModelviewMatrix ().toArray (matrix , 0 , false );
210
219
}
211
220
212
221
return matrix ;
213
222
}
214
223
215
- public static double [] getProjectionMatrix (long hwnd ) {
224
+ public static double [] getProjectionMatrix (long hwnd )
225
+ {
216
226
double [] matrix = new double [16 ];
217
227
218
228
ZebraInputHandler h = getInstance (hwnd );
219
- if (h != null ) {
229
+ if (h != null )
230
+ {
220
231
h .getWorldWindow ().getView ().getProjectionMatrix ().toArray (matrix , 0 , false );
221
232
}
222
233
223
234
return matrix ;
224
235
}
225
236
226
237
// Methods imported from the zebra's arGL2Integrator.dll library and executed by java
238
+
227
239
public native boolean zebraKeyPressed (long hwnd , int keyCode );
228
240
229
241
public native boolean zebraKeyReleased (long hwnd , int keyCode );
0 commit comments