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