17
|
1 package myVncClient;
|
0
|
2 //
|
|
3 // Copyright (C) 2001 HorizonLive.com, Inc. All Rights Reserved.
|
|
4 // Copyright (C) 2001 Constantin Kaplinsky. All Rights Reserved.
|
|
5 // Copyright (C) 2000 Tridia Corporation. All Rights Reserved.
|
|
6 // Copyright (C) 1999 AT&T Laboratories Cambridge. All Rights Reserved.
|
|
7 //
|
|
8 // This is free software; you can redistribute it and/or modify
|
|
9 // it under the terms of the GNU General Public License as published by
|
|
10 // the Free Software Foundation; either version 2 of the License, or
|
|
11 // (at your option) any later version.
|
|
12 //
|
|
13 // This software is distributed in the hope that it will be useful,
|
|
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
16 // GNU General Public License for more details.
|
|
17 //
|
|
18 // You should have received a copy of the GNU General Public License
|
|
19 // along with this software; if not, write to the Free Software
|
|
20 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
|
21 // USA.
|
|
22 //
|
|
23
|
|
24 //
|
|
25 // Options frame.
|
|
26 //
|
|
27 // This deals with all the options the user can play with.
|
|
28 // It sets the encodings array and some booleans.
|
|
29 //
|
|
30
|
|
31 import java.awt.*;
|
|
32 import java.awt.event.*;
|
|
33
|
|
34 class OptionsFrame extends Frame
|
|
35 implements WindowListener, ActionListener, ItemListener {
|
|
36
|
|
37 static String[] names = {
|
|
38 "Encoding",
|
|
39 "Compression level",
|
|
40 "JPEG image quality",
|
|
41 "Cursor shape updates",
|
|
42 "Use CopyRect",
|
|
43 "Restricted colors",
|
|
44 "Mouse buttons 2 and 3",
|
|
45 "View only",
|
|
46 "Scale remote cursor",
|
|
47 "Share desktop",
|
|
48 };
|
|
49
|
|
50 static String[][] values = {
|
|
51 { "Auto", "Raw", "RRE", "CoRRE", "Hextile", "Zlib", "Tight", "ZRLE" },
|
|
52 { "Default", "1", "2", "3", "4", "5", "6", "7", "8", "9" },
|
|
53 { "JPEG off", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" },
|
|
54 { "Enable", "Ignore", "Disable" },
|
|
55 { "Yes", "No" },
|
|
56 { "Yes", "No" },
|
|
57 { "Normal", "Reversed" },
|
|
58 { "Yes", "No" },
|
|
59 { "No", "50%", "75%", "125%", "150%" },
|
|
60 { "Yes", "No" },
|
|
61 };
|
|
62
|
|
63 final int
|
|
64 encodingIndex = 0,
|
|
65 compressLevelIndex = 1,
|
|
66 jpegQualityIndex = 2,
|
|
67 cursorUpdatesIndex = 3,
|
|
68 useCopyRectIndex = 4,
|
|
69 eightBitColorsIndex = 5,
|
|
70 mouseButtonIndex = 6,
|
|
71 viewOnlyIndex = 7,
|
|
72 scaleCursorIndex = 8,
|
|
73 shareDesktopIndex = 9;
|
|
74
|
|
75 Label[] labels = new Label[names.length];
|
|
76 Choice[] choices = new Choice[names.length];
|
|
77 Button closeButton;
|
|
78 VncViewer viewer;
|
|
79
|
|
80
|
|
81 //
|
|
82 // The actual data which other classes look at:
|
|
83 //
|
|
84
|
|
85 int preferredEncoding;
|
|
86 int compressLevel;
|
|
87 int jpegQuality;
|
|
88 boolean useCopyRect;
|
|
89 boolean requestCursorUpdates;
|
|
90 boolean ignoreCursorUpdates;
|
|
91
|
|
92 boolean eightBitColors;
|
|
93
|
|
94 boolean reverseMouseButtons2And3;
|
|
95 boolean shareDesktop;
|
|
96 boolean viewOnly;
|
|
97 int scaleCursor;
|
|
98
|
|
99 boolean autoScale;
|
|
100 int scalingFactor;
|
|
101
|
|
102 //
|
|
103 // Constructor. Set up the labels and choices from the names and values
|
|
104 // arrays.
|
|
105 //
|
|
106
|
|
107 OptionsFrame(VncViewer v) {
|
|
108 super("TightVNC Options");
|
|
109
|
|
110 viewer = v;
|
|
111
|
|
112 GridBagLayout gridbag = new GridBagLayout();
|
|
113 setLayout(gridbag);
|
|
114
|
|
115 GridBagConstraints gbc = new GridBagConstraints();
|
|
116 gbc.fill = GridBagConstraints.BOTH;
|
|
117
|
|
118 for (int i = 0; i < names.length; i++) {
|
|
119 labels[i] = new Label(names[i]);
|
|
120 gbc.gridwidth = 1;
|
|
121 gridbag.setConstraints(labels[i],gbc);
|
|
122 add(labels[i]);
|
|
123
|
|
124 choices[i] = new Choice();
|
|
125 gbc.gridwidth = GridBagConstraints.REMAINDER;
|
|
126 gridbag.setConstraints(choices[i],gbc);
|
|
127 add(choices[i]);
|
|
128 choices[i].addItemListener(this);
|
|
129
|
|
130 for (int j = 0; j < values[i].length; j++) {
|
|
131 choices[i].addItem(values[i][j]);
|
|
132 }
|
|
133 }
|
|
134
|
|
135 closeButton = new Button("Close");
|
|
136 gbc.gridwidth = GridBagConstraints.REMAINDER;
|
|
137 gridbag.setConstraints(closeButton, gbc);
|
|
138 add(closeButton);
|
|
139 closeButton.addActionListener(this);
|
|
140
|
|
141 pack();
|
|
142
|
|
143 addWindowListener(this);
|
|
144
|
|
145 // Set up defaults
|
|
146
|
|
147 choices[encodingIndex].select("Auto");
|
|
148 choices[compressLevelIndex].select("Default");
|
|
149 choices[jpegQualityIndex].select("6");
|
|
150 choices[cursorUpdatesIndex].select("Enable");
|
|
151 choices[useCopyRectIndex].select("Yes");
|
|
152 choices[eightBitColorsIndex].select("No");
|
|
153 choices[mouseButtonIndex].select("Normal");
|
|
154 choices[viewOnlyIndex].select("No");
|
|
155 choices[scaleCursorIndex].select("No");
|
|
156 choices[shareDesktopIndex].select("Yes");
|
|
157
|
|
158 // But let them be overridden by parameters
|
|
159
|
|
160 for (int i = 0; i < names.length; i++) {
|
|
161 String s = viewer.readParameter(names[i], false);
|
|
162 if (s != null) {
|
|
163 for (int j = 0; j < values[i].length; j++) {
|
|
164 if (s.equalsIgnoreCase(values[i][j])) {
|
|
165 choices[i].select(j);
|
|
166 }
|
|
167 }
|
|
168 }
|
|
169 }
|
|
170
|
|
171 // FIXME: Provide some sort of GUI for "Scaling Factor".
|
|
172
|
|
173 autoScale = false;
|
|
174 scalingFactor = 100;
|
|
175 String s = viewer.readParameter("Scaling Factor", false);
|
|
176 if (s != null) {
|
|
177 if (s.equalsIgnoreCase("Auto")) {
|
|
178 autoScale = true;
|
|
179 } else {
|
|
180 // Remove the '%' char at the end of string if present.
|
|
181 if (s.charAt(s.length() - 1) == '%') {
|
|
182 s = s.substring(0, s.length() - 1);
|
|
183 }
|
|
184 // Convert to an integer.
|
|
185 try {
|
|
186 scalingFactor = Integer.parseInt(s);
|
|
187 }
|
|
188 catch (NumberFormatException e) {
|
|
189 scalingFactor = 100;
|
|
190 }
|
|
191 // Make sure scalingFactor is in the range of [1..1000].
|
|
192 if (scalingFactor < 1) {
|
|
193 scalingFactor = 1;
|
|
194 } else if (scalingFactor > 1000) {
|
|
195 scalingFactor = 1000;
|
|
196 }
|
|
197 }
|
|
198 }
|
|
199
|
|
200 // Make the booleans and encodings array correspond to the state of the GUI
|
|
201
|
|
202 setEncodings();
|
|
203 setColorFormat();
|
|
204 setOtherOptions();
|
|
205 }
|
|
206
|
|
207
|
|
208 //
|
|
209 // Disable the shareDesktop option
|
|
210 //
|
|
211
|
|
212 void disableShareDesktop() {
|
|
213 labels[shareDesktopIndex].setEnabled(false);
|
|
214 choices[shareDesktopIndex].setEnabled(false);
|
|
215 }
|
|
216
|
|
217 //
|
|
218 // setEncodings looks at the encoding, compression level, JPEG
|
|
219 // quality level, cursor shape updates and copyRect choices and sets
|
|
220 // corresponding variables properly. Then it calls the VncViewer's
|
|
221 // setEncodings method to send a SetEncodings message to the RFB
|
|
222 // server.
|
|
223 //
|
|
224
|
|
225 void setEncodings() {
|
|
226 useCopyRect = choices[useCopyRectIndex].getSelectedItem().equals("Yes");
|
|
227
|
|
228 preferredEncoding = RfbProto.EncodingRaw;
|
|
229 boolean enableCompressLevel = false;
|
|
230
|
|
231 if (choices[encodingIndex].getSelectedItem().equals("RRE")) {
|
|
232 preferredEncoding = RfbProto.EncodingRRE;
|
|
233 } else if (choices[encodingIndex].getSelectedItem().equals("CoRRE")) {
|
|
234 preferredEncoding = RfbProto.EncodingCoRRE;
|
|
235 } else if (choices[encodingIndex].getSelectedItem().equals("Hextile")) {
|
|
236 preferredEncoding = RfbProto.EncodingHextile;
|
|
237 } else if (choices[encodingIndex].getSelectedItem().equals("ZRLE")) {
|
|
238 preferredEncoding = RfbProto.EncodingZRLE;
|
|
239 } else if (choices[encodingIndex].getSelectedItem().equals("Zlib")) {
|
|
240 preferredEncoding = RfbProto.EncodingZlib;
|
|
241 enableCompressLevel = true;
|
|
242 } else if (choices[encodingIndex].getSelectedItem().equals("Tight")) {
|
|
243 preferredEncoding = RfbProto.EncodingTight;
|
|
244 enableCompressLevel = true;
|
|
245 } else if (choices[encodingIndex].getSelectedItem().equals("Auto")) {
|
|
246 preferredEncoding = -1;
|
|
247 }
|
|
248
|
|
249 // Handle compression level setting.
|
|
250
|
|
251 try {
|
|
252 compressLevel =
|
|
253 Integer.parseInt(choices[compressLevelIndex].getSelectedItem());
|
|
254 }
|
|
255 catch (NumberFormatException e) {
|
|
256 compressLevel = -1;
|
|
257 }
|
|
258 if (compressLevel < 1 || compressLevel > 9) {
|
|
259 compressLevel = -1;
|
|
260 }
|
|
261 labels[compressLevelIndex].setEnabled(enableCompressLevel);
|
|
262 choices[compressLevelIndex].setEnabled(enableCompressLevel);
|
|
263
|
|
264 // Handle JPEG quality setting.
|
|
265
|
|
266 try {
|
|
267 jpegQuality =
|
|
268 Integer.parseInt(choices[jpegQualityIndex].getSelectedItem());
|
|
269 }
|
|
270 catch (NumberFormatException e) {
|
|
271 jpegQuality = -1;
|
|
272 }
|
|
273 if (jpegQuality < 0 || jpegQuality > 9) {
|
|
274 jpegQuality = -1;
|
|
275 }
|
|
276
|
|
277 // Request cursor shape updates if necessary.
|
|
278
|
|
279 requestCursorUpdates =
|
|
280 !choices[cursorUpdatesIndex].getSelectedItem().equals("Disable");
|
|
281
|
|
282 if (requestCursorUpdates) {
|
|
283 ignoreCursorUpdates =
|
|
284 choices[cursorUpdatesIndex].getSelectedItem().equals("Ignore");
|
|
285 }
|
|
286
|
|
287 viewer.setEncodings();
|
|
288 }
|
|
289
|
|
290 //
|
|
291 // setColorFormat sets eightBitColors variable depending on the GUI
|
|
292 // setting, causing switches between 8-bit and 24-bit colors mode if
|
|
293 // necessary.
|
|
294 //
|
|
295
|
|
296 void setColorFormat() {
|
|
297
|
|
298 eightBitColors =
|
|
299 choices[eightBitColorsIndex].getSelectedItem().equals("Yes");
|
|
300
|
|
301 boolean enableJPEG = !eightBitColors;
|
|
302
|
|
303 labels[jpegQualityIndex].setEnabled(enableJPEG);
|
|
304 choices[jpegQualityIndex].setEnabled(enableJPEG);
|
|
305 }
|
|
306
|
|
307 //
|
|
308 // setOtherOptions looks at the "other" choices (ones that do not
|
|
309 // cause sending any protocol messages) and sets the boolean flags
|
|
310 // appropriately.
|
|
311 //
|
|
312
|
|
313 void setOtherOptions() {
|
|
314
|
|
315 reverseMouseButtons2And3
|
|
316 = choices[mouseButtonIndex].getSelectedItem().equals("Reversed");
|
|
317
|
|
318 viewOnly
|
|
319 = choices[viewOnlyIndex].getSelectedItem().equals("Yes");
|
|
320 if (viewer.vc != null)
|
|
321 viewer.vc.enableInput(!viewOnly);
|
|
322
|
|
323 shareDesktop
|
|
324 = choices[shareDesktopIndex].getSelectedItem().equals("Yes");
|
|
325
|
|
326 String scaleString = choices[scaleCursorIndex].getSelectedItem();
|
|
327 if (scaleString.endsWith("%"))
|
|
328 scaleString = scaleString.substring(0, scaleString.length() - 1);
|
|
329 try {
|
|
330 scaleCursor = Integer.parseInt(scaleString);
|
|
331 }
|
|
332 catch (NumberFormatException e) {
|
|
333 scaleCursor = 0;
|
|
334 }
|
|
335 if (scaleCursor < 10 || scaleCursor > 500) {
|
|
336 scaleCursor = 0;
|
|
337 }
|
|
338 if (requestCursorUpdates && !ignoreCursorUpdates && !viewOnly) {
|
|
339 labels[scaleCursorIndex].setEnabled(true);
|
|
340 choices[scaleCursorIndex].setEnabled(true);
|
|
341 } else {
|
|
342 labels[scaleCursorIndex].setEnabled(false);
|
|
343 choices[scaleCursorIndex].setEnabled(false);
|
|
344 }
|
|
345 if (viewer.vc != null)
|
|
346 viewer.vc.createSoftCursor(); // update cursor scaling
|
|
347 }
|
|
348
|
|
349
|
|
350 //
|
|
351 // Respond to actions on Choice controls
|
|
352 //
|
|
353
|
|
354 public void itemStateChanged(ItemEvent evt) {
|
|
355 Object source = evt.getSource();
|
|
356
|
|
357 if (source == choices[encodingIndex] ||
|
|
358 source == choices[compressLevelIndex] ||
|
|
359 source == choices[jpegQualityIndex] ||
|
|
360 source == choices[cursorUpdatesIndex] ||
|
|
361 source == choices[useCopyRectIndex]) {
|
|
362
|
|
363 setEncodings();
|
|
364
|
|
365 if (source == choices[cursorUpdatesIndex]) {
|
|
366 setOtherOptions(); // update scaleCursor state
|
|
367 }
|
|
368
|
|
369 } else if (source == choices[eightBitColorsIndex]) {
|
|
370
|
|
371 setColorFormat();
|
|
372
|
|
373 } else if (source == choices[mouseButtonIndex] ||
|
|
374 source == choices[shareDesktopIndex] ||
|
|
375 source == choices[viewOnlyIndex] ||
|
|
376 source == choices[scaleCursorIndex]) {
|
|
377
|
|
378 setOtherOptions();
|
|
379
|
|
380 }
|
|
381 }
|
|
382
|
|
383 //
|
|
384 // Respond to button press
|
|
385 //
|
|
386
|
|
387 public void actionPerformed(ActionEvent evt) {
|
|
388 if (evt.getSource() == closeButton)
|
|
389 setVisible(false);
|
|
390 }
|
|
391
|
|
392 //
|
|
393 // Respond to window events
|
|
394 //
|
|
395
|
|
396 public void windowClosing(WindowEvent evt) {
|
|
397 setVisible(false);
|
|
398 }
|
|
399
|
|
400 public void windowActivated(WindowEvent evt) {}
|
|
401 public void windowDeactivated(WindowEvent evt) {}
|
|
402 public void windowOpened(WindowEvent evt) {}
|
|
403 public void windowClosed(WindowEvent evt) {}
|
|
404 public void windowIconified(WindowEvent evt) {}
|
|
405 public void windowDeiconified(WindowEvent evt) {}
|
|
406 }
|