1414 * not expected to create instances of this class directly or call its methods. To use it, specify it as the
1515 * gov.nasa.worldwind.avkey.InputHandlerClassName in the WorldWind configuration file.
1616 */
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. */
2220 private static List <ZebraInputHandler > instances = new ArrayList <ZebraInputHandler >();
2321 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 ;
4042 private boolean refresh = false ;
41-
42- public ZebraInputHandler () {
43+
44+ public ZebraInputHandler ()
45+ {
4346 /**
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.
4650 */
47- try {
51+ try
52+ {
4853 System .loadLibrary ("arGL2Integrator" );
4954 arGL2Present = true ;
5055 instances .add (this );
5156 System .out .println ("Loaded arGL2Integrator successfully" );
52- } catch (UnsatisfiedLinkError e ) {
57+ }
58+ catch (UnsatisfiedLinkError e )
59+ {
5360 System .out .println ("FAILED to load arGL2Integrator.dll" );
5461 }
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 );
5967 }
6068 }
6169
62- private synchronized void SetRefresh (boolean value ) {
63- refresh = value ;
70+ private synchronized void SetRefresh (boolean value )
71+ {
72+ refresh = value ;
6473 }
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+ {
7182 boolean consumed = false ;
72- if (arGL2Present ) {
83+ if (arGL2Present )
7384 consumed = zebraKeyPressed (getGLCanvasHandle (), e .getKeyCode ());
74- }
75- if (consumed == true ) {
85+ if (consumed == true )
7686 e .consume ();
77- } else {
87+ else
7888 super .keyPressed (e );
79- }
8089 }
8190
82- public void keyReleased (KeyEvent e ) {
91+ public void keyReleased (KeyEvent e )
92+ {
8393 boolean consumed = false ;
84- if (arGL2Present ) {
94+ if (arGL2Present )
8595 consumed = zebraKeyReleased (getGLCanvasHandle (), e .getKeyCode ());
86- }
87- if (consumed == true ) {
96+ if (consumed == true )
8897 e .consume ();
89- } else {
98+ else
9099 super .keyReleased (e );
91- }
92100 }
93101
94- public void mouseClicked (MouseEvent e ) {
102+ public void mouseClicked (MouseEvent e )
103+ {
95104 boolean consumed = false ;
96- if (arGL2Present ) {
105+ if (arGL2Present )
97106 consumed = zebraMouseReleased (getGLCanvasHandle (), e .getButton (), e .getX (), e .getY ());
98- }
99- if (consumed == true ) {
107+ if (consumed == true )
100108 e .consume ();
101- } else {
109+ else
102110 super .mouseClicked (e );
103- }
104111 }
105112
106- public void mousePressed (MouseEvent e ) {
113+ public void mousePressed (MouseEvent e )
114+ {
107115 boolean consumed = false ;
108- if (arGL2Present ) {
116+ if (arGL2Present )
109117 consumed = zebraMousePressed (getGLCanvasHandle (), e .getButton (), e .getX (), e .getY ());
110- }
111- if (consumed == true ) {
118+ if (consumed == true )
112119 e .consume ();
113- } else {
120+ else
114121 super .mousePressed (e );
115- }
116122 }
117123
118- public void mouseReleased (MouseEvent e ) {
124+ public void mouseReleased (MouseEvent e )
125+ {
119126 boolean consumed = false ;
120- if (arGL2Present ) {
127+ if (arGL2Present )
121128 consumed = zebraMouseReleased (getGLCanvasHandle (), e .getButton (), e .getX (), e .getY ());
122- }
123- if (consumed == true ) {
129+ if (consumed == true )
124130 e .consume ();
125- } else {
131+ else
126132 super .mouseReleased (e );
127- }
128133 }
129134
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. */
134138 int button = 0 ;
135139 button = (e .getModifiersEx () & InputEvent .BUTTON1_DOWN_MASK ) == InputEvent .BUTTON1_DOWN_MASK ? 1 : button ;
136140 button = (e .getModifiersEx () & InputEvent .BUTTON2_DOWN_MASK ) == InputEvent .BUTTON2_DOWN_MASK ? 2 : button ;
137141 button = (e .getModifiersEx () & InputEvent .BUTTON3_DOWN_MASK ) == InputEvent .BUTTON3_DOWN_MASK ? 3 : button ;
138142
139143 boolean consumed = false ;
140- if (arGL2Present ) {
144+ if (arGL2Present )
141145 consumed = zebraMouseMoved (getGLCanvasHandle (), button , e .getX (), e .getY ());
142- }
143- if (consumed == true ) {
146+ if (consumed == true )
144147 e .consume ();
145- } else {
148+ else
146149 super .mouseDragged (e );
147- }
148150 }
149151
150- public void mouseWheelMoved (MouseWheelEvent e ) {
152+ public void mouseWheelMoved (MouseWheelEvent e )
153+ {
151154 boolean consumed = false ;
152- if (arGL2Present ) {
155+ if (arGL2Present )
153156 consumed = zebraMouseWheel (getGLCanvasHandle (), e .getWheelRotation ());
154- }
155- if (consumed == true ) {
157+ if (consumed == true )
156158 e .consume ();
157- } else {
159+ else
158160 super .mouseWheelMoved (e );
159- }
160161 }
161162
162- private long getGLCanvasHandle () {
163+ private long getGLCanvasHandle ()
164+ {
163165 /**
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.
165168 */
166- if (hwnd == 0 ) {
169+ if (hwnd == 0 )
170+ {
167171 WorldWindow ww = this .getWorldWindow ();
168- if (ww != null ) {
172+ if (ww != null )
173+ {
169174 WorldWindowGLCanvas wwgl = (WorldWindowGLCanvas ) ww ;
170175 GLCanvas glc = wwgl ;
171176 Canvas cv = glc ;
@@ -177,53 +182,60 @@ private long getGLCanvasHandle() {
177182 return hwnd ;
178183 }
179184
180- private static ZebraInputHandler getInstance (long hwnd ) {
185+ private static ZebraInputHandler getInstance (long hwnd )
186+ {
181187 Iterator <ZebraInputHandler > itr = instances .iterator ();
182- while (itr .hasNext ()) {
188+ while (itr .hasNext ())
189+ {
183190 ZebraInputHandler h = itr .next ();
184- if (h .hwnd == hwnd ) {
191+ if (h .hwnd == hwnd )
185192 return h ;
186- }
187193 }
188194
189195 return null ;
190196 }
191197
192198 // 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. */
197203 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;
201208 }
202209 }
203210
204- public static double [] getModelviewMatrix (long hwnd ) {
211+ public static double [] getModelviewMatrix (long hwnd )
212+ {
205213 double [] matrix = new double [16 ];
206214
207215 ZebraInputHandler h = getInstance (hwnd );
208- if (h != null ) {
216+ if (h != null )
217+ {
209218 h .getWorldWindow ().getView ().getModelviewMatrix ().toArray (matrix , 0 , false );
210219 }
211220
212221 return matrix ;
213222 }
214223
215- public static double [] getProjectionMatrix (long hwnd ) {
224+ public static double [] getProjectionMatrix (long hwnd )
225+ {
216226 double [] matrix = new double [16 ];
217227
218228 ZebraInputHandler h = getInstance (hwnd );
219- if (h != null ) {
229+ if (h != null )
230+ {
220231 h .getWorldWindow ().getView ().getProjectionMatrix ().toArray (matrix , 0 , false );
221232 }
222233
223234 return matrix ;
224235 }
225236
226237 // Methods imported from the zebra's arGL2Integrator.dll library and executed by java
238+
227239 public native boolean zebraKeyPressed (long hwnd , int keyCode );
228240
229241 public native boolean zebraKeyReleased (long hwnd , int keyCode );
0 commit comments