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