File: optionsFrame.java

package info (click to toggle)
vnc-java 3.3.3r2-7
  • links: PTS
  • area: contrib
  • in suites: etch, etch-m68k, lenny
  • size: 240 kB
  • ctags: 291
  • sloc: java: 2,078; makefile: 83; sh: 41
file content (305 lines) | stat: -rw-r--r-- 8,513 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
//
//  Copyright (C) 2001 Const Kaplinsky.  All Rights Reserved.
//  Copyright (C) 2000 Tridia Corporation.  All Rights Reserved.
//  Copyright (C) 1999 AT&T Laboratories Cambridge.  All Rights Reserved.
//
//  This is free software; you can redistribute it and/or modify
//  it under the terms of the GNU General Public License as published by
//  the Free Software Foundation; either version 2 of the License, or
//  (at your option) any later version.
//
//  This software is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
//
//  You should have received a copy of the GNU General Public License
//  along with this software; if not, write to the Free Software
//  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
//  USA.
//

//
// Options frame.
//
// This deals with all the options the user can play with.
// It sets the encodings array and some booleans.
//

import java.awt.*;

class optionsFrame extends Frame {

  static String[] names = {
    "Encoding",
    "Compression level",
    "Cursor shape updates",
    "Use CopyRect",
    "Mouse buttons 2 and 3",
    "Share desktop",
    "View only",
  };

  static String[][] values = {
    { "Raw", "RRE", "CoRRE", "Hextile", "Zlib", "Tight" },
    { "Default", "1", "2", "3", "4", "5", "6", "7", "8", "9" },
    { "Enable", "Ignore", "Disable" },
    { "Yes", "No" },
    { "Normal", "Reversed" },
    { "Yes", "No" },
    { "Yes", "No" },
  };

  final int
    encodingIndex        	= 0,
    compressLevelIndex   	= 1,
    cursorUpdatesIndex   	= 2,
    useCopyRectIndex     	= 3,
    mouseButtonIndex     	= 4,
    shareDesktopIndex    	= 5,
    viewOnlyIndex   	 	= 6;

  Label[] labels = new Label[names.length];
  Choice[] choices = new Choice[names.length];
  Button dismiss;
  vncviewer v;


  //
  // The actual data which other classes look at:
  //

  int[] encodings = new int[20];
  int nEncodings;

  int compressLevel;

  boolean requestCursorUpdates;
  boolean ignoreCursorUpdates;

  boolean reverseMouseButtons2And3;
  boolean shareDesktop;
  boolean viewOnly;
  boolean showControls;

  //
  // Constructor.  Set up the labels and choices from the names and values
  // arrays.
  //

  optionsFrame(vncviewer v1) {
    super("TightVNC Options");

    v = v1;

    GridBagLayout gridbag = new GridBagLayout();
    setLayout(gridbag);

    GridBagConstraints gbc = new GridBagConstraints();
    gbc.fill = GridBagConstraints.BOTH;

    for (int i = 0; i < names.length; i++) {
      labels[i] = new Label(names[i]);
      gbc.gridwidth = 1;
      gridbag.setConstraints(labels[i],gbc);
      add(labels[i]);

      choices[i] = new Choice();
      gbc.gridwidth = GridBagConstraints.REMAINDER;
      gridbag.setConstraints(choices[i],gbc);
      add(choices[i]);

      for (int j = 0; j < values[i].length; j++) {
	choices[i].addItem(values[i][j]);
      }
    }

    dismiss = new Button("Dismiss");
    gbc.gridwidth = GridBagConstraints.REMAINDER;
    gridbag.setConstraints(dismiss,gbc);
    add(dismiss);

    pack();

    // Set up defaults

    choices[encodingIndex].select("Tight");
    choices[compressLevelIndex].select("Default");
    choices[cursorUpdatesIndex].select("Enable");
    choices[useCopyRectIndex].select("Yes");
    choices[mouseButtonIndex].select("Normal");
    choices[shareDesktopIndex].select("Yes");
    choices[viewOnlyIndex].select("No");

    // But let them be overridden by parameters

    for (int i = 0; i < names.length; i++) {
      String s = v.readParameter(names[i], false);
      if (s != null) {
	for (int j = 0; j < values[i].length; j++) {
	  if (s.equalsIgnoreCase(values[i][j])) {
	    choices[i].select(j);
	  }
	}
      }
    }

    // "Show Controls" setting does not have associated GUI option

    showControls = true;
    String s = v.readParameter("Show Controls", false);
    if (s != null && s.equalsIgnoreCase("No"))
      showControls = false;

    // Make the booleans and encodings array correspond to the state of the GUI

    setEncodings();
    setOtherOptions();
  }


  //
  // Disable shareDesktop option
  //

