blob: d2ae1c88304e61fc2984a78f220eb0fcb7806be1 [file] [log] [blame]
Constantin Kaplinsky1215b992008-04-18 09:51:44 +00001//
2// Copyright (C) 2001,2002 HorizonLive.com, Inc. All Rights Reserved.
3// Copyright (C) 1999 AT&T Laboratories Cambridge. All Rights Reserved.
4//
5// This is free software; you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation; either version 2 of the License, or
8// (at your option) any later version.
9//
10// This software is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15// You should have received a copy of the GNU General Public License
16// along with this software; if not, write to the Free Software
17// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
18// USA.
19//
20
Constantin Kaplinskycf689b32008-04-30 12:50:34 +000021package com.tightvnc.rfbplayer;
wimba.comc23aeb02004-09-16 00:00:00 +000022
Constantin Kaplinsky1215b992008-04-18 09:51:44 +000023import java.awt.*;
24import java.awt.event.*;
25import java.io.*;
Constantin Kaplinsky5d99c952002-05-25 09:49:23 +000026import java.net.*;
Constantin Kaplinsky1215b992008-04-18 09:51:44 +000027
Constantin Kaplinsky903009e2002-05-20 10:55:47 +000028public class RfbPlayer extends java.applet.Applet
Constantin Kaplinsky72e47ef2008-04-18 17:48:16 +000029 implements java.lang.Runnable, WindowListener {
Constantin Kaplinsky1215b992008-04-18 09:51:44 +000030
31 boolean inAnApplet = true;
32 boolean inSeparateFrame = false;
33
wimba.com252eb3b2004-09-21 21:27:54 +000034 /** current applet width */
35 int dispW = 300;
36 /** current applet height */
37 int dispH = 200;
38
Constantin Kaplinsky1215b992008-04-18 09:51:44 +000039 //
40 // main() is called when run as a java program from the command line.
41 // It simply runs the applet inside a newly-created frame.
42 //
Constantin Kaplinsky1215b992008-04-18 09:51:44 +000043 public static void main(String[] argv) {
Constantin Kaplinsky903009e2002-05-20 10:55:47 +000044 RfbPlayer p = new RfbPlayer();
45 p.mainArgs = argv;
46 p.inAnApplet = false;
47 p.inSeparateFrame = true;
Constantin Kaplinsky1215b992008-04-18 09:51:44 +000048
Constantin Kaplinsky903009e2002-05-20 10:55:47 +000049 p.init();
50 p.start();
Constantin Kaplinsky1215b992008-04-18 09:51:44 +000051 }
52
53 String[] mainArgs;
54
Constantin Kaplinsky7b55c4f2008-06-18 09:28:30 +000055 FbsInputStream fbs;
Constantin Kaplinsky1215b992008-04-18 09:51:44 +000056 RfbProto rfb;
57 Thread rfbThread;
58
59 Frame vncFrame;
60 Container vncContainer;
wimba.come8e19102005-02-08 17:15:23 +000061 //ScrollPane desktopScrollPane;
62 LWScrollPane desktopScrollPane;
Constantin Kaplinsky1215b992008-04-18 09:51:44 +000063 GridBagLayout gridbag;
64 ButtonPanel buttonPanel;
Constantin Kaplinsky1215b992008-04-18 09:51:44 +000065 VncCanvas vc;
Constantin Kaplinsky1215b992008-04-18 09:51:44 +000066
Constantin Kaplinsky5d99c952002-05-25 09:49:23 +000067 String sessionURL;
Constantin Kaplinskyc833e012002-05-30 17:59:22 +000068 URL url;
Constantin Kaplinsky972c2572002-05-30 14:19:02 +000069 long initialTimeOffset;
Constantin Kaplinsky7957ca12002-05-30 16:19:11 +000070 double playbackSpeed;
Constantin Kaplinsky5a7133a2002-07-24 17:02:04 +000071 boolean autoPlay;
Constantin Kaplinsky903009e2002-05-20 10:55:47 +000072 boolean showControls;
wimba.comd1f56df2004-11-01 16:18:54 +000073 boolean isQuitting = false;
Constantin Kaplinsky1215b992008-04-18 09:51:44 +000074 int deferScreenUpdates;
Constantin Kaplinsky1215b992008-04-18 09:51:44 +000075
76 //
77 // init()
78 //
Constantin Kaplinsky1215b992008-04-18 09:51:44 +000079 public void init() {
80
wimba.comc23aeb02004-09-16 00:00:00 +000081 // LiveConnect work-a-round
82 RfbSharedStatic.refApplet = this;
83
Constantin Kaplinsky1215b992008-04-18 09:51:44 +000084 readParameters();
85
86 if (inSeparateFrame) {
Constantin Kaplinsky903009e2002-05-20 10:55:47 +000087 vncFrame = new Frame("RFB Session Player");
Constantin Kaplinsky1215b992008-04-18 09:51:44 +000088 if (!inAnApplet) {
Constantin Kaplinsky72e47ef2008-04-18 17:48:16 +000089 vncFrame.add("Center", this);
Constantin Kaplinsky1215b992008-04-18 09:51:44 +000090 }
91 vncContainer = vncFrame;
92 } else {
93 vncContainer = this;
94 }
95
Constantin Kaplinsky1215b992008-04-18 09:51:44 +000096 if (inSeparateFrame)
97 vncFrame.addWindowListener(this);
98
wimba.comd1f56df2004-11-01 16:18:54 +000099 rfbThread = new Thread(this, "RfbThread");
Constantin Kaplinsky1215b992008-04-18 09:51:44 +0000100 rfbThread.start();
101 }
102
103 public void update(Graphics g) {
104 }
105
106 //
Constantin Kaplinsky903009e2002-05-20 10:55:47 +0000107 // run() - executed by the rfbThread to read RFB data.
Constantin Kaplinsky1215b992008-04-18 09:51:44 +0000108 //
Constantin Kaplinsky1215b992008-04-18 09:51:44 +0000109 public void run() {
110
111 gridbag = new GridBagLayout();
112 vncContainer.setLayout(gridbag);
113
114 GridBagConstraints gbc = new GridBagConstraints();
115 gbc.gridwidth = GridBagConstraints.REMAINDER;
116 gbc.anchor = GridBagConstraints.NORTHWEST;
117
Constantin Kaplinsky903009e2002-05-20 10:55:47 +0000118 if (showControls) {
Constantin Kaplinsky1215b992008-04-18 09:51:44 +0000119 buttonPanel = new ButtonPanel(this);
120 buttonPanel.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0));
121 gridbag.setConstraints(buttonPanel, gbc);
122 vncContainer.add(buttonPanel);
123 }
124
Constantin Kaplinsky903009e2002-05-20 10:55:47 +0000125 if (inSeparateFrame) {
126 vncFrame.pack();
Constantin Kaplinskyaa7b5612008-06-17 09:27:52 +0000127 vncFrame.setVisible(true);
Constantin Kaplinsky903009e2002-05-20 10:55:47 +0000128 } else {
129 validate();
130 }
Constantin Kaplinsky1215b992008-04-18 09:51:44 +0000131
Constantin Kaplinsky903009e2002-05-20 10:55:47 +0000132 try {
Constantin Kaplinsky40ad1712002-09-22 08:36:43 +0000133 if (inAnApplet) {
Constantin Kaplinsky72e47ef2008-04-18 17:48:16 +0000134 url = new URL(getCodeBase(), sessionURL);
Constantin Kaplinsky40ad1712002-09-22 08:36:43 +0000135 } else {
Constantin Kaplinsky72e47ef2008-04-18 17:48:16 +0000136 url = new URL(sessionURL);
Constantin Kaplinsky40ad1712002-09-22 08:36:43 +0000137 }
Constantin Kaplinskyb5db87f2008-06-19 12:25:12 +0000138 newFbsConnection(initialTimeOffset);
Constantin Kaplinsky7b55c4f2008-06-18 09:28:30 +0000139 rfb = new RfbProto(fbs);
Constantin Kaplinsky1215b992008-04-18 09:51:44 +0000140
141 vc = new VncCanvas(this);
142 gbc.weightx = 1.0;
143 gbc.weighty = 1.0;
144
wimba.com252eb3b2004-09-21 21:27:54 +0000145 // Create a panel which itself is resizeable and can hold
146 // non-resizeable VncCanvas component at the top left corner.
wimba.come8e19102005-02-08 17:15:23 +0000147 //Panel canvasPanel = new Panel();
148 //canvasPanel.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0));
149 //canvasPanel.add(vc);
wimba.com252eb3b2004-09-21 21:27:54 +0000150
151 // Create a ScrollPane which will hold a panel with VncCanvas
152 // inside.
wimba.come8e19102005-02-08 17:15:23 +0000153 //desktopScrollPane = new ScrollPane(ScrollPane.SCROLLBARS_AS_NEEDED);
154 desktopScrollPane = new LWScrollPane();
wimba.com252eb3b2004-09-21 21:27:54 +0000155 gbc.fill = GridBagConstraints.BOTH;
wimba.come8e19102005-02-08 17:15:23 +0000156 gridbag.setConstraints(vc, gbc);
157 //gridbag.setConstraints(canvasPanel, gbc);
158 desktopScrollPane.addComp(vc);
159 desktopScrollPane.setSize(dispW, dispH);
160 //desktopScrollPane.add(canvasPanel);
wimba.com252eb3b2004-09-21 21:27:54 +0000161
162 // Now add the scroll bar to the container.
Constantin Kaplinsky1215b992008-04-18 09:51:44 +0000163 if (inSeparateFrame) {
Constantin Kaplinsky72e47ef2008-04-18 17:48:16 +0000164 gridbag.setConstraints(desktopScrollPane, gbc);
Constantin Kaplinsky72e47ef2008-04-18 17:48:16 +0000165 vncFrame.add(desktopScrollPane);
166 vncFrame.setTitle(rfb.desktopName);
Constantin Kaplinsky72e47ef2008-04-18 17:48:16 +0000167 vc.resizeDesktopFrame();
Constantin Kaplinsky1215b992008-04-18 09:51:44 +0000168 } else {
wimba.com252eb3b2004-09-21 21:27:54 +0000169 // Size the scroll pane to display size.
170 desktopScrollPane.setSize(dispW, dispH);
Constantin Kaplinsky1215b992008-04-18 09:51:44 +0000171
Constantin Kaplinsky72e47ef2008-04-18 17:48:16 +0000172 // Just add the VncCanvas component to the Applet.
wimba.com252eb3b2004-09-21 21:27:54 +0000173 gbc.fill = GridBagConstraints.NONE;
174 gridbag.setConstraints(desktopScrollPane, gbc);
175 add(desktopScrollPane);
Constantin Kaplinsky72e47ef2008-04-18 17:48:16 +0000176 validate();
wimba.com252eb3b2004-09-21 21:27:54 +0000177 vc.resizeEmbeddedApplet();
Constantin Kaplinsky1215b992008-04-18 09:51:44 +0000178 }
179
wimba.comd1f56df2004-11-01 16:18:54 +0000180 while (!isQuitting) {
Constantin Kaplinsky72e47ef2008-04-18 17:48:16 +0000181 try {
182 setPaused(!autoPlay);
Constantin Kaplinsky7b55c4f2008-06-18 09:28:30 +0000183 fbs.setSpeed(playbackSpeed);
Constantin Kaplinsky72e47ef2008-04-18 17:48:16 +0000184 vc.processNormalProtocol();
185 } catch (EOFException e) {
Constantin Kaplinsky7b55c4f2008-06-18 09:28:30 +0000186 long newTimeOffset;
Constantin Kaplinsky72e47ef2008-04-18 17:48:16 +0000187 if (e.getMessage() != null && e.getMessage().equals("[REWIND]")) {
188 // A special type of EOFException allowing us to seek backwards.
Constantin Kaplinsky7b55c4f2008-06-18 09:28:30 +0000189 newTimeOffset = fbs.getSeekOffset();
190 autoPlay = !fbs.isPaused();
Constantin Kaplinsky72e47ef2008-04-18 17:48:16 +0000191 } else {
192 // Return to the beginning after the playback is finished.
Constantin Kaplinsky7b55c4f2008-06-18 09:28:30 +0000193 newTimeOffset = 0;
Constantin Kaplinsky72e47ef2008-04-18 17:48:16 +0000194 autoPlay = false;
195 }
Constantin Kaplinsky7b55c4f2008-06-18 09:28:30 +0000196 fbs.close();
Constantin Kaplinskyb5db87f2008-06-19 12:25:12 +0000197 newFbsConnection(newTimeOffset);
Constantin Kaplinsky7b55c4f2008-06-18 09:28:30 +0000198 rfb.newSession(fbs);
Constantin Kaplinsky282aaa12002-09-22 11:33:22 +0000199 vc.updateFramebufferSize();
wimba.com30ff9ed2004-11-01 20:54:08 +0000200 } catch (NullPointerException e) {
201 // catching this causes a hang with 1.4.1 JVM's under Win32 IE
202 throw e;
Constantin Kaplinsky72e47ef2008-04-18 17:48:16 +0000203 }
Constantin Kaplinsky903009e2002-05-20 10:55:47 +0000204 }
Constantin Kaplinsky1215b992008-04-18 09:51:44 +0000205
Constantin Kaplinsky903009e2002-05-20 10:55:47 +0000206 } catch (FileNotFoundException e) {
207 fatalError(e.toString());
Constantin Kaplinsky1215b992008-04-18 09:51:44 +0000208 } catch (Exception e) {
209 e.printStackTrace();
210 fatalError(e.toString());
211 }
Constantin Kaplinsky72e47ef2008-04-18 17:48:16 +0000212
Constantin Kaplinsky1215b992008-04-18 09:51:44 +0000213 }
214
Constantin Kaplinsky7b55c4f2008-06-18 09:28:30 +0000215 /**
216 * Open new connection specified by this.url, save new FbsInputStream in
217 * this.fbs.
218 *
Constantin Kaplinskyb5db87f2008-06-19 12:25:12 +0000219 * @param timeOffset set this as current time position in the newly created
220 * FbsInputStream object.
Constantin Kaplinsky7b55c4f2008-06-18 09:28:30 +0000221 * @throws java.io.IOException
222 */
Constantin Kaplinskyb5db87f2008-06-19 12:25:12 +0000223 void newFbsConnection(long timeOffset) throws IOException {
Constantin Kaplinsky7b55c4f2008-06-18 09:28:30 +0000224 URLConnection connection = url.openConnection();
225 fbs = new FbsInputStream(connection.getInputStream());
Constantin Kaplinskyb5db87f2008-06-19 12:25:12 +0000226 fbs.setTimeOffset(timeOffset);
Constantin Kaplinsky7b55c4f2008-06-18 09:28:30 +0000227 }
228
wimba.comb5a90342007-04-02 18:54:41 +0000229 public void setPausedInt(String paused) {
230 // default to true (pause)
231 int pause = 1;
232
233 try {
234 pause = Integer.parseInt(paused);
235 } catch (NumberFormatException e) {
236 }
237
238 if (pause == 0) {
239 setPaused(false);
240 } else {
241 setPaused(true);
242 }
243 }
244
Constantin Kaplinskyac6420d2002-05-29 17:05:39 +0000245 public void setPaused(boolean paused) {
Constantin Kaplinsky972c2572002-05-30 14:19:02 +0000246 if (showControls)
247 buttonPanel.setPaused(paused);
Constantin Kaplinsky37cc43e2002-05-30 17:30:11 +0000248 if (paused) {
Constantin Kaplinsky7b55c4f2008-06-18 09:28:30 +0000249 fbs.pausePlayback();
Constantin Kaplinsky37cc43e2002-05-30 17:30:11 +0000250 } else {
Constantin Kaplinsky7b55c4f2008-06-18 09:28:30 +0000251 fbs.resumePlayback();
Constantin Kaplinsky1215b992008-04-18 09:51:44 +0000252 }
253 }
254
Constantin Kaplinsky7957ca12002-05-30 16:19:11 +0000255 public double getSpeed() {
256 return playbackSpeed;
257 }
258
Constantin Kaplinskyce39d3b2002-05-30 15:54:56 +0000259 public void setSpeed(double speed) {
Constantin Kaplinsky7957ca12002-05-30 16:19:11 +0000260 playbackSpeed = speed;
Constantin Kaplinsky7b55c4f2008-06-18 09:28:30 +0000261 fbs.setSpeed(speed);
Constantin Kaplinskyce39d3b2002-05-30 15:54:56 +0000262 }
263
wimba.comc23aeb02004-09-16 00:00:00 +0000264 public void jumpTo(long pos) {
Constantin Kaplinsky7b55c4f2008-06-18 09:28:30 +0000265 long diff = Math.abs(pos - fbs.getTimeOffset());
wimba.comc23aeb02004-09-16 00:00:00 +0000266
267 // Current threshold is 5 seconds
268 if (diff > 5000) {
Constantin Kaplinsky7b55c4f2008-06-18 09:28:30 +0000269 fbs.pausePlayback();
wimba.comc23aeb02004-09-16 00:00:00 +0000270 setPos(pos);
Constantin Kaplinsky7b55c4f2008-06-18 09:28:30 +0000271 fbs.resumePlayback();
wimba.comc23aeb02004-09-16 00:00:00 +0000272 }
273 }
274
Constantin Kaplinskyc833e012002-05-30 17:59:22 +0000275 public void setPos(long pos) {
Constantin Kaplinsky7b55c4f2008-06-18 09:28:30 +0000276 fbs.setTimeOffset(pos);
Constantin Kaplinsky30f786a2002-05-29 10:59:52 +0000277 }
278
Constantin Kaplinskyfe079832002-05-29 00:52:32 +0000279 public void updatePos() {
Constantin Kaplinskyaa7b5612008-06-17 09:27:52 +0000280 if (showControls && buttonPanel != null)
Constantin Kaplinsky7b55c4f2008-06-18 09:28:30 +0000281 buttonPanel.setPos(fbs.getTimeOffset());
Constantin Kaplinskyfe079832002-05-29 00:52:32 +0000282 }
283
Constantin Kaplinsky1215b992008-04-18 09:51:44 +0000284 //
285 // readParameters() - read parameters from the html source or from the
286 // command line. On the command line, the arguments are just a sequence of
287 // param_name/param_value pairs where the names and values correspond to
288 // those expected in the html applet tag source.
289 //
Constantin Kaplinsky1215b992008-04-18 09:51:44 +0000290 public void readParameters() {
Constantin Kaplinsky1215b992008-04-18 09:51:44 +0000291
Constantin Kaplinsky5d99c952002-05-25 09:49:23 +0000292 sessionURL = readParameter("URL", true);
Constantin Kaplinsky5a7133a2002-07-24 17:02:04 +0000293
Constantin Kaplinsky972c2572002-05-30 14:19:02 +0000294 initialTimeOffset = readLongParameter("Position", 0);
Constantin Kaplinsky7957ca12002-05-30 16:19:11 +0000295 if (initialTimeOffset < 0)
296 initialTimeOffset = 0;
Constantin Kaplinsky5a7133a2002-07-24 17:02:04 +0000297
Constantin Kaplinsky7957ca12002-05-30 16:19:11 +0000298 playbackSpeed = readDoubleParameter("Speed", 1.0);
299 if (playbackSpeed <= 0.0)
300 playbackSpeed = 1.0;
Constantin Kaplinsky903009e2002-05-20 10:55:47 +0000301
Constantin Kaplinsky5a7133a2002-07-24 17:02:04 +0000302 autoPlay = false;
303 String str = readParameter("Autoplay", false);
304 if (str != null && str.equalsIgnoreCase("Yes"))
305 autoPlay = true;
306
Constantin Kaplinsky903009e2002-05-20 10:55:47 +0000307 showControls = true;
wimba.com9bd9c5c2005-09-14 18:42:46 +0000308 str = readParameter("Show_Controls", false);
Constantin Kaplinsky903009e2002-05-20 10:55:47 +0000309 if (str != null && str.equalsIgnoreCase("No"))
310 showControls = false;
Constantin Kaplinsky1215b992008-04-18 09:51:44 +0000311
312 if (inAnApplet) {
wimba.com9bd9c5c2005-09-14 18:42:46 +0000313 str = readParameter("Open_New_Window", false);
Constantin Kaplinsky1215b992008-04-18 09:51:44 +0000314 if (str != null && str.equalsIgnoreCase("Yes"))
Constantin Kaplinsky72e47ef2008-04-18 17:48:16 +0000315 inSeparateFrame = true;
Constantin Kaplinsky1215b992008-04-18 09:51:44 +0000316 }
317
Constantin Kaplinsky1215b992008-04-18 09:51:44 +0000318 // Fine tuning options.
wimba.com9bd9c5c2005-09-14 18:42:46 +0000319 deferScreenUpdates = (int)readLongParameter("Defer_screen_updates", 20);
Constantin Kaplinsky972c2572002-05-30 14:19:02 +0000320 if (deferScreenUpdates < 0)
321 deferScreenUpdates = 0; // Just in case.
wimba.com252eb3b2004-09-21 21:27:54 +0000322
323 // Display width and height.
324 dispW = readIntParameter("DISPLAY_WIDTH", dispW);
325 dispH = readIntParameter("DISPLAY_HEIGHT", dispH);
Constantin Kaplinsky1215b992008-04-18 09:51:44 +0000326 }
327
328 public String readParameter(String name, boolean required) {
329 if (inAnApplet) {
330 String s = getParameter(name);
331 if ((s == null) && required) {
Constantin Kaplinsky72e47ef2008-04-18 17:48:16 +0000332 fatalError(name + " parameter not specified");
Constantin Kaplinsky1215b992008-04-18 09:51:44 +0000333 }
334 return s;
335 }
336
337 for (int i = 0; i < mainArgs.length; i += 2) {
338 if (mainArgs[i].equalsIgnoreCase(name)) {
Constantin Kaplinsky72e47ef2008-04-18 17:48:16 +0000339 try {
340 return mainArgs[i + 1];
341 } catch (Exception e) {
342 if (required) {
343 fatalError(name + " parameter not specified");
344 }
345 return null;
346 }
Constantin Kaplinsky1215b992008-04-18 09:51:44 +0000347 }
348 }
349 if (required) {
350 fatalError(name + " parameter not specified");
351 }
352 return null;
353 }
354
Constantin Kaplinsky972c2572002-05-30 14:19:02 +0000355 long readLongParameter(String name, long defaultValue) {
Constantin Kaplinsky1215b992008-04-18 09:51:44 +0000356 String str = readParameter(name, false);
Constantin Kaplinsky972c2572002-05-30 14:19:02 +0000357 long result = defaultValue;
Constantin Kaplinsky1215b992008-04-18 09:51:44 +0000358 if (str != null) {
359 try {
Constantin Kaplinsky72e47ef2008-04-18 17:48:16 +0000360 result = Long.parseLong(str);
361 } catch (NumberFormatException e) {
362 }
Constantin Kaplinsky1215b992008-04-18 09:51:44 +0000363 }
364 return result;
365 }
366
Constantin Kaplinsky7957ca12002-05-30 16:19:11 +0000367 double readDoubleParameter(String name, double defaultValue) {
368 String str = readParameter(name, false);
369 double result = defaultValue;
370 if (str != null) {
371 try {
Constantin Kaplinsky72e47ef2008-04-18 17:48:16 +0000372 result = Double.valueOf(str).doubleValue();
373 } catch (NumberFormatException e) {
374 }
Constantin Kaplinsky7957ca12002-05-30 16:19:11 +0000375 }
376 return result;
377 }
378
wimba.com252eb3b2004-09-21 21:27:54 +0000379 int readIntParameter(String name, int defaultValue) {
380 String str = readParameter(name, false);
381 int result = defaultValue;
382 if (str != null) {
383 try {
384 result = Integer.parseInt(str);
385 } catch (NumberFormatException e) {
386 }
387 }
388 return result;
389 }
390
Constantin Kaplinsky1215b992008-04-18 09:51:44 +0000391 //
Constantin Kaplinsky1215b992008-04-18 09:51:44 +0000392 // fatalError() - print out a fatal error message.
393 //
Constantin Kaplinsky1215b992008-04-18 09:51:44 +0000394 public void fatalError(String str) {
395 System.out.println(str);
396
397 if (inAnApplet) {
398 vncContainer.removeAll();
399 if (rfb != null) {
Constantin Kaplinsky72e47ef2008-04-18 17:48:16 +0000400 rfb = null;
Constantin Kaplinsky1215b992008-04-18 09:51:44 +0000401 }
402 Label errLabel = new Label(str);
403 errLabel.setFont(new Font("Helvetica", Font.PLAIN, 12));
404 vncContainer.setLayout(new FlowLayout(FlowLayout.LEFT, 30, 30));
405 vncContainer.add(errLabel);
406 if (inSeparateFrame) {
Constantin Kaplinsky72e47ef2008-04-18 17:48:16 +0000407 vncFrame.pack();
Constantin Kaplinsky1215b992008-04-18 09:51:44 +0000408 } else {
Constantin Kaplinsky72e47ef2008-04-18 17:48:16 +0000409 validate();
Constantin Kaplinsky1215b992008-04-18 09:51:44 +0000410 }
411 Thread.currentThread().stop();
412 } else {
413 System.exit(1);
414 }
415 }
416
417
418 //
419 // This method is called before the applet is destroyed.
420 //
Constantin Kaplinsky1215b992008-04-18 09:51:44 +0000421 public void destroy() {
wimba.comd1f56df2004-11-01 16:18:54 +0000422 isQuitting = true;
Constantin Kaplinsky1215b992008-04-18 09:51:44 +0000423 vncContainer.removeAll();
Constantin Kaplinsky7b55c4f2008-06-18 09:28:30 +0000424 if (fbs != null) {
425 fbs.quit();
426 try {
427 fbs.close();
428 } catch (IOException e) {
429 }
wimba.comd1f56df2004-11-01 16:18:54 +0000430 }
431 try {
432 rfbThread.join();
433 } catch (InterruptedException e) {
Constantin Kaplinsky1215b992008-04-18 09:51:44 +0000434 }
435 if (inSeparateFrame) {
wimba.com30ff9ed2004-11-01 20:54:08 +0000436 vncFrame.removeWindowListener(this);
Constantin Kaplinsky1215b992008-04-18 09:51:44 +0000437 vncFrame.dispose();
438 }
439 }
440
wimba.com252eb3b2004-09-21 21:27:54 +0000441 //
442 // Set the new width and height of the applet. Call when browser is resized to
443 // resize the viewer.
444 //
445 public void displaySize(int width, int height) {
446 dispW = width;
447 dispH = height;
448 if (!inSeparateFrame) {
449 vc.resizeEmbeddedApplet();
450 }
451 }
Constantin Kaplinsky1215b992008-04-18 09:51:44 +0000452
453 //
454 // Close application properly on window close event.
455 //
Constantin Kaplinsky1215b992008-04-18 09:51:44 +0000456 public void windowClosing(WindowEvent evt) {
Constantin Kaplinsky903009e2002-05-20 10:55:47 +0000457 vncContainer.removeAll();
Constantin Kaplinsky1215b992008-04-18 09:51:44 +0000458 if (rfb != null)
Constantin Kaplinsky903009e2002-05-20 10:55:47 +0000459 rfb = null;
Constantin Kaplinsky1215b992008-04-18 09:51:44 +0000460
461 vncFrame.dispose();
462 if (!inAnApplet) {
463 System.exit(0);
464 }
465 }
466
467 //
Constantin Kaplinsky1215b992008-04-18 09:51:44 +0000468 // Ignore window events we're not interested in.
469 //
Constantin Kaplinsky72e47ef2008-04-18 17:48:16 +0000470 public void windowActivated(WindowEvent evt) {
471 }
Constantin Kaplinsky1215b992008-04-18 09:51:44 +0000472
Constantin Kaplinsky72e47ef2008-04-18 17:48:16 +0000473 public void windowDeactivated(WindowEvent evt) {
474 }
475
476 public void windowOpened(WindowEvent evt) {
477 }
478
479 public void windowClosed(WindowEvent evt) {
480 }
481
482 public void windowIconified(WindowEvent evt) {
483 }
484
485 public void windowDeiconified(WindowEvent evt) {
486 }
487
Constantin Kaplinsky1215b992008-04-18 09:51:44 +0000488}