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 | b5db87f | 2008-06-19 12:25:12 +0000 | [diff] [blame^] | 138 | newFbsConnection(initialTimeOffset); |
Constantin Kaplinsky | 7b55c4f | 2008-06-18 09:28:30 +0000 | [diff] [blame] | 139 | rfb = new RfbProto(fbs); |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 140 | |
| 141 | vc = new VncCanvas(this); |
| 142 | gbc.weightx = 1.0; |
| 143 | gbc.weighty = 1.0; |
| 144 | |
wimba.com | 252eb3b | 2004-09-21 21:27:54 +0000 | [diff] [blame] | 145 | // Create a panel which itself is resizeable and can hold |
| 146 | // non-resizeable VncCanvas component at the top left corner. |
wimba.com | e8e1910 | 2005-02-08 17:15:23 +0000 | [diff] [blame] | 147 | //Panel canvasPanel = new Panel(); |
| 148 | //canvasPanel.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0)); |
| 149 | //canvasPanel.add(vc); |
wimba.com | 252eb3b | 2004-09-21 21:27:54 +0000 | [diff] [blame] | 150 | |
| 151 | // Create a ScrollPane which will hold a panel with VncCanvas |
| 152 | // inside. |
wimba.com | e8e1910 | 2005-02-08 17:15:23 +0000 | [diff] [blame] | 153 | //desktopScrollPane = new ScrollPane(ScrollPane.SCROLLBARS_AS_NEEDED); |
| 154 | desktopScrollPane = new LWScrollPane(); |
wimba.com | 252eb3b | 2004-09-21 21:27:54 +0000 | [diff] [blame] | 155 | gbc.fill = GridBagConstraints.BOTH; |
wimba.com | e8e1910 | 2005-02-08 17:15:23 +0000 | [diff] [blame] | 156 | gridbag.setConstraints(vc, gbc); |
| 157 | //gridbag.setConstraints(canvasPanel, gbc); |
| 158 | desktopScrollPane.addComp(vc); |
| 159 | desktopScrollPane.setSize(dispW, dispH); |
| 160 | //desktopScrollPane.add(canvasPanel); |
wimba.com | 252eb3b | 2004-09-21 21:27:54 +0000 | [diff] [blame] | 161 | |
| 162 | // Now add the scroll bar to the container. |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 163 | if (inSeparateFrame) { |
Constantin Kaplinsky | 72e47ef | 2008-04-18 17:48:16 +0000 | [diff] [blame] | 164 | gridbag.setConstraints(desktopScrollPane, gbc); |
Constantin Kaplinsky | 72e47ef | 2008-04-18 17:48:16 +0000 | [diff] [blame] | 165 | vncFrame.add(desktopScrollPane); |
| 166 | vncFrame.setTitle(rfb.desktopName); |
Constantin Kaplinsky | 72e47ef | 2008-04-18 17:48:16 +0000 | [diff] [blame] | 167 | vc.resizeDesktopFrame(); |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 168 | } else { |
wimba.com | 252eb3b | 2004-09-21 21:27:54 +0000 | [diff] [blame] | 169 | // Size the scroll pane to display size. |
| 170 | desktopScrollPane.setSize(dispW, dispH); |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 171 | |
Constantin Kaplinsky | 72e47ef | 2008-04-18 17:48:16 +0000 | [diff] [blame] | 172 | // Just add the VncCanvas component to the Applet. |
wimba.com | 252eb3b | 2004-09-21 21:27:54 +0000 | [diff] [blame] | 173 | gbc.fill = GridBagConstraints.NONE; |
| 174 | gridbag.setConstraints(desktopScrollPane, gbc); |
| 175 | add(desktopScrollPane); |
Constantin Kaplinsky | 72e47ef | 2008-04-18 17:48:16 +0000 | [diff] [blame] | 176 | validate(); |
wimba.com | 252eb3b | 2004-09-21 21:27:54 +0000 | [diff] [blame] | 177 | vc.resizeEmbeddedApplet(); |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 178 | } |
| 179 | |
wimba.com | d1f56df | 2004-11-01 16:18:54 +0000 | [diff] [blame] | 180 | while (!isQuitting) { |
Constantin Kaplinsky | 72e47ef | 2008-04-18 17:48:16 +0000 | [diff] [blame] | 181 | try { |
| 182 | setPaused(!autoPlay); |
Constantin Kaplinsky | 7b55c4f | 2008-06-18 09:28:30 +0000 | [diff] [blame] | 183 | fbs.setSpeed(playbackSpeed); |
Constantin Kaplinsky | 72e47ef | 2008-04-18 17:48:16 +0000 | [diff] [blame] | 184 | vc.processNormalProtocol(); |
| 185 | } catch (EOFException e) { |
Constantin Kaplinsky | 7b55c4f | 2008-06-18 09:28:30 +0000 | [diff] [blame] | 186 | long newTimeOffset; |
Constantin Kaplinsky | 72e47ef | 2008-04-18 17:48:16 +0000 | [diff] [blame] | 187 | if (e.getMessage() != null && e.getMessage().equals("[REWIND]")) { |
| 188 | // A special type of EOFException allowing us to seek backwards. |
Constantin Kaplinsky | 7b55c4f | 2008-06-18 09:28:30 +0000 | [diff] [blame] | 189 | newTimeOffset = fbs.getSeekOffset(); |
| 190 | autoPlay = !fbs.isPaused(); |
Constantin Kaplinsky | 72e47ef | 2008-04-18 17:48:16 +0000 | [diff] [blame] | 191 | } else { |
| 192 | // Return to the beginning after the playback is finished. |
Constantin Kaplinsky | 7b55c4f | 2008-06-18 09:28:30 +0000 | [diff] [blame] | 193 | newTimeOffset = 0; |
Constantin Kaplinsky | 72e47ef | 2008-04-18 17:48:16 +0000 | [diff] [blame] | 194 | autoPlay = false; |
| 195 | } |
Constantin Kaplinsky | 7b55c4f | 2008-06-18 09:28:30 +0000 | [diff] [blame] | 196 | fbs.close(); |
Constantin Kaplinsky | b5db87f | 2008-06-19 12:25:12 +0000 | [diff] [blame^] | 197 | newFbsConnection(newTimeOffset); |
Constantin Kaplinsky | 7b55c4f | 2008-06-18 09:28:30 +0000 | [diff] [blame] | 198 | rfb.newSession(fbs); |
Constantin Kaplinsky | 282aaa1 | 2002-09-22 11:33:22 +0000 | [diff] [blame] | 199 | vc.updateFramebufferSize(); |
wimba.com | 30ff9ed | 2004-11-01 20:54:08 +0000 | [diff] [blame] | 200 | } catch (NullPointerException e) { |
| 201 | // catching this causes a hang with 1.4.1 JVM's under Win32 IE |
| 202 | throw e; |
Constantin Kaplinsky | 72e47ef | 2008-04-18 17:48:16 +0000 | [diff] [blame] | 203 | } |
Constantin Kaplinsky | 903009e | 2002-05-20 10:55:47 +0000 | [diff] [blame] | 204 | } |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 205 | |
Constantin Kaplinsky | 903009e | 2002-05-20 10:55:47 +0000 | [diff] [blame] | 206 | } catch (FileNotFoundException e) { |
| 207 | fatalError(e.toString()); |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 208 | } catch (Exception e) { |
| 209 | e.printStackTrace(); |
| 210 | fatalError(e.toString()); |
| 211 | } |
Constantin Kaplinsky | 72e47ef | 2008-04-18 17:48:16 +0000 | [diff] [blame] | 212 | |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 213 | } |
| 214 | |
Constantin Kaplinsky | 7b55c4f | 2008-06-18 09:28:30 +0000 | [diff] [blame] | 215 | /** |
| 216 | * Open new connection specified by this.url, save new FbsInputStream in |
| 217 | * this.fbs. |
| 218 | * |
Constantin Kaplinsky | b5db87f | 2008-06-19 12:25:12 +0000 | [diff] [blame^] | 219 | * @param timeOffset set this as current time position in the newly created |
| 220 | * FbsInputStream object. |
Constantin Kaplinsky | 7b55c4f | 2008-06-18 09:28:30 +0000 | [diff] [blame] | 221 | * @throws java.io.IOException |
| 222 | */ |
Constantin Kaplinsky | b5db87f | 2008-06-19 12:25:12 +0000 | [diff] [blame^] | 223 | void newFbsConnection(long timeOffset) throws IOException { |
Constantin Kaplinsky | 7b55c4f | 2008-06-18 09:28:30 +0000 | [diff] [blame] | 224 | URLConnection connection = url.openConnection(); |
| 225 | fbs = new FbsInputStream(connection.getInputStream()); |
Constantin Kaplinsky | b5db87f | 2008-06-19 12:25:12 +0000 | [diff] [blame^] | 226 | fbs.setTimeOffset(timeOffset); |
Constantin Kaplinsky | 7b55c4f | 2008-06-18 09:28:30 +0000 | [diff] [blame] | 227 | } |
| 228 | |
wimba.com | b5a9034 | 2007-04-02 18:54:41 +0000 | [diff] [blame] | 229 | 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 Kaplinsky | ac6420d | 2002-05-29 17:05:39 +0000 | [diff] [blame] | 245 | public void setPaused(boolean paused) { |
Constantin Kaplinsky | 972c257 | 2002-05-30 14:19:02 +0000 | [diff] [blame] | 246 | if (showControls) |
| 247 | buttonPanel.setPaused(paused); |
Constantin Kaplinsky | 37cc43e | 2002-05-30 17:30:11 +0000 | [diff] [blame] | 248 | if (paused) { |
Constantin Kaplinsky | 7b55c4f | 2008-06-18 09:28:30 +0000 | [diff] [blame] | 249 | fbs.pausePlayback(); |
Constantin Kaplinsky | 37cc43e | 2002-05-30 17:30:11 +0000 | [diff] [blame] | 250 | } else { |
Constantin Kaplinsky | 7b55c4f | 2008-06-18 09:28:30 +0000 | [diff] [blame] | 251 | fbs.resumePlayback(); |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 252 | } |
| 253 | } |
| 254 | |
Constantin Kaplinsky | 7957ca1 | 2002-05-30 16:19:11 +0000 | [diff] [blame] | 255 | public double getSpeed() { |
| 256 | return playbackSpeed; |
| 257 | } |
| 258 | |
Constantin Kaplinsky | ce39d3b | 2002-05-30 15:54:56 +0000 | [diff] [blame] | 259 | public void setSpeed(double speed) { |
Constantin Kaplinsky | 7957ca1 | 2002-05-30 16:19:11 +0000 | [diff] [blame] | 260 | playbackSpeed = speed; |
Constantin Kaplinsky | 7b55c4f | 2008-06-18 09:28:30 +0000 | [diff] [blame] | 261 | fbs.setSpeed(speed); |
Constantin Kaplinsky | ce39d3b | 2002-05-30 15:54:56 +0000 | [diff] [blame] | 262 | } |
| 263 | |
wimba.com | c23aeb0 | 2004-09-16 00:00:00 +0000 | [diff] [blame] | 264 | public void jumpTo(long pos) { |
Constantin Kaplinsky | 7b55c4f | 2008-06-18 09:28:30 +0000 | [diff] [blame] | 265 | long diff = Math.abs(pos - fbs.getTimeOffset()); |
wimba.com | c23aeb0 | 2004-09-16 00:00:00 +0000 | [diff] [blame] | 266 | |
| 267 | // Current threshold is 5 seconds |
| 268 | if (diff > 5000) { |
Constantin Kaplinsky | 7b55c4f | 2008-06-18 09:28:30 +0000 | [diff] [blame] | 269 | fbs.pausePlayback(); |
wimba.com | c23aeb0 | 2004-09-16 00:00:00 +0000 | [diff] [blame] | 270 | setPos(pos); |
Constantin Kaplinsky | 7b55c4f | 2008-06-18 09:28:30 +0000 | [diff] [blame] | 271 | fbs.resumePlayback(); |
wimba.com | c23aeb0 | 2004-09-16 00:00:00 +0000 | [diff] [blame] | 272 | } |
| 273 | } |
| 274 | |
Constantin Kaplinsky | c833e01 | 2002-05-30 17:59:22 +0000 | [diff] [blame] | 275 | public void setPos(long pos) { |
Constantin Kaplinsky | 7b55c4f | 2008-06-18 09:28:30 +0000 | [diff] [blame] | 276 | fbs.setTimeOffset(pos); |
Constantin Kaplinsky | 30f786a | 2002-05-29 10:59:52 +0000 | [diff] [blame] | 277 | } |
| 278 | |
Constantin Kaplinsky | fe07983 | 2002-05-29 00:52:32 +0000 | [diff] [blame] | 279 | public void updatePos() { |
Constantin Kaplinsky | aa7b561 | 2008-06-17 09:27:52 +0000 | [diff] [blame] | 280 | if (showControls && buttonPanel != null) |
Constantin Kaplinsky | 7b55c4f | 2008-06-18 09:28:30 +0000 | [diff] [blame] | 281 | buttonPanel.setPos(fbs.getTimeOffset()); |
Constantin Kaplinsky | fe07983 | 2002-05-29 00:52:32 +0000 | [diff] [blame] | 282 | } |
| 283 | |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 284 | // |
| 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 Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 290 | public void readParameters() { |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 291 | |
Constantin Kaplinsky | 5d99c95 | 2002-05-25 09:49:23 +0000 | [diff] [blame] | 292 | sessionURL = readParameter("URL", true); |
Constantin Kaplinsky | 5a7133a | 2002-07-24 17:02:04 +0000 | [diff] [blame] | 293 | |
Constantin Kaplinsky | 972c257 | 2002-05-30 14:19:02 +0000 | [diff] [blame] | 294 | initialTimeOffset = readLongParameter("Position", 0); |
Constantin Kaplinsky | 7957ca1 | 2002-05-30 16:19:11 +0000 | [diff] [blame] | 295 | if (initialTimeOffset < 0) |
| 296 | initialTimeOffset = 0; |
Constantin Kaplinsky | 5a7133a | 2002-07-24 17:02:04 +0000 | [diff] [blame] | 297 | |
Constantin Kaplinsky | 7957ca1 | 2002-05-30 16:19:11 +0000 | [diff] [blame] | 298 | playbackSpeed = readDoubleParameter("Speed", 1.0); |
| 299 | if (playbackSpeed <= 0.0) |
| 300 | playbackSpeed = 1.0; |
Constantin Kaplinsky | 903009e | 2002-05-20 10:55:47 +0000 | [diff] [blame] | 301 | |
Constantin Kaplinsky | 5a7133a | 2002-07-24 17:02:04 +0000 | [diff] [blame] | 302 | autoPlay = false; |
| 303 | String str = readParameter("Autoplay", false); |
| 304 | if (str != null && str.equalsIgnoreCase("Yes")) |
| 305 | autoPlay = true; |
| 306 | |
Constantin Kaplinsky | 903009e | 2002-05-20 10:55:47 +0000 | [diff] [blame] | 307 | showControls = true; |
wimba.com | 9bd9c5c | 2005-09-14 18:42:46 +0000 | [diff] [blame] | 308 | str = readParameter("Show_Controls", false); |
Constantin Kaplinsky | 903009e | 2002-05-20 10:55:47 +0000 | [diff] [blame] | 309 | if (str != null && str.equalsIgnoreCase("No")) |
| 310 | showControls = false; |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 311 | |
| 312 | if (inAnApplet) { |
wimba.com | 9bd9c5c | 2005-09-14 18:42:46 +0000 | [diff] [blame] | 313 | str = readParameter("Open_New_Window", false); |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 314 | if (str != null && str.equalsIgnoreCase("Yes")) |
Constantin Kaplinsky | 72e47ef | 2008-04-18 17:48:16 +0000 | [diff] [blame] | 315 | inSeparateFrame = true; |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 316 | } |
| 317 | |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 318 | // Fine tuning options. |
wimba.com | 9bd9c5c | 2005-09-14 18:42:46 +0000 | [diff] [blame] | 319 | deferScreenUpdates = (int)readLongParameter("Defer_screen_updates", 20); |
Constantin Kaplinsky | 972c257 | 2002-05-30 14:19:02 +0000 | [diff] [blame] | 320 | if (deferScreenUpdates < 0) |
| 321 | deferScreenUpdates = 0; // Just in case. |
wimba.com | 252eb3b | 2004-09-21 21:27:54 +0000 | [diff] [blame] | 322 | |
| 323 | // Display width and height. |
| 324 | dispW = readIntParameter("DISPLAY_WIDTH", dispW); |
| 325 | dispH = readIntParameter("DISPLAY_HEIGHT", dispH); |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 326 | } |
| 327 | |
| 328 | public String readParameter(String name, boolean required) { |
| 329 | if (inAnApplet) { |
| 330 | String s = getParameter(name); |
| 331 | if ((s == null) && required) { |
Constantin Kaplinsky | 72e47ef | 2008-04-18 17:48:16 +0000 | [diff] [blame] | 332 | fatalError(name + " parameter not specified"); |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 333 | } |
| 334 | return s; |
| 335 | } |
| 336 | |
| 337 | for (int i = 0; i < mainArgs.length; i += 2) { |
| 338 | if (mainArgs[i].equalsIgnoreCase(name)) { |
Constantin Kaplinsky | 72e47ef | 2008-04-18 17:48:16 +0000 | [diff] [blame] | 339 | 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 Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 347 | } |
| 348 | } |
| 349 | if (required) { |
| 350 | fatalError(name + " parameter not specified"); |
| 351 | } |
| 352 | return null; |
| 353 | } |
| 354 | |
Constantin Kaplinsky | 972c257 | 2002-05-30 14:19:02 +0000 | [diff] [blame] | 355 | long readLongParameter(String name, long defaultValue) { |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 356 | String str = readParameter(name, false); |
Constantin Kaplinsky | 972c257 | 2002-05-30 14:19:02 +0000 | [diff] [blame] | 357 | long result = defaultValue; |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 358 | if (str != null) { |
| 359 | try { |
Constantin Kaplinsky | 72e47ef | 2008-04-18 17:48:16 +0000 | [diff] [blame] | 360 | result = Long.parseLong(str); |
| 361 | } catch (NumberFormatException e) { |
| 362 | } |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 363 | } |
| 364 | return result; |
| 365 | } |
| 366 | |
Constantin Kaplinsky | 7957ca1 | 2002-05-30 16:19:11 +0000 | [diff] [blame] | 367 | double readDoubleParameter(String name, double defaultValue) { |
| 368 | String str = readParameter(name, false); |
| 369 | double result = defaultValue; |
| 370 | if (str != null) { |
| 371 | try { |
Constantin Kaplinsky | 72e47ef | 2008-04-18 17:48:16 +0000 | [diff] [blame] | 372 | result = Double.valueOf(str).doubleValue(); |
| 373 | } catch (NumberFormatException e) { |
| 374 | } |
Constantin Kaplinsky | 7957ca1 | 2002-05-30 16:19:11 +0000 | [diff] [blame] | 375 | } |
| 376 | return result; |
| 377 | } |
| 378 | |
wimba.com | 252eb3b | 2004-09-21 21:27:54 +0000 | [diff] [blame] | 379 | 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 Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 391 | // |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 392 | // fatalError() - print out a fatal error message. |
| 393 | // |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 394 | public void fatalError(String str) { |
| 395 | System.out.println(str); |
| 396 | |
| 397 | if (inAnApplet) { |
| 398 | vncContainer.removeAll(); |
| 399 | if (rfb != null) { |
Constantin Kaplinsky | 72e47ef | 2008-04-18 17:48:16 +0000 | [diff] [blame] | 400 | rfb = null; |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 401 | } |
| 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 Kaplinsky | 72e47ef | 2008-04-18 17:48:16 +0000 | [diff] [blame] | 407 | vncFrame.pack(); |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 408 | } else { |
Constantin Kaplinsky | 72e47ef | 2008-04-18 17:48:16 +0000 | [diff] [blame] | 409 | validate(); |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 410 | } |
| 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 Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 421 | public void destroy() { |
wimba.com | d1f56df | 2004-11-01 16:18:54 +0000 | [diff] [blame] | 422 | isQuitting = true; |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 423 | vncContainer.removeAll(); |
Constantin Kaplinsky | 7b55c4f | 2008-06-18 09:28:30 +0000 | [diff] [blame] | 424 | if (fbs != null) { |
| 425 | fbs.quit(); |
| 426 | try { |
| 427 | fbs.close(); |
| 428 | } catch (IOException e) { |
| 429 | } |
wimba.com | d1f56df | 2004-11-01 16:18:54 +0000 | [diff] [blame] | 430 | } |
| 431 | try { |
| 432 | rfbThread.join(); |
| 433 | } catch (InterruptedException e) { |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 434 | } |
| 435 | if (inSeparateFrame) { |
wimba.com | 30ff9ed | 2004-11-01 20:54:08 +0000 | [diff] [blame] | 436 | vncFrame.removeWindowListener(this); |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 437 | vncFrame.dispose(); |
| 438 | } |
| 439 | } |
| 440 | |
wimba.com | 252eb3b | 2004-09-21 21:27:54 +0000 | [diff] [blame] | 441 | // |
| 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 Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 452 | |
| 453 | // |
| 454 | // Close application properly on window close event. |
| 455 | // |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 456 | public void windowClosing(WindowEvent evt) { |
Constantin Kaplinsky | 903009e | 2002-05-20 10:55:47 +0000 | [diff] [blame] | 457 | vncContainer.removeAll(); |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 458 | if (rfb != null) |
Constantin Kaplinsky | 903009e | 2002-05-20 10:55:47 +0000 | [diff] [blame] | 459 | rfb = null; |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 460 | |
| 461 | vncFrame.dispose(); |
| 462 | if (!inAnApplet) { |
| 463 | System.exit(0); |
| 464 | } |
| 465 | } |
| 466 | |
| 467 | // |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 468 | // Ignore window events we're not interested in. |
| 469 | // |
Constantin Kaplinsky | 72e47ef | 2008-04-18 17:48:16 +0000 | [diff] [blame] | 470 | public void windowActivated(WindowEvent evt) { |
| 471 | } |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 472 | |
Constantin Kaplinsky | 72e47ef | 2008-04-18 17:48:16 +0000 | [diff] [blame] | 473 | 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 Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 488 | } |