comparison src/myVncProxy/OptionsNoFrame.java @ 67:f695bc56eb4f

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