1 | //
|
---|
2 | // Copyright (C) 1997, 1998 Olivetti & Oracle Research Laboratory
|
---|
3 | //
|
---|
4 | // This is free software; you can redistribute it and/or modify
|
---|
5 | // it under the terms of the GNU General Public License as published by
|
---|
6 | // the Free Software Foundation; either version 2 of the License, or
|
---|
7 | // (at your option) any later version.
|
---|
8 | //
|
---|
9 | // This software is distributed in the hope that it will be useful,
|
---|
10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
12 | // GNU General Public License for more details.
|
---|
13 | //
|
---|
14 | // You should have received a copy of the GNU General Public License
|
---|
15 | // along with this software; if not, write to the Free Software
|
---|
16 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
---|
17 | // USA.
|
---|
18 | //
|
---|
19 |
|
---|
20 | //
|
---|
21 | // Options frame.
|
---|
22 | //
|
---|
23 | // This deals with all the options the user can play with.
|
---|
24 | // It sets the encodings array and some booleans.
|
---|
25 | //
|
---|
26 | package mindbright.vnc;
|
---|
27 |
|
---|
28 | import java.awt.*;
|
---|
29 | import mindbright.application.MindVNC;
|
---|
30 |
|
---|
31 | public class optionsFrame extends Frame {
|
---|
32 |
|
---|
33 | static String[] names = {
|
---|
34 | "Encoding",
|
---|
35 | "Use CopyRect",
|
---|
36 | "Mouse buttons 2 and 3",
|
---|
37 | "Raw pixel drawing",
|
---|
38 | "CopyRect",
|
---|
39 | "Share desktop",
|
---|
40 | };
|
---|
41 |
|
---|
42 | static String[][] values = {
|
---|
43 | { "Raw", "RRE", "CoRRE", "Hextile" },
|
---|
44 | { "Yes", "No" },
|
---|
45 | { "Normal", "Reversed" },
|
---|
46 | { "Fast", "Reliable" },
|
---|
47 | { "Fast", "Reliable" },
|
---|
48 | { "Yes", "No" },
|
---|
49 | };
|
---|
50 |
|
---|
51 | final int encodingIndex = 0, useCopyRectIndex = 1, mouseButtonIndex = 2,
|
---|
52 | rawPixelDrawingIndex = 3, copyRectFastIndex = 4, shareDesktopIndex = 5;
|
---|
53 |
|
---|
54 | Label[] labels = new Label[names.length];
|
---|
55 | Choice[] choices = new Choice[names.length];
|
---|
56 | Button dismiss;
|
---|
57 | MindVNC v;
|
---|
58 |
|
---|
59 |
|
---|
60 | //
|
---|
61 | // The actual data which other classes look at:
|
---|
62 | //
|
---|
63 |
|
---|
64 | public int[] encodings = new int[10];
|
---|
65 | public int nEncodings;
|
---|
66 |
|
---|
67 | boolean reverseMouseButtons2And3;
|
---|
68 |
|
---|
69 | boolean drawEachPixelForRawRects;
|
---|
70 |
|
---|
71 | boolean copyRectFast;
|
---|
72 |
|
---|
73 | boolean shareDesktop;
|
---|
74 |
|
---|
75 |
|
---|
76 | //
|
---|
77 | // Constructor. Set up the labels and choices from the names and values
|
---|
78 | // arrays.
|
---|
79 | //
|
---|
80 |
|
---|
81 | public optionsFrame(MindVNC v1) {
|
---|
82 | super("VNC Options");
|
---|
83 |
|
---|
84 | v = v1;
|
---|
85 |
|
---|
86 | GridBagLayout gridbag = new GridBagLayout();
|
---|
87 | setLayout(gridbag);
|
---|
88 |
|
---|
89 | GridBagConstraints gbc = new GridBagConstraints();
|
---|
90 | gbc.fill = GridBagConstraints.BOTH;
|
---|
91 |
|
---|
92 | for (int i = 0; i < names.length; i++) {
|
---|
93 | labels[i] = new Label(names[i]);
|
---|
94 | gbc.gridwidth = 1;
|
---|
95 | gridbag.setConstraints(labels[i],gbc);
|
---|
96 | add(labels[i]);
|
---|
97 |
|
---|
98 | choices[i] = new Choice();
|
---|
99 | gbc.gridwidth = GridBagConstraints.REMAINDER;
|
---|
100 | gridbag.setConstraints(choices[i],gbc);
|
---|
101 | add(choices[i]);
|
---|
102 |
|
---|
103 | for (int j = 0; j < values[i].length; j++) {
|
---|
104 | choices[i].addItem(values[i][j]);
|
---|
105 | }
|
---|
106 | }
|
---|
107 |
|
---|
108 | dismiss = new Button("Dismiss");
|
---|
109 | gbc.gridwidth = GridBagConstraints.REMAINDER;
|
---|
110 | gridbag.setConstraints(dismiss,gbc);
|
---|
111 | add(dismiss);
|
---|
112 |
|
---|
113 | pack();
|
---|
114 |
|
---|
115 | // Set up defaults
|
---|
116 |
|
---|
117 | choices[encodingIndex].select("Hextile");
|
---|
118 | choices[useCopyRectIndex].select("Yes");
|
---|
119 | choices[mouseButtonIndex].select("Normal");
|
---|
120 | choices[rawPixelDrawingIndex].select("Reliable");
|
---|
121 | choices[copyRectFastIndex].select("Fast");
|
---|
122 | choices[shareDesktopIndex].select("No");
|
---|
123 |
|
---|
124 | // But let them be overridden by parameters
|
---|
125 |
|
---|
126 | for (int i = 0; i < names.length; i++) {
|
---|
127 | String s = v.readParameter(names[i], false);
|
---|
128 | if (s != null) {
|
---|
129 | for (int j = 0; j < values[i].length; j++) {
|
---|
130 | if (s.equalsIgnoreCase(values[i][j])) {
|
---|
131 | choices[i].select(j);
|
---|
132 | }
|
---|
133 | }
|
---|
134 | }
|
---|
135 | }
|
---|
136 |
|
---|
137 | // Make the booleans and encodings array correspond to the state of the GUI
|
---|
138 |
|
---|
139 | setEncodings();
|
---|
140 | setOtherOptions();
|
---|
141 | }
|
---|
142 |
|
---|
143 |
|
---|
144 | //
|
---|
145 | // Disable shareDesktop option
|
---|
146 | //
|
---|
147 |
|
---|
148 | void disableShareDesktop() {
|
---|
149 | labels[shareDesktopIndex].disable();
|
---|
150 | choices[shareDesktopIndex].disable();
|
---|
151 | }
|
---|
152 |
|
---|
153 | //
|
---|
154 | // setEncodings looks at the encoding and copyRect choices and sets the
|
---|
155 | // encodings array appropriately. It also calls the MindVNC's
|
---|
156 | // setEncodings method to send a message to the RFB server if necessary.
|
---|
157 | //
|
---|
158 |
|
---|
159 | void setEncodings() {
|
---|
160 | nEncodings = 0;
|
---|
161 | if (choices[useCopyRectIndex].getSelectedItem().equals("Yes")) {
|
---|
162 | encodings[nEncodings++] = rfbProto.EncodingCopyRect;
|
---|
163 | }
|
---|
164 |
|
---|
165 | int preferredEncoding = rfbProto.EncodingRaw;
|
---|
166 |
|
---|
167 | if (choices[encodingIndex].getSelectedItem().equals("RRE")) {
|
---|
168 | preferredEncoding = rfbProto.EncodingRRE;
|
---|
169 | } else if (choices[encodingIndex].getSelectedItem().equals("CoRRE")) {
|
---|
170 | preferredEncoding = rfbProto.EncodingCoRRE;
|
---|
171 | } else if (choices[encodingIndex].getSelectedItem().equals("Hextile")) {
|
---|
172 | preferredEncoding = rfbProto.EncodingHextile;
|
---|
173 | }
|
---|
174 |
|
---|
175 | if (preferredEncoding == rfbProto.EncodingRaw) {
|
---|
176 | choices[rawPixelDrawingIndex].select("Fast");
|
---|
177 | drawEachPixelForRawRects = false;
|
---|
178 | }
|
---|
179 |
|
---|
180 | encodings[nEncodings++] = preferredEncoding;
|
---|
181 | if (preferredEncoding != rfbProto.EncodingRRE) {
|
---|
182 | encodings[nEncodings++] = rfbProto.EncodingRRE;
|
---|
183 | }
|
---|
184 | if (preferredEncoding != rfbProto.EncodingCoRRE) {
|
---|
185 | encodings[nEncodings++] = rfbProto.EncodingCoRRE;
|
---|
186 | }
|
---|
187 | if (preferredEncoding != rfbProto.EncodingHextile) {
|
---|
188 | encodings[nEncodings++] = rfbProto.EncodingHextile;
|
---|
189 | }
|
---|
190 |
|
---|
191 | if(v.rfb != null)
|
---|
192 | v.rfb.setEncodings(encodings, nEncodings);
|
---|
193 | }
|
---|
194 |
|
---|
195 | //
|
---|
196 | // setOtherOptions looks at the "other" choices (ones which don't set the
|
---|
197 | // encoding) and sets the boolean flags appropriately.
|
---|
198 | //
|
---|
199 |
|
---|
200 | void setOtherOptions() {
|
---|
201 |
|
---|
202 | reverseMouseButtons2And3
|
---|
203 | = choices[mouseButtonIndex].getSelectedItem().equals("Reversed");
|
---|
204 |
|
---|
205 | drawEachPixelForRawRects
|
---|
206 | = choices[rawPixelDrawingIndex].getSelectedItem().equals("Reliable");
|
---|
207 |
|
---|
208 | copyRectFast
|
---|
209 | = (choices[copyRectFastIndex].getSelectedItem().equals("Fast"));
|
---|
210 |
|
---|
211 | shareDesktop
|
---|
212 | = (choices[shareDesktopIndex].getSelectedItem().equals("Yes"));
|
---|
213 | }
|
---|
214 |
|
---|
215 |
|
---|
216 |
|
---|
217 | //
|
---|
218 | // Respond to an action i.e. choice or button press
|
---|
219 | //
|
---|
220 |
|
---|
221 | public boolean action(Event evt, Object arg) {
|
---|
222 |
|
---|
223 | if (evt.target == dismiss) {
|
---|
224 | hide();
|
---|
225 | return true;
|
---|
226 |
|
---|
227 | } else if ((evt.target == choices[encodingIndex]) ||
|
---|
228 | (evt.target == choices[useCopyRectIndex])) {
|
---|
229 |
|
---|
230 | setEncodings();
|
---|
231 | return true;
|
---|
232 |
|
---|
233 | } else if ((evt.target == choices[mouseButtonIndex]) ||
|
---|
234 | (evt.target == choices[rawPixelDrawingIndex]) ||
|
---|
235 | (evt.target == choices[copyRectFastIndex]) ||
|
---|
236 | (evt.target == choices[shareDesktopIndex])) {
|
---|
237 |
|
---|
238 | setOtherOptions();
|
---|
239 | return true;
|
---|
240 | }
|
---|
241 | return false;
|
---|
242 | }
|
---|
243 | }
|
---|