Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 1 | // |
| 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 Kaplinsky | cf689b3 | 2008-04-30 12:50:34 +0000 | [diff] [blame] | 21 | package com.tightvnc.rfbplayer; |
wimba.com | c23aeb0 | 2004-09-16 00:00:00 +0000 | [diff] [blame] | 22 | |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 23 | import java.awt.*; |
| 24 | import java.awt.event.*; |
| 25 | import java.io.*; |
Constantin Kaplinsky | 5d99c95 | 2002-05-25 09:49:23 +0000 | [diff] [blame] | 26 | import java.net.*; |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 27 | |
Constantin Kaplinsky | 903009e | 2002-05-20 10:55:47 +0000 | [diff] [blame] | 28 | public class RfbPlayer extends java.applet.Applet |
Constantin Kaplinsky | 72e47ef | 2008-04-18 17:48:16 +0000 | [diff] [blame] | 29 | implements java.lang.Runnable, WindowListener { |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 30 | |
| 31 | boolean inAnApplet = true; |
| 32 | boolean inSeparateFrame = false; |
| 33 | |
wimba.com | 252eb3b | 2004-09-21 21:27:54 +0000 | [diff] [blame] | 34 | /** current applet width */ |
| 35 | int dispW = 300; |
| 36 | /** current applet height */ |
| 37 | int dispH = 200; |
| 38 | |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 39 | // |
| 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 Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 43 | public static void main(String[] argv) { |
Constantin Kaplinsky | 903009e | 2002-05-20 10:55:47 +0000 | [diff] [blame] | 44 | RfbPlayer p = new RfbPlayer(); |
| 45 | p.mainArgs = argv; |
| 46 | p.inAnApplet = false; |
| 47 | p.inSeparateFrame = true; |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 48 | |
Constantin Kaplinsky | 903009e | 2002-05-20 10:55:47 +0000 | [diff] [blame] | 49 | p.init(); |
| 50 | p.start(); |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | String[] mainArgs; |
| 54 | |
Constantin Kaplinsky | 7b55c4f | 2008-06-18 09:28:30 +0000 | [diff] [blame] | 55 | FbsInputStream fbs; |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 56 | RfbProto rfb; |
| 57 | Thread rfbThread; |
| 58 | |
| 59 | Frame vncFrame; |
| 60 | Container vncContainer; |
wimba.com | e8e1910 | 2005-02-08 17:15:23 +0000 | [diff] [blame] | 61 | //ScrollPane desktopScrollPane; |
| 62 | LWScrollPane desktopScrollPane; |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 63 | GridBagLayout gridbag; |
| 64 | ButtonPanel buttonPanel; |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 65 | VncCanvas vc; |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 66 | |
Constantin Kaplinsky | 5d99c95 | 2002-05-25 09:49:23 +0000 | [diff] [blame] | 67 | String sessionURL; |
Constantin Kaplinsky | c833e01 | 2002-05-30 17:59:22 +0000 | [diff] [blame] | 68 | URL url; |
Constantin Kaplinsky | 972c257 | 2002-05-30 14:19:02 +0000 | [diff] [blame] | 69 | long initialTimeOffset; |
Constantin Kaplinsky | 7957ca1 | 2002-05-30 16:19:11 +0000 | [diff] [blame] | 70 | double playbackSpeed; |
Constantin Kaplinsky | 5a7133a | 2002-07-24 17:02:04 +0000 | [diff] [blame] | 71 | boolean autoPlay; |
Constantin Kaplinsky | 903009e | 2002-05-20 10:55:47 +0000 | [diff] [blame] | 72 | boolean showControls; |
wimba.com | d1f56df | 2004-11-01 16:18:54 +0000 | [diff] [blame] | 73 | boolean isQuitting = false; |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 74 | int deferScreenUpdates; |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 75 | |
| 76 | // |
| 77 | // init() |
| 78 | // |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 79 | public void init() { |
| 80 | |
wimba.com | c23aeb0 | 2004-09-16 00:00:00 +0000 | [diff] [blame] | 81 | // LiveConnect work-a-round |
| 82 | RfbSharedStatic.refApplet = this; |
| 83 | |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 84 | readParameters(); |
| 85 | |
| 86 | if (inSeparateFrame) { |
Constantin Kaplinsky | 903009e | 2002-05-20 10:55:47 +0000 | [diff] [blame] | 87 | vncFrame = new Frame("RFB Session Player"); |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 88 | if (!inAnApplet) { |
Constantin Kaplinsky | 72e47ef | 2008-04-18 17:48:16 +0000 | [diff] [blame] | 89 | vncFrame.add("Center", this); |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 90 | } |
| 91 | vncContainer = vncFrame; |
| 92 | } else { |
| 93 | vncContainer = this; |
| 94 | } |
| 95 | |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 96 | if (inSeparateFrame) |
| 97 | vncFrame.addWindowListener(this); |
| 98 | |
wimba.com | d1f56df | 2004-11-01 16:18:54 +0000 | [diff] [blame] | 99 | rfbThread = new Thread(this, "RfbThread"); |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 100 | rfbThread.start(); |
| 101 | } |
| 102 | |
| 103 | public void update(Graphics g) { |
| 104 | } |
| 105 | |
| 106 | // |
Constantin Kaplinsky | 903009e | 2002-05-20 10:55:47 +0000 | [diff] [blame] | 107 | // run() - executed by the rfbThread to read RFB data. |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 108 | // |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 109 | 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 Kaplinsky | 903009e | 2002-05-20 10:55:47 +0000 | [diff] [blame] | 118 | if (showControls) { |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 119 | 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 Kaplinsky | 903009e | 2002-05-20 10:55:47 +0000 | [diff] [blame] | 125 | if (inSeparateFrame) { |
| 126 | vncFrame.pack(); |
Constantin Kaplinsky | aa7b561 | 2008-06-17 09:27:52 +0000 | [diff] [blame] | 127 | vncFrame.setVisible(true); |
Constantin Kaplinsky | 903009e | 2002-05-20 10:55:47 +0000 | [diff] [blame] | 128 | } else { |
| 129 | validate(); |
| 130 | } |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 131 | |
Constantin Kaplinsky | 903009e | 2002-05-20 10:55:47 +0000 | [diff] [blame] | 132 | try { |
Constantin Kaplinsky | 40ad171 | 2002-09-22 08:36:43 +0000 | [diff] [blame] | 133 | if (inAnApplet) { |
Constantin Kaplinsky | 72e47ef | 2008-04-18 17:48:16 +0000 | [diff] [blame] | 134 | url = new URL(getCodeBase(), sessionURL); |
Constantin Kaplinsky | 40ad171 | 2002-09-22 08:36:43 +0000 | [diff] [blame] | 135 | } else { |
Constantin Kaplinsky | 72e47ef | 2008-04-18 17:48:16 +0000 | [diff] [blame] | 136 | url = new URL(sessionURL); |
Constantin Kaplinsky | 40ad171 | 2002-09-22 08:36:43 +0000 | [diff] [blame] | 137 | } |
Constantin Kaplinsky | 7b55c4f | 2008-06-18 09:28:30 +0000 | [diff] [blame] | 138 | newFbsConnection(); |
| 139 | fbs.setTimeOffset(initialTimeOffset); |
| 140 | rfb = new RfbProto(fbs); |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 141 | |
| 142 | vc = new VncCanvas(this); |
| 143 | gbc.weightx = 1.0; |
| 144 | gbc.weighty = 1.0; |
| 145 | |
wimba.com | 252eb3b | 2004-09-21 21:27:54 +0000 | [diff] [blame] | 146 | // Create a panel which itself is resizeable and can hold |
| 147 | // non-resizeable VncCanvas component at the top left corner. |
wimba.com | e8e1910 | 2005-02-08 17:15:23 +0000 | [diff] [blame] | 148 | //Panel canvasPanel = new Panel(); |
| 149 | //canvasPanel.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0)); |
| 150 | //canvasPanel.add(vc); |
wimba.com | 252eb3b | 2004-09-21 21:27:54 +0000 | [diff] [blame] | 151 | |
| 152 | // Create a ScrollPane which will hold a panel with VncCanvas |
| 153 | // inside. |
wimba.com | e8e1910 | 2005-02-08 17:15:23 +0000 | [diff] [blame] | 154 | //desktopScrollPane = new ScrollPane(ScrollPane.SCROLLBARS_AS_NEEDED); |
| 155 | desktopScrollPane = new LWScrollPane(); |
wimba.com | 252eb3b | 2004-09-21 21:27:54 +0000 | [diff] [blame] | 156 | gbc.fill = GridBagConstraints.BOTH; |
wimba.com | e8e1910 | 2005-02-08 17:15:23 +0000 | [diff] [blame] | 157 | gridbag.setConstraints(vc, gbc); |
| 158 | //gridbag.setConstraints(canvasPanel, gbc); |
| 159 | desktopScrollPane.addComp(vc); |
| 160 | desktopScrollPane.setSize(dispW, dispH); |
| 161 | //desktopScrollPane.add(canvasPanel); |
wimba.com | 252eb3b | 2004-09-21 21:27:54 +0000 | [diff] [blame] | 162 | |
| 163 | // Now add the scroll bar to the container. |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 164 | if (inSeparateFrame) { |
Constantin Kaplinsky | 72e47ef | 2008-04-18 17:48:16 +0000 | [diff] [blame] | 165 | gridbag.setConstraints(desktopScrollPane, gbc); |
Constantin Kaplinsky | 72e47ef | 2008-04-18 17:48:16 +0000 | [diff] [blame] | 166 | vncFrame.add(desktopScrollPane); |
| 167 | vncFrame.setTitle(rfb.desktopName); |
Constantin Kaplinsky | 72e47ef | 2008-04-18 17:48:16 +0000 | [diff] [blame] | 168 | vc.resizeDesktopFrame(); |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 169 | } else { |
wimba.com | 252eb3b | 2004-09-21 21:27:54 +0000 | [diff] [blame] | 170 | // Size the scroll pane to display size. |
| 171 | desktopScrollPane.setSize(dispW, dispH); |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 172 | |
Constantin Kaplinsky | 72e47ef | 2008-04-18 17:48:16 +0000 | [diff] [blame] | 173 | // Just add the VncCanvas component to the Applet. |
wimba.com | 252eb3b | 2004-09-21 21:27:54 +0000 | [diff] [blame] | 174 | gbc.fill = GridBagConstraints.NONE; |
| 175 | gridbag.setConstraints(desktopScrollPane, gbc); |
| 176 | add(desktopScrollPane); |
Constantin Kaplinsky | 72e47ef | 2008-04-18 17:48:16 +0000 | [diff] [blame] | 177 | validate(); |
wimba.com | 252eb3b | 2004-09-21 21:27:54 +0000 | [diff] [blame] | 178 | vc.resizeEmbeddedApplet(); |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 179 | } |
| 180 | |
wimba.com | d1f56df | 2004-11-01 16:18:54 +0000 | [diff] [blame] | 181 | while (!isQuitting) { |
Constantin Kaplinsky | 72e47ef | 2008-04-18 17:48:16 +0000 | [diff] [blame] | 182 | try { |
| 183 | setPaused(!autoPlay); |
Constantin Kaplinsky | 7b55c4f | 2008-06-18 09:28:30 +0000 | [diff] [blame] | 184 | fbs.setSpeed(playbackSpeed); |
Constantin Kaplinsky | 72e47ef | 2008-04-18 17:48:16 +0000 | [diff] [blame] | 185 | vc.processNormalProtocol(); |
| 186 | } catch (EOFException e) { |
Constantin Kaplinsky | 7b55c4f | 2008-06-18 09:28:30 +0000 | [diff] [blame] | 187 | long newTimeOffset; |
Constantin Kaplinsky | 72e47ef | 2008-04-18 17:48:16 +0000 | [diff] [blame] | 188 | if (e.getMessage() != null && e.getMessage().equals("[REWIND]")) { |
| 189 | // A special type of EOFException allowing us to seek backwards. |
Constantin Kaplinsky | 7b55c4f | 2008-06-18 09:28:30 +0000 | [diff] [blame] | 190 | newTimeOffset = fbs.getSeekOffset(); |
| 191 | autoPlay = !fbs.isPaused(); |
Constantin Kaplinsky | 72e47ef | 2008-04-18 17:48:16 +0000 | [diff] [blame] | 192 | } else { |
| 193 | // Return to the beginning after the playback is finished. |
Constantin Kaplinsky | 7b55c4f | 2008-06-18 09:28:30 +0000 | [diff] [blame] | 194 | newTimeOffset = 0; |
Constantin Kaplinsky | 72e47ef | 2008-04-18 17:48:16 +0000 | [diff] [blame] | 195 | autoPlay = false; |
| 196 | } |
Constantin Kaplinsky | 7b55c4f | 2008-06-18 09:28:30 +0000 | [diff] [blame] | 197 | fbs.close(); |
| 198 | newFbsConnection(); |
| 199 | fbs.setTimeOffset(newTimeOffset); |
| 200 | rfb.newSession(fbs); |
Constantin Kaplinsky | 282aaa1 | 2002-09-22 11:33:22 +0000 | [diff] [blame] | 201 | vc.updateFramebufferSize(); |
wimba.com | 30ff9ed | 2004-11-01 20:54:08 +0000 | [diff] [blame] | 202 | } catch (NullPointerException e) { |
| 203 | // catching this causes a hang with 1.4.1 JVM's under Win32 IE |
| 204 | throw e; |
Constantin Kaplinsky | 72e47ef | 2008-04-18 17:48:16 +0000 | [diff] [blame] | 205 | } |
Constantin Kaplinsky | 903009e | 2002-05-20 10:55:47 +0000 | [diff] [blame] | 206 | } |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 207 | |
Constantin Kaplinsky | 903009e | 2002-05-20 10:55:47 +0000 | [diff] [blame] | 208 | } catch (FileNotFoundException e) { |
| 209 | fatalError(e.toString()); |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 210 | } catch (Exception e) { |
| 211 | e.printStackTrace(); |
| 212 | fatalError(e.toString()); |
| 213 | } |
Constantin Kaplinsky | 72e47ef | 2008-04-18 17:48:16 +0000 | [diff] [blame] | 214 | |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 215 | } |
| 216 | |
Constantin Kaplinsky | 7b55c4f | 2008-06-18 09:28:30 +0000 | [diff] [blame] | 217 | /** |
| 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.com | b5a9034 | 2007-04-02 18:54:41 +0000 | [diff] [blame] | 228 | 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 Kaplinsky | ac6420d | 2002-05-29 17:05:39 +0000 | [diff] [blame] | 244 | public void setPaused(boolean paused) { |
Constantin Kaplinsky | 972c257 | 2002-05-30 14:19:02 +0000 | [diff] [blame] | 245 | if (showControls) |
| 246 | buttonPanel.setPaused(paused); |
Constantin Kaplinsky | 37cc43e | 2002-05-30 17:30:11 +0000 | [diff] [blame] | 247 | if (paused) { |
Constantin Kaplinsky | 7b55c4f | 2008-06-18 09:28:30 +0000 | [diff] [blame] | 248 | fbs.pausePlayback(); |
Constantin Kaplinsky | 37cc43e | 2002-05-30 17:30:11 +0000 | [diff] [blame] | 249 | } else { |
Constantin Kaplinsky | 7b55c4f | 2008-06-18 09:28:30 +0000 | [diff] [blame] | 250 | fbs.resumePlayback(); |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 251 | } |
| 252 | } |
| 253 | |
Constantin Kaplinsky | 7957ca1 | 2002-05-30 16:19:11 +0000 | [diff] [blame] | 254 | public double getSpeed() { |
| 255 | return playbackSpeed; |
| 256 | } |
| 257 | |
Constantin Kaplinsky | ce39d3b | 2002-05-30 15:54:56 +0000 | [diff] [blame] | 258 | public void setSpeed(double speed) { |
Constantin Kaplinsky | 7957ca1 | 2002-05-30 16:19:11 +0000 | [diff] [blame] | 259 | playbackSpeed = speed; |
Constantin Kaplinsky | 7b55c4f | 2008-06-18 09:28:30 +0000 | [diff] [blame] | 260 | fbs.setSpeed(speed); |
Constantin Kaplinsky | ce39d3b | 2002-05-30 15:54:56 +0000 | [diff] [blame] | 261 | } |
| 262 | |
wimba.com | c23aeb0 | 2004-09-16 00:00:00 +0000 | [diff] [blame] | 263 | public void jumpTo(long pos) { |
Constantin Kaplinsky | 7b55c4f | 2008-06-18 09:28:30 +0000 | [diff] [blame] | 264 | long diff = Math.abs(pos - fbs.getTimeOffset()); |
wimba.com | c23aeb0 | 2004-09-16 00:00:00 +0000 | [diff] [blame] | 265 | |
| 266 | // Current threshold is 5 seconds |
| 267 | if (diff > 5000) { |
Constantin Kaplinsky | 7b55c4f | 2008-06-18 09:28:30 +0000 | [diff] [blame] | 268 | fbs.pausePlayback(); |
wimba.com | c23aeb0 | 2004-09-16 00:00:00 +0000 | [diff] [blame] | 269 | setPos(pos); |
Constantin Kaplinsky | 7b55c4f | 2008-06-18 09:28:30 +0000 | [diff] [blame] | 270 | fbs.resumePlayback(); |
wimba.com | c23aeb0 | 2004-09-16 00:00:00 +0000 | [diff] [blame] | 271 | } |
| 272 | } |
| 273 | |
Constantin Kaplinsky | c833e01 | 2002-05-30 17:59:22 +0000 | [diff] [blame] | 274 | public void setPos(long pos) { |
Constantin Kaplinsky | 7b55c4f | 2008-06-18 09:28:30 +0000 | [diff] [blame] | 275 | fbs.setTimeOffset(pos); |
Constantin Kaplinsky | 30f786a | 2002-05-29 10:59:52 +0000 | [diff] [blame] | 276 | } |
| 277 | |
Constantin Kaplinsky | fe07983 | 2002-05-29 00:52:32 +0000 | [diff] [blame] | 278 | public void updatePos() { |
Constantin Kaplinsky | aa7b561 | 2008-06-17 09:27:52 +0000 | [diff] [blame] | 279 | if (showControls && buttonPanel != null) |
Constantin Kaplinsky | 7b55c4f | 2008-06-18 09:28:30 +0000 | [diff] [blame] | 280 | buttonPanel.setPos(fbs.getTimeOffset()); |
Constantin Kaplinsky | fe07983 | 2002-05-29 00:52:32 +0000 | [diff] [blame] | 281 | } |
| 282 | |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 283 | // |
| 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 Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 289 | public void readParameters() { |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 290 | |
Constantin Kaplinsky | 5d99c95 | 2002-05-25 09:49:23 +0000 | [diff] [blame] | 291 | sessionURL = readParameter("URL", true); |
Constantin Kaplinsky | 5a7133a | 2002-07-24 17:02:04 +0000 | [diff] [blame] | 292 | |
Constantin Kaplinsky | 972c257 | 2002-05-30 14:19:02 +0000 | [diff] [blame] | 293 | initialTimeOffset = readLongParameter("Position", 0); |
Constantin Kaplinsky | 7957ca1 | 2002-05-30 16:19:11 +0000 | [diff] [blame] | 294 | if (initialTimeOffset < 0) |
| 295 | initialTimeOffset = 0; |
Constantin Kaplinsky | 5a7133a | 2002-07-24 17:02:04 +0000 | [diff] [blame] | 296 | |
Constantin Kaplinsky | 7957ca1 | 2002-05-30 16:19:11 +0000 | [diff] [blame] | 297 | playbackSpeed = readDoubleParameter("Speed", 1.0); |
| 298 | if (playbackSpeed <= 0.0) |
| 299 | playbackSpeed = 1.0; |
Constantin Kaplinsky | 903009e | 2002-05-20 10:55:47 +0000 | [diff] [blame] | 300 | |
Constantin Kaplinsky | 5a7133a | 2002-07-24 17:02:04 +0000 | [diff] [blame] | 301 | autoPlay = false; |
| 302 | String str = readParameter("Autoplay", false); |
| 303 | if (str != null && str.equalsIgnoreCase("Yes")) |
| 304 | autoPlay = true; |
| 305 | |
Constantin Kaplinsky | 903009e | 2002-05-20 10:55:47 +0000 | [diff] [blame] | 306 | showControls = true; |
wimba.com | 9bd9c5c | 2005-09-14 18:42:46 +0000 | [diff] [blame] | 307 | str = readParameter("Show_Controls", false); |
Constantin Kaplinsky | 903009e | 2002-05-20 10:55:47 +0000 | [diff] [blame] | 308 | if (str != null && str.equalsIgnoreCase("No")) |
| 309 | showControls = false; |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 310 | |
| 311 | if (inAnApplet) { |
wimba.com | 9bd9c5c | 2005-09-14 18:42:46 +0000 | [diff] [blame] | 312 | str = readParameter("Open_New_Window", false); |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 313 | if (str != null && str.equalsIgnoreCase("Yes")) |
Constantin Kaplinsky | 72e47ef | 2008-04-18 17:48:16 +0000 | [diff] [blame] | 314 | inSeparateFrame = true; |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 315 | } |
| 316 | |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 317 | // Fine tuning options. |
wimba.com | 9bd9c5c | 2005-09-14 18:42:46 +0000 | [diff] [blame] | 318 | deferScreenUpdates = (int)readLongParameter("Defer_screen_updates", 20); |
Constantin Kaplinsky | 972c257 | 2002-05-30 14:19:02 +0000 | [diff] [blame] | 319 | if (deferScreenUpdates < 0) |
| 320 | deferScreenUpdates = 0; // Just in case. |
wimba.com | 252eb3b | 2004-09-21 21:27:54 +0000 | [diff] [blame] | 321 | |
| 322 | // Display width and height. |
| 323 | dispW = readIntParameter("DISPLAY_WIDTH", dispW); |
| 324 | dispH = readIntParameter("DISPLAY_HEIGHT", dispH); |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 325 | } |
| 326 | |
| 327 | public String readParameter(String name, boolean required) { |
| 328 | if (inAnApplet) { |
| 329 | String s = getParameter(name); |
| 330 | if ((s == null) && required) { |
Constantin Kaplinsky | 72e47ef | 2008-04-18 17:48:16 +0000 | [diff] [blame] | 331 | fatalError(name + " parameter not specified"); |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 332 | } |
| 333 | return s; |
| 334 | } |
| 335 | |
| 336 | for (int i = 0; i < mainArgs.length; i += 2) { |
| 337 | if (mainArgs[i].equalsIgnoreCase(name)) { |
Constantin Kaplinsky | 72e47ef | 2008-04-18 17:48:16 +0000 | [diff] [blame] | 338 | 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 Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 346 | } |
| 347 | } |
| 348 | if (required) { |
| 349 | fatalError(name + " parameter not specified"); |
| 350 | } |
| 351 | return null; |
| 352 | } |
| 353 | |
Constantin Kaplinsky | 972c257 | 2002-05-30 14:19:02 +0000 | [diff] [blame] | 354 | long readLongParameter(String name, long defaultValue) { |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 355 | String str = readParameter(name, false); |
Constantin Kaplinsky | 972c257 | 2002-05-30 14:19:02 +0000 | [diff] [blame] | 356 | long result = defaultValue; |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 357 | if (str != null) { |
| 358 | try { |
Constantin Kaplinsky | 72e47ef | 2008-04-18 17:48:16 +0000 | [diff] [blame] | 359 | result = Long.parseLong(str); |
| 360 | } catch (NumberFormatException e) { |
| 361 | } |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 362 | } |
| 363 | return result; |
| 364 | } |
| 365 | |
Constantin Kaplinsky | 7957ca1 | 2002-05-30 16:19:11 +0000 | [diff] [blame] | 366 | double readDoubleParameter(String name, double defaultValue) { |
| 367 | String str = readParameter(name, false); |
| 368 | double result = defaultValue; |
| 369 | if (str != null) { |
| 370 | try { |
Constantin Kaplinsky | 72e47ef | 2008-04-18 17:48:16 +0000 | [diff] [blame] | 371 | result = Double.valueOf(str).doubleValue(); |
| 372 | } catch (NumberFormatException e) { |
| 373 | } |
Constantin Kaplinsky | 7957ca1 | 2002-05-30 16:19:11 +0000 | [diff] [blame] | 374 | } |
| 375 | return result; |
| 376 | } |
| 377 | |
wimba.com | 252eb3b | 2004-09-21 21:27:54 +0000 | [diff] [blame] | 378 | 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 Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 390 | // |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 391 | // fatalError() - print out a fatal error message. |
| 392 | // |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 393 | public void fatalError(String str) { |
| 394 | System.out.println(str); |
| 395 | |
| 396 | if (inAnApplet) { |
| 397 | vncContainer.removeAll(); |
| 398 | if (rfb != null) { |
Constantin Kaplinsky | 72e47ef | 2008-04-18 17:48:16 +0000 | [diff] [blame] | 399 | rfb = null; |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 400 | } |
| 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 Kaplinsky | 72e47ef | 2008-04-18 17:48:16 +0000 | [diff] [blame] | 406 | vncFrame.pack(); |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 407 | } else { |
Constantin Kaplinsky | 72e47ef | 2008-04-18 17:48:16 +0000 | [diff] [blame] | 408 | validate(); |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 409 | } |
| 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 Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 420 | public void destroy() { |
wimba.com | d1f56df | 2004-11-01 16:18:54 +0000 | [diff] [blame] | 421 | isQuitting = true; |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 422 | vncContainer.removeAll(); |
Constantin Kaplinsky | 7b55c4f | 2008-06-18 09:28:30 +0000 | [diff] [blame] | 423 | if (fbs != null) { |
| 424 | fbs.quit(); |
| 425 | try { |
| 426 | fbs.close(); |
| 427 | } catch (IOException e) { |
| 428 | } |
wimba.com | d1f56df | 2004-11-01 16:18:54 +0000 | [diff] [blame] | 429 | } |
| 430 | try { |
| 431 | rfbThread.join(); |
| 432 | } catch (InterruptedException e) { |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 433 | } |
| 434 | if (inSeparateFrame) { |
wimba.com | 30ff9ed | 2004-11-01 20:54:08 +0000 | [diff] [blame] | 435 | vncFrame.removeWindowListener(this); |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 436 | vncFrame.dispose(); |
| 437 | } |
| 438 | } |
| 439 | |
wimba.com | 252eb3b | 2004-09-21 21:27:54 +0000 | [diff] [blame] | 440 | // |
| 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 Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 451 | |
| 452 | // |
| 453 | // Close application properly on window close event. |
| 454 | // |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 455 | public void windowClosing(WindowEvent evt) { |
Constantin Kaplinsky | 903009e | 2002-05-20 10:55:47 +0000 | [diff] [blame] | 456 | vncContainer.removeAll(); |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 457 | if (rfb != null) |
Constantin Kaplinsky | 903009e | 2002-05-20 10:55:47 +0000 | [diff] [blame] | 458 | rfb = null; |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 459 | |
| 460 | vncFrame.dispose(); |
| 461 | if (!inAnApplet) { |
| 462 | System.exit(0); |
| 463 | } |
| 464 | } |
| 465 | |
| 466 | // |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 467 | // Ignore window events we're not interested in. |
| 468 | // |
Constantin Kaplinsky | 72e47ef | 2008-04-18 17:48:16 +0000 | [diff] [blame] | 469 | public void windowActivated(WindowEvent evt) { |
| 470 | } |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 471 | |
Constantin Kaplinsky | 72e47ef | 2008-04-18 17:48:16 +0000 | [diff] [blame] | 472 | 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 Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 487 | } |