annotate src/VncViewer.java @ 3:63b738afb839

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