2 // Copyright (C) 2001 HorizonLive.com, Inc. All Rights Reserved.
3 // Copyright (C) 2001 Constantin Kaplinsky. All Rights Reserved.
4 // Copyright (C) 2000 Tridia Corporation. All Rights Reserved.
5 // Copyright (C) 1999 AT&T Laboratories Cambridge. All Rights Reserved.
7 // This is free software; you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by
9 // the Free Software Foundation; either version 2 of the License, or
10 // (at your option) any later version.
12 // This software is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with this software; if not, write to the Free Software
19 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
26 // This deals with all the options the user can play with.
27 // It sets the encodings array and some booleans.
31 import java.awt.event.*;
33 class OptionsFrame extends Frame
34 implements WindowListener, ActionListener, ItemListener {
36 static String[] names = {
40 "Cursor shape updates",
43 "Mouse buttons 2 and 3",
45 "Scale remote cursor",
49 static String[][] values = {
50 { "Auto", "Raw", "RRE", "CoRRE", "Hextile", "Zlib", "Tight", "ZRLE" },
51 { "Default", "1", "2", "3", "4", "5", "6", "7", "8", "9" },
52 { "JPEG off", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" },
53 { "Enable", "Ignore", "Disable" },
56 { "Normal", "Reversed" },
58 { "No", "50%", "75%", "125%", "150%" },
64 compressLevelIndex = 1,
66 cursorUpdatesIndex = 3,
68 eightBitColorsIndex = 5,
72 shareDesktopIndex = 9;
74 Label[] labels = new Label[names.length];
75 Choice[] choices = new Choice[names.length];
81 // The actual data which other classes look at:
84 int preferredEncoding;
88 boolean requestCursorUpdates;
89 boolean ignoreCursorUpdates;
91 boolean eightBitColors;
93 boolean reverseMouseButtons2And3;
102 // Constructor. Set up the labels and choices from the names and values
106 OptionsFrame(VncViewer v) {
107 super("TightVNC Options");
111 GridBagLayout gridbag = new GridBagLayout();
114 GridBagConstraints gbc = new GridBagConstraints();
115 gbc.fill = GridBagConstraints.BOTH;
117 for (int i = 0; i < names.length; i++) {
118 labels[i] = new Label(names[i]);
120 gridbag.setConstraints(labels[i],gbc);
123 choices[i] = new Choice();
124 gbc.gridwidth = GridBagConstraints.REMAINDER;
125 gridbag.setConstraints(choices[i],gbc);
127 choices[i].addItemListener(this);
129 for (int j = 0; j < values[i].length; j++) {
130 choices[i].addItem(values[i][j]);
134 closeButton = new Button("Close");
135 gbc.gridwidth = GridBagConstraints.REMAINDER;
136 gridbag.setConstraints(closeButton, gbc);
138 closeButton.addActionListener(this);
142 addWindowListener(this);
146 choices[encodingIndex].select("Auto");
147 choices[compressLevelIndex].select("Default");
148 choices[jpegQualityIndex].select("6");
149 choices[cursorUpdatesIndex].select("Enable");
150 choices[useCopyRectIndex].select("Yes");
151 choices[eightBitColorsIndex].select("No");
152 choices[mouseButtonIndex].select("Normal");
153 choices[viewOnlyIndex].select("No");
154 choices[scaleCursorIndex].select("No");
155 choices[shareDesktopIndex].select("Yes");
157 // But let them be overridden by parameters
159 for (int i = 0; i < names.length; i++) {
160 String s = viewer.readParameter(names[i], false);
162 for (int j = 0; j < values[i].length; j++) {
163 if (s.equalsIgnoreCase(values[i][j])) {
164 choices[i].select(j);
170 // FIXME: Provide some sort of GUI for "Scaling Factor".
174 String s = viewer.readParameter("Scaling Factor", false);
176 if (s.equalsIgnoreCase("Auto")) {
179 // Remove the '%' char at the end of string if present.
180 if (s.charAt(s.length() - 1) == '%') {
181 s = s.substring(0, s.length() - 1);
183 // Convert to an integer.
185 scalingFactor = Integer.parseInt(s);
187 catch (NumberFormatException e) {
190 // Make sure scalingFactor is in the range of [1..1000].
191 if (scalingFactor < 1) {
193 } else if (scalingFactor > 1000) {
194 scalingFactor = 1000;
199 // Make the booleans and encodings array correspond to the state of the GUI
208 // Disable the shareDesktop option
211 void disableShareDesktop() {
212 labels[shareDesktopIndex].setEnabled(false);
213 choices[shareDesktopIndex].setEnabled(false);
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
225 void setEncodings() {
226 useCopyRect = choices[useCopyRectIndex].getSelectedItem().equals("Yes");
228 preferredEncoding = RfbProto.EncodingRaw;
229 boolean enableCompressLevel = false;
230 boolean enableQualityLevel = false;
232 if (choices[encodingIndex].getSelectedItem().equals("RRE")) {
233 preferredEncoding = RfbProto.EncodingRRE;
234 } else if (choices[encodingIndex].getSelectedItem().equals("CoRRE")) {
235 preferredEncoding = RfbProto.EncodingCoRRE;
236 } else if (choices[encodingIndex].getSelectedItem().equals("Hextile")) {
237 preferredEncoding = RfbProto.EncodingHextile;
238 } else if (choices[encodingIndex].getSelectedItem().equals("ZRLE")) {
239 preferredEncoding = RfbProto.EncodingZRLE;
240 } else if (choices[encodingIndex].getSelectedItem().equals("Zlib")) {
241 preferredEncoding = RfbProto.EncodingZlib;
242 enableCompressLevel = true;
243 } else if (choices[encodingIndex].getSelectedItem().equals("Tight")) {
244 preferredEncoding = RfbProto.EncodingTight;
245 enableCompressLevel = true;
246 enableQualityLevel = !eightBitColors;
247 } else if (choices[encodingIndex].getSelectedItem().equals("Auto")) {
248 preferredEncoding = -1;
249 enableQualityLevel = !eightBitColors;
252 // Handle compression level setting.
256 Integer.parseInt(choices[compressLevelIndex].getSelectedItem());
258 catch (NumberFormatException e) {
261 if (compressLevel < 1 || compressLevel > 9) {
264 labels[compressLevelIndex].setEnabled(enableCompressLevel);
265 choices[compressLevelIndex].setEnabled(enableCompressLevel);
267 // Handle JPEG quality setting.
271 Integer.parseInt(choices[jpegQualityIndex].getSelectedItem());
273 catch (NumberFormatException e) {
276 if (jpegQuality < 0 || jpegQuality > 9) {
279 labels[jpegQualityIndex].setEnabled(enableQualityLevel);
280 choices[jpegQualityIndex].setEnabled(enableQualityLevel);
282 // Request cursor shape updates if necessary.
284 requestCursorUpdates =
285 !choices[cursorUpdatesIndex].getSelectedItem().equals("Disable");
287 if (requestCursorUpdates) {
288 ignoreCursorUpdates =
289 choices[cursorUpdatesIndex].getSelectedItem().equals("Ignore");
292 viewer.setEncodings();
296 // setColorFormat sets eightBitColors variable depending on the GUI
297 // setting, causing switches between 8-bit and 24-bit colors mode if
301 void setColorFormat() {
304 choices[eightBitColorsIndex].getSelectedItem().equals("Yes");
306 boolean enableJPEG = !eightBitColors &&
307 (choices[encodingIndex].getSelectedItem().equals("Tight") ||
308 choices[encodingIndex].getSelectedItem().equals("Auto"));
310 labels[jpegQualityIndex].setEnabled(enableJPEG);
311 choices[jpegQualityIndex].setEnabled(enableJPEG);
315 // setOtherOptions looks at the "other" choices (ones which don't set the
316 // encoding or the color format) and sets the boolean flags appropriately.
319 void setOtherOptions() {
321 reverseMouseButtons2And3
322 = choices[mouseButtonIndex].getSelectedItem().equals("Reversed");
325 = choices[viewOnlyIndex].getSelectedItem().equals("Yes");
326 if (viewer.vc != null)
327 viewer.vc.enableInput(!viewOnly);
330 = choices[shareDesktopIndex].getSelectedItem().equals("Yes");
332 String scaleString = choices[scaleCursorIndex].getSelectedItem();
333 if (scaleString.endsWith("%"))
334 scaleString = scaleString.substring(0, scaleString.length() - 1);
336 scaleCursor = Integer.parseInt(scaleString);
338 catch (NumberFormatException e) {
341 if (scaleCursor < 10 || scaleCursor > 500) {
344 if (requestCursorUpdates && !ignoreCursorUpdates && !viewOnly) {
345 labels[scaleCursorIndex].setEnabled(true);
346 choices[scaleCursorIndex].setEnabled(true);
348 labels[scaleCursorIndex].setEnabled(false);
349 choices[scaleCursorIndex].setEnabled(false);
351 if (viewer.vc != null)
352 viewer.vc.createSoftCursor(); // update cursor scaling
357 // Respond to actions on Choice controls
360 public void itemStateChanged(ItemEvent evt) {
361 Object source = evt.getSource();
363 if (source == choices[encodingIndex] ||
364 source == choices[compressLevelIndex] ||
365 source == choices[jpegQualityIndex] ||
366 source == choices[cursorUpdatesIndex] ||
367 source == choices[useCopyRectIndex]) {
371 if (source == choices[cursorUpdatesIndex]) {
372 setOtherOptions(); // update scaleCursor state
375 } else if (source == choices[eightBitColorsIndex]) {
379 } else if (source == choices[mouseButtonIndex] ||
380 source == choices[shareDesktopIndex] ||
381 source == choices[viewOnlyIndex] ||
382 source == choices[scaleCursorIndex]) {
389 // Respond to button press
392 public void actionPerformed(ActionEvent evt) {
393 if (evt.getSource() == closeButton)
398 // Respond to window events
401 public void windowClosing(WindowEvent evt) {
405 public void windowActivated(WindowEvent evt) {}
406 public void windowDeactivated(WindowEvent evt) {}
407 public void windowOpened(WindowEvent evt) {}
408 public void windowClosed(WindowEvent evt) {}
409 public void windowIconified(WindowEvent evt) {}
410 public void windowDeiconified(WindowEvent evt) {}