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