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 | |
wimba.com | c23aeb0 | 2004-09-16 00:00:00 +0000 | [diff] [blame] | 21 | package com.HorizonLive.RfbPlayer; |
| 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 | |
| 55 | RfbProto rfb; |
| 56 | Thread rfbThread; |
| 57 | |
| 58 | Frame vncFrame; |
| 59 | Container vncContainer; |
| 60 | ScrollPane desktopScrollPane; |
| 61 | GridBagLayout gridbag; |
| 62 | ButtonPanel buttonPanel; |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 63 | VncCanvas vc; |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 64 | |
Constantin Kaplinsky | 5d99c95 | 2002-05-25 09:49:23 +0000 | [diff] [blame] | 65 | String sessionURL; |
Constantin Kaplinsky | c833e01 | 2002-05-30 17:59:22 +0000 | [diff] [blame] | 66 | URL url; |
Constantin Kaplinsky | 972c257 | 2002-05-30 14:19:02 +0000 | [diff] [blame] | 67 | long initialTimeOffset; |
Constantin Kaplinsky | 7957ca1 | 2002-05-30 16:19:11 +0000 | [diff] [blame] | 68 | double playbackSpeed; |
Constantin Kaplinsky | 5a7133a | 2002-07-24 17:02:04 +0000 | [diff] [blame] | 69 | boolean autoPlay; |
Constantin Kaplinsky | 903009e | 2002-05-20 10:55:47 +0000 | [diff] [blame] | 70 | boolean showControls; |
wimba.com | d1f56df | 2004-11-01 16:18:54 +0000 | [diff] [blame] | 71 | boolean isQuitting = false; |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 72 | int deferScreenUpdates; |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 73 | |
| 74 | // |
| 75 | // init() |
| 76 | // |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 77 | public void init() { |
| 78 | |
wimba.com | c23aeb0 | 2004-09-16 00:00:00 +0000 | [diff] [blame] | 79 | // LiveConnect work-a-round |
| 80 | RfbSharedStatic.refApplet = this; |
| 81 | |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 82 | readParameters(); |
| 83 | |
| 84 | if (inSeparateFrame) { |
Constantin Kaplinsky | 903009e | 2002-05-20 10:55:47 +0000 | [diff] [blame] | 85 | vncFrame = new Frame("RFB Session Player"); |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 86 | if (!inAnApplet) { |
Constantin Kaplinsky | 72e47ef | 2008-04-18 17:48:16 +0000 | [diff] [blame] | 87 | vncFrame.add("Center", this); |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 88 | } |
| 89 | vncContainer = vncFrame; |
| 90 | } else { |
| 91 | vncContainer = this; |
| 92 | } |
| 93 | |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 94 | if (inSeparateFrame) |
| 95 | vncFrame.addWindowListener(this); |
| 96 | |
wimba.com | d1f56df | 2004-11-01 16:18:54 +0000 | [diff] [blame] | 97 | rfbThread = new Thread(this, "RfbThread"); |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 98 | rfbThread.start(); |
| 99 | } |
| 100 | |
| 101 | public void update(Graphics g) { |
| 102 | } |
| 103 | |
| 104 | // |
Constantin Kaplinsky | 903009e | 2002-05-20 10:55:47 +0000 | [diff] [blame] | 105 | // run() - executed by the rfbThread to read RFB data. |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 106 | // |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 107 | public void run() { |
| 108 | |
| 109 | gridbag = new GridBagLayout(); |
| 110 | vncContainer.setLayout(gridbag); |
| 111 | |
| 112 | GridBagConstraints gbc = new GridBagConstraints(); |
| 113 | gbc.gridwidth = GridBagConstraints.REMAINDER; |
| 114 | gbc.anchor = GridBagConstraints.NORTHWEST; |
| 115 | |
Constantin Kaplinsky | 903009e | 2002-05-20 10:55:47 +0000 | [diff] [blame] | 116 | if (showControls) { |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 117 | buttonPanel = new ButtonPanel(this); |
| 118 | buttonPanel.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0)); |
| 119 | gridbag.setConstraints(buttonPanel, gbc); |
| 120 | vncContainer.add(buttonPanel); |
| 121 | } |
| 122 | |
Constantin Kaplinsky | 903009e | 2002-05-20 10:55:47 +0000 | [diff] [blame] | 123 | if (inSeparateFrame) { |
| 124 | vncFrame.pack(); |
| 125 | vncFrame.show(); |
| 126 | } else { |
| 127 | validate(); |
| 128 | } |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 129 | |
Constantin Kaplinsky | 903009e | 2002-05-20 10:55:47 +0000 | [diff] [blame] | 130 | try { |
Constantin Kaplinsky | 40ad171 | 2002-09-22 08:36:43 +0000 | [diff] [blame] | 131 | if (inAnApplet) { |
Constantin Kaplinsky | 72e47ef | 2008-04-18 17:48:16 +0000 | [diff] [blame] | 132 | url = new URL(getCodeBase(), sessionURL); |
Constantin Kaplinsky | 40ad171 | 2002-09-22 08:36:43 +0000 | [diff] [blame] | 133 | } else { |
Constantin Kaplinsky | 72e47ef | 2008-04-18 17:48:16 +0000 | [diff] [blame] | 134 | url = new URL(sessionURL); |
Constantin Kaplinsky | 40ad171 | 2002-09-22 08:36:43 +0000 | [diff] [blame] | 135 | } |
Constantin Kaplinsky | 37cc43e | 2002-05-30 17:30:11 +0000 | [diff] [blame] | 136 | rfb = new RfbProto(url); |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 137 | |
| 138 | vc = new VncCanvas(this); |
| 139 | gbc.weightx = 1.0; |
| 140 | gbc.weighty = 1.0; |
| 141 | |
wimba.com | 252eb3b | 2004-09-21 21:27:54 +0000 | [diff] [blame] | 142 | // Create a panel which itself is resizeable and can hold |
| 143 | // non-resizeable VncCanvas component at the top left corner. |
| 144 | Panel canvasPanel = new Panel(); |
| 145 | canvasPanel.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0)); |
| 146 | canvasPanel.add(vc); |
| 147 | |
| 148 | // Create a ScrollPane which will hold a panel with VncCanvas |
| 149 | // inside. |
| 150 | desktopScrollPane = new ScrollPane(ScrollPane.SCROLLBARS_AS_NEEDED); |
| 151 | gbc.fill = GridBagConstraints.BOTH; |
| 152 | gridbag.setConstraints(canvasPanel, gbc); |
| 153 | desktopScrollPane.add(canvasPanel); |
| 154 | |
| 155 | // Now add the scroll bar to the container. |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 156 | if (inSeparateFrame) { |
Constantin Kaplinsky | 72e47ef | 2008-04-18 17:48:16 +0000 | [diff] [blame] | 157 | gridbag.setConstraints(desktopScrollPane, gbc); |
Constantin Kaplinsky | 72e47ef | 2008-04-18 17:48:16 +0000 | [diff] [blame] | 158 | vncFrame.add(desktopScrollPane); |
| 159 | vncFrame.setTitle(rfb.desktopName); |
| 160 | vncFrame.pack(); |
| 161 | vc.resizeDesktopFrame(); |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 162 | } else { |
wimba.com | 252eb3b | 2004-09-21 21:27:54 +0000 | [diff] [blame] | 163 | // Size the scroll pane to display size. |
| 164 | desktopScrollPane.setSize(dispW, dispH); |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 165 | |
Constantin Kaplinsky | 72e47ef | 2008-04-18 17:48:16 +0000 | [diff] [blame] | 166 | // Just add the VncCanvas component to the Applet. |
wimba.com | 252eb3b | 2004-09-21 21:27:54 +0000 | [diff] [blame] | 167 | gbc.fill = GridBagConstraints.NONE; |
| 168 | gridbag.setConstraints(desktopScrollPane, gbc); |
| 169 | add(desktopScrollPane); |
Constantin Kaplinsky | 72e47ef | 2008-04-18 17:48:16 +0000 | [diff] [blame] | 170 | validate(); |
wimba.com | 252eb3b | 2004-09-21 21:27:54 +0000 | [diff] [blame] | 171 | vc.resizeEmbeddedApplet(); |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 172 | } |
| 173 | |
wimba.com | d1f56df | 2004-11-01 16:18:54 +0000 | [diff] [blame] | 174 | while (!isQuitting) { |
Constantin Kaplinsky | 72e47ef | 2008-04-18 17:48:16 +0000 | [diff] [blame] | 175 | try { |
| 176 | setPaused(!autoPlay); |
| 177 | rfb.fbs.setSpeed(playbackSpeed); |
| 178 | if (initialTimeOffset > rfb.fbs.getTimeOffset()) |
| 179 | setPos(initialTimeOffset); // don't seek backwards here |
| 180 | vc.processNormalProtocol(); |
| 181 | } catch (EOFException e) { |
| 182 | if (e.getMessage() != null && e.getMessage().equals("[REWIND]")) { |
| 183 | // A special type of EOFException allowing us to seek backwards. |
| 184 | initialTimeOffset = rfb.fbs.getSeekOffset(); |
| 185 | autoPlay = !rfb.fbs.isPaused(); |
| 186 | } else { |
| 187 | // Return to the beginning after the playback is finished. |
| 188 | initialTimeOffset = 0; |
| 189 | autoPlay = false; |
| 190 | } |
Constantin Kaplinsky | 282aaa1 | 2002-09-22 11:33:22 +0000 | [diff] [blame] | 191 | rfb.newSession(url); |
| 192 | vc.updateFramebufferSize(); |
wimba.com | 30ff9ed | 2004-11-01 20:54:08 +0000 | [diff] [blame^] | 193 | } catch (NullPointerException e) { |
| 194 | // catching this causes a hang with 1.4.1 JVM's under Win32 IE |
| 195 | throw e; |
Constantin Kaplinsky | 72e47ef | 2008-04-18 17:48:16 +0000 | [diff] [blame] | 196 | } |
Constantin Kaplinsky | 903009e | 2002-05-20 10:55:47 +0000 | [diff] [blame] | 197 | } |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 198 | |
Constantin Kaplinsky | 903009e | 2002-05-20 10:55:47 +0000 | [diff] [blame] | 199 | } catch (FileNotFoundException e) { |
| 200 | fatalError(e.toString()); |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 201 | } catch (Exception e) { |
| 202 | e.printStackTrace(); |
| 203 | fatalError(e.toString()); |
| 204 | } |
Constantin Kaplinsky | 72e47ef | 2008-04-18 17:48:16 +0000 | [diff] [blame] | 205 | |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 206 | } |
| 207 | |
Constantin Kaplinsky | ac6420d | 2002-05-29 17:05:39 +0000 | [diff] [blame] | 208 | public void setPaused(boolean paused) { |
Constantin Kaplinsky | 972c257 | 2002-05-30 14:19:02 +0000 | [diff] [blame] | 209 | if (showControls) |
| 210 | buttonPanel.setPaused(paused); |
Constantin Kaplinsky | 37cc43e | 2002-05-30 17:30:11 +0000 | [diff] [blame] | 211 | if (paused) { |
| 212 | rfb.fbs.pausePlayback(); |
| 213 | } else { |
| 214 | rfb.fbs.resumePlayback(); |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 215 | } |
| 216 | } |
| 217 | |
Constantin Kaplinsky | 7957ca1 | 2002-05-30 16:19:11 +0000 | [diff] [blame] | 218 | public double getSpeed() { |
| 219 | return playbackSpeed; |
| 220 | } |
| 221 | |
Constantin Kaplinsky | ce39d3b | 2002-05-30 15:54:56 +0000 | [diff] [blame] | 222 | public void setSpeed(double speed) { |
Constantin Kaplinsky | 7957ca1 | 2002-05-30 16:19:11 +0000 | [diff] [blame] | 223 | playbackSpeed = speed; |
Constantin Kaplinsky | 37cc43e | 2002-05-30 17:30:11 +0000 | [diff] [blame] | 224 | rfb.fbs.setSpeed(speed); |
Constantin Kaplinsky | ce39d3b | 2002-05-30 15:54:56 +0000 | [diff] [blame] | 225 | } |
| 226 | |
wimba.com | c23aeb0 | 2004-09-16 00:00:00 +0000 | [diff] [blame] | 227 | public void jumpTo(long pos) { |
| 228 | long diff = Math.abs(pos - rfb.fbs.getTimeOffset()); |
| 229 | |
| 230 | // Current threshold is 5 seconds |
| 231 | if (diff > 5000) { |
| 232 | rfb.fbs.pausePlayback(); |
| 233 | setPos(pos); |
| 234 | rfb.fbs.resumePlayback(); |
| 235 | } |
| 236 | } |
| 237 | |
Constantin Kaplinsky | c833e01 | 2002-05-30 17:59:22 +0000 | [diff] [blame] | 238 | public void setPos(long pos) { |
Constantin Kaplinsky | 5b1b92a | 2002-05-30 18:02:34 +0000 | [diff] [blame] | 239 | rfb.fbs.setTimeOffset(pos); |
Constantin Kaplinsky | 30f786a | 2002-05-29 10:59:52 +0000 | [diff] [blame] | 240 | } |
| 241 | |
Constantin Kaplinsky | fe07983 | 2002-05-29 00:52:32 +0000 | [diff] [blame] | 242 | public void updatePos() { |
Constantin Kaplinsky | 972c257 | 2002-05-30 14:19:02 +0000 | [diff] [blame] | 243 | if (showControls) |
Constantin Kaplinsky | c833e01 | 2002-05-30 17:59:22 +0000 | [diff] [blame] | 244 | buttonPanel.setPos(rfb.fbs.getTimeOffset()); |
Constantin Kaplinsky | fe07983 | 2002-05-29 00:52:32 +0000 | [diff] [blame] | 245 | } |
| 246 | |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 247 | // |
| 248 | // readParameters() - read parameters from the html source or from the |
| 249 | // command line. On the command line, the arguments are just a sequence of |
| 250 | // param_name/param_value pairs where the names and values correspond to |
| 251 | // those expected in the html applet tag source. |
| 252 | // |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 253 | public void readParameters() { |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 254 | |
Constantin Kaplinsky | 5d99c95 | 2002-05-25 09:49:23 +0000 | [diff] [blame] | 255 | sessionURL = readParameter("URL", true); |
Constantin Kaplinsky | 5a7133a | 2002-07-24 17:02:04 +0000 | [diff] [blame] | 256 | |
Constantin Kaplinsky | 972c257 | 2002-05-30 14:19:02 +0000 | [diff] [blame] | 257 | initialTimeOffset = readLongParameter("Position", 0); |
Constantin Kaplinsky | 7957ca1 | 2002-05-30 16:19:11 +0000 | [diff] [blame] | 258 | if (initialTimeOffset < 0) |
| 259 | initialTimeOffset = 0; |
Constantin Kaplinsky | 5a7133a | 2002-07-24 17:02:04 +0000 | [diff] [blame] | 260 | |
Constantin Kaplinsky | 7957ca1 | 2002-05-30 16:19:11 +0000 | [diff] [blame] | 261 | playbackSpeed = readDoubleParameter("Speed", 1.0); |
| 262 | if (playbackSpeed <= 0.0) |
| 263 | playbackSpeed = 1.0; |
Constantin Kaplinsky | 903009e | 2002-05-20 10:55:47 +0000 | [diff] [blame] | 264 | |
Constantin Kaplinsky | 5a7133a | 2002-07-24 17:02:04 +0000 | [diff] [blame] | 265 | autoPlay = false; |
| 266 | String str = readParameter("Autoplay", false); |
| 267 | if (str != null && str.equalsIgnoreCase("Yes")) |
| 268 | autoPlay = true; |
| 269 | |
Constantin Kaplinsky | 903009e | 2002-05-20 10:55:47 +0000 | [diff] [blame] | 270 | showControls = true; |
Constantin Kaplinsky | 5a7133a | 2002-07-24 17:02:04 +0000 | [diff] [blame] | 271 | str = readParameter("Show Controls", false); |
Constantin Kaplinsky | 903009e | 2002-05-20 10:55:47 +0000 | [diff] [blame] | 272 | if (str != null && str.equalsIgnoreCase("No")) |
| 273 | showControls = false; |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 274 | |
| 275 | if (inAnApplet) { |
| 276 | str = readParameter("Open New Window", false); |
| 277 | if (str != null && str.equalsIgnoreCase("Yes")) |
Constantin Kaplinsky | 72e47ef | 2008-04-18 17:48:16 +0000 | [diff] [blame] | 278 | inSeparateFrame = true; |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 279 | } |
| 280 | |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 281 | // Fine tuning options. |
Constantin Kaplinsky | 972c257 | 2002-05-30 14:19:02 +0000 | [diff] [blame] | 282 | deferScreenUpdates = (int)readLongParameter("Defer screen updates", 20); |
| 283 | if (deferScreenUpdates < 0) |
| 284 | deferScreenUpdates = 0; // Just in case. |
wimba.com | 252eb3b | 2004-09-21 21:27:54 +0000 | [diff] [blame] | 285 | |
| 286 | // Display width and height. |
| 287 | dispW = readIntParameter("DISPLAY_WIDTH", dispW); |
| 288 | dispH = readIntParameter("DISPLAY_HEIGHT", dispH); |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 289 | } |
| 290 | |
| 291 | public String readParameter(String name, boolean required) { |
| 292 | if (inAnApplet) { |
| 293 | String s = getParameter(name); |
| 294 | if ((s == null) && required) { |
Constantin Kaplinsky | 72e47ef | 2008-04-18 17:48:16 +0000 | [diff] [blame] | 295 | fatalError(name + " parameter not specified"); |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 296 | } |
| 297 | return s; |
| 298 | } |
| 299 | |
| 300 | for (int i = 0; i < mainArgs.length; i += 2) { |
| 301 | if (mainArgs[i].equalsIgnoreCase(name)) { |
Constantin Kaplinsky | 72e47ef | 2008-04-18 17:48:16 +0000 | [diff] [blame] | 302 | try { |
| 303 | return mainArgs[i + 1]; |
| 304 | } catch (Exception e) { |
| 305 | if (required) { |
| 306 | fatalError(name + " parameter not specified"); |
| 307 | } |
| 308 | return null; |
| 309 | } |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 310 | } |
| 311 | } |
| 312 | if (required) { |
| 313 | fatalError(name + " parameter not specified"); |
| 314 | } |
| 315 | return null; |
| 316 | } |
| 317 | |
Constantin Kaplinsky | 972c257 | 2002-05-30 14:19:02 +0000 | [diff] [blame] | 318 | long readLongParameter(String name, long defaultValue) { |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 319 | String str = readParameter(name, false); |
Constantin Kaplinsky | 972c257 | 2002-05-30 14:19:02 +0000 | [diff] [blame] | 320 | long result = defaultValue; |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 321 | if (str != null) { |
| 322 | try { |
Constantin Kaplinsky | 72e47ef | 2008-04-18 17:48:16 +0000 | [diff] [blame] | 323 | result = Long.parseLong(str); |
| 324 | } catch (NumberFormatException e) { |
| 325 | } |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 326 | } |
| 327 | return result; |
| 328 | } |
| 329 | |
Constantin Kaplinsky | 7957ca1 | 2002-05-30 16:19:11 +0000 | [diff] [blame] | 330 | double readDoubleParameter(String name, double defaultValue) { |
| 331 | String str = readParameter(name, false); |
| 332 | double result = defaultValue; |
| 333 | if (str != null) { |
| 334 | try { |
Constantin Kaplinsky | 72e47ef | 2008-04-18 17:48:16 +0000 | [diff] [blame] | 335 | result = Double.valueOf(str).doubleValue(); |
| 336 | } catch (NumberFormatException e) { |
| 337 | } |
Constantin Kaplinsky | 7957ca1 | 2002-05-30 16:19:11 +0000 | [diff] [blame] | 338 | } |
| 339 | return result; |
| 340 | } |
| 341 | |
wimba.com | 252eb3b | 2004-09-21 21:27:54 +0000 | [diff] [blame] | 342 | int readIntParameter(String name, int defaultValue) { |
| 343 | String str = readParameter(name, false); |
| 344 | int result = defaultValue; |
| 345 | if (str != null) { |
| 346 | try { |
| 347 | result = Integer.parseInt(str); |
| 348 | } catch (NumberFormatException e) { |
| 349 | } |
| 350 | } |
| 351 | return result; |
| 352 | } |
| 353 | |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 354 | // |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 355 | // fatalError() - print out a fatal error message. |
| 356 | // |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 357 | public void fatalError(String str) { |
| 358 | System.out.println(str); |
| 359 | |
| 360 | if (inAnApplet) { |
| 361 | vncContainer.removeAll(); |
| 362 | if (rfb != null) { |
Constantin Kaplinsky | 72e47ef | 2008-04-18 17:48:16 +0000 | [diff] [blame] | 363 | rfb = null; |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 364 | } |
| 365 | Label errLabel = new Label(str); |
| 366 | errLabel.setFont(new Font("Helvetica", Font.PLAIN, 12)); |
| 367 | vncContainer.setLayout(new FlowLayout(FlowLayout.LEFT, 30, 30)); |
| 368 | vncContainer.add(errLabel); |
| 369 | if (inSeparateFrame) { |
Constantin Kaplinsky | 72e47ef | 2008-04-18 17:48:16 +0000 | [diff] [blame] | 370 | vncFrame.pack(); |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 371 | } else { |
Constantin Kaplinsky | 72e47ef | 2008-04-18 17:48:16 +0000 | [diff] [blame] | 372 | validate(); |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 373 | } |
| 374 | Thread.currentThread().stop(); |
| 375 | } else { |
| 376 | System.exit(1); |
| 377 | } |
| 378 | } |
| 379 | |
| 380 | |
| 381 | // |
| 382 | // This method is called before the applet is destroyed. |
| 383 | // |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 384 | public void destroy() { |
wimba.com | d1f56df | 2004-11-01 16:18:54 +0000 | [diff] [blame] | 385 | isQuitting = true; |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 386 | vncContainer.removeAll(); |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 387 | if (rfb != null) { |
wimba.com | d1f56df | 2004-11-01 16:18:54 +0000 | [diff] [blame] | 388 | rfb.quit(); |
| 389 | } |
| 390 | try { |
| 391 | rfbThread.join(); |
| 392 | } catch (InterruptedException e) { |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 393 | } |
| 394 | if (inSeparateFrame) { |
wimba.com | 30ff9ed | 2004-11-01 20:54:08 +0000 | [diff] [blame^] | 395 | vncFrame.removeWindowListener(this); |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 396 | vncFrame.dispose(); |
| 397 | } |
| 398 | } |
| 399 | |
wimba.com | 252eb3b | 2004-09-21 21:27:54 +0000 | [diff] [blame] | 400 | // |
| 401 | // Set the new width and height of the applet. Call when browser is resized to |
| 402 | // resize the viewer. |
| 403 | // |
| 404 | public void displaySize(int width, int height) { |
| 405 | dispW = width; |
| 406 | dispH = height; |
| 407 | if (!inSeparateFrame) { |
| 408 | vc.resizeEmbeddedApplet(); |
| 409 | } |
| 410 | } |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 411 | |
| 412 | // |
| 413 | // Close application properly on window close event. |
| 414 | // |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 415 | public void windowClosing(WindowEvent evt) { |
Constantin Kaplinsky | 903009e | 2002-05-20 10:55:47 +0000 | [diff] [blame] | 416 | vncContainer.removeAll(); |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 417 | if (rfb != null) |
Constantin Kaplinsky | 903009e | 2002-05-20 10:55:47 +0000 | [diff] [blame] | 418 | rfb = null; |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 419 | |
| 420 | vncFrame.dispose(); |
| 421 | if (!inAnApplet) { |
| 422 | System.exit(0); |
| 423 | } |
| 424 | } |
| 425 | |
| 426 | // |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 427 | // Ignore window events we're not interested in. |
| 428 | // |
Constantin Kaplinsky | 72e47ef | 2008-04-18 17:48:16 +0000 | [diff] [blame] | 429 | public void windowActivated(WindowEvent evt) { |
| 430 | } |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 431 | |
Constantin Kaplinsky | 72e47ef | 2008-04-18 17:48:16 +0000 | [diff] [blame] | 432 | public void windowDeactivated(WindowEvent evt) { |
| 433 | } |
| 434 | |
| 435 | public void windowOpened(WindowEvent evt) { |
| 436 | } |
| 437 | |
| 438 | public void windowClosed(WindowEvent evt) { |
| 439 | } |
| 440 | |
| 441 | public void windowIconified(WindowEvent evt) { |
| 442 | } |
| 443 | |
| 444 | public void windowDeiconified(WindowEvent evt) { |
| 445 | } |
| 446 | |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 447 | } |