3
|
1 /**
|
|
2 * Title: tn5250J
|
|
3 * Copyright: Copyright (c) 2001
|
|
4 * Company:
|
|
5 * @author Kenneth J. Pouncey
|
|
6 * @version 0.4
|
|
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 public class ScreenField {
|
|
29
|
|
30 protected ScreenField(Screen5250 s) {
|
|
31
|
|
32 this.s = s;
|
|
33
|
|
34 }
|
|
35
|
|
36 protected ScreenField setField(int attr, int len, int ffw1, int ffw2,
|
|
37 int fcw1, int fcw2) {
|
|
38
|
|
39 return setField(attr,
|
|
40 s.getCurrentRow() - 1,
|
|
41 s.getCurrentCol() - 1,
|
|
42 len,
|
|
43 ffw1,
|
|
44 ffw2,
|
|
45 fcw1,
|
|
46 fcw2);
|
|
47 }
|
|
48
|
|
49 protected ScreenField setField(int attr, int row, int col, int len, int ffw1, int ffw2,
|
|
50 int fcw1, int fcw2) {
|
|
51
|
|
52 // startRow = row;
|
|
53 // startCol = col;
|
|
54 startPos = (row * s.getColumns()) + col;
|
|
55 endPos = startPos + length -1;
|
|
56 cursorProg = 0;
|
|
57 fieldId = 0;
|
|
58 length = len;
|
|
59 endPos = startPos + length -1;
|
|
60 this.attr = attr;
|
|
61 setFFWs(ffw1,ffw2);
|
|
62 setFCWs(fcw1,fcw2);
|
|
63
|
|
64 next = null;
|
|
65 prev = null;
|
|
66
|
|
67 return this;
|
|
68
|
|
69 }
|
|
70
|
|
71 public int getAttr(){
|
|
72 return attr;
|
|
73 }
|
|
74
|
|
75 public int getHighlightedAttr(){
|
|
76 return (fcw2 & 0x0f) | 0x20;
|
|
77 }
|
|
78
|
|
79 public int getLength(){
|
|
80 return length;
|
|
81 }
|
|
82
|
|
83 protected boolean setFFWs(int ffw1, int ffw2) {
|
|
84
|
|
85 this.ffw1 = ffw1;
|
|
86 this.ffw2 = ffw2;
|
|
87
|
|
88 int adj = getAdjustment();
|
|
89
|
|
90 if (adj > 0) {
|
|
91 checkCanSend = true;
|
|
92
|
|
93 switch (adj) {
|
|
94
|
|
95 case 5:
|
|
96 case 6:
|
|
97 rightAdjd = false;
|
|
98 break;
|
|
99 case 7:
|
|
100 manditoried = false;
|
|
101 break;
|
|
102 }
|
|
103
|
|
104 }
|
|
105 mdt = (ffw1 & 0x8 ) == 0x8;
|
|
106 // if (mdt)
|
|
107 // s.masterMDT = true;
|
|
108 return mdt;
|
|
109 }
|
|
110
|
|
111
|
|
112 public int getFFW1(){
|
|
113 return ffw1;
|
|
114 }
|
|
115 public int getFFW2(){
|
|
116 return ffw2;
|
|
117 }
|
|
118
|
|
119 protected void setFCWs(int fcw1, int fcw2) {
|
|
120
|
|
121 this.fcw1 = fcw1;
|
|
122 this.fcw2 = fcw2;
|
|
123
|
|
124 // if ((fcw1 & 0x88) == 0x88) {
|
|
125 if (fcw1 == 0x88) {
|
|
126
|
|
127 cursorProg = fcw2;
|
|
128 }
|
|
129 }
|
|
130
|
|
131 public int getFCW1(){
|
|
132 return fcw1;
|
|
133 }
|
|
134
|
|
135 public int getFCW2(){
|
|
136 return fcw2;
|
|
137 }
|
|
138
|
|
139 public int getFieldLength(){
|
|
140 return length;
|
|
141 }
|
|
142
|
|
143 public int getCursorProgression() {
|
|
144 return cursorProg;
|
|
145 }
|
|
146
|
|
147 public int getFieldId() {
|
|
148 return fieldId;
|
|
149 }
|
|
150
|
|
151 protected void setFieldId(int fi) {
|
|
152 fieldId = fi;
|
|
153 }
|
|
154
|
|
155 public int getCursorRow() {
|
|
156
|
|
157 return cursorPos / s.getColumns();
|
|
158 }
|
|
159
|
|
160 public int getCursorCol() {
|
|
161
|
|
162 return cursorPos % s.getColumns();
|
|
163 }
|
|
164
|
|
165 protected void changePos(int i) {
|
|
166
|
|
167 cursorPos += i;
|
|
168
|
|
169 }
|
|
170
|
|
171 protected String getText() {
|
|
172
|
|
173
|
|
174 StringBuffer text = new StringBuffer();
|
|
175 getKeyPos(endPos);
|
|
176 int x = length;
|
|
177 text.setLength(x);
|
|
178 while (x-- > 0) {
|
|
179
|
|
180 // here we manipulate the unicode characters a little for attributes
|
|
181 // that are imbedded in input fields. We will offset them by unicode
|
|
182 // \uff00. All routines that process these fields will have to
|
|
183 // return them to their proper offsets.
|
|
184 // example:
|
|
185 // if we read an attribute byte of 32 for normal display the unicode
|
|
186 // character for this is \u0020 and the unicode character for
|
|
187 // a space is also \u0020 thus the offset.
|
|
188 if (s.planes.isAttributePlace(cursorPos)) {
|
|
189 text.setCharAt(x,(char)('\uff00' + s.planes.getCharAttr(cursorPos)));
|
|
190 }
|
|
191 else {
|
|
192 text.setCharAt(x,s.planes.getChar(cursorPos));
|
|
193 }
|
|
194 changePos(-1);
|
|
195
|
|
196 }
|
|
197
|
|
198 // Since only the mdt of the first continued field is set we will get
|
|
199 // the text of the next continued field if we are dealing with continued
|
|
200 // fields. See routine setMDT for the whys of this. This is only
|
|
201 // executed if this is the first field of a continued field.
|
|
202 if (isContinued() && isContinuedFirst()) {
|
|
203 ScreenField sf = this;
|
|
204 do {
|
|
205 sf = sf.next;
|
|
206 text.append(sf.getText());
|
|
207 }
|
|
208 while (!sf.isContinuedLast());
|
|
209
|
|
210 sf = null;
|
|
211 }
|
|
212
|
|
213 return text.toString();
|
|
214
|
|
215 }
|
|
216
|
|
217 public String getString() {
|
|
218
|
|
219
|
|
220 StringBuffer text = new StringBuffer();
|
|
221 getKeyPos(endPos);
|
|
222 int x = length;
|
|
223 text.setLength(x);
|
|
224 while (x-- > 0) {
|
|
225
|
|
226 // here we manipulate the unicode characters a little for attributes
|
|
227 // that are imbedded in input fields. We will offset them by unicode
|
|
228 // \uff00. All routines that process these fields will have to
|
|
229 // return them to their proper offsets.
|
|
230 // example:
|
|
231 // if we read an attribute byte of 32 for normal display the unicode
|
|
232 // character for this is \u0020 and the unicode character for
|
|
233 // a space is also \u0020 thus the offset.
|
|
234 if (s.planes.isAttributePlace(cursorPos)) {
|
|
235 text.setCharAt(x,(char)('\uff00' + s.planes.getCharAttr(cursorPos)));
|
|
236 }
|
|
237 else {
|
|
238 if (s.planes.getChar(cursorPos) < ' ')
|
|
239 text.setCharAt(x,' ');
|
|
240 else
|
|
241 text.setCharAt(x,s.planes.getChar(cursorPos));
|
|
242 }
|
|
243 changePos(-1);
|
|
244
|
|
245 }
|
|
246
|
|
247 // Since only the mdt of the first continued field is set we will get
|
|
248 // the text of the next continued field if we are dealing with continued
|
|
249 // fields. See routine setMDT for the whys of this. This is only
|
|
250 // executed if this is the first field of a continued field.
|
|
251 if (isContinued() && isContinuedFirst()) {
|
|
252 ScreenField sf = this;
|
|
253 do {
|
|
254 sf = sf.next;
|
|
255 text.append(sf.getString());
|
|
256 }
|
|
257 while (!sf.isContinuedLast());
|
|
258
|
|
259 sf = null;
|
|
260 }
|
|
261
|
|
262 return text.toString();
|
|
263
|
|
264 }
|
|
265
|
|
266 public void setFieldChar(char c) {
|
|
267
|
|
268 int x = length;
|
|
269 cursorPos = startPos;
|
|
270 while (x-- > 0) {
|
|
271 s.planes.setChar(cursorPos,c);
|
|
272 changePos(1);
|
|
273 }
|
|
274
|
|
275 }
|
|
276
|
|
277 public void setFieldChar(int lastPos, char c) {
|
|
278
|
|
279 int x = endPos - lastPos + 1;
|
|
280 cursorPos = lastPos;
|
|
281 while (x-- > 0) {
|
|
282 s.planes.setChar(cursorPos,c);
|
|
283 s.setDirty(cursorPos);
|
|
284 changePos(1);
|
|
285 }
|
|
286 }
|
|
287
|
|
288 protected void setRightAdjusted() {
|
|
289 rightAdjd = true;
|
|
290 }
|
|
291
|
|
292 protected void setManditoryEntered() {
|
|
293
|
|
294 manditoried = true;
|
|
295 }
|
|
296
|
|
297 protected void resetMDT() {
|
|
298 mdt = false;
|
|
299
|
|
300 }
|
|
301
|
|
302 protected void setMDT() {
|
|
303
|
|
304 // get the first field of a continued edit field if it is continued
|
|
305 if (isContinued() && !isContinuedFirst()) {
|
|
306 ScreenField sf = prev;
|
|
307 while (sf.isContinued() && !sf.isContinuedFirst()) {
|
|
308
|
|
309 sf = sf.prev;
|
|
310
|
|
311 }
|
|
312 sf.setMDT();
|
|
313 sf = null;
|
|
314 }
|
|
315 else {
|
|
316 mdt = true;
|
|
317 }
|
|
318
|
|
319 }
|
|
320
|
|
321 public boolean isBypassField() {
|
|
322
|
|
323 return (ffw1 & 0x20) == 0x20;
|
|
324
|
|
325 }
|
|
326
|
|
327 public int getAdjustment () {
|
|
328
|
|
329 return (ffw2 & 0x7);
|
|
330 }
|
|
331
|
|
332 // is field exit required
|
|
333 public boolean isFER () {
|
|
334
|
|
335 return (ffw2 & 0x40) == 0x40;
|
|
336 }
|
|
337
|
|
338 // is field manditory enter
|
|
339 public boolean isMandatoryEnter() {
|
|
340
|
|
341 return (ffw2 & 0x8) == 0x8;
|
|
342
|
|
343 }
|
|
344
|
|
345 public boolean isToUpper() {
|
|
346
|
|
347 return (ffw2 & 0x20) == 0x20;
|
|
348
|
|
349 }
|
|
350
|
|
351 // bits 5 - 7
|
|
352 public int getFieldShift () {
|
|
353
|
|
354 return (ffw1 & 0x7);
|
|
355
|
|
356 }
|
|
357
|
|
358 public boolean isHiglightedEntry() {
|
|
359
|
|
360 return (fcw1 == 0x89);
|
|
361
|
|
362 }
|
|
363
|
|
364 public boolean isAutoEnter() {
|
|
365
|
|
366 return (ffw2 & 0x80) == 0x80;
|
|
367
|
|
368 }
|
|
369
|
|
370 public boolean isSignedNumeric () {
|
|
371
|
|
372 return (getFieldShift() == 7);
|
|
373
|
|
374 }
|
|
375
|
|
376 public boolean isRightToLeft() {
|
|
377 return (getFieldShift() == 0x04);
|
|
378 }
|
|
379
|
|
380 public boolean isNumeric () {
|
|
381
|
|
382 return (getFieldShift() == 3);
|
|
383
|
|
384 }
|
|
385
|
|
386 public boolean isDupEnabled() {
|
|
387
|
|
388 return (ffw1 & 0x10) == 0x10;
|
|
389
|
|
390 }
|
|
391
|
|
392 public boolean isContinued() {
|
|
393
|
|
394 return (fcw1 & 0x86) == 0x86 && (fcw2 >= 1 && fcw2 <= 3) ;
|
|
395
|
|
396 }
|
|
397
|
|
398 public boolean isContinuedFirst() {
|
|
399
|
|
400 return (fcw1 & 0x86) == 0x86 && (fcw2 == 1);
|
|
401
|
|
402 }
|
|
403
|
|
404 public boolean isContinuedMiddle() {
|
|
405
|
|
406 return (fcw1 & 0x86) == 0x86 && (fcw2 == 3);
|
|
407
|
|
408 }
|
|
409
|
|
410 public boolean isContinuedLast() {
|
|
411
|
|
412 return (fcw1 & 0x86) == 0x86 && (fcw2 == 2);
|
|
413
|
|
414 }
|
|
415
|
|
416 protected boolean isCanSend() {
|
|
417
|
|
418 int adj = getAdjustment();
|
|
419
|
|
420 // here we need to check the Field Exit Required value first before checking
|
|
421 // the adjustments. If the last character has been entered and we are
|
|
422 // now setting past the last position then we are allowed to process the
|
|
423 // the field without continuing.
|
|
424 if (isFER() && cursorPos > endPos) {
|
|
425 return true;
|
|
426 }
|
|
427
|
|
428 // signed numeric fields need to be checked as well.
|
|
429 if (isSignedNumeric() && cursorPos < endPos - 1) {
|
|
430 return false;
|
|
431 }
|
|
432
|
|
433 if (adj > 0) {
|
|
434
|
|
435 switch (adj) {
|
|
436
|
|
437 case 5:
|
|
438 case 6:
|
|
439 return rightAdjd;
|
|
440 case 7:
|
|
441 return manditoried;
|
|
442 default:
|
|
443 return true;
|
|
444 }
|
|
445
|
|
446 }
|
|
447 return true;
|
|
448 }
|
|
449
|
|
450 public boolean isSelectionField() {
|
|
451
|
|
452 return isSelectionField;
|
|
453
|
|
454 }
|
|
455
|
|
456 public void setSelectionFieldInfo(int type, int index, int position) {
|
|
457
|
|
458 selectionFieldType = type;
|
|
459 selectionIndex = index;
|
|
460 selectionPos = position;
|
|
461 isSelectionField = true;
|
|
462
|
|
463 }
|
|
464
|
|
465 protected int getKeyPos(int row1, int col1) {
|
|
466
|
|
467 int x = ((row1 * s.getColumns()) + col1);
|
|
468 int y = x - startPos();
|
|
469 cursorPos = x;
|
|
470
|
|
471 return y;
|
|
472 }
|
|
473
|
|
474 protected int getKeyPos(int pos) {
|
|
475
|
|
476 int y = pos - startPos();
|
|
477 cursorPos = pos;
|
|
478
|
|
479 return y;
|
|
480 }
|
|
481
|
|
482 public int getCurrentPos() {
|
|
483
|
|
484 return cursorPos;
|
|
485 }
|
|
486
|
|
487 public boolean withinField (int pos) {
|
|
488
|
|
489 if (pos >= startPos && pos <= endPos)
|
|
490 return true;
|
|
491 return false;
|
|
492
|
|
493 }
|
|
494
|
|
495 public int startPos() {
|
|
496
|
|
497 return startPos;
|
|
498 }
|
|
499
|
|
500 /**
|
|
501 * Get the starting row of the field. Offset is 0 so row 6 returned
|
|
502 * is row 7 mapped to screen
|
|
503 * @return int starting row of the field offset 0
|
|
504 */
|
|
505 public int startRow() {
|
|
506
|
|
507 return startPos / s.getColumns();
|
|
508
|
|
509 }
|
|
510
|
|
511 /**
|
|
512 * Get the starting column of the field. Offset is 0 so column 6 returned
|
|
513 * is column 7 mapped to screen
|
|
514 * @return int starting column of the field offset 0
|
|
515 */
|
|
516 public int startCol() {
|
|
517
|
|
518 return startPos % s.getColumns();
|
|
519
|
|
520 }
|
|
521
|
|
522 public int endPos() {
|
|
523
|
|
524 return endPos;
|
|
525
|
|
526 }
|
|
527
|
|
528 /**
|
|
529 * Sets the field's text plane to the specified string. If the string is
|
|
530 * shorter than the length of the field, the rest of the field is cleared.
|
|
531 * If the string is longer than the field, the text is truncated. A subsequent
|
|
532 * call to getText on this field will not show the changed text. To see the
|
|
533 * changed text, do a refresh on the iOhioFields collection and retrieve the
|
|
534 * refreshed field object.
|
|
535 *
|
|
536 * @param text - The text to be placed in the field's text plane.
|
|
537 */
|
|
538 public void setString(String text) {
|
|
539
|
|
540 int y = length;
|
|
541 cursorPos = startPos;
|
|
542 int len = text.length();
|
|
543 char[] c = text.toCharArray();
|
|
544 char tc = ' ';
|
|
545
|
|
546 for (int x = 0; x < y; x++) {
|
|
547 tc = ' ';
|
|
548 if (x < len) {
|
|
549 tc = c[x];
|
|
550 }
|
|
551 s.getPlanes().setChar(cursorPos,tc);
|
|
552 changePos(1);
|
|
553 }
|
|
554 setMDT();
|
|
555 s.getScreenFields().setMasterMDT();
|
|
556 }
|
|
557
|
|
558 public String toString() {
|
|
559 int fcw = (fcw1 & 0xff) << 8 | fcw2 & 0xff;
|
|
560 return "startRow = " + startRow() + " startCol = " + startCol() +
|
|
561 " length = " + length + " ffw1 = (0x" + Integer.toHexString(ffw1) +
|
|
562 ") ffw2 = (0x" + Integer.toHexString(ffw2) +
|
|
563 ") fcw1 = (0x" + Integer.toHexString(fcw1) +
|
|
564 ") fcw2 = (0x" + Integer.toHexString(fcw2) +
|
|
565 ") fcw = (" + Integer.toBinaryString(fcw) +
|
|
566 ") fcw hex = (0x" + Integer.toHexString(fcw) +
|
|
567 ") is bypass field = " + isBypassField() +
|
|
568 ") is autoenter = " + isAutoEnter() +
|
|
569 ") is manditoryenter = " + isMandatoryEnter() +
|
|
570 ") is field exit required = " + isFER() +
|
|
571 ") is Numeric = " + isNumeric() +
|
|
572 ") is Signed Numeric = " + isSignedNumeric() +
|
|
573 ") is cursor progression = " + (fcw1 == 0x88) +
|
|
574 ") next progression field = " + fcw2 +
|
|
575 ") field id " + fieldId +
|
|
576 " continued edit field = " + isContinued() +
|
|
577 " first continued edit field = " + isContinuedFirst() +
|
|
578 " middle continued edit field = " + isContinuedMiddle() +
|
|
579 " last continued edit field = " + isContinuedLast() +
|
|
580 " mdt = " + mdt;
|
|
581 }
|
|
582
|
|
583 int startPos = 0;
|
|
584 int endPos = 0;
|
|
585 boolean mdt = false;
|
|
586 protected boolean checkCanSend;
|
|
587 protected boolean rightAdjd;
|
|
588 protected boolean manditoried;
|
|
589 boolean canSend = true;
|
|
590 int attr = 0;
|
|
591 int length = 0;
|
|
592 int ffw1 = 0;
|
|
593 int ffw2 = 0;
|
|
594 int fcw1 = 0;
|
|
595 int fcw2 = 0;
|
|
596 int cursorPos = 0;
|
|
597 Screen5250 s;
|
|
598 int cursorProg = 0;
|
|
599 int fieldId = 0;
|
|
600 ScreenField next = null;
|
|
601 ScreenField prev = null;
|
|
602 boolean isSelectionField;
|
|
603 int selectionFieldType;
|
|
604 int selectionIndex;
|
|
605 int selectionPos;
|
|
606 } |