67
|
1 package myVncProxy;
|
|
2
|
|
3 import java.awt.*;
|
|
4 import java.awt.event.*;
|
|
5
|
|
6 class OptionsNoFrame{
|
|
7
|
|
8 static String[] names = {
|
|
9 "Encoding",
|
|
10 "Compression level",
|
|
11 "JPEG image quality",
|
|
12 "Cursor shape updates",
|
|
13 "Use CopyRect",
|
|
14 "Restricted colors",
|
|
15 "Mouse buttons 2 and 3",
|
|
16 "View only",
|
|
17 "Scale remote cursor",
|
|
18 "Share desktop",
|
|
19 };
|
|
20
|
|
21 static String[][] values = {
|
|
22 { "Auto", "Raw", "RRE", "CoRRE", "Hextile", "Zlib", "Tight", "ZRLE" },
|
|
23 { "Default", "1", "2", "3", "4", "5", "6", "7", "8", "9" },
|
|
24 { "JPEG off", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" },
|
|
25 { "Enable", "Ignore", "Disable" },
|
|
26 { "Yes", "No" },
|
|
27 { "Yes", "No" },
|
|
28 { "Normal", "Reversed" },
|
|
29 { "Yes", "No" },
|
|
30 { "No", "50%", "75%", "125%", "150%" },
|
|
31 { "Yes", "No" },
|
|
32 };
|
|
33
|
|
34 final int
|
|
35 encodingIndex = 0,
|
|
36 compressLevelIndex = 1,
|
|
37 jpegQualityIndex = 2,
|
|
38 cursorUpdatesIndex = 3,
|
|
39 useCopyRectIndex = 4,
|
|
40 eightBitColorsIndex = 5,
|
|
41 mouseButtonIndex = 6,
|
|
42 viewOnlyIndex = 7,
|
|
43 scaleCursorIndex = 8,
|
|
44 shareDesktopIndex = 9;
|
|
45
|
|
46 Label[] labels = new Label[names.length];
|
|
47 Choice[] choices = new Choice[names.length];
|
|
48 Button closeButton;
|
|
49 VncProxyService viewer;
|
|
50
|
|
51
|
|
52 //
|
|
53 // The actual data which other classes look at:
|
|
54 //
|
|
55
|
|
56 int preferredEncoding;
|
|
57 int compressLevel;
|
|
58 int jpegQuality;
|
|
59 boolean useCopyRect;
|
|
60 boolean requestCursorUpdates;
|
|
61 boolean ignoreCursorUpdates;
|
|
62
|
|
63 boolean eightBitColors;
|
|
64
|
|
65 boolean reverseMouseButtons2And3;
|
|
66 boolean shareDesktop;
|
|
67 boolean viewOnly;
|
|
68 int scaleCursor;
|
|
69
|
|
70 boolean autoScale;
|
|
71 int scalingFactor;
|
|
72
|
|
73 //
|
|
74 // Constructor. Set up the labels and choices from the names and values
|
|
75 // arrays.
|
|
76 //
|
124
|
77
|
67
|
78 OptionsNoFrame(VncProxyService v) {
|
124
|
79 viewer = v;
|
|
80 }
|
|
81
|
|
82 OptionsNoFrame(VncProxyService v, VncCanvas vc) {
|
67
|
83
|
|
84 for (int i = 0; i < names.length; i++) {
|
|
85 labels[i] = new Label(names[i]);
|
|
86
|
|
87 choices[i] = new Choice();
|
|
88
|
|
89
|
|
90 for (int j = 0; j < values[i]. length; j++) {
|
|
91 choices[i].addItem(values[i][j]);
|
|
92 }
|
|
93 }
|
|
94
|
|
95 // Set up defaults
|
|
96
|
|
97 choices[encodingIndex].select("Auto");
|
|
98 choices[compressLevelIndex].select("Default");
|
|
99 choices[jpegQualityIndex].select("6");
|
|
100 choices[cursorUpdatesIndex].select("Enable");
|
|
101 choices[useCopyRectIndex].select("Yes");
|
|
102 choices[eightBitColorsIndex].select("No");
|
|
103 choices[mouseButtonIndex].select("Normal");
|
|
104 choices[viewOnlyIndex].select("No");
|
|
105 choices[scaleCursorIndex].select("No");
|
|
106 choices[shareDesktopIndex].select("Yes");
|
|
107
|
|
108 // But let them be overridden by parameters
|
|
109
|
|
110 for (int i = 0; i < names.length; i++) {
|
|
111 String s = viewer.readParameter(names[i], false);
|
|
112 if (s != null) {
|
|
113 for (int j = 0; j < values[i].length; j++) {
|
|
114 if (s.equalsIgnoreCase(values[i][j])) {
|
|
115 choices[i].select(j);
|
|
116 }
|
|
117 }
|
|
118 }
|
|
119 }
|
|
120
|
|
121 // FIXME: Provide some sort of GUI for "Scaling Factor".
|
|
122
|
|
123 autoScale = false;
|
|
124 scalingFactor = 100;
|
|
125 String s = viewer.readParameter("Scaling Factor", false);
|
|
126 if (s != null) {
|
|
127 if (s.equalsIgnoreCase("Auto")) {
|
|
128 autoScale = true;
|
|
129 } else {
|
|
130 // Remove the '%' char at the end of string if present.
|
|
131 if (s.charAt(s.length() - 1) == '%') {
|
|
132 s = s.substring(0, s.length() - 1);
|
|
133 }
|
|
134 // Convert to an integer.
|
|
135 try {
|
|
136 scalingFactor = Integer.parseInt(s);
|
|
137 }
|
|
138 catch (NumberFormatException e) {
|
|
139 scalingFactor = 100;
|
|
140 }
|
|
141 // Make sure scalingFactor is in the range of [1..1000].
|
|
142 if (scalingFactor < 1) {
|
|
143 scalingFactor = 1;
|
|
144 } else if (scalingFactor > 1000) {
|
|
145 scalingFactor = 1000;
|
|
146 }
|
|
147 }
|
|
148 }
|
|
149
|
|
150 // Make the booleans and encodings array correspond to the state of the GUI
|
|
151
|
|
152 setEncodings();
|
|
153 setColorFormat();
|
|
154 setOtherOptions();
|
|
155 }
|
|
156
|
|
157
|
|
158 //
|
|
159 // Disable the shareDesktop option
|
|
160 //
|
|
161
|
|
162 void disableShareDesktop() {
|
|
163 labels[shareDesktopIndex].setEnabled(false);
|
|
164 choices[shareDesktopIndex].setEnabled(false);
|
|
165 }
|
|
166
|
|
167 //
|
|
168 // setEncodings looks at the encoding, compression level, JPEG
|
|
169 // quality level, cursor shape updates and copyRect choices and sets
|
|
170 // corresponding variables properly. Then it calls the VncViewer's
|
|
171 // setEncodings method to send a SetEncodings message to the RFB
|
|
172 // server.
|
|
173 //
|
|
174
|
|
175 void setEncodings() {
|
|
176 // useCopyRect = choices[useCopyRectIndex].getSelectedItem().equals("Yes");
|
|
177
|
|
178 preferredEncoding = RfbProto.EncodingRaw;
|
|
179 boolean enableCompressLevel = false;
|
|
180
|
|
181 if (choices[encodingIndex].getSelectedItem().equals("RRE")) {
|
|
182 preferredEncoding = RfbProto.EncodingRRE;
|
|
183 } else if (choices[encodingIndex].getSelectedItem().equals("CoRRE")) {
|
|
184 preferredEncoding = RfbProto.EncodingCoRRE;
|
|
185 } else if (choices[encodingIndex].getSelectedItem().equals("Hextile")) {
|
|
186 preferredEncoding = RfbProto.EncodingHextile;
|
|
187 } else if (choices[encodingIndex].getSelectedItem().equals("ZRLE")) {
|
|
188 preferredEncoding = RfbProto.EncodingZRLE;
|
|
189 } else if (choices[encodingIndex].getSelectedItem().equals("Zlib")) {
|
|
190 preferredEncoding = RfbProto.EncodingZlib;
|
|
191 enableCompressLevel = true;
|
|
192 } else if (choices[encodingIndex].getSelectedItem().equals("Tight")) {
|
|
193 preferredEncoding = RfbProto.EncodingTight;
|
|
194 enableCompressLevel = true;
|
|
195 } else if (choices[encodingIndex].getSelectedItem().equals("Auto")) {
|
|
196 preferredEncoding = -1;
|
|
197 }
|
|
198
|
|
199 // Handle compression level setting.
|
|
200
|
|
201 try {
|
|
202 compressLevel =
|
|
203 Integer.parseInt(choices[compressLevelIndex].getSelectedItem());
|
|
204 }
|
|
205 catch (NumberFormatException e) {
|
|
206 compressLevel = -1;
|
|
207 }
|
|
208 if (compressLevel < 1 || compressLevel > 9) {
|
|
209 compressLevel = -1;
|
|
210 }
|
|
211 labels[compressLevelIndex].setEnabled(enableCompressLevel);
|
|
212 choices[compressLevelIndex].setEnabled(enableCompressLevel);
|
|
213
|
|
214 // Handle JPEG quality setting.
|
|
215
|
|
216 try {
|
|
217 jpegQuality =
|
|
218 Integer.parseInt(choices[jpegQualityIndex].getSelectedItem());
|
|
219 }
|
|
220 catch (NumberFormatException e) {
|
|
221 jpegQuality = -1;
|
|
222 }
|
|
223 if (jpegQuality < 0 || jpegQuality > 9) {
|
|
224 jpegQuality = -1;
|
|
225 }
|
|
226
|
|
227 // Request cursor shape updates if necessary.
|
|
228
|
|
229 requestCursorUpdates =
|
|
230 !choices[cursorUpdatesIndex].getSelectedItem().equals("Disable");
|
|
231
|
|
232 if (requestCursorUpdates) {
|
|
233 ignoreCursorUpdates =
|
|
234 choices[cursorUpdatesIndex].getSelectedItem().equals("Ignore");
|
|
235 }
|
|
236
|
|
237 viewer.setEncodings();
|
|
238 }
|
|
239
|
|
240 //
|
|
241 // setColorFormat sets eightBitColors variable depending on the GUI
|
|
242 // setting, causing switches between 8-bit and 24-bit colors mode if
|
|
243 // necessary.
|
|
244 //
|
|
245
|
|
246 void setColorFormat() {
|
|
247
|
|
248 eightBitColors =
|
|
249 choices[eightBitColorsIndex].getSelectedItem().equals("Yes");
|
|
250
|
|
251 boolean enableJPEG = !eightBitColors;
|
|
252
|
|
253 labels[jpegQualityIndex].setEnabled(enableJPEG);
|
|
254 choices[jpegQualityIndex].setEnabled(enableJPEG);
|
|
255 }
|
|
256
|
|
257 //
|
|
258 // setOtherOptions looks at the "other" choices (ones that do not
|
|
259 // cause sending any protocol messages) and sets the boolean flags
|
|
260 // appropriately.
|
|
261 //
|
|
262
|
|
263 void setOtherOptions() {
|
|
264
|
|
265 reverseMouseButtons2And3
|
|
266 = choices[mouseButtonIndex].getSelectedItem().equals("Reversed");
|
|
267
|
|
268 viewOnly
|
|
269 = choices[viewOnlyIndex].getSelectedItem().equals("Yes");
|
|
270 if (viewer.vc != null)
|
|
271 viewer.vc.enableInput(!viewOnly);
|
|
272
|
|
273 shareDesktop
|
|
274 = choices[shareDesktopIndex].getSelectedItem().equals("Yes");
|
|
275
|
|
276 String scaleString = choices[scaleCursorIndex].getSelectedItem();
|
|
277 if (scaleString.endsWith("%"))
|
|
278 scaleString = scaleString.substring(0, scaleString.length() - 1);
|
|
279 try {
|
|
280 scaleCursor = Integer.parseInt(scaleString);
|
|
281 }
|
|
282 catch (NumberFormatException e) {
|
|
283 scaleCursor = 0;
|
|
284 }
|
|
285 if (scaleCursor < 10 || scaleCursor > 500) {
|
|
286 scaleCursor = 0;
|
|
287 }
|
|
288 if (requestCursorUpdates && !ignoreCursorUpdates && !viewOnly) {
|
|
289 labels[scaleCursorIndex].setEnabled(true);
|
|
290 choices[scaleCursorIndex].setEnabled(true);
|
|
291 } else {
|
|
292 labels[scaleCursorIndex].setEnabled(false);
|
|
293 choices[scaleCursorIndex].setEnabled(false);
|
|
294 }
|
|
295 if (viewer.vc != null)
|
|
296 viewer.vc.createSoftCursor(); // update cursor scaling
|
|
297 }
|
|
298
|
|
299
|
|
300 //
|
|
301 // Respond to actions on Choice controls
|
|
302 //
|
|
303
|
|
304 public void itemStateChanged(ItemEvent evt) {
|
|
305 Object source = evt.getSource();
|
|
306
|
|
307 if (source == choices[encodingIndex] ||
|
|
308 source == choices[compressLevelIndex] ||
|
|
309 source == choices[jpegQualityIndex] ||
|
|
310 source == choices[cursorUpdatesIndex] ||
|
|
311 source == choices[useCopyRectIndex]) {
|
|
312
|
|
313 setEncodings();
|
|
314
|
|
315 if (source == choices[cursorUpdatesIndex]) {
|
|
316 setOtherOptions(); // update scaleCursor state
|
|
317 }
|
|
318
|
|
319 } else if (source == choices[eightBitColorsIndex]) {
|
|
320
|
|
321 setColorFormat();
|
|
322
|
|
323 } else if (source == choices[mouseButtonIndex] ||
|
|
324 source == choices[shareDesktopIndex] ||
|
|
325 source == choices[viewOnlyIndex] ||
|
|
326 source == choices[scaleCursorIndex]) {
|
|
327
|
|
328 setOtherOptions();
|
|
329
|
|
330 }
|
|
331 }
|
|
332
|
|
333 }
|