comparison src/treeVnc/OptionsNoFrame.java @ 0:756bfaf731f3

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