blob: 8cff6e19d35a402ec1144bd45fa4a99d639f4de7 [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 Kaplinsky7b55c4f2008-06-18 09:28:30 +0000138 newFbsConnection();
139 fbs.setTimeOffset(initialTimeOffset);
140 rfb = new RfbProto(fbs);
Constantin Kaplinsky1215b992008-04-18 09:51:44 +0000141
142 vc = new VncCanvas(this);
143 gbc.weightx = 1.0;
144 gbc.weighty = 1.0;
145
wimba.com252eb3b2004-09-21 21:27:54 +0000146 // Create a panel which itself is resizeable and can hold
147 // non-resizeable VncCanvas component at the top left corner.
wimba.come8e19102005-02-08 17:15:23 +0000148 //Panel canvasPanel = new Panel();
149 //canvasPanel.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0));
150 //canvasPanel.add(vc);
wimba.com252eb3b2004-09-21 21:27:54 +0000151
152 // Create a ScrollPane which will hold a panel with VncCanvas
153 // inside.
wimba.come8e19102005-02-08 17:15:23 +0000154 //desktopScrollPane = new ScrollPane(ScrollPane.SCROLLBARS_AS_NEEDED);
155 desktopScrollPane = new LWScrollPane();
wimba.com252eb3b2004-09-21 21:27:54 +0000156 gbc.fill = GridBagConstraints.BOTH;
wimba.come8e19102005-02-08 17:15:23 +0000157 gridbag.setConstraints(vc, gbc);
158 //gridbag.setConstraints(canvasPanel, gbc);
159 desktopScrollPane.addComp(vc);
160 desktopScrollPane.setSize(dispW, dispH);
161 //desktopScrollPane.add(canvasPanel);
wimba.com252eb3b2004-09-21 21:27:54 +0000162
163 // Now add the scroll bar to the container.
Constantin Kaplinsky1215b992008-04-18 09:51:44 +0000164 if (inSeparateFrame) {
Constantin Kaplinsky72e47ef2008-04-18 17:48:16 +0000165 gridbag.setConstraints(desktopScrollPane, gbc);
Constantin Kaplinsky72e47ef2008-04-18 17:48:16 +0000166 vncFrame.add(desktopScrollPane);
167 vncFrame.setTitle(rfb.desktopName);
Constantin Kaplinsky72e47ef2008-04-18 17:48:16 +0000168 vc.resizeDesktopFrame();
Constantin Kaplinsky1215b992008-04-18 09:51:44 +0000169 } else {
wimba.com252eb3b2004-09-21 21:27:54 +0000170 // Size the scroll pane to display size.
171 desktopScrollPane.setSize(dispW, dispH);
Constantin Kaplinsky1215b992008-04-18 09:51:44 +0000172
Constantin Kaplinsky72e47ef2008-04-18 17:48:16 +0000173 // Just add the VncCanvas component to the Applet.
wimba.com252eb3b2004-09-21 21:27:54 +0000174 gbc.fill = GridBagConstraints.NONE;
175 gridbag.setConstraints(desktopScrollPane, gbc);
176 add(desktopScrollPane);
Constantin Kaplinsky72e47ef2008-04-18 17:48:16 +0000177 validate();
wimba.com252eb3b2004-09-21 21:27:54 +0000178 vc.resizeEmbeddedApplet();
Constantin Kaplinsky1215b992008-04-18 09:51:44 +0000179 }
180
wimba.comd1f56df2004-11-01 16:18:54 +0000181 while (!isQuitting) {
Constantin Kaplinsky72e47ef2008-04-18 17:48:16 +0000182 try {
183 setPaused(!autoPlay);
Constantin Kaplinsky7b55c4f2008-06-18 09:28:30 +0000184 fbs.setSpeed(playbackSpeed);
Constantin Kaplinsky72e47ef2008-04-18 17:48:16 +0000185 vc.processNormalProtocol();
186 } catch (EOFException e) {
Constantin Kaplinsky7b55c4f2008-06-18 09:28:30 +0000187 long newTimeOffset;
Constantin Kaplinsky72e47ef2008-04-18 17:48:16 +0000188 if (e.getMessage() != null && e.getMessage().equals("[REWIND]")) {
189 // A special type of EOFException allowing us to seek backwards.
Constantin Kaplinsky7b55c4f2008-06-18 09:28:30 +0000190 newTimeOffset = fbs.getSeekOffset();
191 autoPlay = !fbs.isPaused();
Constantin Kaplinsky72e47ef2008-04-18 17:48:16 +0000192 } else {
193 // Return to the beginning after the playback is finished.
Constantin Kaplinsky7b55c4f2008-06-18 09:28:30 +0000194 newTimeOffset = 0;
Constantin Kaplinsky72e47ef2008-04-18 17:48:16 +0000195 autoPlay = false;
196 }
Constantin Kaplinsky7b55c4f2008-06-18 09:28:30 +0000197 fbs.close();
198 newFbsConnection();
199 fbs.setTimeOffset(newTimeOffset);
200 rfb.newSession(fbs);
Constantin Kaplinsky282aaa12002-09-22 11:33:22 +0000201 vc.updateFramebufferSize();
wimba.com30ff9ed2004-11-01 20:54:08 +0000202 } catch (NullPointerException e) {
203 // catching this causes a hang with 1.4.1 JVM's under Win32 IE
204 throw e;
Constantin Kaplinsky72e47ef2008-04-18 17:48:16 +0000205 }
Constantin Kaplinsky903009e2002-05-20 10:55:47 +0000206 }
Constantin Kaplinsky1215b992008-04-18 09:51:44 +0000207
Constantin Kaplinsky903009e2002-05-20 10:55:47 +0000208 } catch (FileNotFoundException e) {
209 fatalError(e.toString());
Constantin Kaplinsky1215b992008-04-18 09:51:44 +0000210 } catch (Exception e) {
211 e.printStackTrace();
212 fatalError(e.toString());
213 }
Constantin Kaplinsky72e47ef2008-04-18 17:48:16 +0000214
Constantin Kaplinsky1215b992008-04-18 09:51:44 +0000215 }
216
Constantin Kaplinsky7b55c4f2008-06-18 09:28:30 +0000217 /**
218 * Open new connection specified by this.url, save new FbsInputStream in
219 * this.fbs.
220 *
221 * @throws java.io.IOException
222 */
223 void newFbsConnection() throws IOException {
224 URLConnection connection = url.openConnection();
225 fbs = new FbsInputStream(connection.getInputStream());
226 }
227
wimba.comb5a90342007-04-02 18:54:41 +0000228 public void setPausedInt(String paused) {
229 // default to true (pause)
230 int pause = 1;
231
232 try {
233 pause = Integer.parseInt(paused);
234 } catch (NumberFormatException e) {
235 }
236
237 if (pause == 0) {
238 setPaused(false);
239 } else {
240 setPaused(true);
241 }
242 }
243
Constantin Kaplinskyac6420d2002-05-29 17:05:39 +0000244 public void setPaused(boolean paused) {
Constantin Kaplinsky972c2572002-05-30 14:19:02 +0000245 if (showControls)
246 buttonPanel.setPaused(paused);
Constantin Kaplinsky37cc43e2002-05-30 17:30:11 +0000247 if (paused) {
Constantin Kaplinsky7b55c4f2008-06-18 09:28:30 +0000248 fbs.pausePlayback();
Constantin Kaplinsky37cc43e2002-05-30 17:30:11 +0000249 } else {
Constantin Kaplinsky7b55c4f2008-06-18 09:28:30 +0000250 fbs.resumePlayback();
Constantin Kaplinsky1215b992008-04-18 09:51:44 +0000251 }
252 }
253
Constantin Kaplinsky7957ca12002-05-30 16:19:11 +0000254 public double getSpeed() {
255 return playbackSpeed;
256 }
257
Constantin Kaplinskyce39d3b2002-05-30 15:54:56 +0000258 public void setSpeed(double speed) {
Constantin Kaplinsky7957ca12002-05-30 16:19:11 +0000259 playbackSpeed = speed;
Constantin Kaplinsky7b55c4f2008-06-18 09:28:30 +0000260 fbs.setSpeed(speed);
Constantin Kaplinskyce39d3b2002-05-30 15:54:56 +0000261 }
262
wimba.comc23aeb02004-09-16 00:00:00 +0000263 public void jumpTo(long pos) {
Constantin Kaplinsky7b55c4f2008-06-18 09:28:30 +0000264 long diff = Math.abs(pos - fbs.getTimeOffset());
wimba.comc23aeb02004-09-16 00:00:00 +0000265
266 // Current threshold is 5 seconds
267 if (diff > 5000) {
Constantin Kaplinsky7b55c4f2008-06-18 09:28:30 +0000268 fbs.pausePlayback();
wimba.comc23aeb02004-09-16 00:00:00 +0000269 setPos(pos);
Constantin Kaplinsky7b55c4f2008-06-18 09:28:30 +0000270 fbs.resumePlayback();
wimba.comc23aeb02004-09-16 00:00:00 +0000271 }
272 }
273
Constantin Kaplinskyc833e012002-05-30 17:59:22 +0000274 public void setPos(long pos) {
Constantin Kaplinsky7b55c4f2008-06-18 09:28:30 +0000275 fbs.setTimeOffset(pos);
Constantin Kaplinsky30f786a2002-05-29 10:59:52 +0000276 }
277
Constantin Kaplinskyfe079832002-05-29 00:52:32 +0000278 public void updatePos() {
Constantin Kaplinskyaa7b5612008-06-17 09:27:52 +0000279 if (showControls && buttonPanel != null)
Constantin Kaplinsky7b55c4f2008-06-18 09:28:30 +0000280 buttonPanel.setPos(fbs.getTimeOffset());
Constantin Kaplinskyfe079832002-05-29 00:52:32 +0000281 }
282
Constantin Kaplinsky1215b992008-04-18 09:51:44 +0000283 //
284 // readParameters() - read parameters from the html source or from the
285 // command line. On the command line, the arguments are just a sequence of
286 // param_name/param_value pairs where the names and values correspond to
287 // those expected in the html applet tag source.
288 //
Constantin Kaplinsky1215b992008-04-18 09:51:44 +0000289 public void readParameters() {
Constantin Kaplinsky1215b992008-04-18 09:51:44 +0000290
Constantin Kaplinsky5d99c952002-05-25 09:49:23 +0000291 sessionURL = readParameter("URL", true);
Constantin Kaplinsky5a7133a2002-07-24 17:02:04 +0000292
Constantin Kaplinsky972c2572002-05-30 14:19:02 +0000293 initialTimeOffset = readLongParameter("Position", 0);
Constantin Kaplinsky7957ca12002-05-30 16:19:11 +0000294 if (initialTimeOffset < 0)
295 initialTimeOffset = 0;
Constantin Kaplinsky5a7133a2002-07-24 17:02:04 +0000296
Constantin Kaplinsky7957ca12002-05-30 16:19:11 +0000297 playbackSpeed = readDoubleParameter("Speed", 1.0);
298 if (playbackSpeed <= 0.0)
299 playbackSpeed = 1.0;
Constantin Kaplinsky903009e2002-05-20 10:55:47 +0000300
Constantin Kaplinsky5a7133a2002-07-24 17:02:04 +0000301 autoPlay = false;
302 String str = readParameter("Autoplay", false);
303 if (str != null && str.equalsIgnoreCase("Yes"))
304 autoPlay = true;
305
Constantin Kaplinsky903009e2002-05-20 10:55:47 +0000306 showControls = true;
wimba.com9bd9c5c2005-09-14 18:42:46 +0000307 str = readParameter("Show_Controls", false);
Constantin Kaplinsky903009e2002-05-20 10:55:47 +0000308 if (str != null && str.equalsIgnoreCase("No"))
309 showControls = false;
Constantin Kaplinsky1215b992008-04-18 09:51:44 +0000310
311 if (inAnApplet) {
wimba.com9bd9c5c2005-09-14 18:42:46 +0000312 str = readParameter("Open_New_Window", false);
Constantin Kaplinsky1215b992008-04-18 09:51:44 +0000313 if (str != null && str.equalsIgnoreCase("Yes"))
Constantin Kaplinsky72e47ef2008-04-18 17:48:16 +0000314 inSeparateFrame = true;
Constantin Kaplinsky1215b992008-04-18 09:51:44 +0000315 }
316
Constantin Kaplinsky1215b992008-04-18 09:51:44 +0000317 // Fine tuning options.
wimba.com9bd9c5c2005-09-14 18:42:46 +0000318 deferScreenUpdates = (int)readLongParameter("Defer_screen_updates", 20);
Constantin Kaplinsky972c2572002-05-30 14:19:02 +0000319 if (deferScreenUpdates < 0)
320 deferScreenUpdates = 0; // Just in case.
wimba.com252eb3b2004-09-21 21:27:54 +0000321
322 // Display width and height.
323 dispW = readIntParameter("DISPLAY_WIDTH", dispW);
324 dispH = readIntParameter("DISPLAY_HEIGHT", dispH);
Constantin Kaplinsky1215b992008-04-18 09:51:44 +0000325 }
326
327 public String readParameter(String name, boolean required) {
328 if (inAnApplet) {
329 String s = getParameter(name);
330 if ((s == null) && required) {
Constantin Kaplinsky72e47ef2008-04-18 17:48:16 +0000331 fatalError(name + " parameter not specified");
Constantin Kaplinsky1215b992008-04-18 09:51:44 +0000332 }
333 return s;
334 }
335
336 for (int i = 0; i < mainArgs.length; i += 2) {
337 if (mainArgs[i].equalsIgnoreCase(name)) {
Constantin Kaplinsky72e47ef2008-04-18 17:48:16 +0000338 try {
339 return mainArgs[i + 1];
340 } catch (Exception e) {
341 if (required) {
342 fatalError(name + " parameter not specified");
343 }
344 return null;
345 }
Constantin Kaplinsky1215b992008-04-18 09:51:44 +0000346 }
347 }
348 if (required) {
349 fatalError(name + " parameter not specified");
350 }
351 return null;
352 }
353
Constantin Kaplinsky972c2572002-05-30 14:19:02 +0000354 long readLongParameter(String name, long defaultValue) {
Constantin Kaplinsky1215b992008-04-18 09:51:44 +0000355 String str = readParameter(name, false);
Constantin Kaplinsky972c2572002-05-30 14:19:02 +0000356 long result = defaultValue;
Constantin Kaplinsky1215b992008-04-18 09:51:44 +0000357 if (str != null) {
358 try {
Constantin Kaplinsky72e47ef2008-04-18 17:48:16 +0000359 result = Long.parseLong(str);
360 } catch (NumberFormatException e) {
361 }
Constantin Kaplinsky1215b992008-04-18 09:51:44 +0000362 }
363 return result;
364 }
365
Constantin Kaplinsky7957ca12002-05-30 16:19:11 +0000366 double readDoubleParameter(String name, double defaultValue) {
367 String str = readParameter(name, false);
368 double result = defaultValue;
369 if (str != null) {
370 try {
Constantin Kaplinsky72e47ef2008-04-18 17:48:16 +0000371 result = Double.valueOf(str).doubleValue();
372 } catch (NumberFormatException e) {
373 }
Constantin Kaplinsky7957ca12002-05-30 16:19:11 +0000374 }
375 return result;
376 }
377
wimba.com252eb3b2004-09-21 21:27:54 +0000378 int readIntParameter(String name, int defaultValue) {
379 String str = readParameter(name, false);
380 int result = defaultValue;
381 if (str != null) {
382 try {
383 result = Integer.parseInt(str);
384 } catch (NumberFormatException e) {
385 }
386 }
387 return result;
388 }
389
Constantin Kaplinsky1215b992008-04-18 09:51:44 +0000390 //
Constantin Kaplinsky1215b992008-04-18 09:51:44 +0000391 // fatalError() - print out a fatal error message.
392 //
Constantin Kaplinsky1215b992008-04-18 09:51:44 +0000393 public void fatalError(String str) {
394 System.out.println(str);
395
396 if (inAnApplet) {
397 vncContainer.removeAll();
398 if (rfb != null) {
Constantin Kaplinsky72e47ef2008-04-18 17:48:16 +0000399 rfb = null;
Constantin Kaplinsky1215b992008-04-18 09:51:44 +0000400 }
401 Label errLabel = new Label(str);
402 errLabel.setFont(new Font("Helvetica", Font.PLAIN, 12));
403 vncContainer.setLayout(new FlowLayout(FlowLayout.LEFT, 30, 30));
404 vncContainer.add(errLabel);
405 if (inSeparateFrame) {
Constantin Kaplinsky72e47ef2008-04-18 17:48:16 +0000406 vncFrame.pack();
Constantin Kaplinsky1215b992008-04-18 09:51:44 +0000407 } else {
Constantin Kaplinsky72e47ef2008-04-18 17:48:16 +0000408 validate();
Constantin Kaplinsky1215b992008-04-18 09:51:44 +0000409 }
410 Thread.currentThread().stop();
411 } else {
412 System.exit(1);
413 }
414 }
415
416
417 //
418 // This method is called before the applet is destroyed.
419 //
Constantin Kaplinsky1215b992008-04-18 09:51:44 +0000420 public void destroy() {
wimba.comd1f56df2004-11-01 16:18:54 +0000421 isQuitting = true;
Constantin Kaplinsky1215b992008-04-18 09:51:44 +0000422 vncContainer.removeAll();
Constantin Kaplinsky7b55c4f2008-06-18 09:28:30 +0000423 if (fbs != null) {
424 fbs.quit();
425 try {
426 fbs.close();
427 } catch (IOException e) {
428 }
wimba.comd1f56df2004-11-01 16:18:54 +0000429 }
430 try {
431 rfbThread.join();
432 } catch (InterruptedException e) {
Constantin Kaplinsky1215b992008-04-18 09:51:44 +0000433 }
434 if (inSeparateFrame) {
wimba.com30ff9ed2004-11-01 20:54:08 +0000435 vncFrame.removeWindowListener(this);
Constantin Kaplinsky1215b992008-04-18 09:51:44 +0000436 vncFrame.dispose();
437 }
438 }
439
wimba.com252eb3b2004-09-21 21:27:54 +0000440 //
441 // Set the new width and height of the applet. Call when browser is resized to
442 // resize the viewer.
443 //
444 public void displaySize(int width, int height) {
445 dispW = width;
446 dispH = height;
447 if (!inSeparateFrame) {
448 vc.resizeEmbeddedApplet();
449 }
450 }
Constantin Kaplinsky1215b992008-04-18 09:51:44 +0000451
452 //
453 // Close application properly on window close event.
454 //
Constantin Kaplinsky1215b992008-04-18 09:51:44 +0000455 public void windowClosing(WindowEvent evt) {
Constantin Kaplinsky903009e2002-05-20 10:55:47 +0000456 vncContainer.removeAll();
Constantin Kaplinsky1215b992008-04-18 09:51:44 +0000457 if (rfb != null)
Constantin Kaplinsky903009e2002-05-20 10:55:47 +0000458 rfb = null;
Constantin Kaplinsky1215b992008-04-18 09:51:44 +0000459
460 vncFrame.dispose();
461 if (!inAnApplet) {
462 System.exit(0);
463 }
464 }
465
466 //
Constantin Kaplinsky1215b992008-04-18 09:51:44 +0000467 // Ignore window events we're not interested in.
468 //
Constantin Kaplinsky72e47ef2008-04-18 17:48:16 +0000469 public void windowActivated(WindowEvent evt) {
470 }
Constantin Kaplinsky1215b992008-04-18 09:51:44 +0000471
Constantin Kaplinsky72e47ef2008-04-18 17:48:16 +0000472 public void windowDeactivated(WindowEvent evt) {
473 }
474
475 public void windowOpened(WindowEvent evt) {
476 }
477
478 public void windowClosed(WindowEvent evt) {
479 }
480
481 public void windowIconified(WindowEvent evt) {
482 }
483
484 public void windowDeiconified(WindowEvent evt) {
485 }
486
Constantin Kaplinsky1215b992008-04-18 09:51:44 +0000487}