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