annotate src/myVncProxy/VncViewer.java @ 26:0aa0e0bd742c

succeed drawFirstImage()!!
author e085711
date Tue, 26 Apr 2011 09:08:49 +0900
parents 87b29d6039a6
children 13d4d3118cb8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
24
87b29d6039a6 add package myVncProxy
e085711
parents: 11
diff changeset
1 package myVncProxy;
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
2 //
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
3 // Copyright (C) 2001-2004 HorizonLive.com, Inc. All Rights Reserved.
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
4 // Copyright (C) 2002 Constantin Kaplinsky. All Rights Reserved.
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
5 // Copyright (C) 1999 AT&T Laboratories Cambridge. All Rights Reserved.
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
6 //
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
7 // This is free software; you can redistribute it and/or modify
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
8 // it under the terms of the GNU General Public License as published by
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
9 // the Free Software Foundation; either version 2 of the License, or
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
10 // (at your option) any later version.
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
11 //
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
12 // This software is distributed in the hope that it will be useful,
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
15 // GNU General Public License for more details.
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
16 //
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
17 // You should have received a copy of the GNU General Public License
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
18 // along with this software; if not, write to the Free Software
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
19 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
20 // USA.
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
21 //
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
22
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
23 //
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
24 // VncViewer.java - the VNC viewer applet. This class mainly just sets up the
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
25 // user interface, leaving it to the VncCanvas to do the actual rendering of
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
26 // a VNC desktop.
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
27 //
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
28
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
29 import java.awt.*;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
30 import java.awt.event.*;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
31 import java.io.*;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
32 import java.net.*;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
33
4
e085711
parents: 3
diff changeset
34 public class VncViewer extends java.applet.Applet implements
e085711
parents: 3
diff changeset
35 java.lang.Runnable, WindowListener {
e085711
parents: 3
diff changeset
36
e085711
parents: 3
diff changeset
37 boolean inAnApplet = true;
e085711
parents: 3
diff changeset
38 boolean inSeparateFrame = false;
e085711
parents: 3
diff changeset
39
e085711
parents: 3
diff changeset
40 //
e085711
parents: 3
diff changeset
41 // main() is called when run as a java program from the command line.
e085711
parents: 3
diff changeset
42 // It simply runs the applet inside a newly-created frame.
e085711
parents: 3
diff changeset
43 //
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
44
4
e085711
parents: 3
diff changeset
45 public static void main(String[] argv) {
e085711
parents: 3
diff changeset
46 VncViewer v = new VncViewer();
e085711
parents: 3
diff changeset
47 v.mainArgs = argv;
e085711
parents: 3
diff changeset
48 v.inAnApplet = false;
e085711
parents: 3
diff changeset
49 v.inSeparateFrame = true;
e085711
parents: 3
diff changeset
50 /*
e085711
parents: 3
diff changeset
51 * if(argv.length > 1){ v.host = argv[0]; v.port =
e085711
parents: 3
diff changeset
52 * Integer.parseInt(argv[1]); }
e085711
parents: 3
diff changeset
53 */
e085711
parents: 3
diff changeset
54 v.init();
e085711
parents: 3
diff changeset
55 v.start();
e085711
parents: 3
diff changeset
56 }
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
57
4
e085711
parents: 3
diff changeset
58 String[] mainArgs;
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
59
10
2840c7a259f1 add acceptThread
e085711
parents: 9
diff changeset
60 // RfbProto rfb;
8
67caa17deb6f create accept setSoTimeout initServSock
e085711
parents: 4
diff changeset
61 MyRfbProto rfb;
4
e085711
parents: 3
diff changeset
62 Thread rfbThread;
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
63
4
e085711
parents: 3
diff changeset
64 Frame vncFrame;
e085711
parents: 3
diff changeset
65 Container vncContainer;
e085711
parents: 3
diff changeset
66 ScrollPane desktopScrollPane;
e085711
parents: 3
diff changeset
67 GridBagLayout gridbag;
e085711
parents: 3
diff changeset
68 ButtonPanel buttonPanel;
e085711
parents: 3
diff changeset
69 Label connStatusLabel;
e085711
parents: 3
diff changeset
70 VncCanvas vc;
e085711
parents: 3
diff changeset
71 OptionsFrame options;
e085711
parents: 3
diff changeset
72 ClipboardFrame clipboard;
e085711
parents: 3
diff changeset
73 RecordingFrame rec;
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
74
4
e085711
parents: 3
diff changeset
75 // Control session recording.
e085711
parents: 3
diff changeset
76 Object recordingSync;
e085711
parents: 3
diff changeset
77 String sessionFileName;
e085711
parents: 3
diff changeset
78 boolean recordingActive;
e085711
parents: 3
diff changeset
79 boolean recordingStatusChanged;
e085711
parents: 3
diff changeset
80 String cursorUpdatesDef;
e085711
parents: 3
diff changeset
81 String eightBitColorsDef;
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
82
4
e085711
parents: 3
diff changeset
83 // Variables read from parameter values.
e085711
parents: 3
diff changeset
84 String socketFactory;
e085711
parents: 3
diff changeset
85 String host;
e085711
parents: 3
diff changeset
86 int port;
e085711
parents: 3
diff changeset
87 String passwordParam;
e085711
parents: 3
diff changeset
88 boolean showControls;
e085711
parents: 3
diff changeset
89 boolean offerRelogin;
e085711
parents: 3
diff changeset
90 boolean showOfflineDesktop;
e085711
parents: 3
diff changeset
91 int deferScreenUpdates;
e085711
parents: 3
diff changeset
92 int deferCursorUpdates;
e085711
parents: 3
diff changeset
93 int deferUpdateRequests;
e085711
parents: 3
diff changeset
94 int debugStatsExcludeUpdates;
e085711
parents: 3
diff changeset
95 int debugStatsMeasureUpdates;
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
96
4
e085711
parents: 3
diff changeset
97 // Reference to this applet for inter-applet communication.
e085711
parents: 3
diff changeset
98 public static java.applet.Applet refApplet;
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
99
4
e085711
parents: 3
diff changeset
100 //
e085711
parents: 3
diff changeset
101 // init()
e085711
parents: 3
diff changeset
102 //
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
103
4
e085711
parents: 3
diff changeset
104 public void init() {
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
105
4
e085711
parents: 3
diff changeset
106 readParameters();
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
107
4
e085711
parents: 3
diff changeset
108 refApplet = this;
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
109
4
e085711
parents: 3
diff changeset
110 if (inSeparateFrame) {
e085711
parents: 3
diff changeset
111 vncFrame = new Frame("TightVNC");
e085711
parents: 3
diff changeset
112 if (!inAnApplet) {
e085711
parents: 3
diff changeset
113 vncFrame.add("Center", this);
e085711
parents: 3
diff changeset
114 }
e085711
parents: 3
diff changeset
115 vncContainer = vncFrame;
e085711
parents: 3
diff changeset
116 } else {
e085711
parents: 3
diff changeset
117 vncContainer = this;
e085711
parents: 3
diff changeset
118 }
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
119
4
e085711
parents: 3
diff changeset
120 recordingSync = new Object();
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
121
4
e085711
parents: 3
diff changeset
122 options = new OptionsFrame(this);
e085711
parents: 3
diff changeset
123 clipboard = new ClipboardFrame(this);
e085711
parents: 3
diff changeset
124 if (RecordingFrame.checkSecurity())
e085711
parents: 3
diff changeset
125 rec = new RecordingFrame(this);
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
126
4
e085711
parents: 3
diff changeset
127 sessionFileName = null;
e085711
parents: 3
diff changeset
128 recordingActive = false;
e085711
parents: 3
diff changeset
129 recordingStatusChanged = false;
e085711
parents: 3
diff changeset
130 cursorUpdatesDef = null;
e085711
parents: 3
diff changeset
131 eightBitColorsDef = null;
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
132
4
e085711
parents: 3
diff changeset
133 if (inSeparateFrame)
e085711
parents: 3
diff changeset
134 vncFrame.addWindowListener(this);
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
135
4
e085711
parents: 3
diff changeset
136 rfbThread = new Thread(this);
e085711
parents: 3
diff changeset
137 rfbThread.start();
e085711
parents: 3
diff changeset
138 }
e085711
parents: 3
diff changeset
139
e085711
parents: 3
diff changeset
140 public void update(Graphics g) {
e085711
parents: 3
diff changeset
141 }
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
142
4
e085711
parents: 3
diff changeset
143 //
e085711
parents: 3
diff changeset
144 // run() - executed by the rfbThread to deal with the RFB socket.
e085711
parents: 3
diff changeset
145 //
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
146
4
e085711
parents: 3
diff changeset
147 public void run() {
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
148
4
e085711
parents: 3
diff changeset
149 gridbag = new GridBagLayout();
e085711
parents: 3
diff changeset
150 vncContainer.setLayout(gridbag);
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
151
4
e085711
parents: 3
diff changeset
152 GridBagConstraints gbc = new GridBagConstraints();
e085711
parents: 3
diff changeset
153 gbc.gridwidth = GridBagConstraints.REMAINDER;
e085711
parents: 3
diff changeset
154 gbc.anchor = GridBagConstraints.NORTHWEST;
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
155
4
e085711
parents: 3
diff changeset
156 if (showControls) {
e085711
parents: 3
diff changeset
157 buttonPanel = new ButtonPanel(this);
e085711
parents: 3
diff changeset
158 gridbag.setConstraints(buttonPanel, gbc);
e085711
parents: 3
diff changeset
159 vncContainer.add(buttonPanel);
e085711
parents: 3
diff changeset
160 }
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
161
4
e085711
parents: 3
diff changeset
162 try {
e085711
parents: 3
diff changeset
163 connectAndAuthenticate();
e085711
parents: 3
diff changeset
164 doProtocolInitialisation();
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
165
4
e085711
parents: 3
diff changeset
166 // FIXME: Use auto-scaling not only in a separate frame.
e085711
parents: 3
diff changeset
167 if (options.autoScale && inSeparateFrame) {
e085711
parents: 3
diff changeset
168 Dimension screenSize;
e085711
parents: 3
diff changeset
169 try {
e085711
parents: 3
diff changeset
170 screenSize = vncContainer.getToolkit().getScreenSize();
e085711
parents: 3
diff changeset
171 } catch (Exception e) {
e085711
parents: 3
diff changeset
172 screenSize = new Dimension(0, 0);
e085711
parents: 3
diff changeset
173 }
e085711
parents: 3
diff changeset
174 createCanvas(screenSize.width - 32, screenSize.height - 32);
e085711
parents: 3
diff changeset
175 } else {
e085711
parents: 3
diff changeset
176 createCanvas(0, 0);
e085711
parents: 3
diff changeset
177 }
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
178
4
e085711
parents: 3
diff changeset
179 gbc.weightx = 1.0;
e085711
parents: 3
diff changeset
180 gbc.weighty = 1.0;
e085711
parents: 3
diff changeset
181
e085711
parents: 3
diff changeset
182 if (inSeparateFrame) {
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
183
4
e085711
parents: 3
diff changeset
184 // Create a panel which itself is resizeable and can hold
e085711
parents: 3
diff changeset
185 // non-resizeable VncCanvas component at the top left corner.
e085711
parents: 3
diff changeset
186 Panel canvasPanel = new Panel();
e085711
parents: 3
diff changeset
187 canvasPanel.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0));
e085711
parents: 3
diff changeset
188 canvasPanel.add(vc);
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
189
4
e085711
parents: 3
diff changeset
190 // Create a ScrollPane which will hold a panel with VncCanvas
e085711
parents: 3
diff changeset
191 // inside.
e085711
parents: 3
diff changeset
192 desktopScrollPane = new ScrollPane(
e085711
parents: 3
diff changeset
193 ScrollPane.SCROLLBARS_AS_NEEDED);
e085711
parents: 3
diff changeset
194 gbc.fill = GridBagConstraints.BOTH;
e085711
parents: 3
diff changeset
195 gridbag.setConstraints(desktopScrollPane, gbc);
e085711
parents: 3
diff changeset
196 desktopScrollPane.add(canvasPanel);
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
197
4
e085711
parents: 3
diff changeset
198 // Finally, add our ScrollPane to the Frame window.
e085711
parents: 3
diff changeset
199 vncFrame.add(desktopScrollPane);
e085711
parents: 3
diff changeset
200 vncFrame.setTitle(rfb.desktopName);
e085711
parents: 3
diff changeset
201 vncFrame.pack();
e085711
parents: 3
diff changeset
202 vc.resizeDesktopFrame();
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
203
4
e085711
parents: 3
diff changeset
204 } else {
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
205
4
e085711
parents: 3
diff changeset
206 // Just add the VncCanvas component to the Applet.
e085711
parents: 3
diff changeset
207 gridbag.setConstraints(vc, gbc);
e085711
parents: 3
diff changeset
208 add(vc);
e085711
parents: 3
diff changeset
209 validate();
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
210
4
e085711
parents: 3
diff changeset
211 }
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
212
4
e085711
parents: 3
diff changeset
213 if (showControls)
e085711
parents: 3
diff changeset
214 buttonPanel.enableButtons();
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
215
4
e085711
parents: 3
diff changeset
216 moveFocusToDesktop();
e085711
parents: 3
diff changeset
217 processNormalProtocol();// main loop
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
218
4
e085711
parents: 3
diff changeset
219 } catch (NoRouteToHostException e) {
e085711
parents: 3
diff changeset
220 fatalError("Network error: no route to server: " + host, e);
e085711
parents: 3
diff changeset
221 } catch (UnknownHostException e) {
e085711
parents: 3
diff changeset
222 fatalError("Network error: server name unknown: " + host, e);
e085711
parents: 3
diff changeset
223 } catch (ConnectException e) {
e085711
parents: 3
diff changeset
224 fatalError("Network error: could not connect to server: " + host
e085711
parents: 3
diff changeset
225 + ":" + port, e);
e085711
parents: 3
diff changeset
226 } catch (EOFException e) {
e085711
parents: 3
diff changeset
227 if (showOfflineDesktop) {
e085711
parents: 3
diff changeset
228 e.printStackTrace();
e085711
parents: 3
diff changeset
229 System.out
e085711
parents: 3
diff changeset
230 .println("Network error: remote side closed connection");
e085711
parents: 3
diff changeset
231 if (vc != null) {
e085711
parents: 3
diff changeset
232 vc.enableInput(false);
e085711
parents: 3
diff changeset
233 }
e085711
parents: 3
diff changeset
234 if (inSeparateFrame) {
e085711
parents: 3
diff changeset
235 vncFrame.setTitle(rfb.desktopName + " [disconnected]");
e085711
parents: 3
diff changeset
236 }
e085711
parents: 3
diff changeset
237 if (rfb != null && !rfb.closed())
e085711
parents: 3
diff changeset
238 rfb.close();
e085711
parents: 3
diff changeset
239 if (showControls && buttonPanel != null) {
e085711
parents: 3
diff changeset
240 buttonPanel.disableButtonsOnDisconnect();
e085711
parents: 3
diff changeset
241 if (inSeparateFrame) {
e085711
parents: 3
diff changeset
242 vncFrame.pack();
e085711
parents: 3
diff changeset
243 } else {
e085711
parents: 3
diff changeset
244 validate();
e085711
parents: 3
diff changeset
245 }
e085711
parents: 3
diff changeset
246 }
e085711
parents: 3
diff changeset
247 } else {
e085711
parents: 3
diff changeset
248 fatalError("Network error: remote side closed connection", e);
e085711
parents: 3
diff changeset
249 }
e085711
parents: 3
diff changeset
250 } catch (IOException e) {
e085711
parents: 3
diff changeset
251 String str = e.getMessage();
e085711
parents: 3
diff changeset
252 if (str != null && str.length() != 0) {
e085711
parents: 3
diff changeset
253 fatalError("Network Error: " + str, e);
e085711
parents: 3
diff changeset
254 } else {
e085711
parents: 3
diff changeset
255 fatalError(e.toString(), e);
e085711
parents: 3
diff changeset
256 }
e085711
parents: 3
diff changeset
257 } catch (Exception e) {
e085711
parents: 3
diff changeset
258 String str = e.getMessage();
e085711
parents: 3
diff changeset
259 if (str != null && str.length() != 0) {
e085711
parents: 3
diff changeset
260 fatalError("Error: " + str, e);
e085711
parents: 3
diff changeset
261 } else {
e085711
parents: 3
diff changeset
262 fatalError(e.toString(), e);
e085711
parents: 3
diff changeset
263 }
e085711
parents: 3
diff changeset
264 }
e085711
parents: 3
diff changeset
265
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
266 }
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
267
4
e085711
parents: 3
diff changeset
268 //
e085711
parents: 3
diff changeset
269 // Create a VncCanvas instance.
e085711
parents: 3
diff changeset
270 //
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
271
4
e085711
parents: 3
diff changeset
272 void createCanvas(int maxWidth, int maxHeight) throws IOException {
e085711
parents: 3
diff changeset
273 // Determine if Java 2D API is available and use a special
e085711
parents: 3
diff changeset
274 // version of VncCanvas if it is present.
e085711
parents: 3
diff changeset
275 vc = null;
e085711
parents: 3
diff changeset
276 try {
e085711
parents: 3
diff changeset
277 // This throws ClassNotFoundException if there is no Java 2D API.
e085711
parents: 3
diff changeset
278 Class cl = Class.forName("java.awt.Graphics2D");
e085711
parents: 3
diff changeset
279 // If we could load Graphics2D class, then we can use VncCanvas2D.
e085711
parents: 3
diff changeset
280 cl = Class.forName("VncCanvas2");
e085711
parents: 3
diff changeset
281 Class[] argClasses = { this.getClass(), Integer.TYPE, Integer.TYPE };
e085711
parents: 3
diff changeset
282 java.lang.reflect.Constructor cstr = cl.getConstructor(argClasses);
e085711
parents: 3
diff changeset
283 Object[] argObjects = { this, new Integer(maxWidth),
e085711
parents: 3
diff changeset
284 new Integer(maxHeight) };
e085711
parents: 3
diff changeset
285 vc = (VncCanvas) cstr.newInstance(argObjects);
e085711
parents: 3
diff changeset
286 } catch (Exception e) {
e085711
parents: 3
diff changeset
287 System.out.println("Warning: Java 2D API is not available");
e085711
parents: 3
diff changeset
288 }
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
289
4
e085711
parents: 3
diff changeset
290 // If we failed to create VncCanvas2D, use old VncCanvas.
e085711
parents: 3
diff changeset
291 if (vc == null)
e085711
parents: 3
diff changeset
292 vc = new VncCanvas(this, maxWidth, maxHeight);
e085711
parents: 3
diff changeset
293 }
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
294
4
e085711
parents: 3
diff changeset
295 //
e085711
parents: 3
diff changeset
296 // Process RFB socket messages.
e085711
parents: 3
diff changeset
297 // If the rfbThread is being stopped, ignore any exceptions,
e085711
parents: 3
diff changeset
298 // otherwise rethrow the exception so it can be handled.
e085711
parents: 3
diff changeset
299 //
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
300
4
e085711
parents: 3
diff changeset
301 void processNormalProtocol() throws Exception {
e085711
parents: 3
diff changeset
302 try {
e085711
parents: 3
diff changeset
303 vc.processNormalProtocol();// main loop
e085711
parents: 3
diff changeset
304 } catch (Exception e) {
e085711
parents: 3
diff changeset
305 if (rfbThread == null) {
e085711
parents: 3
diff changeset
306 System.out.println("Ignoring RFB socket exceptions"
e085711
parents: 3
diff changeset
307 + " because applet is stopping");
e085711
parents: 3
diff changeset
308 } else {
e085711
parents: 3
diff changeset
309 throw e;
e085711
parents: 3
diff changeset
310 }
e085711
parents: 3
diff changeset
311 }
e085711
parents: 3
diff changeset
312 }
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
313
4
e085711
parents: 3
diff changeset
314 //
e085711
parents: 3
diff changeset
315 // Connect to the RFB server and authenticate the user.
e085711
parents: 3
diff changeset
316 //
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
317
4
e085711
parents: 3
diff changeset
318 void connectAndAuthenticate() throws Exception {
e085711
parents: 3
diff changeset
319 showConnectionStatus("Initializing...");
e085711
parents: 3
diff changeset
320 if (inSeparateFrame) {
e085711
parents: 3
diff changeset
321 vncFrame.pack();
e085711
parents: 3
diff changeset
322 vncFrame.setVisible(true);
e085711
parents: 3
diff changeset
323 } else {
e085711
parents: 3
diff changeset
324 validate();
e085711
parents: 3
diff changeset
325 }
e085711
parents: 3
diff changeset
326
e085711
parents: 3
diff changeset
327 showConnectionStatus("Connecting to " + host + ", port " + port + "...");
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
328
10
2840c7a259f1 add acceptThread
e085711
parents: 9
diff changeset
329 // rfb = new RfbProto(host, port, this);
8
67caa17deb6f create accept setSoTimeout initServSock
e085711
parents: 4
diff changeset
330 rfb = new MyRfbProto(host, port, this);
4
e085711
parents: 3
diff changeset
331 showConnectionStatus("Connected to server");
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
332
4
e085711
parents: 3
diff changeset
333 rfb.readVersionMsg();
e085711
parents: 3
diff changeset
334 showConnectionStatus("RFB server supports protocol version "
e085711
parents: 3
diff changeset
335 + rfb.serverMajor + "." + rfb.serverMinor);
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
336
4
e085711
parents: 3
diff changeset
337 rfb.writeVersionMsg();
e085711
parents: 3
diff changeset
338 showConnectionStatus("Using RFB protocol version " + rfb.clientMajor
e085711
parents: 3
diff changeset
339 + "." + rfb.clientMinor);
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
340
4
e085711
parents: 3
diff changeset
341 int secType = rfb.negotiateSecurity();
e085711
parents: 3
diff changeset
342 int authType;
e085711
parents: 3
diff changeset
343 if (secType == RfbProto.SecTypeTight) {
e085711
parents: 3
diff changeset
344 showConnectionStatus("Enabling TightVNC protocol extensions");
e085711
parents: 3
diff changeset
345 rfb.setupTunneling();
e085711
parents: 3
diff changeset
346 authType = rfb.negotiateAuthenticationTight();
e085711
parents: 3
diff changeset
347 } else {
e085711
parents: 3
diff changeset
348 authType = secType;
e085711
parents: 3
diff changeset
349 }
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
350
4
e085711
parents: 3
diff changeset
351 switch (authType) {
e085711
parents: 3
diff changeset
352 case RfbProto.AuthNone:
e085711
parents: 3
diff changeset
353 showConnectionStatus("No authentication needed");
e085711
parents: 3
diff changeset
354 rfb.authenticateNone();
e085711
parents: 3
diff changeset
355 break;
e085711
parents: 3
diff changeset
356 case RfbProto.AuthVNC:
e085711
parents: 3
diff changeset
357 showConnectionStatus("Performing standard VNC authentication");
e085711
parents: 3
diff changeset
358 if (passwordParam != null) {
e085711
parents: 3
diff changeset
359 rfb.authenticateVNC(passwordParam);
e085711
parents: 3
diff changeset
360 } else {
e085711
parents: 3
diff changeset
361 String pw = askPassword();
e085711
parents: 3
diff changeset
362 rfb.authenticateVNC(pw);
e085711
parents: 3
diff changeset
363 }
e085711
parents: 3
diff changeset
364 break;
e085711
parents: 3
diff changeset
365 default:
e085711
parents: 3
diff changeset
366 throw new Exception("Unknown authentication scheme " + authType);
e085711
parents: 3
diff changeset
367 }
e085711
parents: 3
diff changeset
368 }
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
369
4
e085711
parents: 3
diff changeset
370 //
e085711
parents: 3
diff changeset
371 // Show a message describing the connection status.
e085711
parents: 3
diff changeset
372 // To hide the connection status label, use (msg == null).
e085711
parents: 3
diff changeset
373 //
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
374
4
e085711
parents: 3
diff changeset
375 void showConnectionStatus(String msg) {
e085711
parents: 3
diff changeset
376 if (msg == null) {
e085711
parents: 3
diff changeset
377 if (vncContainer.isAncestorOf(connStatusLabel)) {
e085711
parents: 3
diff changeset
378 vncContainer.remove(connStatusLabel);
e085711
parents: 3
diff changeset
379 }
e085711
parents: 3
diff changeset
380 return;
e085711
parents: 3
diff changeset
381 }
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
382
4
e085711
parents: 3
diff changeset
383 System.out.println(msg);
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
384
4
e085711
parents: 3
diff changeset
385 if (connStatusLabel == null) {
e085711
parents: 3
diff changeset
386 connStatusLabel = new Label("Status: " + msg);
e085711
parents: 3
diff changeset
387 connStatusLabel.setFont(new Font("Helvetica", Font.PLAIN, 12));
e085711
parents: 3
diff changeset
388 } else {
e085711
parents: 3
diff changeset
389 connStatusLabel.setText("Status: " + msg);
e085711
parents: 3
diff changeset
390 }
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
391
4
e085711
parents: 3
diff changeset
392 if (!vncContainer.isAncestorOf(connStatusLabel)) {
e085711
parents: 3
diff changeset
393 GridBagConstraints gbc = new GridBagConstraints();
e085711
parents: 3
diff changeset
394 gbc.gridwidth = GridBagConstraints.REMAINDER;
e085711
parents: 3
diff changeset
395 gbc.fill = GridBagConstraints.HORIZONTAL;
e085711
parents: 3
diff changeset
396 gbc.anchor = GridBagConstraints.NORTHWEST;
e085711
parents: 3
diff changeset
397 gbc.weightx = 1.0;
e085711
parents: 3
diff changeset
398 gbc.weighty = 1.0;
e085711
parents: 3
diff changeset
399 gbc.insets = new Insets(20, 30, 20, 30);
e085711
parents: 3
diff changeset
400 gridbag.setConstraints(connStatusLabel, gbc);
e085711
parents: 3
diff changeset
401 vncContainer.add(connStatusLabel);
e085711
parents: 3
diff changeset
402 }
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
403
4
e085711
parents: 3
diff changeset
404 if (inSeparateFrame) {
e085711
parents: 3
diff changeset
405 vncFrame.pack();
e085711
parents: 3
diff changeset
406 } else {
e085711
parents: 3
diff changeset
407 validate();
e085711
parents: 3
diff changeset
408 }
e085711
parents: 3
diff changeset
409 }
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
410
4
e085711
parents: 3
diff changeset
411 //
e085711
parents: 3
diff changeset
412 // Show an authentication panel.
e085711
parents: 3
diff changeset
413 //
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
414
4
e085711
parents: 3
diff changeset
415 String askPassword() throws Exception {
e085711
parents: 3
diff changeset
416 showConnectionStatus(null);
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
417
4
e085711
parents: 3
diff changeset
418 AuthPanel authPanel = new AuthPanel(this);
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
419
4
e085711
parents: 3
diff changeset
420 GridBagConstraints gbc = new GridBagConstraints();
e085711
parents: 3
diff changeset
421 gbc.gridwidth = GridBagConstraints.REMAINDER;
e085711
parents: 3
diff changeset
422 gbc.anchor = GridBagConstraints.NORTHWEST;
e085711
parents: 3
diff changeset
423 gbc.weightx = 1.0;
e085711
parents: 3
diff changeset
424 gbc.weighty = 1.0;
e085711
parents: 3
diff changeset
425 gbc.ipadx = 100;
e085711
parents: 3
diff changeset
426 gbc.ipady = 50;
e085711
parents: 3
diff changeset
427 gridbag.setConstraints(authPanel, gbc);
e085711
parents: 3
diff changeset
428 vncContainer.add(authPanel);
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
429
4
e085711
parents: 3
diff changeset
430 if (inSeparateFrame) {
e085711
parents: 3
diff changeset
431 vncFrame.pack();
e085711
parents: 3
diff changeset
432 } else {
e085711
parents: 3
diff changeset
433 validate();
e085711
parents: 3
diff changeset
434 }
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
435
4
e085711
parents: 3
diff changeset
436 authPanel.moveFocusToDefaultField();
e085711
parents: 3
diff changeset
437 String pw = authPanel.getPassword();
e085711
parents: 3
diff changeset
438 vncContainer.remove(authPanel);
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
439
4
e085711
parents: 3
diff changeset
440 return pw;
e085711
parents: 3
diff changeset
441 }
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
442
4
e085711
parents: 3
diff changeset
443 //
e085711
parents: 3
diff changeset
444 // Do the rest of the protocol initialisation.
e085711
parents: 3
diff changeset
445 //
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
446
4
e085711
parents: 3
diff changeset
447 void doProtocolInitialisation() throws IOException {
e085711
parents: 3
diff changeset
448 rfb.writeClientInit();
e085711
parents: 3
diff changeset
449 rfb.readServerInit();
e085711
parents: 3
diff changeset
450
e085711
parents: 3
diff changeset
451 System.out.println("Desktop name is " + rfb.desktopName);
e085711
parents: 3
diff changeset
452 System.out.println("Desktop size is " + rfb.framebufferWidth + " x "
e085711
parents: 3
diff changeset
453 + rfb.framebufferHeight);
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
454
4
e085711
parents: 3
diff changeset
455 setEncodings();
e085711
parents: 3
diff changeset
456
e085711
parents: 3
diff changeset
457 showConnectionStatus(null);
e085711
parents: 3
diff changeset
458 }
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
459
4
e085711
parents: 3
diff changeset
460 //
e085711
parents: 3
diff changeset
461 // Send current encoding list to the RFB server.
e085711
parents: 3
diff changeset
462 //
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
463
4
e085711
parents: 3
diff changeset
464 int[] encodingsSaved;
e085711
parents: 3
diff changeset
465 int nEncodingsSaved;
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
466
4
e085711
parents: 3
diff changeset
467 void setEncodings() {
e085711
parents: 3
diff changeset
468 setEncodings(false);
e085711
parents: 3
diff changeset
469 }
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
470
4
e085711
parents: 3
diff changeset
471 void autoSelectEncodings() {
e085711
parents: 3
diff changeset
472 setEncodings(true);
e085711
parents: 3
diff changeset
473 }
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
474
4
e085711
parents: 3
diff changeset
475 void setEncodings(boolean autoSelectOnly) {
e085711
parents: 3
diff changeset
476 if (options == null || rfb == null || !rfb.inNormalProtocol)
e085711
parents: 3
diff changeset
477 return;
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
478
4
e085711
parents: 3
diff changeset
479 int preferredEncoding = options.preferredEncoding;
e085711
parents: 3
diff changeset
480 if (preferredEncoding == -1) {
e085711
parents: 3
diff changeset
481 long kbitsPerSecond = rfb.kbitsPerSecond();
e085711
parents: 3
diff changeset
482 if (nEncodingsSaved < 1) {
e085711
parents: 3
diff changeset
483 // Choose Tight or ZRLE encoding for the very first update.
e085711
parents: 3
diff changeset
484 System.out.println("Using Tight/ZRLE encodings");
e085711
parents: 3
diff changeset
485 preferredEncoding = RfbProto.EncodingTight;
e085711
parents: 3
diff changeset
486 } else if (kbitsPerSecond > 2000
e085711
parents: 3
diff changeset
487 && encodingsSaved[0] != RfbProto.EncodingHextile) {
e085711
parents: 3
diff changeset
488 // Switch to Hextile if the connection speed is above 2Mbps.
e085711
parents: 3
diff changeset
489 System.out.println("Throughput " + kbitsPerSecond
e085711
parents: 3
diff changeset
490 + " kbit/s - changing to Hextile encoding");
e085711
parents: 3
diff changeset
491 preferredEncoding = RfbProto.EncodingHextile;
e085711
parents: 3
diff changeset
492 } else if (kbitsPerSecond < 1000
e085711
parents: 3
diff changeset
493 && encodingsSaved[0] != RfbProto.EncodingTight) {
e085711
parents: 3
diff changeset
494 // Switch to Tight/ZRLE if the connection speed is below 1Mbps.
e085711
parents: 3
diff changeset
495 System.out.println("Throughput " + kbitsPerSecond
e085711
parents: 3
diff changeset
496 + " kbit/s - changing to Tight/ZRLE encodings");
e085711
parents: 3
diff changeset
497 preferredEncoding = RfbProto.EncodingTight;
e085711
parents: 3
diff changeset
498 } else {
e085711
parents: 3
diff changeset
499 // Don't change the encoder.
e085711
parents: 3
diff changeset
500 if (autoSelectOnly)
e085711
parents: 3
diff changeset
501 return;
e085711
parents: 3
diff changeset
502 preferredEncoding = encodingsSaved[0];
e085711
parents: 3
diff changeset
503 }
e085711
parents: 3
diff changeset
504 } else {
e085711
parents: 3
diff changeset
505 // Auto encoder selection is not enabled.
e085711
parents: 3
diff changeset
506 if (autoSelectOnly)
e085711
parents: 3
diff changeset
507 return;
e085711
parents: 3
diff changeset
508 }
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
509
4
e085711
parents: 3
diff changeset
510 int[] encodings = new int[20];
e085711
parents: 3
diff changeset
511 int nEncodings = 0;
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
512
4
e085711
parents: 3
diff changeset
513 encodings[nEncodings++] = preferredEncoding;
e085711
parents: 3
diff changeset
514 if (options.useCopyRect) {
e085711
parents: 3
diff changeset
515 encodings[nEncodings++] = RfbProto.EncodingCopyRect;
e085711
parents: 3
diff changeset
516 }
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
517
4
e085711
parents: 3
diff changeset
518 if (preferredEncoding != RfbProto.EncodingTight) {
e085711
parents: 3
diff changeset
519 encodings[nEncodings++] = RfbProto.EncodingTight;
e085711
parents: 3
diff changeset
520 }
e085711
parents: 3
diff changeset
521 if (preferredEncoding != RfbProto.EncodingZRLE) {
e085711
parents: 3
diff changeset
522 encodings[nEncodings++] = RfbProto.EncodingZRLE;
e085711
parents: 3
diff changeset
523 }
e085711
parents: 3
diff changeset
524 if (preferredEncoding != RfbProto.EncodingHextile) {
e085711
parents: 3
diff changeset
525 encodings[nEncodings++] = RfbProto.EncodingHextile;
e085711
parents: 3
diff changeset
526 }
e085711
parents: 3
diff changeset
527 if (preferredEncoding != RfbProto.EncodingZlib) {
e085711
parents: 3
diff changeset
528 encodings[nEncodings++] = RfbProto.EncodingZlib;
e085711
parents: 3
diff changeset
529 }
e085711
parents: 3
diff changeset
530 if (preferredEncoding != RfbProto.EncodingCoRRE) {
e085711
parents: 3
diff changeset
531 encodings[nEncodings++] = RfbProto.EncodingCoRRE;
e085711
parents: 3
diff changeset
532 }
e085711
parents: 3
diff changeset
533 if (preferredEncoding != RfbProto.EncodingRRE) {
e085711
parents: 3
diff changeset
534 encodings[nEncodings++] = RfbProto.EncodingRRE;
e085711
parents: 3
diff changeset
535 }
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
536
4
e085711
parents: 3
diff changeset
537 if (options.compressLevel >= 0 && options.compressLevel <= 9) {
e085711
parents: 3
diff changeset
538 encodings[nEncodings++] = RfbProto.EncodingCompressLevel0
e085711
parents: 3
diff changeset
539 + options.compressLevel;
e085711
parents: 3
diff changeset
540 }
e085711
parents: 3
diff changeset
541 if (options.jpegQuality >= 0 && options.jpegQuality <= 9) {
e085711
parents: 3
diff changeset
542 encodings[nEncodings++] = RfbProto.EncodingQualityLevel0
e085711
parents: 3
diff changeset
543 + options.jpegQuality;
e085711
parents: 3
diff changeset
544 }
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
545
4
e085711
parents: 3
diff changeset
546 if (options.requestCursorUpdates) {
e085711
parents: 3
diff changeset
547 encodings[nEncodings++] = RfbProto.EncodingXCursor;
e085711
parents: 3
diff changeset
548 encodings[nEncodings++] = RfbProto.EncodingRichCursor;
e085711
parents: 3
diff changeset
549 if (!options.ignoreCursorUpdates)
e085711
parents: 3
diff changeset
550 encodings[nEncodings++] = RfbProto.EncodingPointerPos;
e085711
parents: 3
diff changeset
551 }
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
552
4
e085711
parents: 3
diff changeset
553 encodings[nEncodings++] = RfbProto.EncodingLastRect;
e085711
parents: 3
diff changeset
554 encodings[nEncodings++] = RfbProto.EncodingNewFBSize;
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
555
4
e085711
parents: 3
diff changeset
556 boolean encodingsWereChanged = false;
e085711
parents: 3
diff changeset
557 if (nEncodings != nEncodingsSaved) {
e085711
parents: 3
diff changeset
558 encodingsWereChanged = true;
e085711
parents: 3
diff changeset
559 } else {
e085711
parents: 3
diff changeset
560 for (int i = 0; i < nEncodings; i++) {
e085711
parents: 3
diff changeset
561 if (encodings[i] != encodingsSaved[i]) {
e085711
parents: 3
diff changeset
562 encodingsWereChanged = true;
e085711
parents: 3
diff changeset
563 break;
e085711
parents: 3
diff changeset
564 }
e085711
parents: 3
diff changeset
565 }
e085711
parents: 3
diff changeset
566 }
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
567
4
e085711
parents: 3
diff changeset
568 if (encodingsWereChanged) {
e085711
parents: 3
diff changeset
569 try {
e085711
parents: 3
diff changeset
570 rfb.writeSetEncodings(encodings, nEncodings);
e085711
parents: 3
diff changeset
571 if (vc != null) {
e085711
parents: 3
diff changeset
572 vc.softCursorFree();
e085711
parents: 3
diff changeset
573 }
e085711
parents: 3
diff changeset
574 } catch (Exception e) {
e085711
parents: 3
diff changeset
575 e.printStackTrace();
e085711
parents: 3
diff changeset
576 }
e085711
parents: 3
diff changeset
577 encodingsSaved = encodings;
e085711
parents: 3
diff changeset
578 nEncodingsSaved = nEncodings;
e085711
parents: 3
diff changeset
579 }
e085711
parents: 3
diff changeset
580 }
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
581
4
e085711
parents: 3
diff changeset
582 //
e085711
parents: 3
diff changeset
583 // setCutText() - send the given cut text to the RFB server.
e085711
parents: 3
diff changeset
584 //
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
585
4
e085711
parents: 3
diff changeset
586 void setCutText(String text) {
e085711
parents: 3
diff changeset
587 try {
e085711
parents: 3
diff changeset
588 if (rfb != null && rfb.inNormalProtocol) {
e085711
parents: 3
diff changeset
589 rfb.writeClientCutText(text);
e085711
parents: 3
diff changeset
590 }
e085711
parents: 3
diff changeset
591 } catch (Exception e) {
e085711
parents: 3
diff changeset
592 e.printStackTrace();
e085711
parents: 3
diff changeset
593 }
e085711
parents: 3
diff changeset
594 }
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
595
4
e085711
parents: 3
diff changeset
596 //
e085711
parents: 3
diff changeset
597 // Order change in session recording status. To stop recording, pass
e085711
parents: 3
diff changeset
598 // null in place of the fname argument.
e085711
parents: 3
diff changeset
599 //
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
600
4
e085711
parents: 3
diff changeset
601 void setRecordingStatus(String fname) {
e085711
parents: 3
diff changeset
602 synchronized (recordingSync) {
e085711
parents: 3
diff changeset
603 sessionFileName = fname;
e085711
parents: 3
diff changeset
604 recordingStatusChanged = true;
e085711
parents: 3
diff changeset
605 }
e085711
parents: 3
diff changeset
606 }
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
607
4
e085711
parents: 3
diff changeset
608 //
e085711
parents: 3
diff changeset
609 // Start or stop session recording. Returns true if this method call
e085711
parents: 3
diff changeset
610 // causes recording of a new session.
e085711
parents: 3
diff changeset
611 //
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
612
4
e085711
parents: 3
diff changeset
613 boolean checkRecordingStatus() throws IOException {
e085711
parents: 3
diff changeset
614 synchronized (recordingSync) {
e085711
parents: 3
diff changeset
615 if (recordingStatusChanged) {
e085711
parents: 3
diff changeset
616 recordingStatusChanged = false;
e085711
parents: 3
diff changeset
617 if (sessionFileName != null) {
e085711
parents: 3
diff changeset
618 startRecording();
e085711
parents: 3
diff changeset
619 return true;
e085711
parents: 3
diff changeset
620 } else {
e085711
parents: 3
diff changeset
621 stopRecording();
e085711
parents: 3
diff changeset
622 }
e085711
parents: 3
diff changeset
623 }
e085711
parents: 3
diff changeset
624 }
e085711
parents: 3
diff changeset
625 return false;
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
626 }
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
627
4
e085711
parents: 3
diff changeset
628 //
e085711
parents: 3
diff changeset
629 // Start session recording.
e085711
parents: 3
diff changeset
630 //
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
631
4
e085711
parents: 3
diff changeset
632 protected void startRecording() throws IOException {
e085711
parents: 3
diff changeset
633 synchronized (recordingSync) {
e085711
parents: 3
diff changeset
634 if (!recordingActive) {
e085711
parents: 3
diff changeset
635 // Save settings to restore them after recording the session.
e085711
parents: 3
diff changeset
636 cursorUpdatesDef = options.choices[options.cursorUpdatesIndex]
e085711
parents: 3
diff changeset
637 .getSelectedItem();
e085711
parents: 3
diff changeset
638 eightBitColorsDef = options.choices[options.eightBitColorsIndex]
e085711
parents: 3
diff changeset
639 .getSelectedItem();
e085711
parents: 3
diff changeset
640 // Set options to values suitable for recording.
e085711
parents: 3
diff changeset
641 options.choices[options.cursorUpdatesIndex].select("Disable");
e085711
parents: 3
diff changeset
642 options.choices[options.cursorUpdatesIndex].setEnabled(false);
e085711
parents: 3
diff changeset
643 options.setEncodings();
e085711
parents: 3
diff changeset
644 options.choices[options.eightBitColorsIndex].select("No");
e085711
parents: 3
diff changeset
645 options.choices[options.eightBitColorsIndex].setEnabled(false);
e085711
parents: 3
diff changeset
646 options.setColorFormat();
e085711
parents: 3
diff changeset
647 } else {
e085711
parents: 3
diff changeset
648 rfb.closeSession();
e085711
parents: 3
diff changeset
649 }
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
650
4
e085711
parents: 3
diff changeset
651 System.out.println("Recording the session in " + sessionFileName);
e085711
parents: 3
diff changeset
652 rfb.startSession(sessionFileName);
e085711
parents: 3
diff changeset
653 recordingActive = true;
e085711
parents: 3
diff changeset
654 }
e085711
parents: 3
diff changeset
655 }
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
656
4
e085711
parents: 3
diff changeset
657 //
e085711
parents: 3
diff changeset
658 // Stop session recording.
e085711
parents: 3
diff changeset
659 //
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
660
4
e085711
parents: 3
diff changeset
661 protected void stopRecording() throws IOException {
e085711
parents: 3
diff changeset
662 synchronized (recordingSync) {
e085711
parents: 3
diff changeset
663 if (recordingActive) {
e085711
parents: 3
diff changeset
664 // Restore options.
e085711
parents: 3
diff changeset
665 options.choices[options.cursorUpdatesIndex]
e085711
parents: 3
diff changeset
666 .select(cursorUpdatesDef);
e085711
parents: 3
diff changeset
667 options.choices[options.cursorUpdatesIndex].setEnabled(true);
e085711
parents: 3
diff changeset
668 options.setEncodings();
e085711
parents: 3
diff changeset
669 options.choices[options.eightBitColorsIndex]
e085711
parents: 3
diff changeset
670 .select(eightBitColorsDef);
e085711
parents: 3
diff changeset
671 options.choices[options.eightBitColorsIndex].setEnabled(true);
e085711
parents: 3
diff changeset
672 options.setColorFormat();
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
673
4
e085711
parents: 3
diff changeset
674 rfb.closeSession();
e085711
parents: 3
diff changeset
675 System.out.println("Session recording stopped.");
e085711
parents: 3
diff changeset
676 }
e085711
parents: 3
diff changeset
677 sessionFileName = null;
e085711
parents: 3
diff changeset
678 recordingActive = false;
e085711
parents: 3
diff changeset
679 }
e085711
parents: 3
diff changeset
680 }
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
681
4
e085711
parents: 3
diff changeset
682 //
e085711
parents: 3
diff changeset
683 // readParameters() - read parameters from the html source or from the
e085711
parents: 3
diff changeset
684 // command line. On the command line, the arguments are just a sequence of
e085711
parents: 3
diff changeset
685 // param_name/param_value pairs where the names and values correspond to
e085711
parents: 3
diff changeset
686 // those expected in the html applet tag source.
e085711
parents: 3
diff changeset
687 //
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
688
4
e085711
parents: 3
diff changeset
689 void readParameters() {
e085711
parents: 3
diff changeset
690 // host = readParameter("HOST", !inAnApplet);
e085711
parents: 3
diff changeset
691 if (mainArgs.length > 0)
e085711
parents: 3
diff changeset
692 host = mainArgs[0];
e085711
parents: 3
diff changeset
693 else
e085711
parents: 3
diff changeset
694 host = "hades.cr.ie.u-ryukyu.ac.jp";
e085711
parents: 3
diff changeset
695 /*
e085711
parents: 3
diff changeset
696 * if (host == null) { host = getCodeBase().getHost(); if
e085711
parents: 3
diff changeset
697 * (host.equals("")) { fatalError("HOST parameter not specified"); } }
e085711
parents: 3
diff changeset
698 */
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
699
4
e085711
parents: 3
diff changeset
700 // port = readIntParameter("PORT", 5900);
e085711
parents: 3
diff changeset
701 if (mainArgs.length > 1)
e085711
parents: 3
diff changeset
702 port = Integer.parseInt(mainArgs[1]);
e085711
parents: 3
diff changeset
703 else
e085711
parents: 3
diff changeset
704 port = 5900;
e085711
parents: 3
diff changeset
705 // Read "ENCPASSWORD" or "PASSWORD" parameter if specified.
e085711
parents: 3
diff changeset
706 readPasswordParameters();
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
707
4
e085711
parents: 3
diff changeset
708 String str;
e085711
parents: 3
diff changeset
709 if (inAnApplet) {
e085711
parents: 3
diff changeset
710 str = readParameter("Open New Window", false);
e085711
parents: 3
diff changeset
711 if (str != null && str.equalsIgnoreCase("Yes"))
e085711
parents: 3
diff changeset
712 inSeparateFrame = true;
e085711
parents: 3
diff changeset
713 }
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
714
4
e085711
parents: 3
diff changeset
715 // "Show Controls" set to "No" disables button panel.
e085711
parents: 3
diff changeset
716 showControls = true;
e085711
parents: 3
diff changeset
717 str = readParameter("Show Controls", false);
e085711
parents: 3
diff changeset
718 if (str != null && str.equalsIgnoreCase("No"))
e085711
parents: 3
diff changeset
719 showControls = false;
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
720
4
e085711
parents: 3
diff changeset
721 // "Offer Relogin" set to "No" disables "Login again" and "Close
e085711
parents: 3
diff changeset
722 // window" buttons under error messages in applet mode.
e085711
parents: 3
diff changeset
723 offerRelogin = true;
e085711
parents: 3
diff changeset
724 str = readParameter("Offer Relogin", false);
e085711
parents: 3
diff changeset
725 if (str != null && str.equalsIgnoreCase("No"))
e085711
parents: 3
diff changeset
726 offerRelogin = false;
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
727
4
e085711
parents: 3
diff changeset
728 // Do we continue showing desktop on remote disconnect?
e085711
parents: 3
diff changeset
729 showOfflineDesktop = false;
e085711
parents: 3
diff changeset
730 str = readParameter("Show Offline Desktop", false);
e085711
parents: 3
diff changeset
731 if (str != null && str.equalsIgnoreCase("Yes"))
e085711
parents: 3
diff changeset
732 showOfflineDesktop = true;
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
733
4
e085711
parents: 3
diff changeset
734 // Fine tuning options.
e085711
parents: 3
diff changeset
735 deferScreenUpdates = readIntParameter("Defer screen updates", 20);
e085711
parents: 3
diff changeset
736 deferCursorUpdates = readIntParameter("Defer cursor updates", 10);
e085711
parents: 3
diff changeset
737 deferUpdateRequests = readIntParameter("Defer update requests", 0);
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
738
4
e085711
parents: 3
diff changeset
739 // Debugging options.
e085711
parents: 3
diff changeset
740 debugStatsExcludeUpdates = readIntParameter("DEBUG_XU", 0);
e085711
parents: 3
diff changeset
741 debugStatsMeasureUpdates = readIntParameter("DEBUG_CU", 0);
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
742
4
e085711
parents: 3
diff changeset
743 // SocketFactory.
e085711
parents: 3
diff changeset
744 socketFactory = readParameter("SocketFactory", false);
e085711
parents: 3
diff changeset
745 }
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
746
4
e085711
parents: 3
diff changeset
747 //
e085711
parents: 3
diff changeset
748 // Read password parameters. If an "ENCPASSWORD" parameter is set,
e085711
parents: 3
diff changeset
749 // then decrypt the password into the passwordParam string. Otherwise,
e085711
parents: 3
diff changeset
750 // try to read the "PASSWORD" parameter directly to passwordParam.
e085711
parents: 3
diff changeset
751 //
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
752
4
e085711
parents: 3
diff changeset
753 private void readPasswordParameters() {
e085711
parents: 3
diff changeset
754 String encPasswordParam = readParameter("ENCPASSWORD", false);
e085711
parents: 3
diff changeset
755 if (encPasswordParam == null) {
e085711
parents: 3
diff changeset
756 passwordParam = readParameter("PASSWORD", false);
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
757
4
e085711
parents: 3
diff changeset
758 } else {
e085711
parents: 3
diff changeset
759 // ENCPASSWORD is hexascii-encoded. Decode.
e085711
parents: 3
diff changeset
760 byte[] pw = { 0, 0, 0, 0, 0, 0, 0, 0 };
e085711
parents: 3
diff changeset
761 int len = encPasswordParam.length() / 2;
e085711
parents: 3
diff changeset
762 if (len > 8)
e085711
parents: 3
diff changeset
763 len = 8;
e085711
parents: 3
diff changeset
764 for (int i = 0; i < len; i++) {
e085711
parents: 3
diff changeset
765 String hex = encPasswordParam.substring(i * 2, i * 2 + 2);
e085711
parents: 3
diff changeset
766 Integer x = new Integer(Integer.parseInt(hex, 16));
e085711
parents: 3
diff changeset
767 pw[i] = x.byteValue();
e085711
parents: 3
diff changeset
768 }
e085711
parents: 3
diff changeset
769 // Decrypt the password.
e085711
parents: 3
diff changeset
770 byte[] key = { 23, 82, 107, 6, 35, 78, 88, 7 };
e085711
parents: 3
diff changeset
771 DesCipher des = new DesCipher(key);
e085711
parents: 3
diff changeset
772 des.decrypt(pw, 0, pw, 0);
e085711
parents: 3
diff changeset
773 passwordParam = new String(pw);
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
774
4
e085711
parents: 3
diff changeset
775 }
e085711
parents: 3
diff changeset
776 }
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
777
4
e085711
parents: 3
diff changeset
778 public String readParameter(String name, boolean required) {
e085711
parents: 3
diff changeset
779 if (inAnApplet) {
e085711
parents: 3
diff changeset
780 String s = getParameter(name);
e085711
parents: 3
diff changeset
781 if ((s == null) && required) {
e085711
parents: 3
diff changeset
782 fatalError(name + " parameter not specified");
e085711
parents: 3
diff changeset
783 }
e085711
parents: 3
diff changeset
784 return s;
e085711
parents: 3
diff changeset
785 }
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
786
4
e085711
parents: 3
diff changeset
787 for (int i = 0; i < mainArgs.length; i += 2) {
e085711
parents: 3
diff changeset
788 if (mainArgs[i].equalsIgnoreCase(name)) {
e085711
parents: 3
diff changeset
789 try {
e085711
parents: 3
diff changeset
790 return mainArgs[i + 1];
e085711
parents: 3
diff changeset
791 } catch (Exception e) {
e085711
parents: 3
diff changeset
792 if (required) {
e085711
parents: 3
diff changeset
793 fatalError(name + " parameter not specified");
e085711
parents: 3
diff changeset
794 }
e085711
parents: 3
diff changeset
795 return null;
e085711
parents: 3
diff changeset
796 }
e085711
parents: 3
diff changeset
797 }
e085711
parents: 3
diff changeset
798 }
e085711
parents: 3
diff changeset
799 if (required) {
e085711
parents: 3
diff changeset
800 fatalError(name + " parameter not specified");
e085711
parents: 3
diff changeset
801 }
e085711
parents: 3
diff changeset
802 return null;
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
803 }
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
804
4
e085711
parents: 3
diff changeset
805 int readIntParameter(String name, int defaultValue) {
e085711
parents: 3
diff changeset
806 String str = readParameter(name, false);
e085711
parents: 3
diff changeset
807 int result = defaultValue;
e085711
parents: 3
diff changeset
808 if (str != null) {
e085711
parents: 3
diff changeset
809 try {
e085711
parents: 3
diff changeset
810 result = Integer.parseInt(str);
e085711
parents: 3
diff changeset
811 } catch (NumberFormatException e) {
e085711
parents: 3
diff changeset
812 }
e085711
parents: 3
diff changeset
813 }
e085711
parents: 3
diff changeset
814 return result;
e085711
parents: 3
diff changeset
815 }
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
816
4
e085711
parents: 3
diff changeset
817 //
e085711
parents: 3
diff changeset
818 // moveFocusToDesktop() - move keyboard focus either to VncCanvas.
e085711
parents: 3
diff changeset
819 //
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
820
4
e085711
parents: 3
diff changeset
821 void moveFocusToDesktop() {
e085711
parents: 3
diff changeset
822 if (vncContainer != null) {
e085711
parents: 3
diff changeset
823 if (vc != null && vncContainer.isAncestorOf(vc))
e085711
parents: 3
diff changeset
824 vc.requestFocus();
e085711
parents: 3
diff changeset
825 }
e085711
parents: 3
diff changeset
826 }
e085711
parents: 3
diff changeset
827
e085711
parents: 3
diff changeset
828 //
e085711
parents: 3
diff changeset
829 // disconnect() - close connection to server.
e085711
parents: 3
diff changeset
830 //
e085711
parents: 3
diff changeset
831
e085711
parents: 3
diff changeset
832 synchronized public void disconnect() {
e085711
parents: 3
diff changeset
833 System.out.println("Disconnecting");
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
834
4
e085711
parents: 3
diff changeset
835 if (vc != null) {
e085711
parents: 3
diff changeset
836 double sec = (System.currentTimeMillis() - vc.statStartTime) / 1000.0;
e085711
parents: 3
diff changeset
837 double rate = Math.round(vc.statNumUpdates / sec * 100) / 100.0;
e085711
parents: 3
diff changeset
838 int nRealRects = vc.statNumPixelRects;
e085711
parents: 3
diff changeset
839 int nPseudoRects = vc.statNumTotalRects - vc.statNumPixelRects;
e085711
parents: 3
diff changeset
840 System.out.println("Updates received: " + vc.statNumUpdates + " ("
e085711
parents: 3
diff changeset
841 + nRealRects + " rectangles + " + nPseudoRects
e085711
parents: 3
diff changeset
842 + " pseudo), " + rate + " updates/sec");
e085711
parents: 3
diff changeset
843 int numRectsOther = nRealRects - vc.statNumRectsTight
e085711
parents: 3
diff changeset
844 - vc.statNumRectsZRLE - vc.statNumRectsHextile
e085711
parents: 3
diff changeset
845 - vc.statNumRectsRaw - vc.statNumRectsCopy;
e085711
parents: 3
diff changeset
846 System.out.println("Rectangles:" + " Tight=" + vc.statNumRectsTight
e085711
parents: 3
diff changeset
847 + "(JPEG=" + vc.statNumRectsTightJPEG + ") ZRLE="
e085711
parents: 3
diff changeset
848 + vc.statNumRectsZRLE + " Hextile="
e085711
parents: 3
diff changeset
849 + vc.statNumRectsHextile + " Raw=" + vc.statNumRectsRaw
e085711
parents: 3
diff changeset
850 + " CopyRect=" + vc.statNumRectsCopy + " other="
e085711
parents: 3
diff changeset
851 + numRectsOther);
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
852
4
e085711
parents: 3
diff changeset
853 int raw = vc.statNumBytesDecoded;
e085711
parents: 3
diff changeset
854 int compressed = vc.statNumBytesEncoded;
e085711
parents: 3
diff changeset
855 if (compressed > 0) {
e085711
parents: 3
diff changeset
856 double ratio = Math.round((double) raw / compressed * 1000) / 1000.0;
e085711
parents: 3
diff changeset
857 System.out.println("Pixel data: " + vc.statNumBytesDecoded
e085711
parents: 3
diff changeset
858 + " bytes, " + vc.statNumBytesEncoded
e085711
parents: 3
diff changeset
859 + " compressed, ratio " + ratio);
e085711
parents: 3
diff changeset
860 }
e085711
parents: 3
diff changeset
861 }
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
862
4
e085711
parents: 3
diff changeset
863 if (rfb != null && !rfb.closed())
e085711
parents: 3
diff changeset
864 rfb.close();
e085711
parents: 3
diff changeset
865 options.dispose();
e085711
parents: 3
diff changeset
866 clipboard.dispose();
e085711
parents: 3
diff changeset
867 if (rec != null)
e085711
parents: 3
diff changeset
868 rec.dispose();
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
869
4
e085711
parents: 3
diff changeset
870 if (inAnApplet) {
e085711
parents: 3
diff changeset
871 showMessage("Disconnected");
e085711
parents: 3
diff changeset
872 } else {
e085711
parents: 3
diff changeset
873 System.exit(0);
e085711
parents: 3
diff changeset
874 }
e085711
parents: 3
diff changeset
875 }
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
876
4
e085711
parents: 3
diff changeset
877 //
e085711
parents: 3
diff changeset
878 // fatalError() - print out a fatal error message.
e085711
parents: 3
diff changeset
879 // FIXME: Do we really need two versions of the fatalError() method?
e085711
parents: 3
diff changeset
880 //
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
881
4
e085711
parents: 3
diff changeset
882 synchronized public void fatalError(String str) {
e085711
parents: 3
diff changeset
883 System.out.println(str);
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
884
4
e085711
parents: 3
diff changeset
885 if (inAnApplet) {
e085711
parents: 3
diff changeset
886 // vncContainer null, applet not inited,
e085711
parents: 3
diff changeset
887 // can not present the error to the user.
e085711
parents: 3
diff changeset
888 Thread.currentThread().stop();
e085711
parents: 3
diff changeset
889 } else {
e085711
parents: 3
diff changeset
890 System.exit(1);
e085711
parents: 3
diff changeset
891 }
e085711
parents: 3
diff changeset
892 }
e085711
parents: 3
diff changeset
893
e085711
parents: 3
diff changeset
894 synchronized public void fatalError(String str, Exception e) {
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
895
4
e085711
parents: 3
diff changeset
896 if (rfb != null && rfb.closed()) {
e085711
parents: 3
diff changeset
897 // Not necessary to show error message if the error was caused
e085711
parents: 3
diff changeset
898 // by I/O problems after the rfb.close() method call.
e085711
parents: 3
diff changeset
899 System.out.println("RFB thread finished");
e085711
parents: 3
diff changeset
900 return;
e085711
parents: 3
diff changeset
901 }
e085711
parents: 3
diff changeset
902
e085711
parents: 3
diff changeset
903 System.out.println(str);
e085711
parents: 3
diff changeset
904 e.printStackTrace();
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
905
4
e085711
parents: 3
diff changeset
906 if (rfb != null)
e085711
parents: 3
diff changeset
907 rfb.close();
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
908
4
e085711
parents: 3
diff changeset
909 if (inAnApplet) {
e085711
parents: 3
diff changeset
910 showMessage(str);
e085711
parents: 3
diff changeset
911 } else {
e085711
parents: 3
diff changeset
912 System.exit(1);
e085711
parents: 3
diff changeset
913 }
e085711
parents: 3
diff changeset
914 }
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
915
4
e085711
parents: 3
diff changeset
916 //
e085711
parents: 3
diff changeset
917 // Show message text and optionally "Relogin" and "Close" buttons.
e085711
parents: 3
diff changeset
918 //
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
919
4
e085711
parents: 3
diff changeset
920 void showMessage(String msg) {
e085711
parents: 3
diff changeset
921 vncContainer.removeAll();
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
922
4
e085711
parents: 3
diff changeset
923 Label errLabel = new Label(msg, Label.CENTER);
e085711
parents: 3
diff changeset
924 errLabel.setFont(new Font("Helvetica", Font.PLAIN, 12));
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
925
4
e085711
parents: 3
diff changeset
926 if (offerRelogin) {
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
927
4
e085711
parents: 3
diff changeset
928 Panel gridPanel = new Panel(new GridLayout(0, 1));
e085711
parents: 3
diff changeset
929 Panel outerPanel = new Panel(new FlowLayout(FlowLayout.LEFT));
e085711
parents: 3
diff changeset
930 outerPanel.add(gridPanel);
e085711
parents: 3
diff changeset
931 vncContainer.setLayout(new FlowLayout(FlowLayout.LEFT, 30, 16));
e085711
parents: 3
diff changeset
932 vncContainer.add(outerPanel);
e085711
parents: 3
diff changeset
933 Panel textPanel = new Panel(new FlowLayout(FlowLayout.CENTER));
e085711
parents: 3
diff changeset
934 textPanel.add(errLabel);
e085711
parents: 3
diff changeset
935 gridPanel.add(textPanel);
e085711
parents: 3
diff changeset
936 gridPanel.add(new ReloginPanel(this));
e085711
parents: 3
diff changeset
937
e085711
parents: 3
diff changeset
938 } else {
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
939
4
e085711
parents: 3
diff changeset
940 vncContainer.setLayout(new FlowLayout(FlowLayout.LEFT, 30, 30));
e085711
parents: 3
diff changeset
941 vncContainer.add(errLabel);
e085711
parents: 3
diff changeset
942
e085711
parents: 3
diff changeset
943 }
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
944
4
e085711
parents: 3
diff changeset
945 if (inSeparateFrame) {
e085711
parents: 3
diff changeset
946 vncFrame.pack();
e085711
parents: 3
diff changeset
947 } else {
e085711
parents: 3
diff changeset
948 validate();
e085711
parents: 3
diff changeset
949 }
e085711
parents: 3
diff changeset
950 }
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
951
4
e085711
parents: 3
diff changeset
952 //
e085711
parents: 3
diff changeset
953 // Stop the applet.
e085711
parents: 3
diff changeset
954 // Main applet thread will terminate on first exception
e085711
parents: 3
diff changeset
955 // after seeing that rfbThread has been set to null.
e085711
parents: 3
diff changeset
956 //
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
957
4
e085711
parents: 3
diff changeset
958 public void stop() {
e085711
parents: 3
diff changeset
959 System.out.println("Stopping applet");
e085711
parents: 3
diff changeset
960 rfbThread = null;
e085711
parents: 3
diff changeset
961 }
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
962
4
e085711
parents: 3
diff changeset
963 //
e085711
parents: 3
diff changeset
964 // This method is called before the applet is destroyed.
e085711
parents: 3
diff changeset
965 //
e085711
parents: 3
diff changeset
966
e085711
parents: 3
diff changeset
967 public void destroy() {
e085711
parents: 3
diff changeset
968 System.out.println("Destroying applet");
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
969
4
e085711
parents: 3
diff changeset
970 vncContainer.removeAll();
e085711
parents: 3
diff changeset
971 options.dispose();
e085711
parents: 3
diff changeset
972 clipboard.dispose();
e085711
parents: 3
diff changeset
973 if (rec != null)
e085711
parents: 3
diff changeset
974 rec.dispose();
e085711
parents: 3
diff changeset
975 if (rfb != null && !rfb.closed())
e085711
parents: 3
diff changeset
976 rfb.close();
e085711
parents: 3
diff changeset
977 if (inSeparateFrame)
e085711
parents: 3
diff changeset
978 vncFrame.dispose();
e085711
parents: 3
diff changeset
979 }
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
980
4
e085711
parents: 3
diff changeset
981 //
e085711
parents: 3
diff changeset
982 // Start/stop receiving mouse events.
e085711
parents: 3
diff changeset
983 //
e085711
parents: 3
diff changeset
984
e085711
parents: 3
diff changeset
985 public void enableInput(boolean enable) {
e085711
parents: 3
diff changeset
986 vc.enableInput(enable);
e085711
parents: 3
diff changeset
987 }
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
988
4
e085711
parents: 3
diff changeset
989 //
e085711
parents: 3
diff changeset
990 // Close application properly on window close event.
e085711
parents: 3
diff changeset
991 //
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
992
4
e085711
parents: 3
diff changeset
993 public void windowClosing(WindowEvent evt) {
e085711
parents: 3
diff changeset
994 System.out.println("Closing window");
e085711
parents: 3
diff changeset
995 if (rfb != null)
e085711
parents: 3
diff changeset
996 disconnect();
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
997
4
e085711
parents: 3
diff changeset
998 vncContainer.hide();
e085711
parents: 3
diff changeset
999
e085711
parents: 3
diff changeset
1000 if (!inAnApplet) {
e085711
parents: 3
diff changeset
1001 System.exit(0);
e085711
parents: 3
diff changeset
1002 }
e085711
parents: 3
diff changeset
1003 }
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1004
4
e085711
parents: 3
diff changeset
1005 //
e085711
parents: 3
diff changeset
1006 // Ignore window events we're not interested in.
e085711
parents: 3
diff changeset
1007 //
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1008
4
e085711
parents: 3
diff changeset
1009 public void windowActivated(WindowEvent evt) {
e085711
parents: 3
diff changeset
1010 }
e085711
parents: 3
diff changeset
1011
e085711
parents: 3
diff changeset
1012 public void windowDeactivated(WindowEvent evt) {
e085711
parents: 3
diff changeset
1013 }
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1014
4
e085711
parents: 3
diff changeset
1015 public void windowOpened(WindowEvent evt) {
e085711
parents: 3
diff changeset
1016 }
e085711
parents: 3
diff changeset
1017
e085711
parents: 3
diff changeset
1018 public void windowClosed(WindowEvent evt) {
e085711
parents: 3
diff changeset
1019 }
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1020
4
e085711
parents: 3
diff changeset
1021 public void windowIconified(WindowEvent evt) {
e085711
parents: 3
diff changeset
1022 }
e085711
parents: 3
diff changeset
1023
e085711
parents: 3
diff changeset
1024 public void windowDeiconified(WindowEvent evt) {
e085711
parents: 3
diff changeset
1025 }
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1026 }