Mercurial > 510Connectbot
comparison app/src/main/java/org/tn5250j/framework/tn5250/WTDSFParser.java @ 438:d29cce60f393
migrate from Eclipse to Android Studio
author | Carl Byington <carl@five-ten-sg.com> |
---|---|
date | Thu, 03 Dec 2015 11:23:55 -0800 |
parents | src/org/tn5250j/framework/tn5250/WTDSFParser.java@77ac18bc1b2f |
children |
comparison
equal
deleted
inserted
replaced
437:208b31032318 | 438:d29cce60f393 |
---|---|
1 /** | |
2 * Title: tn5250J | |
3 * Copyright: Copyright (c) 2001 | |
4 * Company: | |
5 * @author Kenneth J. Pouncey | |
6 * @version 0.5 | |
7 * | |
8 * Description: | |
9 * | |
10 * This program is free software; you can redistribute it and/or modify | |
11 * it under the terms of the GNU General Public License as published by | |
12 * the Free Software Foundation; either version 2, or (at your option) | |
13 * any later version. | |
14 * | |
15 * This program is distributed in the hope that it will be useful, | |
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 * GNU General Public License for more details. | |
19 * | |
20 * You should have received a copy of the GNU General Public License | |
21 * along with this software; see the file COPYING. If not, write to | |
22 * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, | |
23 * Boston, MA 02111-1307 USA | |
24 * | |
25 */ | |
26 package org.tn5250j.framework.tn5250; | |
27 | |
28 import static org.tn5250j.TN5250jConstants.BOTTOM; | |
29 import static org.tn5250j.TN5250jConstants.GUI_LEFT; | |
30 import static org.tn5250j.TN5250jConstants.GUI_RIGHT; | |
31 import static org.tn5250j.TN5250jConstants.LOWER_LEFT; | |
32 import static org.tn5250j.TN5250jConstants.LOWER_RIGHT; | |
33 import static org.tn5250j.TN5250jConstants.NO_GUI; | |
34 import static org.tn5250j.TN5250jConstants.NR_REQUEST_ERROR; | |
35 import static org.tn5250j.TN5250jConstants.UPPER; | |
36 import static org.tn5250j.TN5250jConstants.UPPER_LEFT; | |
37 import static org.tn5250j.TN5250jConstants.UPPER_RIGHT; | |
38 | |
39 import java.util.ArrayList; | |
40 import java.util.List; | |
41 | |
42 import org.tn5250j.encoding.ICodePage; | |
43 import android.util.Log; | |
44 | |
45 | |
46 /** | |
47 * | |
48 * Write To Display Structured Field: | |
49 * | |
50 * This module will parse the structured field information for enhanced | |
51 * emulation mode. | |
52 * | |
53 */ | |
54 public class WTDSFParser { | |
55 private static final String TAG = "WTDSFParser"; | |
56 private Screen5250 screen52; | |
57 private tnvt vt; | |
58 private ICodePage codePage; | |
59 int pos; | |
60 byte[] segment; | |
61 int length; | |
62 boolean error; | |
63 boolean guiStructsExist; | |
64 | |
65 | |
66 | |
67 private final List<Window> guiStructs = new ArrayList<Window>(3); | |
68 private final List<ChoiceField> choices = new ArrayList<ChoiceField>(3); | |
69 | |
70 | |
71 WTDSFParser(tnvt vt) { | |
72 this.vt = vt; | |
73 screen52 = vt.screen52; | |
74 codePage = vt.codePage; | |
75 } | |
76 | |
77 protected class ChoiceField { | |
78 | |
79 int x; | |
80 int y; | |
81 int row; | |
82 int col; | |
83 int width; | |
84 int height; | |
85 char mnemonic; | |
86 int fieldId; | |
87 int selectIndex; | |
88 | |
89 ChoiceField(int row, int col, int fldRow, int fldCol) { | |
90 x = row; | |
91 y = col; | |
92 row = fldRow; | |
93 col = fldCol; | |
94 } | |
95 } | |
96 | |
97 protected class Window { | |
98 | |
99 byte[] window; | |
100 int pos; | |
101 | |
102 Window(byte[] seg, int pos) { | |
103 //Log.i(TAG,"window created at " + pos); | |
104 window = seg; | |
105 this.pos = pos; | |
106 guiStructsExist = true; | |
107 } | |
108 | |
109 } | |
110 | |
111 protected void addChoiceField(int row, int col, int fldRow, int fldCol, String text) { | |
112 ChoiceField cf = new ChoiceField(row, col, fldRow, fldCol); | |
113 cf.fieldId = screen52.getScreenFields().getCurrentField().getFieldId(); | |
114 choices.add(cf); | |
115 } | |
116 | |
117 protected boolean isGuisExists() { | |
118 return guiStructsExist; | |
119 } | |
120 | |
121 protected byte[] getSegmentAtPos(int pos) { | |
122 int len = guiStructs.size(); | |
123 | |
124 for (int x = 0; x < len; x++) { | |
125 Window w = guiStructs.get(x); | |
126 | |
127 if (w.pos == pos) | |
128 return w.window; | |
129 } | |
130 | |
131 return null; | |
132 } | |
133 | |
134 protected void clearGuiStructs() { | |
135 guiStructs.clear(); | |
136 } | |
137 | |
138 protected boolean parseWriteToDisplayStructuredField(byte[] seg) { | |
139 // bk = vt.bk; | |
140 error = false; | |
141 boolean done = false; | |
142 boolean windowDefined = false; | |
143 // int nextone; | |
144 pos = 0; | |
145 segment = seg; | |
146 // try { | |
147 length = ((segment[pos++] & 0xff) << 8 | (segment[pos++] & 0xff)); | |
148 | |
149 while (!done) { | |
150 int s = segment[pos++] & 0xff; | |
151 | |
152 switch (s) { | |
153 case 0xD9: // Class Type 0xD9 - Create Window | |
154 switch (segment[pos++]) { | |
155 case 0x50: // Define Selection Field | |
156 defineSelectionField(length); | |
157 done = true; | |
158 break; | |
159 | |
160 case 0x51: // Create Window | |
161 guiStructs.add(new Window(segment, screen52.getLastPos())); | |
162 boolean cr = false; | |
163 int rows = 0; | |
164 int cols = 0; | |
165 | |
166 // pull down not supported yet | |
167 if ((segment[pos++] & 0x80) == 0x80) | |
168 cr = true; // restrict cursor | |
169 | |
170 pos++; // get reserved field pos 6 | |
171 pos++; // get reserved field pos 7 | |
172 rows = segment[pos++]; // get window depth rows pos 8 | |
173 cols = segment[pos++]; // get window width cols pos 9 | |
174 length -= 9; | |
175 | |
176 if (length == 0) { | |
177 done = true; | |
178 // System.out.println("Create Window"); | |
179 // System.out.println(" restrict cursor " + cr); | |
180 // System.out.println(" Depth = " + rows + " Width = " + cols); | |
181 // screen52.createWindow(rows,cols,1,true,32,58, | |
182 createWindow(rows, cols, 1, true, 32, 58, | |
183 '.', | |
184 '.', | |
185 '.', | |
186 ':', | |
187 ':', | |
188 ':', | |
189 '.', | |
190 ':'); | |
191 windowDefined = true; | |
192 break; | |
193 } | |
194 | |
195 // pos 10 is Minor Structure | |
196 int ml = 0; | |
197 int type = 0; | |
198 int lastPos = screen52.getLastPos(); | |
199 // if (cr) | |
200 // screen52.setPendingInsert(true, | |
201 // screen52.getCurrentRow(), | |
202 // screen52.getCurrentCol()); | |
203 int mAttr = 0; | |
204 int cAttr = 0; | |
205 | |
206 while (length > 0) { | |
207 // get minor length | |
208 ml = (segment[pos++] & 0xff); | |
209 length -= ml; | |
210 // only normal windows are supported at this time | |
211 type = segment[pos++]; | |
212 | |
213 switch (type) { | |
214 case 0x01 : // Border presentation | |
215 boolean gui = false; | |
216 | |
217 if ((segment[pos++] & 0x80) == 0x80) | |
218 gui = true; | |
219 | |
220 mAttr = segment[pos++]; | |
221 cAttr = segment[pos++]; | |
222 char ul = '.'; | |
223 char upper = '.'; | |
224 char ur = '.'; | |
225 char left = ':'; | |
226 char right = ':'; | |
227 char ll = ':'; | |
228 char bottom = '.'; | |
229 char lr = ':'; | |
230 | |
231 // if minor length is greater than 5 then | |
232 // the border characters are specified | |
233 if (ml > 5) { | |
234 ul = codePage.ebcdic2uni(segment[pos++]); | |
235 | |
236 // ul = getASCIIChar(segment[pos++]); | |
237 if (ul == 0) | |
238 ul = '.'; | |
239 | |
240 upper = codePage.ebcdic2uni(segment[pos++]); | |
241 | |
242 // upper = getASCIIChar(segment[pos++]); | |
243 if (upper == 0) | |
244 upper = '.'; | |
245 | |
246 ur = codePage.ebcdic2uni(segment[pos++]); | |
247 | |
248 // ur = getASCIIChar(segment[pos++]); | |
249 if (ur == 0) | |
250 ur = '.'; | |
251 | |
252 left = codePage.ebcdic2uni(segment[pos++]); | |
253 | |
254 // left = getASCIIChar(segment[pos++]); | |
255 if (left == 0) | |
256 left = ':'; | |
257 | |
258 right = codePage.ebcdic2uni(segment[pos++]); | |
259 | |
260 // right = getASCIIChar(segment[pos++]); | |
261 if (right == 0) | |
262 right = ':'; | |
263 | |
264 ll = codePage.ebcdic2uni(segment[pos++]); | |
265 | |
266 // ll = getASCIIChar(segment[pos++]); | |
267 if (ll == 0) | |
268 ll = ':'; | |
269 | |
270 bottom = codePage.ebcdic2uni(segment[pos++]); | |
271 | |
272 // bottom = getASCIIChar(segment[pos++]); | |
273 if (bottom == 0) | |
274 bottom = '.'; | |
275 | |
276 lr = codePage.ebcdic2uni(segment[pos++]); | |
277 | |
278 // lr = getASCIIChar(segment[pos++]); | |
279 if (lr == 0) | |
280 lr = ':'; | |
281 } | |
282 | |
283 // System.out.println("Create Window"); | |
284 // System.out.println(" restrict cursor " + cr); | |
285 // System.out.println(" Depth = " + rows + " Width = " + cols); | |
286 // System.out.println(" type = " + type + " gui = " + gui); | |
287 // System.out.println(" mono attr = " + mAttr + " color attr = " + cAttr); | |
288 // System.out.println(" ul = " + ul + " upper = " + upper + | |
289 // " ur = " + ur + | |
290 // " left = " + left + | |
291 // " right = " + right + | |
292 // " ll = " + ll + | |
293 // " bottom = " + bottom + | |
294 // " lr = " + lr | |
295 // ); | |
296 // screen52.createWindow(rows,cols,type,gui,mAttr,cAttr, | |
297 createWindow(rows, cols, type, gui, mAttr, cAttr, | |
298 ul, | |
299 upper, | |
300 ur, | |
301 left, | |
302 right, | |
303 ll, | |
304 bottom, | |
305 lr); | |
306 windowDefined = true; | |
307 break; | |
308 | |
309 // | |
310 // The following shows the input for window with a title | |
311 // | |
312 // +0000 019A12A0 00000400 00020411 00200107 .?.?..?...?..?. | |
313 // +0010 00000018 00000011 06131500 37D95180 ........?.?..R?? | |
314 // +0020 00000A24 0D018023 23404040 40404040 ..??..??? | |
315 // +0030 40211000 000000D7 C2C1D9C4 C5D4D67A \uFFFD.....PBARDEMO: | |
316 // +0040 40D79996 879985A2 A2408281 99408485 Progress bar de | |
317 // +0050 94961108 1520D5A4 94828599 40968640 mo.???Number of | |
318 // +0060 8595A399 8985A24B 4B4B4B4B 4B7A2011 entries......:?. | |
319 // +0070 082E2040 404040F5 F0F06BF0 F0F02011 ?.? 500,000?. | |
320 // +0080 091520C3 A4999985 95A34085 95A399A8 \uFFFD??Current entry | |
321 // +0090 4095A494 8285994B 4B4B7A20 11092E20 number...:?.\uFFFD.? | |
322 // +00A0 40404040 4040F56B F0F0F020 110A1520 5,000?.??? | |
323 // +00B0 D9859481 89958995 87408595 A3998985 Remaining entrie | |
324 // +00C0 A24B4B4B 4B4B4B7A 20110A2E 20404040 s......:?.?.? | |
325 // +00D0 40F4F9F5 6BF0F0F0 20110C15 20E2A381 495,000?..??Sta | |
326 // +00E0 99A340A3 8994854B 4B4B4B4B 4B4B4B4B rt time......... | |
327 // +00F0 4B4B4B4B 7A20110C 2F2040F7 7AF5F37A ....:?...? 7:53: | |
328 | |
329 case 0x10 : // Window title/footer | |
330 if (!windowDefined) { | |
331 // screen52.createWindow(rows,cols,1,true,32,58, | |
332 guiStructs.add(new Window(segment, screen52.getLastPos())); | |
333 createWindow(rows, cols, 1, true, 32, 58, | |
334 '.', | |
335 '.', | |
336 '.', | |
337 ':', | |
338 ':', | |
339 ':', | |
340 '.', | |
341 ':'); | |
342 windowDefined = true; | |
343 } | |
344 | |
345 byte orientation = segment[pos++]; | |
346 mAttr = segment[pos++]; | |
347 cAttr = segment[pos++]; | |
348 //reserved | |
349 pos++; | |
350 ml -= 6; | |
351 StringBuffer hfBuffer = new StringBuffer(ml); | |
352 | |
353 while (ml-- > 0) { | |
354 //LDC - 13/02/2003 - Convert it to unicode | |
355 hfBuffer.append(codePage.ebcdic2uni(segment[pos++])); | |
356 // hfBuffer.append(getASCIIChar(segment[pos++])); | |
357 } | |
358 | |
359 Log.d(TAG, | |
360 " orientation " + Integer.toBinaryString(orientation) + | |
361 " mAttr " + mAttr + | |
362 " cAttr " + cAttr + | |
363 " Header/Footer " + hfBuffer); | |
364 screen52.writeWindowTitle(lastPos, | |
365 rows, | |
366 cols, | |
367 orientation, | |
368 mAttr, | |
369 cAttr, | |
370 hfBuffer); | |
371 break; | |
372 | |
373 default: | |
374 Log.w(TAG, "Invalid Window minor structure"); | |
375 length = 0; | |
376 done = true; | |
377 } | |
378 } | |
379 | |
380 done = true; | |
381 break; | |
382 | |
383 case 0x53: // Scroll Bar | |
384 int sblen = 15; | |
385 byte sbflag = segment[pos++]; // flag position 5 | |
386 pos++; // reserved position 6 | |
387 // position 7,8 | |
388 int totalRowScrollable = ((segment[pos++] & 0xff) << 8 | |
389 | (segment[pos++] & 0xff)); | |
390 // position 9,10 | |
391 int totalColScrollable = ((segment[pos++] & 0xff) << 8 | |
392 | (segment[pos++] & 0xff)); | |
393 // position 11,12 | |
394 int sliderRowPos = ((segment[pos++] & 0xff) << 8 | |
395 | (segment[pos++] & 0xff)); | |
396 // position 13,14 | |
397 int sliderColPos = ((segment[pos++] & 0xff) << 8 | |
398 | (segment[pos++] & 0xff)); | |
399 // position 15 | |
400 int sliderRC = segment[pos++]; | |
401 screen52.createScrollBar(sbflag, totalRowScrollable, | |
402 totalColScrollable, | |
403 sliderRowPos, | |
404 sliderColPos, | |
405 sliderRC); | |
406 length -= 15; | |
407 done = true; | |
408 break; | |
409 | |
410 case 0x5B: // Remove GUI ScrollBar field | |
411 pos++; // reserved must be set to off pos 5 | |
412 pos++; // reserved must be set to zero pos 6 | |
413 done = true; | |
414 break; | |
415 | |
416 case 0x5F: // Remove All GUI Constructs | |
417 Log.i(TAG, "remove all gui contructs"); | |
418 clearGuiStructs(); | |
419 guiStructsExist = false; | |
420 int len = 4; | |
421 int d = 0; | |
422 length -= s; | |
423 | |
424 while (--len > 0) | |
425 d = segment[pos++]; | |
426 | |
427 // if (length > 0) { | |
428 // len = (segment[pos++] & 0xff )<< 8; | |
429 // | |
430 // while (--len > 0) | |
431 // d = segment[pos++]; | |
432 // } | |
433 screen52.clearGuiStuff(); | |
434 // per 14.6.13.4 documentation we should clear the | |
435 // format table after this command | |
436 screen52.clearTable(); | |
437 done = true; | |
438 break; | |
439 | |
440 case 0x59: // remove gui window | |
441 Log.i(TAG, " remove window at " + screen52.getCurrentPos()); | |
442 done = true; | |
443 break; | |
444 | |
445 case 0x60: // Erase/Draw Grid Lines - not supported | |
446 // do not know what they are | |
447 // as of 03/11/2002 we should not be getting | |
448 // this anymore but I will leave it here | |
449 // just in case. | |
450 // System.out.println("erase/draw grid lines " + length); | |
451 len = 6; | |
452 d = 0; | |
453 length -= 9; | |
454 | |
455 while (--len > 0) | |
456 d = segment[pos++]; | |
457 | |
458 if (length > 0) { | |
459 len = (segment[pos++] & 0xff) << 8; | |
460 | |
461 while (--len > 0) { | |
462 d = segment[pos++]; | |
463 } | |
464 } | |
465 | |
466 done = true; | |
467 break; | |
468 | |
469 default: | |
470 vt.sendNegResponse(NR_REQUEST_ERROR, 0x03, 0x01, 0x01, "invalid wtd structured field sub command " | |
471 + (pos - 1)); | |
472 // + bk.getByteOffset(-1)); | |
473 error = true; | |
474 break; | |
475 } | |
476 | |
477 break; | |
478 | |
479 default: | |
480 vt.sendNegResponse(NR_REQUEST_ERROR, 0x03, 0x01, 0x01, | |
481 "invalid wtd structured field command " | |
482 + (pos - 1)); | |
483 // + bk.getByteOffset(-1)); | |
484 error = true; | |
485 break; | |
486 } | |
487 | |
488 if (error) | |
489 done = true; | |
490 } | |
491 | |
492 // } | |
493 // catch (Exception e) {}; | |
494 return error; | |
495 } | |
496 | |
497 /** | |
498 * Creates a window on the screen | |
499 * | |
500 * @param depth | |
501 * @param width | |
502 * @param type | |
503 * @param gui | |
504 * @param monoAttr | |
505 * @param colorAttr | |
506 * @param ul | |
507 * @param upper | |
508 * @param ur | |
509 * @param left | |
510 * @param right | |
511 * @param ll | |
512 * @param bottom | |
513 * @param lr | |
514 */ | |
515 protected void createWindow(int depth, int width, int type, boolean gui, | |
516 int monoAttr, int colorAttr, int ul, int upper, int ur, int left, | |
517 int right, int ll, int bottom, int lr) { | |
518 int lastPos = screen52.getLastPos(); | |
519 int numCols = screen52.getColumns(); | |
520 int c = screen52.getCol(lastPos); | |
521 int w = 0; | |
522 width++; | |
523 w = width; | |
524 char initChar = Screen5250.initChar; | |
525 int initAttr = Screen5250.initAttr; | |
526 // set leading attribute byte | |
527 screen52.setScreenCharAndAttr(initChar, initAttr, true); | |
528 | |
529 // set upper left | |
530 if (gui) { | |
531 screen52.setScreenCharAndAttr((char) ul, colorAttr, UPPER_LEFT, false); | |
532 } | |
533 else { | |
534 screen52.setScreenCharAndAttr((char) ul, colorAttr, false); | |
535 } | |
536 | |
537 // draw top row | |
538 while (w-- >= 0) { | |
539 if (gui) { | |
540 screen52.setScreenCharAndAttr((char) upper, colorAttr, UPPER, false); | |
541 } | |
542 else { | |
543 screen52.setScreenCharAndAttr((char) upper, colorAttr, false); | |
544 } | |
545 } | |
546 | |
547 // set upper right | |
548 if (gui) { | |
549 screen52.setScreenCharAndAttr((char) ur, colorAttr, UPPER_RIGHT, false); | |
550 } | |
551 else { | |
552 screen52.setScreenCharAndAttr((char) ur, colorAttr, false); | |
553 } | |
554 | |
555 // set ending attribute byte | |
556 screen52.setScreenCharAndAttr(initChar, initAttr, true); | |
557 lastPos = ((screen52.getRow(lastPos) + 1) * numCols) + c; | |
558 screen52.goto_XY(lastPos); | |
559 | |
560 // now handle body of window | |
561 while (depth-- > 0) { | |
562 // set leading attribute byte | |
563 screen52.setScreenCharAndAttr(initChar, initAttr, true); | |
564 | |
565 // set left | |
566 if (gui) { | |
567 screen52.setScreenCharAndAttr((char) left, colorAttr, GUI_LEFT, false); | |
568 } | |
569 else { | |
570 screen52.setScreenCharAndAttr((char) left, colorAttr, false); | |
571 } | |
572 | |
573 w = width - 2; | |
574 screen52.setScreenCharAndAttr(initChar, initAttr, NO_GUI, true); | |
575 | |
576 // fill it in | |
577 while (w-- >= 0) { | |
578 // if (!planes.isUseGui(screen52.getLastPos())) | |
579 screen52.setScreenCharAndAttr(initChar, initAttr, NO_GUI, false); | |
580 } | |
581 | |
582 screen52.setScreenCharAndAttr(initChar, initAttr, NO_GUI, true); | |
583 | |
584 // set right | |
585 if (gui) { | |
586 screen52.setScreenCharAndAttr((char) right, colorAttr, GUI_RIGHT, false); | |
587 } | |
588 else { | |
589 screen52.setScreenCharAndAttr((char) right, colorAttr, false); | |
590 } | |
591 | |
592 screen52.setScreenCharAndAttr(initChar, initAttr, true); | |
593 lastPos = ((screen52.getRow(lastPos) + 1) * numCols) + c; | |
594 screen52.goto_XY(lastPos); | |
595 } | |
596 | |
597 // set leading attribute byte | |
598 screen52.setScreenCharAndAttr(initChar, initAttr, true); | |
599 | |
600 if (gui) { | |
601 screen52.setScreenCharAndAttr((char) ll, colorAttr, LOWER_LEFT, false); | |
602 } | |
603 else { | |
604 screen52.setScreenCharAndAttr((char) ll, colorAttr, false); | |
605 } | |
606 | |
607 w = width; | |
608 | |
609 // draw bottom row | |
610 while (w-- >= 0) { | |
611 if (gui) { | |
612 screen52.setScreenCharAndAttr((char) bottom, colorAttr, BOTTOM, false); | |
613 } | |
614 else { | |
615 screen52.setScreenCharAndAttr((char) bottom, colorAttr, false); | |
616 } | |
617 } | |
618 | |
619 // set lower right | |
620 if (gui) { | |
621 screen52.setScreenCharAndAttr((char) lr, colorAttr, LOWER_RIGHT, false); | |
622 } | |
623 else { | |
624 screen52.setScreenCharAndAttr((char) lr, colorAttr, false); | |
625 } | |
626 | |
627 // set ending attribute byte | |
628 screen52.setScreenCharAndAttr(initChar, initAttr, true); | |
629 } | |
630 | |
631 /* *** NEVER USED LOCALLY ************************************************** */ | |
632 // private void clearWindowBody(ScreenPlanes planes, int startPos, int depth, int width) { | |
633 // | |
634 // int lastPos = startPos; | |
635 // char initChar = Screen5250.initChar; | |
636 // int initAttr = Screen5250.initAttr; | |
637 // | |
638 // // now handle body of window | |
639 // while (depth-- > 0) { | |
640 // | |
641 // // set leading attribute byte | |
642 //// planes.setScreenCharAndAttr(lastPos,initChar, initAttr, true); | |
643 //// setDirty(lastPos); | |
644 //// advancePos(); | |
645 //// | |
646 //// // set left | |
647 //// planes.setScreenCharAndAttr(lastPos, (char) left, colorAttr, false); | |
648 //// | |
649 //// if (gui) { | |
650 //// planes.setUseGUI(lastPos,GUI_LEFT); | |
651 //// } | |
652 //// setDirty(lastPos); | |
653 //// advancePos(); | |
654 // | |
655 // int w = width; | |
656 // // fill it in | |
657 // while (w-- >= 0) { | |
658 //// screen[lastPos].setCharAndAttr(initChar, initAttr, true); | |
659 // planes.setScreenCharAndAttr(lastPos,initChar, initAttr, true); | |
660 //// screen[lastPos].setUseGUI(NO_GUI); | |
661 // planes.setUseGUI(lastPos,NO_GUI); | |
662 //// setDirty(lastPos); | |
663 // lastPos++; | |
664 // advancePos(); | |
665 // } | |
666 // | |
667 //// // set right | |
668 //// // screen[lastPos].setCharAndAttr((char) right, colorAttr, false); | |
669 //// planes.setScreenCharAndAttr(lastPos,(char) right, colorAttr, false); | |
670 //// if (gui) { | |
671 //// // screen[lastPos].setUseGUI(RIGHT); | |
672 //// planes.setUseGUI(lastPos,GUI_RIGHT); | |
673 //// } | |
674 //// | |
675 //// setDirty(lastPos); | |
676 //// advancePos(); | |
677 //// | |
678 //// // set ending attribute byte | |
679 //// // screen[lastPos].setCharAndAttr(initChar, initAttr, true); | |
680 //// planes.setScreenCharAndAttr(lastPos,initChar, initAttr, true); | |
681 //// setDirty(lastPos); | |
682 // | |
683 // lastPos = startPos; | |
684 // } | |
685 // | |
686 // } | |
687 | |
688 /* *** NEVER USED LOCALLY ************************************************** */ | |
689 // private void setDirty(int pos) { | |
690 // | |
691 // screen52.setDirty(pos); | |
692 // | |
693 // } | |
694 | |
695 /* *** NEVER USED LOCALLY ************************************************** */ | |
696 // private void advancePos() { | |
697 // | |
698 // screen52.advancePos(); | |
699 // } | |
700 | |
701 private void defineSelectionField(int majLen) { | |
702 // 0030: 20 00 2C 3E 00 00 00 69 12 A0 00 00 04 00 00 03 .,>...i........ | |
703 // 0040: 04 40 04 11 00 28 01 07 00 00 00 19 00 00 04 11 .@...(.......... | |
704 // 0050: 14 19 15 00 48 D9 50 00 60 00 11 01 84 84 00 00 ....H.P.`....... | |
705 // 0060: 05 03 01 01 00 00 00 13 01 E0 00 21 00 21 00 3B ...........!.!.; | |
706 // 0070: 22 20 20 20 20 3A 24 20 20 3A 0B 10 08 00 E0 00 " :$ :...... | |
707 // 0080: D6 95 85 40 40 0B 10 08 00 E0 00 E3 A6 96 40 40 ...@@.........@@ | |
708 // 0090: 0B 10 08 00 E0 00 E3 88 99 85 85 04 52 00 00 FF ............R... | |
709 // 00A0: EF . | |
710 try { | |
711 int flag1 = segment[pos++]; // Flag byte 1 - byte 5 | |
712 int flag2 = segment[pos++]; // Flag byte 2 - byte 6 | |
713 int flag3 = segment[pos++]; // Flag byte 3 - byte 7 | |
714 int typeSelection = segment[pos++]; // Type of selection Field - byte 8 | |
715 // GUI Device Characteristics: | |
716 // This byte is used if the target device is a GUI PWS or a GUI-like | |
717 // NWS. If neigher of these WS are the targets, this byte is ignored | |
718 int guiDevice = segment[pos++]; // byte 9 | |
719 int withMnemonic = segment[pos++]; // byte 10 | |
720 int noMnemonic = segment[pos++]; // byte 11 | |
721 pos++; // Reserved - byte 12 | |
722 pos++; // Reserved - byte 13 | |
723 int cols = segment[pos++]; // Text Size - byte 14 | |
724 int rows = segment[pos++]; // Rows - byte 15 | |
725 int maxColChoice = segment[pos++]; // byte 16 num of column choices | |
726 int padding = segment[pos++]; // byte 17 | |
727 int numSepChar = segment[pos++]; // byte 18 | |
728 int ctySepChar = segment[pos++]; // byte 19 | |
729 int cancelAID = segment[pos++]; // byte 20 | |
730 int cnt = 0; | |
731 int minLen = 0; | |
732 majLen -= 21; | |
733 Log.d(TAG, " row: " + screen52.getCurrentRow() | |
734 + " col: " + screen52.getCurrentCol() | |
735 + " type " + typeSelection | |
736 + " gui " + guiDevice | |
737 + " withMnemonic " + Integer.toHexString(withMnemonic & 0xf0) | |
738 + " noMnemonic " + Integer.toHexString(noMnemonic & 0xf0) | |
739 + " noMnemonic " + Integer.toBinaryString(noMnemonic) | |
740 + " noMnemonicType " + Integer.toBinaryString((noMnemonic & 0xf0)) | |
741 + " noMnemonicSel " + Integer.toBinaryString((noMnemonic & 0x0f)) | |
742 + " maxcols " + maxColChoice | |
743 + " cols " + cols | |
744 + " rows " + rows); | |
745 int rowCtr = 0; | |
746 int colCtr = 0; | |
747 int chcRowStart = screen52.getCurrentRow(); | |
748 int chcColStart = screen52.getCurrentCol(); | |
749 int chcRow = chcRowStart; | |
750 int chcCol = chcColStart; | |
751 int chcPos = screen52.getPos(chcRow - 1, chcCol); | |
752 // client access | |
753 //0000 00 04 ac 9e b9 35 00 01 02 32 bb 4e 08 00 45 00 .....5...2.N..E. | |
754 //0010 00 3c 4f 8e 40 00 80 06 00 00 c1 a8 33 58 c1 a8 .<O.@.......3X.. | |
755 //0020 33 01 09 e4 00 17 5b bf b7 a4 c3 41 43 d1 50 18 3.....[....AC.P. | |
756 //0030 fc de e9 d8 00 00 00 12 12 a0 00 00 04 00 80 03 ................ | |
757 //0040 16 18 f1 11 14 1a 00 22 ff ef .......".. | |
758 int colAvail = 0x20; | |
759 int colSelAvail = 0x20; | |
760 int fld = 0; | |
761 | |
762 do { | |
763 minLen = segment[pos++]; // Minor Length byte 21 | |
764 int minType = segment[pos++]; // Minor Type | |
765 | |
766 switch (minType) { | |
767 case 0x01: // Choice Presentation Display | |
768 // flag | |
769 int flagCP1 = segment[pos++]; | |
770 pos++; // mon select cursor avail emphasis - byte4 | |
771 colSelAvail = segment[pos++]; // -byte 5 | |
772 pos++; // mon select cursor - byte 6 | |
773 int colSelCur = segment[pos++]; // -byte 7 | |
774 pos++; // mon select cursor not avail emphasis - byte 8 | |
775 int colSelNotAvail = segment[pos++]; // -byte 9 | |
776 pos++; // mon avail emphasis - byte 10 | |
777 colAvail = segment[pos++]; // -byte 11 | |
778 pos++; // mon select emphasis - byte 12 | |
779 int colSel = segment[pos++]; // -byte 13 | |
780 pos++; // mon not avail emphasis - byte 14 | |
781 int colNotAvail = segment[pos++]; // -byte 15 | |
782 pos++; // mon indicator emphasis - byte 16 | |
783 int colInd = segment[pos++]; // -byte 17 | |
784 pos++; // mon indicator not avail emphasis - byte 18 | |
785 int colNotAvailInd = segment[pos++]; // -byte 19 | |
786 break; | |
787 | |
788 case 0x10: // Choice Text minor structure | |
789 cnt = 5; | |
790 int flagCT1 = segment[pos++]; | |
791 int flagCT2 = segment[pos++]; | |
792 int flagCT3 = segment[pos++]; | |
793 int mnemOffset = 0; | |
794 boolean aid = false; | |
795 boolean selected = false; | |
796 | |
797 // is in selected state | |
798 if ((flagCT1 & 0x40) == 0x40) { | |
799 Log.d(TAG, " selected "); | |
800 selected = true; | |
801 } | |
802 | |
803 //System.out.println(Integer.toBinaryString((flagCT1 & 0xf0))); | |
804 // is mnemonic offset specified | |
805 if ((flagCT1 & 0x08) == 8) { | |
806 Log.d(TAG, " mnemOffset " + mnemOffset); | |
807 mnemOffset = segment[pos++]; | |
808 cnt++; | |
809 } | |
810 | |
811 // is aid key specified | |
812 if ((flagCT1 & 0x04) == 4) { | |
813 aid = true; | |
814 Log.d(TAG, " aidKey " + aid); | |
815 // cnt++; | |
816 } | |
817 | |
818 // is single digit number specified | |
819 if ((flagCT1 & 0x01) == 0x01) { | |
820 Log.d(TAG, " single digit "); | |
821 pos++; | |
822 cnt++; | |
823 } | |
824 | |
825 // is double digint number specified | |
826 if ((flagCT1 & 0x02) == 0x02) { | |
827 Log.d(TAG, " double digit "); | |
828 pos++; | |
829 cnt++; | |
830 } | |
831 | |
832 String s = ""; | |
833 byte byte0 = 0; | |
834 fld++; | |
835 screen52.setCursor(chcRowStart, chcColStart); | |
836 | |
837 // we do not add a selection if it is marked as unavailable | |
838 if ((flagCT1 & 0x80) != 0x80) { | |
839 screen52.addField(0x26, 1, 0, 0, 0, 0); | |
840 screen52.getScreenFields().getCurrentField().setFieldChar('.'); | |
841 screen52.getScreenFields().getCurrentField().setSelectionFieldInfo(17, | |
842 fld, | |
843 chcPos); | |
844 screen52.setCursor(chcRowStart, chcColStart + 3); | |
845 | |
846 for (; cnt < minLen; cnt++) { | |
847 byte0 = segment[pos++]; | |
848 s += vt.codePage.ebcdic2uni(byte0); | |
849 screen52.setChar(vt.codePage.ebcdic2uni(byte0)); | |
850 } | |
851 | |
852 addChoiceField(chcRowStart, chcColStart, chcRow, chcCol, s); | |
853 } | |
854 | |
855 // screen52.getScreenFields().getCurrentField().setMDT(); | |
856 Log.d(TAG, s + " selected " + selected); | |
857 // chcRowStart; | |
858 //maxColChoice | |
859 colCtr++; | |
860 | |
861 // rowCtr++; | |
862 if (colCtr >= maxColChoice) { | |
863 rowCtr++; | |
864 colCtr = 0; | |
865 chcColStart = chcCol; | |
866 chcRowStart = chcRow + rowCtr; | |
867 | |
868 if (rowCtr > rows) { | |
869 chcRowStart = chcRow; | |
870 rowCtr = 0; | |
871 chcColStart = chcColStart + 3 + cols + padding; | |
872 } | |
873 } | |
874 else { | |
875 chcColStart = chcColStart + padding + cols + 3; | |
876 // | |
877 } | |
878 | |
879 break; | |
880 | |
881 default: | |
882 for (cnt = 2; cnt < minLen; cnt++) { | |
883 pos++; | |
884 } | |
885 } | |
886 | |
887 majLen -= minLen; | |
888 } | |
889 while (majLen > 0); | |
890 } | |
891 catch (Exception exc) { | |
892 Log.w(TAG, " defineSelectionField :", exc); | |
893 exc.printStackTrace(); | |
894 } | |
895 } | |
896 | |
897 // negotiating commands | |
898 // private static final byte IAC = (byte)-1; // 255 FF | |
899 // private static final byte DONT = (byte)-2; //254 FE | |
900 // private static final byte DO = (byte)-3; //253 FD | |
901 // private static final byte WONT = (byte)-4; //252 FC | |
902 // private static final byte WILL = (byte)-5; //251 FB | |
903 // private static final byte SB = (byte)-6; //250 Sub Begin FA | |
904 // private static final byte SE = (byte)-16; //240 Sub End F0 | |
905 // private static final byte EOR = (byte)-17; //239 End of Record EF | |
906 // private static final byte TERMINAL_TYPE = (byte)24; // 18 | |
907 // private static final byte OPT_END_OF_RECORD = (byte)25; // 19 | |
908 // private static final byte TRANSMIT_BINARY = (byte)0; // 0 | |
909 // private static final byte QUAL_IS = (byte)0; // 0 | |
910 // private static final byte TIMING_MARK = (byte)6; // 6 | |
911 // private static final byte NEW_ENVIRONMENT = (byte)39; // 27 | |
912 // private static final byte IS = (byte)0; // 0 | |
913 // private static final byte SEND = (byte)1; // 1 | |
914 // private static final byte INFO = (byte)2; // 2 | |
915 // private static final byte VAR = (byte)0; // 0 | |
916 // private static final byte VALUE = (byte)1; // 1 | |
917 // private static final byte NEGOTIATE_ESC = (byte)2; // 2 | |
918 // private static final byte USERVAR = (byte)3; // 3 | |
919 | |
920 // miscellaneous | |
921 // private static final byte ESC = 0x04; // 04 | |
922 // private static final char char0 = 0; | |
923 | |
924 // private static final byte CMD_READ_IMMEDIATE_ALT = (byte)0x83; // 131 | |
925 | |
926 | |
927 } |