  void disableShareDesktop() {
    labels[shareDesktopIndex].disable();
    choices[shareDesktopIndex].disable();
  }


  void disableViewOnly() {
    labels[viewOnlyIndex].disable();
    choices[viewOnlyIndex].disable();
  }

  //
  // setEncodings looks at the encoding, compression level, cursor
  // shape updates and copyRect choices and sets the encodings array
  // appropriately. It also calls the vncviewer's setEncodings method
  // to send a message to the RFB server if necessary.
  //

  void setEncodings() {
    nEncodings = 0;
    if (choices[useCopyRectIndex].getSelectedItem().equals("Yes")) {
      encodings[nEncodings++] = rfbProto.EncodingCopyRect;
    }

    int preferredEncoding = rfbProto.EncodingRaw;
    boolean enableCompressLevel = false;

    if (choices[encodingIndex].getSelectedItem().equals("RRE")) {
      preferredEncoding = rfbProto.EncodingRRE;
    } else if (choices[encodingIndex].getSelectedItem().equals("CoRRE")) {
      preferredEncoding = rfbProto.EncodingCoRRE;
    } else if (choices[encodingIndex].getSelectedItem().equals("Hextile")) {
      preferredEncoding = rfbProto.EncodingHextile;
    } else if (choices[encodingIndex].getSelectedItem().equals("Zlib")) {
      preferredEncoding = rfbProto.EncodingZlib;
      enableCompressLevel = true;
    } else if (choices[encodingIndex].getSelectedItem().equals("Tight")) {
      preferredEncoding = rfbProto.EncodingTight;
      enableCompressLevel = true;
    }

    encodings[nEncodings++] = preferredEncoding;
    if (preferredEncoding != rfbProto.EncodingHextile) {
      encodings[nEncodings++] = rfbProto.EncodingHextile;
    }
    if (preferredEncoding != rfbProto.EncodingTight) {
      encodings[nEncodings++] = rfbProto.EncodingTight;
    }
    if (preferredEncoding != rfbProto.EncodingZlib) {
      encodings[nEncodings++] = rfbProto.EncodingZlib;
    }
    if (preferredEncoding != rfbProto.EncodingCoRRE) {
      encodings[nEncodings++] = rfbProto.EncodingCoRRE;
    }
    if (preferredEncoding != rfbProto.EncodingRRE) {
      encodings[nEncodings++] = rfbProto.EncodingRRE;
    }

    if (enableCompressLevel) {
      labels[compressLevelIndex].enable();
      choices[compressLevelIndex].enable();
      try {
	compressLevel =
	  Integer.parseInt(choices[compressLevelIndex].getSelectedItem());
      }
      catch (NumberFormatException e) {
	compressLevel = -1;
      }
      if (compressLevel >= 1 && compressLevel <= 9) {
	encodings[nEncodings++] =
	  rfbProto.EncodingCompressLevel0 + compressLevel;
      }
    } else {
      labels[compressLevelIndex].disable();
      choices[compressLevelIndex].disable();
    }

    // Request cursor shape updates if necessary.

    requestCursorUpdates =
      !choices[cursorUpdatesIndex].getSelectedItem().equals("Disable");

    if (requestCursorUpdates) {
      encodings[nEncodings++] = rfbProto.EncodingXCursor;
      encodings[nEncodings++] = rfbProto.EncodingRichCursor;
      ignoreCursorUpdates =
	choices[cursorUpdatesIndex].getSelectedItem().equals("Ignore");
    }

    encodings[nEncodings++] = rfbProto.EncodingLastRect;

    v.setEncodings();
  }

  //
  // setOtherOptions looks at the "other" choices (ones which don't set the
  // encoding) and sets the boolean flags appropriately.
  //

  void setOtherOptions() {

    reverseMouseButtons2And3
      = choices[mouseButtonIndex].getSelectedItem().equals("Reversed");

    shareDesktop
      = choices[shareDesktopIndex].getSelectedItem().equals("Yes");

    viewOnly 
      = choices[viewOnlyIndex].getSelectedItem().equals("Yes");
  }



  //
  // Respond to an action i.e. choice or button press
  //

  public boolean action(Event evt, Object arg) {

    if (evt.target == dismiss) {
      hide();
      return true;

    } else if ((evt.target == choices[encodingIndex]) ||
	       (evt.target == choices[compressLevelIndex]) ||
	       (evt.target == choices[cursorUpdatesIndex]) ||
	       (evt.target == choices[useCopyRectIndex])) {

      setEncodings();
      return true;

    } else if ((evt.target == choices[mouseButtonIndex]) ||
	       (evt.target == choices[shareDesktopIndex]) ||
	       (evt.target == choices[viewOnlyIndex])) {

      setOtherOptions();
      return true;
    }
    return false;
  }
}