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