13
|
1 import java.awt.*;
|
|
2 import java.awt.event.*;
|
|
3 import java.io.*;
|
|
4 import java.net.*;
|
|
5
|
|
6 public class VncProxyService implements java.lang.Runnable {
|
|
7
|
|
8 public static void main(String[] argv) {
|
|
9 VncProxyService v = new VncProxyService();
|
|
10 v.mainArgs = argv;
|
|
11
|
|
12 v.init();
|
|
13 // v.start();
|
|
14 }
|
15
|
15
|
13
|
16 String[] mainArgs;
|
|
17
|
|
18 // RfbProto rfb;
|
|
19 MyRfbProto rfb;
|
|
20 Thread rfbThread;
|
|
21
|
|
22 Frame vncFrame;
|
|
23 Container vncContainer;
|
|
24 ScrollPane desktopScrollPane;
|
|
25 GridBagLayout gridbag;
|
|
26 ButtonPanel buttonPanel;
|
|
27 Label connStatusLabel;
|
|
28 ProxyVncCanvas vc;
|
|
29 OptionsFrame options;
|
|
30 ClipboardFrame clipboard;
|
|
31 RecordingFrame rec;
|
|
32
|
|
33 // Control session recording.
|
|
34 Object recordingSync;
|
|
35 String sessionFileName;
|
|
36 boolean recordingActive;
|
|
37 boolean recordingStatusChanged;
|
|
38 String cursorUpdatesDef;
|
|
39 String eightBitColorsDef;
|
|
40
|
|
41 // Variables read from parameter values.
|
|
42 String socketFactory;
|
|
43 String host;
|
|
44 int port;
|
|
45 String passwordParam;
|
|
46 boolean showControls;
|
|
47 boolean offerRelogin;
|
|
48 boolean showOfflineDesktop;
|
|
49 int deferScreenUpdates;
|
|
50 int deferCursorUpdates;
|
|
51 int deferUpdateRequests;
|
|
52 int debugStatsExcludeUpdates;
|
|
53 int debugStatsMeasureUpdates;
|
|
54
|
|
55 //
|
|
56 // init()
|
|
57 //
|
|
58
|
|
59 public void init() {
|
|
60
|
|
61 readParameters();
|
|
62
|
|
63 recordingSync = new Object();
|
|
64
|
|
65 sessionFileName = null;
|
|
66 recordingActive = false;
|
|
67 recordingStatusChanged = false;
|
|
68 cursorUpdatesDef = null;
|
|
69 eightBitColorsDef = null;
|
|
70
|
|
71 rfbThread = new Thread(this);
|
|
72 rfbThread.start();
|
20
|
73
|
21
|
74
|
20
|
75
|
13
|
76 }
|
|
77
|
|
78 //
|
|
79 // run() - executed by the rfbThread to deal with the RFB socket.
|
|
80 //
|
|
81
|
|
82 public void run() {
|
|
83
|
|
84 try {
|
|
85 connectAndAuthenticate();
|
|
86 doProtocolInitialisation();
|
|
87
|
|
88 vc = new ProxyVncCanvas(this, 0, 0);
|
|
89
|
|
90 processNormalProtocol();// main loop
|
|
91
|
|
92 } catch (NoRouteToHostException e) {
|
|
93 fatalError("Network error: no route to server: " + host, e);
|
|
94 } catch (UnknownHostException e) {
|
|
95 fatalError("Network error: server name unknown: " + host, e);
|
|
96 } catch (ConnectException e) {
|
|
97 fatalError("Network error: could not connect to server: " + host
|
|
98 + ":" + port, e);
|
|
99 } catch (EOFException e) {
|
|
100 if (showOfflineDesktop) {
|
|
101 e.printStackTrace();
|
|
102 System.out
|
|
103 .println("Network error: remote side closed connection");
|
|
104 if (vc != null) {
|
|
105 vc.enableInput(false);
|
|
106 }
|
|
107 if (rfb != null && !rfb.closed())
|
|
108 rfb.close();
|
|
109 if (showControls && buttonPanel != null) {
|
|
110 buttonPanel.disableButtonsOnDisconnect();
|
|
111 }
|
|
112 } else {
|
|
113 fatalError("Network error: remote side closed connection", e);
|
|
114 }
|
|
115 } catch (IOException e) {
|
|
116 String str = e.getMessage();
|
|
117 if (str != null && str.length() != 0) {
|
|
118 fatalError("Network Error: " + str, e);
|
|
119 } else {
|
|
120 fatalError(e.toString(), e);
|
|
121 }
|
|
122 } catch (Exception e) {
|
|
123 String str = e.getMessage();
|
|
124 if (str != null && str.length() != 0) {
|
|
125 fatalError("Error: " + str, e);
|
|
126 } else {
|
|
127 fatalError(e.toString(), e);
|
|
128 }
|
|
129 }
|
|
130
|
|
131 }
|
|
132
|
|
133 //
|
|
134 // Process RFB socket messages.
|
|
135 // If the rfbThread is being stopped, ignore any exceptions,
|
|
136 // otherwise rethrow the exception so it can be handled.
|
|
137 //
|
|
138
|
|
139 void processNormalProtocol() throws Exception {
|
|
140 try {
|
|
141 vc.processNormalProtocol();// main loop
|
|
142 } catch (Exception e) {
|
|
143 if (rfbThread == null) {
|
|
144 System.out.println("Ignoring RFB socket exceptions"
|
|
145 + " because applet is stopping");
|
|
146 } else {
|
|
147 throw e;
|
|
148 }
|
|
149 }
|
|
150 }
|
|
151
|
|
152 //
|
|
153 // Connect to the RFB server and authenticate the user.
|
|
154 //
|
|
155
|
|
156 void connectAndAuthenticate() throws Exception {
|
|
157 showConnectionStatus("Initializing...");
|
|
158
|
|
159 showConnectionStatus("Connecting to " + host + ", port " + port + "...");
|
|
160
|
|
161 // rfb = new RfbProto(host, port, this);
|
|
162 rfb = new MyRfbProto(host, port);
|
|
163 showConnectionStatus("Connected to server");
|
|
164
|
|
165 rfb.readVersionMsg();
|
|
166 showConnectionStatus("RFB server supports protocol version "
|
|
167 + rfb.serverMajor + "." + rfb.serverMinor);
|
|
168
|
|
169 rfb.writeVersionMsg();
|
|
170 showConnectionStatus("Using RFB protocol version " + rfb.clientMajor
|
|
171 + "." + rfb.clientMinor);
|
|
172
|
|
173 int secType = rfb.negotiateSecurity();
|
|
174 int authType;
|
|
175 if (secType == RfbProto.SecTypeTight) {
|
|
176 showConnectionStatus("Enabling TightVNC protocol extensions");
|
|
177 rfb.setupTunneling();
|
|
178 authType = rfb.negotiateAuthenticationTight();
|
|
179 } else {
|
|
180 authType = secType;
|
|
181 }
|
|
182
|
|
183 switch (authType) {
|
|
184 case RfbProto.AuthNone:
|
|
185 showConnectionStatus("No authentication needed");
|
|
186 rfb.authenticateNone();
|
|
187 break;
|
|
188 case RfbProto.AuthVNC:
|
|
189 showConnectionStatus("Performing standard VNC authentication");
|
|
190 if (passwordParam != null) {
|
|
191 rfb.authenticateVNC(passwordParam);
|
|
192 } else {
|
|
193 String pw = askPassword();
|
|
194 rfb.authenticateVNC(pw);
|
|
195 }
|
|
196 break;
|
|
197 default:
|
|
198 throw new Exception("Unknown authentication scheme " + authType);
|
|
199 }
|
|
200 }
|
|
201
|
|
202 //
|
|
203 // Show a message describing the connection status.
|
|
204 // To hide the connection status label, use (msg == null).
|
|
205 //
|
|
206
|
|
207 void showConnectionStatus(String msg) {
|
|
208 System.out.println(msg);
|
|
209 }
|
|
210
|
|
211 //
|
|
212 // Show an authentication panel.
|
|
213 //
|
|
214
|
|
215 String askPassword() throws Exception {
|
|
216 showConnectionStatus(null);
|
|
217 /*
|
|
218 * AuthPanel authPanel = new AuthPanel(this);
|
|
219 *
|
|
220 * GridBagConstraints gbc = new GridBagConstraints(); gbc.gridwidth =
|
|
221 * GridBagConstraints.REMAINDER; gbc.anchor =
|
|
222 * GridBagConstraints.NORTHWEST; gbc.weightx = 1.0; gbc.weighty = 1.0;
|
|
223 * gbc.ipadx = 100; gbc.ipady = 50; gridbag.setConstraints(authPanel,
|
|
224 * gbc); vncContainer.add(authPanel);
|
|
225
|
|
226
|
|
227 authPanel.moveFocusToDefaultField();
|
|
228 vncContainer.remove(authPanel);
|
|
229 */
|
|
230 String pw = mainArgs[2];
|
|
231 return pw;
|
|
232 }
|
|
233
|
|
234 //
|
|
235 // Do the rest of the protocol initialisation.
|
|
236 //
|
|
237
|
|
238 void doProtocolInitialisation() throws IOException {
|
|
239 rfb.writeClientInit();
|
|
240 rfb.readServerInit();
|
|
241
|
|
242
|
|
243 System.out.println("Desktop name is " + rfb.desktopName);
|
|
244 System.out.println("Desktop size is " + rfb.framebufferWidth + " x "
|
|
245 + rfb.framebufferHeight);
|
|
246
|
|
247 setEncodings();
|
|
248
|
|
249 showConnectionStatus(null);
|
|
250 }
|
|
251
|
|
252 //
|
|
253 // Send current encoding list to the RFB server.
|
|
254 //
|
|
255
|
|
256 int[] encodingsSaved;
|
|
257 int nEncodingsSaved;
|
|
258
|
|
259 void setEncodings() {
|
|
260 setEncodings(false);
|
|
261 }
|
|
262
|
|
263 void autoSelectEncodings() {
|
|
264 setEncodings(true);
|
|
265 }
|
|
266
|
|
267 void setEncodings(boolean autoSelectOnly) {
|
|
268 if (options == null || rfb == null || !rfb.inNormalProtocol)
|
|
269 return;
|
|
270
|
|
271 int preferredEncoding = options.preferredEncoding;
|
|
272 if (preferredEncoding == -1) {
|
|
273 long kbitsPerSecond = rfb.kbitsPerSecond();
|
|
274 if (nEncodingsSaved < 1) {
|
|
275 // Choose Tight or ZRLE encoding for the very first update.
|
|
276 System.out.println("Using Tight/ZRLE encodings");
|
|
277 preferredEncoding = RfbProto.EncodingTight;
|
|
278 } else if (kbitsPerSecond > 2000
|
|
279 && encodingsSaved[0] != RfbProto.EncodingHextile) {
|
|
280 // Switch to Hextile if the connection speed is above 2Mbps.
|
|
281 System.out.println("Throughput " + kbitsPerSecond
|
|
282 + " kbit/s - changing to Hextile encoding");
|
|
283 preferredEncoding = RfbProto.EncodingHextile;
|
|
284 } else if (kbitsPerSecond < 1000
|
|
285 && encodingsSaved[0] != RfbProto.EncodingTight) {
|
|
286 // Switch to Tight/ZRLE if the connection speed is below 1Mbps.
|
|
287 System.out.println("Throughput " + kbitsPerSecond
|
|
288 + " kbit/s - changing to Tight/ZRLE encodings");
|
|
289 preferredEncoding = RfbProto.EncodingTight;
|
|
290 } else {
|
|
291 // Don't change the encoder.
|
|
292 if (autoSelectOnly)
|
|
293 return;
|
|
294 preferredEncoding = encodingsSaved[0];
|
|
295 }
|
|
296 } else {
|
|
297 // Auto encoder selection is not enabled.
|
|
298 if (autoSelectOnly)
|
|
299 return;
|
|
300 }
|
|
301
|
|
302 int[] encodings = new int[20];
|
|
303 int nEncodings = 0;
|
|
304
|
|
305 encodings[nEncodings++] = preferredEncoding;
|
|
306 if (options.useCopyRect) {
|
|
307 encodings[nEncodings++] = RfbProto.EncodingCopyRect;
|
|
308 }
|
|
309
|
|
310 if (preferredEncoding != RfbProto.EncodingTight) {
|
|
311 encodings[nEncodings++] = RfbProto.EncodingTight;
|
|
312 }
|
|
313 if (preferredEncoding != RfbProto.EncodingZRLE) {
|
|
314 encodings[nEncodings++] = RfbProto.EncodingZRLE;
|
|
315 }
|
|
316 if (preferredEncoding != RfbProto.EncodingHextile) {
|
|
317 encodings[nEncodings++] = RfbProto.EncodingHextile;
|
|
318 }
|
|
319 if (preferredEncoding != RfbProto.EncodingZlib) {
|
|
320 encodings[nEncodings++] = RfbProto.EncodingZlib;
|
|
321 }
|
|
322 if (preferredEncoding != RfbProto.EncodingCoRRE) {
|
|
323 encodings[nEncodings++] = RfbProto.EncodingCoRRE;
|
|
324 }
|
|
325 if (preferredEncoding != RfbProto.EncodingRRE) {
|
|
326 encodings[nEncodings++] = RfbProto.EncodingRRE;
|
|
327 }
|
|
328
|
|
329 if (options.compressLevel >= 0 && options.compressLevel <= 9) {
|
|
330 encodings[nEncodings++] = RfbProto.EncodingCompressLevel0
|
|
331 + options.compressLevel;
|
|
332 }
|
|
333 if (options.jpegQuality >= 0 && options.jpegQuality <= 9) {
|
|
334 encodings[nEncodings++] = RfbProto.EncodingQualityLevel0
|
|
335 + options.jpegQuality;
|
|
336 }
|
|
337
|
|
338 if (options.requestCursorUpdates) {
|
|
339 encodings[nEncodings++] = RfbProto.EncodingXCursor;
|
|
340 encodings[nEncodings++] = RfbProto.EncodingRichCursor;
|
|
341 if (!options.ignoreCursorUpdates)
|
|
342 encodings[nEncodings++] = RfbProto.EncodingPointerPos;
|
|
343 }
|
|
344
|
|
345 encodings[nEncodings++] = RfbProto.EncodingLastRect;
|
|
346 encodings[nEncodings++] = RfbProto.EncodingNewFBSize;
|
|
347
|
|
348 boolean encodingsWereChanged = false;
|
|
349 if (nEncodings != nEncodingsSaved) {
|
|
350 encodingsWereChanged = true;
|
|
351 } else {
|
|
352 for (int i = 0; i < nEncodings; i++) {
|
|
353 if (encodings[i] != encodingsSaved[i]) {
|
|
354 encodingsWereChanged = true;
|
|
355 break;
|
|
356 }
|
|
357 }
|
|
358 }
|
|
359
|
|
360 if (encodingsWereChanged) {
|
|
361 try {
|
|
362 rfb.writeSetEncodings(encodings, nEncodings);
|
|
363 if (vc != null) {
|
|
364 vc.softCursorFree();
|
|
365 }
|
|
366 } catch (Exception e) {
|
|
367 e.printStackTrace();
|
|
368 }
|
|
369 encodingsSaved = encodings;
|
|
370 nEncodingsSaved = nEncodings;
|
|
371 }
|
|
372 }
|
|
373
|
|
374 //
|
|
375 // setCutText() - send the given cut text to the RFB server.
|
|
376 //
|
|
377
|
|
378 void setCutText(String text) {
|
|
379 try {
|
|
380 if (rfb != null && rfb.inNormalProtocol) {
|
|
381 rfb.writeClientCutText(text);
|
|
382 }
|
|
383 } catch (Exception e) {
|
|
384 e.printStackTrace();
|
|
385 }
|
|
386 }
|
|
387
|
|
388 //
|
|
389 // Order change in session recording status. To stop recording, pass
|
|
390 // null in place of the fname argument.
|
|
391 //
|
|
392
|
|
393 void setRecordingStatus(String fname) {
|
|
394 synchronized (recordingSync) {
|
|
395 sessionFileName = fname;
|
|
396 recordingStatusChanged = true;
|
|
397 }
|
|
398 }
|
|
399
|
|
400 //
|
|
401 // Start or stop session recording. Returns true if this method call
|
|
402 // causes recording of a new session.
|
|
403 //
|
|
404
|
|
405 boolean checkRecordingStatus() throws IOException {
|
|
406 synchronized (recordingSync) {
|
|
407 if (recordingStatusChanged) {
|
|
408 recordingStatusChanged = false;
|
|
409 if (sessionFileName != null) {
|
|
410 startRecording();
|
|
411 return true;
|
|
412 } else {
|
|
413 stopRecording();
|
|
414 }
|
|
415 }
|
|
416 }
|
|
417 return false;
|
|
418 }
|
|
419
|
|
420 //
|
|
421 // Start session recording.
|
|
422 //
|
|
423
|
|
424 protected void startRecording() throws IOException {
|
|
425 synchronized (recordingSync) {
|
|
426 if (!recordingActive) {
|
|
427 // Save settings to restore them after recording the session.
|
|
428 cursorUpdatesDef = options.choices[options.cursorUpdatesIndex]
|
|
429 .getSelectedItem();
|
|
430 eightBitColorsDef = options.choices[options.eightBitColorsIndex]
|
|
431 .getSelectedItem();
|
|
432 // Set options to values suitable for recording.
|
|
433 options.choices[options.cursorUpdatesIndex].select("Disable");
|
|
434 options.choices[options.cursorUpdatesIndex].setEnabled(false);
|
|
435 options.setEncodings();
|
|
436 options.choices[options.eightBitColorsIndex].select("No");
|
|
437 options.choices[options.eightBitColorsIndex].setEnabled(false);
|
|
438 options.setColorFormat();
|
|
439 } else {
|
|
440 rfb.closeSession();
|
|
441 }
|
|
442
|
|
443 System.out.println("Recording the session in " + sessionFileName);
|
|
444 rfb.startSession(sessionFileName);
|
|
445 recordingActive = true;
|
|
446 }
|
|
447 }
|
|
448
|
|
449 //
|
|
450 // Stop session recording.
|
|
451 //
|
|
452
|
|
453 protected void stopRecording() throws IOException {
|
|
454 synchronized (recordingSync) {
|
|
455 if (recordingActive) {
|
|
456 // Restore options.
|
|
457 options.choices[options.cursorUpdatesIndex]
|
|
458 .select(cursorUpdatesDef);
|
|
459 options.choices[options.cursorUpdatesIndex].setEnabled(true);
|
|
460 options.setEncodings();
|
|
461 options.choices[options.eightBitColorsIndex]
|
|
462 .select(eightBitColorsDef);
|
|
463 options.choices[options.eightBitColorsIndex].setEnabled(true);
|
|
464 options.setColorFormat();
|
|
465
|
|
466 rfb.closeSession();
|
|
467 System.out.println("Session recording stopped.");
|
|
468 }
|
|
469 sessionFileName = null;
|
|
470 recordingActive = false;
|
|
471 }
|
|
472 }
|
|
473
|
|
474 //
|
|
475 // readParameters() - read parameters from the html source or from the
|
|
476 // command line. On the command line, the arguments are just a sequence of
|
|
477 // param_name/param_value pairs where the names and values correspond to
|
|
478 // those expected in the html applet tag source.
|
|
479 //
|
|
480
|
|
481 void readParameters() {
|
|
482
|
|
483 if (mainArgs.length > 0)
|
|
484 host = mainArgs[0];
|
|
485 else
|
|
486 host = "hades.cr.ie.u-ryukyu.ac.jp";
|
|
487
|
|
488 if (mainArgs.length > 1)
|
|
489 port = Integer.parseInt(mainArgs[1]);
|
|
490 else
|
|
491 port = 5900;
|
|
492
|
|
493 // Read "ENCPASSWORD" or "PASSWORD" parameter if specified.
|
|
494 // readPasswordParameters();
|
|
495
|
|
496 String str;
|
|
497
|
|
498 // "Show Controls" set to "No" disables button panel.
|
|
499 showControls = true;
|
|
500 str = readParameter("Show Controls", false);
|
|
501 if (str != null && str.equalsIgnoreCase("No"))
|
|
502 showControls = false;
|
|
503
|
|
504 // "Offer Relogin" set to "No" disables "Login again" and "Close
|
|
505 // window" buttons under error messages in applet mode.
|
|
506 offerRelogin = true;
|
|
507 str = readParameter("Offer Relogin", false);
|
|
508 if (str != null && str.equalsIgnoreCase("No"))
|
|
509 offerRelogin = false;
|
|
510
|
|
511 // Do we continue showing desktop on remote disconnect?
|
|
512 showOfflineDesktop = false;
|
|
513 str = readParameter("Show Offline Desktop", false);
|
|
514 if (str != null && str.equalsIgnoreCase("Yes"))
|
|
515 showOfflineDesktop = true;
|
|
516
|
|
517 // Fine tuning options.
|
|
518 deferScreenUpdates = readIntParameter("Defer screen updates", 20);
|
|
519 deferCursorUpdates = readIntParameter("Defer cursor updates", 10);
|
|
520 deferUpdateRequests = readIntParameter("Defer update requests", 0);
|
|
521
|
|
522 // Debugging options.
|
|
523 debugStatsExcludeUpdates = readIntParameter("DEBUG_XU", 0);
|
|
524 debugStatsMeasureUpdates = readIntParameter("DEBUG_CU", 0);
|
|
525
|
|
526 // SocketFactory.
|
|
527 socketFactory = readParameter("SocketFactory", false);
|
|
528 }
|
|
529
|
|
530 //
|
|
531 // Read password parameters. If an "ENCPASSWORD" parameter is set,
|
|
532 // then decrypt the password into the passwordParam string. Otherwise,
|
|
533 // try to read the "PASSWORD" parameter directly to passwordParam.
|
|
534 //
|
|
535
|
|
536 private void readPasswordParameters() {
|
|
537 // String encPasswordParam = readParameter("ENCPASSWORD", false);
|
|
538 String encPasswordParam = mainArgs[2];
|
|
539
|
|
540 if (encPasswordParam == null) {
|
|
541 // passwordParam = readParameter("PASSWORD", false);
|
|
542
|
|
543 } else {
|
|
544 // ENCPASSWORD is hexascii-encoded. Decode.
|
|
545 byte[] pw = { 0, 0, 0, 0, 0, 0, 0, 0 };
|
|
546 int len = encPasswordParam.length() / 2;
|
|
547 if (len > 8)
|
|
548 len = 8;
|
|
549 for (int i = 0; i < len; i++) {
|
|
550 String hex = encPasswordParam.substring(i * 2, i * 2 + 2);
|
|
551 Integer x = new Integer(Integer.parseInt(hex, 16));
|
|
552 pw[i] = x.byteValue();
|
|
553 }
|
|
554 // Decrypt the password.
|
|
555 byte[] key = { 23, 82, 107, 6, 35, 78, 88, 7 };
|
|
556 DesCipher des = new DesCipher(key);
|
|
557 des.decrypt(pw, 0, pw, 0);
|
|
558 passwordParam = new String(pw);
|
|
559
|
|
560 }
|
|
561 }
|
|
562
|
|
563 public String readParameter(String name, boolean required) {
|
|
564 for (int i = 0; i < mainArgs.length; i += 2) {
|
|
565 if (mainArgs[i].equalsIgnoreCase(name)) {
|
|
566 try {
|
|
567 return mainArgs[i + 1];
|
|
568 } catch (Exception e) {
|
|
569 if (required) {
|
|
570 fatalError(name + " parameter not specified");
|
|
571 }
|
|
572 return null;
|
|
573 }
|
|
574 }
|
|
575 }
|
|
576 if (required) {
|
|
577 fatalError(name + " parameter not specified");
|
|
578 }
|
|
579 return null;
|
|
580 }
|
|
581
|
|
582 int readIntParameter(String name, int defaultValue) {
|
|
583 String str = readParameter(name, false);
|
|
584 int result = defaultValue;
|
|
585 if (str != null) {
|
|
586 try {
|
|
587 result = Integer.parseInt(str);
|
|
588 } catch (NumberFormatException e) {
|
|
589 }
|
|
590 }
|
|
591 return result;
|
|
592 }
|
|
593
|
|
594 //
|
|
595 // disconnect() - close connection to server.
|
|
596 //
|
|
597
|
|
598 synchronized public void disconnect() {
|
|
599 System.out.println("Disconnecting");
|
|
600
|
|
601 if (vc != null) {
|
|
602 double sec = (System.currentTimeMillis() - vc.statStartTime) / 1000.0;
|
|
603 double rate = Math.round(vc.statNumUpdates / sec * 100) / 100.0;
|
|
604 int nRealRects = vc.statNumPixelRects;
|
|
605 int nPseudoRects = vc.statNumTotalRects - vc.statNumPixelRects;
|
|
606 System.out.println("Updates received: " + vc.statNumUpdates + " ("
|
|
607 + nRealRects + " rectangles + " + nPseudoRects
|
|
608 + " pseudo), " + rate + " updates/sec");
|
|
609 int numRectsOther = nRealRects - vc.statNumRectsTight
|
|
610 - vc.statNumRectsZRLE - vc.statNumRectsHextile
|
|
611 - vc.statNumRectsRaw - vc.statNumRectsCopy;
|
|
612 System.out.println("Rectangles:" + " Tight=" + vc.statNumRectsTight
|
|
613 + "(JPEG=" + vc.statNumRectsTightJPEG + ") ZRLE="
|
|
614 + vc.statNumRectsZRLE + " Hextile="
|
|
615 + vc.statNumRectsHextile + " Raw=" + vc.statNumRectsRaw
|
|
616 + " CopyRect=" + vc.statNumRectsCopy + " other="
|
|
617 + numRectsOther);
|
|
618
|
|
619 int raw = vc.statNumBytesDecoded;
|
|
620 int compressed = vc.statNumBytesEncoded;
|
|
621 if (compressed > 0) {
|
|
622 double ratio = Math.round((double) raw / compressed * 1000) / 1000.0;
|
|
623 System.out.println("Pixel data: " + vc.statNumBytesDecoded
|
|
624 + " bytes, " + vc.statNumBytesEncoded
|
|
625 + " compressed, ratio " + ratio);
|
|
626 }
|
|
627 }
|
|
628
|
|
629 if (rfb != null && !rfb.closed())
|
|
630 rfb.close();
|
|
631 options.dispose();
|
|
632 clipboard.dispose();
|
|
633 if (rec != null)
|
|
634 rec.dispose();
|
|
635
|
|
636 System.exit(0);
|
|
637
|
|
638 }
|
|
639
|
|
640 //
|
|
641 // fatalError() - print out a fatal error message.
|
|
642 // FIXME: Do we really need two versions of the fatalError() method?
|
|
643 //
|
|
644
|
|
645 synchronized public void fatalError(String str) {
|
|
646 System.out.println(str);
|
|
647 System.exit(1);
|
|
648 }
|
|
649
|
|
650 synchronized public void fatalError(String str, Exception e) {
|
|
651
|
|
652 if (rfb != null && rfb.closed()) {
|
|
653 // Not necessary to show error message if the error was caused
|
|
654 // by I/O problems after the rfb.close() method call.
|
|
655 System.out.println("RFB thread finished");
|
|
656 return;
|
|
657 }
|
|
658
|
|
659 System.out.println(str);
|
|
660 e.printStackTrace();
|
|
661
|
|
662 if (rfb != null)
|
|
663 rfb.close();
|
|
664
|
|
665 System.exit(1);
|
|
666
|
|
667 }
|
|
668
|
|
669 //
|
|
670 // Show message text and optionally "Relogin" and "Close" buttons.
|
|
671 //
|
|
672
|
|
673 void showMessage(String msg) {
|
|
674 vncContainer.removeAll();
|
|
675
|
|
676 Label errLabel = new Label(msg, Label.CENTER);
|
|
677 errLabel.setFont(new Font("Helvetica", Font.PLAIN, 12));
|
|
678
|
|
679 if (offerRelogin) {
|
|
680 /*
|
|
681 * Panel gridPanel = new Panel(new GridLayout(0, 1)); Panel
|
|
682 * outerPanel = new Panel(new FlowLayout(FlowLayout.LEFT));
|
|
683 * outerPanel.add(gridPanel); vncContainer.setLayout(new
|
|
684 * FlowLayout(FlowLayout.LEFT, 30, 16));
|
|
685 * vncContainer.add(outerPanel); Panel textPanel = new Panel(new
|
|
686 * FlowLayout(FlowLayout.CENTER)); textPanel.add(errLabel);
|
|
687 * gridPanel.add(textPanel); gridPanel.add(new ReloginPanel(this));
|
|
688 */
|
|
689 } else {
|
|
690 /*
|
|
691 * vncContainer.setLayout(new FlowLayout(FlowLayout.LEFT, 30, 30));
|
|
692 * vncContainer.add(errLabel);
|
|
693 */
|
|
694 }
|
|
695
|
|
696 }
|
|
697
|
|
698 //
|
|
699 // Stop the applet.
|
|
700 // Main applet thread will terminate on first exception
|
|
701 // after seeing that rfbThread has been set to null.
|
|
702 //
|
|
703
|
|
704 public void stop() {
|
|
705 System.out.println("Stopping applet");
|
|
706 rfbThread = null;
|
|
707 }
|
|
708
|
|
709 //
|
|
710 // This method is called before the applet is destroyed.
|
|
711 //
|
|
712
|
|
713 public void destroy() {
|
|
714 System.out.println("Destroying applet");
|
|
715
|
|
716 vncContainer.removeAll();
|
|
717 options.dispose();
|
|
718 clipboard.dispose();
|
|
719 if (rec != null)
|
|
720 rec.dispose();
|
|
721 if (rfb != null && !rfb.closed())
|
|
722 rfb.close();
|
|
723 }
|
|
724
|
|
725 //
|
|
726 // Start/stop receiving mouse events.
|
|
727 //
|
|
728
|
|
729 public void enableInput(boolean enable) {
|
|
730 vc.enableInput(enable);
|
|
731 }
|
|
732
|
|
733 //
|
|
734 // Close application properly on window close event.
|
|
735 //
|
|
736
|
|
737 public void windowClosing(WindowEvent evt) {
|
|
738 System.out.println("Closing window");
|
|
739 if (rfb != null)
|
|
740 disconnect();
|
|
741
|
|
742 vncContainer.hide();
|
|
743
|
|
744 }
|
|
745
|
|
746 //
|
|
747 // Ignore window events we're not interested in.
|
|
748 //
|
|
749
|
|
750 public void windowActivated(WindowEvent evt) {
|
|
751 }
|
|
752
|
|
753 public void windowDeactivated(WindowEvent evt) {
|
|
754 }
|
|
755
|
|
756 public void windowOpened(WindowEvent evt) {
|
|
757 }
|
|
758
|
|
759 public void windowClosed(WindowEvent evt) {
|
|
760 }
|
|
761
|
|
762 public void windowIconified(WindowEvent evt) {
|
|
763 }
|
|
764
|
|
765 public void windowDeiconified(WindowEvent evt) {
|
|
766 }
|
|
767 }
|