Mercurial > 510Connectbot
comparison app/src/main/java/org/tn5250j/framework/tn5250/ScreenField.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/ScreenField.java@29076621bab0 |
children | 8fa8e73e2f5c |
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.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 this.s = s; | |
32 } | |
33 | |
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 } | |
45 | |
46 protected ScreenField setField(int attr, int row, int col, int len, int ffw1, int ffw2, | |
47 int fcw1, int fcw2) { | |
48 // startRow = row; | |
49 // startCol = col; | |
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 } | |
62 | |
63 public int getAttr() { | |
64 return attr; | |
65 } | |
66 | |
67 public int getHighlightedAttr() { | |
68 return (fcw2 & 0x0f) | 0x20; | |
69 } | |
70 | |
71 public int getLength() { | |
72 return length; | |
73 } | |
74 | |
75 protected boolean setFFWs(int ffw1, int ffw2) { | |
76 this.ffw1 = ffw1; | |
77 this.ffw2 = ffw2; | |
78 int adj = getAdjustment(); | |
79 | |
80 if (adj > 0) { | |
81 checkCanSend = true; | |
82 | |
83 switch (adj) { | |
84 case 5: | |
85 case 6: | |
86 rightAdjd = false; | |
87 break; | |
88 | |
89 case 7: | |
90 mandatory = false; | |
91 break; | |
92 } | |
93 } | |
94 | |
95 mdt = (ffw1 & 0x8) == 0x8; | |
96 // if (mdt) | |
97 // s.masterMDT = true; | |
98 return mdt; | |
99 } | |
100 | |
101 | |
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 } | |
122 | |
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 } | |
134 | |
135 public int getFieldId() { | |
136 return fieldId; | |
137 } | |
138 | |
139 protected void setFieldId(int fi) { | |
140 fieldId = fi; | |
141 } | |
142 | |
143 public int getCursorRow() { | |
144 return cursorPos / s.getColumns(); | |
145 } | |
146 | |
147 public int getCursorCol() { | |
148 return cursorPos % s.getColumns(); | |
149 } | |
150 | |
151 protected void changePos(int i) { | |
152 cursorPos += i; | |
153 } | |
154 | |
155 protected String getText() { | |
156 StringBuffer text = new StringBuffer(); | |
157 getKeyPos(endPos); | |
158 int x = length; | |
159 text.setLength(x); | |
160 | |
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 } | |
176 | |
177 changePos(-1); | |
178 } | |
179 | |
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; | |
186 | |
187 do { | |
188 sf = sf.next; | |
189 text.append(sf.getText()); | |
190 } | |
191 while (!sf.isContinuedLast()); | |
192 | |
193 sf = null; | |
194 } | |
195 | |
196 return text.toString(); | |
197 } | |
198 | |
199 public String getString() { | |
200 StringBuffer text = new StringBuffer(); | |
201 getKeyPos(endPos); | |
202 int x = length; | |
203 text.setLength(x); | |
204 | |
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 } | |
223 | |
224 changePos(-1); | |
225 } | |
226 | |
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; | |
233 | |
234 do { | |
235 sf = sf.next; | |
236 text.append(sf.getString()); | |
237 } | |
238 while (!sf.isContinuedLast()); | |
239 | |
240 sf = null; | |
241 } | |
242 | |
243 return text.toString(); | |
244 } | |
245 | |
246 public void setFieldChar(char c) { | |
247 int x = length; | |
248 cursorPos = startPos; | |
249 | |
250 while (x-- > 0) { | |
251 s.planes.setChar(cursorPos, c); | |
252 changePos(1); | |
253 } | |
254 } | |
255 | |
256 public void setFieldChar(int lastPos, char c) { | |
257 int x = endPos - lastPos + 1; | |
258 cursorPos = lastPos; | |
259 | |
260 while (x-- > 0) { | |
261 s.planes.setChar(cursorPos, c); | |
262 s.setDirty(cursorPos); | |
263 changePos(1); | |
264 } | |
265 } | |
266 | |
267 protected void setRightAdjusted() { | |
268 rightAdjd = true; | |
269 } | |
270 | |
271 protected void setMandatoryEntered() { | |
272 mandatory = true; | |
273 } | |
274 | |
275 protected void resetMDT() { | |
276 mdt = false; | |
277 } | |
278 | |
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; | |
283 | |
284 while (sf.isContinued() && !sf.isContinuedFirst()) { | |
285 sf = sf.prev; | |
286 } | |
287 | |
288 sf.setMDT(); | |
289 sf = null; | |
290 } | |
291 else { | |
292 mdt = true; | |
293 } | |
294 } | |
295 | |
296 public boolean isBypassField() { | |
297 return (ffw1 & 0x20) == 0x20; | |
298 } | |
299 | |
300 public int getAdjustment() { | |
301 return (ffw2 & 0x7); | |
302 } | |
303 | |
304 // is field exit required | |
305 public boolean isFER() { | |
306 return (ffw2 & 0x40) == 0x40; | |
307 } | |
308 | |
309 // is field mandatory enter | |
310 public boolean isMandatoryEnter() { | |
311 return (ffw2 & 0x8) == 0x8; | |
312 } | |
313 | |
314 public boolean isToUpper() { | |
315 return (ffw2 & 0x20) == 0x20; | |
316 } | |
317 | |
318 // bits 5 - 7 | |
319 public int getFieldShift() { | |
320 return (ffw1 & 0x7); | |
321 } | |
322 | |
323 public boolean isHiglightedEntry() { | |
324 return (fcw1 == 0x89); | |
325 } | |
326 | |
327 public boolean isAutoEnter() { | |
328 return (ffw2 & 0x80) == 0x80; | |
329 } | |
330 | |
331 public boolean isSignedNumeric() { | |
332 return (getFieldShift() == 7); | |
333 } | |
334 | |
335 public boolean isRightToLeft() { | |
336 return (getFieldShift() == 0x04); | |
337 } | |
338 | |
339 public boolean isNumeric() { | |
340 return (getFieldShift() == 3); | |
341 } | |
342 | |
343 public boolean isDupEnabled() { | |
344 return (ffw1 & 0x10) == 0x10; | |
345 } | |
346 | |
347 public boolean isContinued() { | |
348 return (fcw1 & 0x86) == 0x86 && (fcw2 >= 1 && fcw2 <= 3) ; | |
349 } | |
350 | |
351 public boolean isContinuedFirst() { | |
352 return (fcw1 & 0x86) == 0x86 && (fcw2 == 1); | |
353 } | |
354 | |
355 public boolean isContinuedMiddle() { | |
356 return (fcw1 & 0x86) == 0x86 && (fcw2 == 3); | |
357 } | |
358 | |
359 public boolean isContinuedLast() { | |
360 return (fcw1 & 0x86) == 0x86 && (fcw2 == 2); | |
361 } | |
362 | |
363 protected boolean isCanSend() { | |
364 int adj = getAdjustment(); | |
365 | |
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) { | |
371 return true; | |
372 } | |
373 | |
374 // signed numeric fields need to be checked as well. | |
375 if (isSignedNumeric() && cursorPos < endPos - 1) { | |
376 return false; | |
377 } | |
378 | |
379 if (adj > 0) { | |
380 switch (adj) { | |
381 case 5: | |
382 case 6: | |
383 return rightAdjd; | |
384 | |
385 case 7: | |
386 return mandatory; | |
387 | |
388 default: | |
389 return true; | |
390 } | |
391 } | |
392 | |
393 return true; | |
394 } | |
395 | |
396 public boolean isSelectionField() { | |
397 return isSelectionField; | |
398 } | |
399 | |
400 public void setSelectionFieldInfo(int type, int index, int position) { | |
401 selectionFieldType = type; | |
402 selectionIndex = index; | |
403 selectionPos = position; | |
404 isSelectionField = true; | |
405 } | |
406 | |
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 } | |
413 | |
414 protected int getKeyPos(int pos) { | |
415 int y = pos - startPos(); | |
416 cursorPos = pos; | |
417 return y; | |
418 } | |
419 | |
420 public int getCurrentPos() { | |
421 return cursorPos; | |
422 } | |
423 | |
424 public boolean withinField(int pos) { | |
425 if (pos >= startPos && pos <= endPos) | |
426 return true; | |
427 | |
428 return false; | |
429 } | |
430 | |
431 public int startPos() { | |
432 return startPos; | |
433 } | |
434 | |
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 } | |
452 | |
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) { | |
468 cursorPos = startPos; | |
469 | |
470 if (isRightToLeft()) { | |
471 text = new StringBuilder(text).reverse().toString(); | |
472 } | |
473 | |
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(); | |
482 } | |
483 | |
484 @Override | |
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() + | |
496 ") is mandatoryenter = " + isMandatoryEnter() + | |
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 } | |
509 | |
510 public int getStartPos() { | |
511 return startPos; | |
512 } | |
513 | |
514 int startPos = 0; | |
515 int endPos = 0; | |
516 boolean mdt = false; | |
517 protected boolean checkCanSend; | |
518 protected boolean rightAdjd; | |
519 protected boolean mandatory; | |
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; | |
537 } |