Mercurial > 510Connectbot
comparison src/org/tn5250j/framework/tn5250/ScreenFields.java @ 112:77ac18bc1b2f
cleanup java formatting
author | Carl Byington <carl@five-ten-sg.com> |
---|---|
date | Wed, 18 Jun 2014 13:03:01 -0700 |
parents | 294435151b0c |
children |
comparison
equal
deleted
inserted
replaced
111:6a0ad4d384ea | 112:77ac18bc1b2f |
---|---|
33 | 33 |
34 import org.tn5250j.encoding.ICodePage; | 34 import org.tn5250j.encoding.ICodePage; |
35 | 35 |
36 public class ScreenFields { | 36 public class ScreenFields { |
37 | 37 |
38 private ScreenField[] screenFields; | 38 private ScreenField[] screenFields; |
39 private ScreenField currentField; | 39 private ScreenField currentField; |
40 private ScreenField saveCurrent; | 40 private ScreenField saveCurrent; |
41 private int sizeFields; | 41 private int sizeFields; |
42 private boolean cpfExists; | 42 private boolean cpfExists; |
43 private int nextField; | 43 private int nextField; |
44 private int fieldIds; | 44 private int fieldIds; |
45 private Screen5250 screen; | 45 private Screen5250 screen; |
46 private boolean masterMDT; | 46 private boolean masterMDT; |
47 protected boolean currentModified; | 47 protected boolean currentModified; |
48 | 48 |
49 public ScreenFields(Screen5250 s) { | 49 public ScreenFields(Screen5250 s) { |
50 | 50 screen = s; |
51 screen = s; | 51 screenFields = new ScreenField[256]; |
52 screenFields = new ScreenField[256]; | 52 } |
53 } | 53 |
54 | 54 protected void clearFFT() { |
55 protected void clearFFT() { | 55 sizeFields = nextField = fieldIds = 0; |
56 | 56 cpfExists = false; // clear the cursor progression fields flag |
57 sizeFields = nextField = fieldIds = 0; | 57 currentField = null; |
58 cpfExists = false; // clear the cursor progression fields flag | 58 masterMDT = false; |
59 currentField = null; | 59 } |
60 masterMDT = false; | 60 |
61 | 61 protected boolean existsAtPos(int lastPos) { |
62 } | 62 ScreenField sf = null; |
63 | 63 |
64 protected boolean existsAtPos(int lastPos) { | 64 // from 14.6.12 for Start of Field Order 5940 function manual |
65 | 65 // examine the format table for an entry that begins at the current |
66 ScreenField sf = null; | 66 // starting address plus 1. |
67 | 67 for (int x = 0; x < sizeFields; x++) { |
68 // from 14.6.12 for Start of Field Order 5940 function manual | 68 sf = screenFields[x]; |
69 // examine the format table for an entry that begins at the current | 69 |
70 // starting address plus 1. | 70 if (lastPos == sf.startPos()) { |
71 for (int x = 0;x < sizeFields; x++) { | 71 currentField = sf; |
72 sf = screenFields[x]; | 72 currentModified = false; |
73 | 73 return true; |
74 if (lastPos == sf.startPos()) { | 74 } |
75 } | |
76 | |
77 return false; | |
78 } | |
79 | |
80 public boolean isMasterMDT() { | |
81 return masterMDT; | |
82 } | |
83 | |
84 protected void setMasterMDT() { | |
85 masterMDT = true; | |
86 } | |
87 | |
88 public boolean isCurrentField() { | |
89 return currentField == null; | |
90 } | |
91 | |
92 public boolean isCurrentFieldFER() { | |
93 return currentField.isFER(); | |
94 } | |
95 | |
96 public boolean isCurrentFieldDupEnabled() { | |
97 return currentField.isDupEnabled(); | |
98 } | |
99 | |
100 public boolean isCurrentFieldToUpper() { | |
101 return currentField.isToUpper(); | |
102 } | |
103 | |
104 public boolean isCurrentFieldBypassField() { | |
105 return currentField.isBypassField(); | |
106 } | |
107 | |
108 public boolean isCurrentFieldHighlightedEntry() { | |
109 if (currentField != null) | |
110 return currentField.isHiglightedEntry(); | |
111 else | |
112 return false; | |
113 } | |
114 | |
115 public boolean isCurrentFieldAutoEnter() { | |
116 return currentField.isAutoEnter(); | |
117 } | |
118 | |
119 public boolean withinCurrentField(int pos) { | |
120 return currentField.withinField(pos); | |
121 } | |
122 | |
123 public boolean isCurrentFieldContinued() { | |
124 return currentField.isContinued(); | |
125 } | |
126 | |
127 public boolean isCurrentFieldContinuedFirst() { | |
128 return currentField.isContinuedFirst(); | |
129 } | |
130 | |
131 public boolean isCurrentFieldContinuedMiddle() { | |
132 return currentField.isContinuedMiddle(); | |
133 } | |
134 | |
135 public boolean isCurrentFieldContinuedLast() { | |
136 return currentField.isContinuedLast(); | |
137 } | |
138 | |
139 public boolean isCurrentFieldModified() { | |
140 return currentModified; | |
141 } | |
142 | |
143 /** | |
144 * This routine is used to check if we can send the Aid key to the host | |
145 * | |
146 * Taken from Section 16.2.1.2 Enter/Rec Adv Key | |
147 * | |
148 * In the normal unlocked state, when the workstation operator presses the | |
149 * Enter/Rec Adv key: | |
150 * | |
151 * 1. The 5494 checks for the completion of mandatory-fill, self-check, and | |
152 * right-adjust fields when in an active field. (An active field is one in | |
153 * which the workstation operator has begun entering data.) If the | |
154 * requirements of the field have not been satisfied, an error occurs. | |
155 * | |
156 * @return | |
157 * | |
158 */ | |
159 public boolean isCanSendAid() { | |
160 // We also have to check if we are still in the field. | |
161 if (currentField != null && | |
162 (currentField.getAdjustment() > 0 || currentField.isSignedNumeric()) | |
163 && currentModified && isInField() | |
164 && !currentField.isCanSend()) | |
165 return false; | |
166 else | |
167 return true; | |
168 } | |
169 | |
170 protected void saveCurrentField() { | |
171 saveCurrent = currentField; | |
172 } | |
173 | |
174 protected void restoreCurrentField() { | |
175 currentField = saveCurrent; | |
176 } | |
177 | |
178 protected void setCurrentField(ScreenField sf) { | |
179 currentField = sf; | |
180 } | |
181 | |
182 protected void setCurrentFieldMDT() { | |
183 currentField.setMDT(); | |
184 currentModified = true; | |
185 masterMDT = true; | |
186 } | |
187 | |
188 protected void setCurrentFieldFFWs(int ffw1, int ffw2) { | |
189 masterMDT = currentField.setFFWs(ffw1, ffw2); | |
190 } | |
191 | |
192 | |
193 protected ScreenField setField(int attr, int row, int col, int len, int ffw1, | |
194 int ffw2, int fcw1, int fcw2) { | |
195 ScreenField sf = null; | |
196 screenFields[nextField] = new ScreenField(screen); | |
197 screenFields[nextField].setField(attr, row, col, len, ffw1, ffw2, fcw1, fcw2); | |
198 sf = screenFields[nextField++]; | |
199 sizeFields++; | |
200 // set the field id if it is not a bypass field | |
201 // this is used for cursor progression | |
202 // changed this because of problems not allocating field id's for | |
203 // all fields. kjp 2002/10/21 | |
204 // if (!sf.isBypassField()) | |
205 sf.setFieldId(++fieldIds); | |
206 | |
207 // check if the cursor progression field flag should be set. | |
208 // if ((fcw1 & 0x88) == 0x88) | |
209 if (fcw1 == 0x88) | |
210 cpfExists = true; | |
211 | |
212 if (currentField != null) { | |
213 currentField.next = sf; | |
214 sf.prev = currentField; | |
215 } | |
216 | |
217 currentField = sf; | |
218 | |
219 // check if the Modified Data Tag was set while creating the field | |
220 if (!masterMDT) | |
221 masterMDT = currentField.mdt; | |
222 | |
223 currentModified = false; | |
224 return currentField; | |
225 } | |
226 | |
227 public ScreenField getField(int index) { | |
228 return screenFields[index]; | |
229 } | |
230 | |
231 public ScreenField getCurrentField() { | |
232 return currentField; | |
233 } | |
234 | |
235 public int getCurrentFieldPos() { | |
236 return currentField.getCurrentPos(); | |
237 } | |
238 | |
239 protected int getCurrentFieldShift() { | |
240 return currentField.getFieldShift(); | |
241 } | |
242 | |
243 public String getCurrentFieldText() { | |
244 return currentField.getText(); | |
245 } | |
246 | |
247 public int getCurrentFieldHighlightedAttr() { | |
248 return currentField.getHighlightedAttr(); | |
249 } | |
250 | |
251 public int getSize() { | |
252 return sizeFields; | |
253 } | |
254 | |
255 public int getFieldCount() { | |
256 return sizeFields; | |
257 } | |
258 | |
259 protected boolean isInField(int pos) { | |
260 return isInField(pos, true); | |
261 } | |
262 | |
263 protected boolean isInField() { | |
264 return isInField(screen.getLastPos(), true); | |
265 } | |
266 | |
267 protected boolean isInField(int pos, boolean chgToField) { | |
268 ScreenField sf; | |
269 | |
270 for (int x = 0; x < sizeFields; x++) { | |
271 sf = screenFields[x]; | |
272 | |
273 if (sf.withinField(pos)) { | |
274 if (chgToField) { | |
275 if (!currentField.equals(sf)) | |
276 currentModified = false; | |
277 | |
278 currentField = sf; | |
279 } | |
280 | |
281 return true; | |
282 } | |
283 } | |
284 | |
285 return false; | |
286 } | |
287 | |
288 /** | |
289 * Searches the collection for the target string and returns the iOhioField | |
290 * object containing that string. The string must be totally contained | |
291 * within the field to be considered a match. | |
292 * | |
293 * @param targetString The target string. | |
294 * @param startPos The row and column where to start the search. The position | |
295 * is inclusive (for example, row 1, col 1 means that | |
296 * position 1,1 will be used as the starting location and | |
297 * 1,1 will be included in the search). | |
298 * @param length The length from startPos to include in the search. | |
299 * @param dir An OHIO_DIRECTION value: | |
300 * | |
301 * <table BORDER COLS=3 WIDTH="50%" > | |
302 * <tr><th>Constant </th><th>Value</th> | |
303 * <th>Description</th></tr> | |
304 * <tr><td>OS_OHIO_DIRECTION_FORWARD </td><td>0</td> | |
305 * <td>Forward (beginning towards end)</td></tr> | |
306 * <tr><td>OS_OHIO_DIRECTION_BACKWARD </td><td>1</td> | |
307 * <td>Backward (end towards beginning)</td></tr> | |
308 * </table> | |
309 * Constant Value Description | |
310 * ignoreCase - Indicates whether the search is case sensitive. | |
311 * True means that case will be ignored. False means the search will | |
312 * be case sensitive. | |
313 * @return If found, an iOhioField object containing the target string. If | |
314 * not found, returns a null. | |
315 */ | |
316 public ScreenField findByString(String targetString, | |
317 int startPos, | |
318 int length, | |
319 int dir, | |
320 boolean ignoreCase) { | |
321 // first lets check if the string exists in the screen space | |
322 // iOhioPosition pos = screen.findString(targetString, startPos, length, | |
323 // dir, ignoreCase); | |
324 // if it does exist then lets search the fields by the position that | |
325 // was found and return the results of that search. | |
326 // if (pos != null) { | |
327 return findByPosition(startPos); | |
328 // } | |
329 //return null; | |
330 } | |
331 | |
332 /** | |
333 * Searches the collection for the target position and returns the ScreenField | |
334 * object containing that position. | |
335 * | |
336 * @param targetPosition The target row and column expressed as a linear | |
337 * position within the presentation space. | |
338 * | |
339 * @return If found, a ScreenField object containing the target position. | |
340 * If not found, returns a null. | |
341 */ | |
342 public ScreenField findByPosition(int targetPosition) { | |
343 ScreenField sf = null; | |
344 | |
345 for (int x = 0; x < sizeFields; x++) { | |
346 sf = screenFields[x]; | |
347 | |
348 if (sf.withinField(targetPosition)) { | |
349 return sf; | |
350 } | |
351 } | |
352 | |
353 return null; | |
354 } | |
355 | |
356 /** | |
357 * Searches the collection for the target position and returns the ScreenField | |
358 * object containing that position. | |
359 * | |
360 * @param row The beginning row to start search with in the presentation space. | |
361 * @param col The beginning column to start search with in the presentation space. | |
362 * | |
363 * @return If found, a ScreenField object containing the target position. | |
364 * If not found, returns a null. | |
365 */ | |
366 public ScreenField findByPosition(int row, int col) { | |
367 return findByPosition(screen.getPos(row, col)); | |
368 } | |
369 | |
370 public ScreenField[] getFields() { | |
371 ScreenField[] fields = new ScreenField[sizeFields]; | |
372 | |
373 for (int x = 0; x < sizeFields; x++) { | |
374 fields[x] = screenFields[x]; | |
375 } | |
376 | |
377 return fields; | |
378 } | |
379 | |
380 public ScreenField getFirstInputField() { | |
381 if (sizeFields <= 0) | |
382 return null; | |
383 | |
384 int f = 0; | |
385 ScreenField sf = screenFields[f]; | |
386 | |
387 while (sf.isBypassField() && f++ < sizeFields) { | |
388 sf = screenFields[f]; | |
389 } | |
390 | |
391 if (sf.isBypassField()) | |
392 return null; | |
393 else | |
394 return sf; | |
395 } | |
396 | |
397 public void gotoFieldNext() { | |
398 // sanity check - we were getting null pointers after a restore of screen | |
399 // and cursor was not positioned on a field when returned | |
400 // *** Note *** to myself | |
401 // maybe this is fixed I will have to check this some time | |
402 int lastPos = screen.getLastPos(); | |
403 | |
404 if (currentField == null && (sizeFields != 0) && !isInField(lastPos, true)) { | |
405 int pos = lastPos; | |
406 screen.setCursorOff(); | |
407 screen.advancePos(); | |
408 lastPos = screen.getLastPos(); | |
409 | |
410 while (!isInField() && pos != lastPos) { | |
411 screen.advancePos(); | |
412 } | |
413 | |
414 screen.setCursorOn(); | |
415 } | |
416 | |
417 // if we are still null do nothing | |
418 if (currentField == null) | |
419 return; | |
420 | |
421 ScreenField sf = currentField; | |
422 | |
423 if (!sf.withinField(lastPos)) { | |
424 screen.setCursorOff(); | |
425 | |
426 if (sizeFields > 0) { | |
427 // lets get the current position so we can test if we have looped | |
428 // the screen and not found a valid field. | |
429 int pos = lastPos; | |
430 int savPos = lastPos; | |
431 boolean done = false; | |
432 | |
433 do { | |
434 screen.advancePos(); | |
435 lastPos = screen.getLastPos(); | |
436 | |
437 if (isInField(lastPos) | |
438 || pos == lastPos) { | |
439 if (!currentField.isBypassField()) { | |
440 screen.gotoField(currentField); | |
441 done = true; | |
442 } | |
443 } | |
444 } | |
445 while (!done && lastPos != savPos); | |
446 } | |
447 | |
448 currentModified = false; | |
449 screen.setCursorOn(); | |
450 } | |
451 else { | |
452 if (!cpfExists) { | |
453 do { | |
454 sf = sf.next; | |
455 } | |
456 while (sf != null && sf.isBypassField()); | |
457 } | |
458 else { | |
459 int f = 0; | |
460 int cp = sf.getCursorProgression(); | |
461 | |
462 if (cp == 0) { | |
463 do { | |
464 sf = sf.next; | |
465 } | |
466 while (sf != null && sf.isBypassField()); | |
467 } | |
468 else { | |
469 ScreenField sf1 = null; | |
470 boolean found = false; | |
471 | |
472 while (!found && f < sizeFields) { | |
473 sf1 = screenFields[f++]; | |
474 | |
475 if (sf1.getFieldId() == cp) | |
476 found = true; | |
477 } | |
478 | |
479 if (found) | |
480 sf = sf1; | |
481 else { | |
482 do { | |
483 sf = sf.next; | |
484 } | |
485 while (sf != null && sf.isBypassField()); | |
486 } | |
487 | |
488 sf1 = null; | |
489 } | |
490 } | |
491 | |
492 if (sf == null) | |
493 screen.gotoField(1); | |
494 else { | |
495 currentField = sf; | |
496 screen.gotoField(currentField); | |
497 } | |
498 | |
499 currentModified = false; | |
500 } | |
501 } | |
502 | |
503 public void gotoFieldPrev() { | |
504 ScreenField sf = currentField; | |
505 int lastPos = screen.getLastPos(); | |
506 | |
507 if (!sf.withinField(lastPos)) { | |
508 screen.setCursorOff(); | |
509 | |
510 if (sizeFields > 0) { | |
511 // lets get the current position so we can test if we have looped | |
512 // the screen and not found a valid field. | |
513 int pos = lastPos; | |
514 int savPos = lastPos; | |
515 boolean done = false; | |
516 | |
517 do { | |
518 screen.changePos(-1); | |
519 lastPos = screen.getLastPos(); | |
520 | |
521 if (isInField(lastPos) | |
522 || (pos == lastPos)) { | |
523 if (!currentField.isBypassField()) { | |
524 screen.gotoField(currentField); | |
525 done = true; | |
526 } | |
527 } | |
528 } | |
529 while (!done && lastPos != savPos); | |
530 } | |
531 | |
532 screen.setCursorOn(); | |
533 } | |
534 else { | |
535 if (sf.startPos() == lastPos) { | |
536 if (!cpfExists) { | |
537 do { | |
538 sf = sf.prev; | |
539 } | |
540 while (sf != null && sf.isBypassField()); | |
541 } | |
542 else { | |
543 int f = 0; | |
544 int cp = sf.getFieldId(); | |
545 ScreenField sf1 = null; | |
546 boolean found = false; | |
547 | |
548 while (!found && f < sizeFields) { | |
549 sf1 = screenFields[f++]; | |
550 | |
551 if (sf1.getCursorProgression() == cp) | |
552 found = true; | |
553 } | |
554 | |
555 if (found) | |
556 sf = sf1; | |
557 else { | |
558 do { | |
559 sf = sf.prev; | |
560 } | |
561 while (sf != null && sf.isBypassField()); | |
562 } | |
563 | |
564 sf1 = null; | |
565 } | |
566 } | |
567 | |
568 if (sf == null) { | |
569 int size = sizeFields; | |
570 sf = screenFields[size - 1]; | |
571 | |
572 while (sf.isBypassField() && size-- > 0) { | |
573 sf = screenFields[size]; | |
574 } | |
575 } | |
576 | |
75 currentField = sf; | 577 currentField = sf; |
76 currentModified = false; | 578 currentModified = false; |
77 return true; | |
78 } | |
79 | |
80 } | |
81 | |
82 return false; | |
83 } | |
84 | |
85 public boolean isMasterMDT() { | |
86 return masterMDT; | |
87 } | |
88 | |
89 protected void setMasterMDT() { | |
90 masterMDT = true; | |
91 } | |
92 | |
93 public boolean isCurrentField() { | |
94 return currentField == null; | |
95 } | |
96 | |
97 public boolean isCurrentFieldFER() { | |
98 return currentField.isFER(); | |
99 } | |
100 | |
101 public boolean isCurrentFieldDupEnabled() { | |
102 return currentField.isDupEnabled(); | |
103 } | |
104 | |
105 public boolean isCurrentFieldToUpper() { | |
106 return currentField.isToUpper(); | |
107 } | |
108 | |
109 public boolean isCurrentFieldBypassField() { | |
110 return currentField.isBypassField(); | |
111 } | |
112 | |
113 public boolean isCurrentFieldHighlightedEntry() { | |
114 if (currentField != null) | |
115 return currentField.isHiglightedEntry(); | |
116 else | |
117 return false; | |
118 } | |
119 | |
120 public boolean isCurrentFieldAutoEnter() { | |
121 return currentField.isAutoEnter(); | |
122 } | |
123 | |
124 public boolean withinCurrentField(int pos) { | |
125 return currentField.withinField(pos); | |
126 } | |
127 | |
128 public boolean isCurrentFieldContinued() { | |
129 return currentField.isContinued(); | |
130 } | |
131 | |
132 public boolean isCurrentFieldContinuedFirst() { | |
133 return currentField.isContinuedFirst(); | |
134 } | |
135 | |
136 public boolean isCurrentFieldContinuedMiddle() { | |
137 return currentField.isContinuedMiddle(); | |
138 } | |
139 | |
140 public boolean isCurrentFieldContinuedLast() { | |
141 return currentField.isContinuedLast(); | |
142 } | |
143 | |
144 public boolean isCurrentFieldModified() { | |
145 return currentModified; | |
146 } | |
147 | |
148 /** | |
149 * This routine is used to check if we can send the Aid key to the host | |
150 * | |
151 * Taken from Section 16.2.1.2 Enter/Rec Adv Key | |
152 * | |
153 * In the normal unlocked state, when the workstation operator presses the | |
154 * Enter/Rec Adv key: | |
155 * | |
156 * 1. The 5494 checks for the completion of mandatory-fill, self-check, and | |
157 * right-adjust fields when in an active field. (An active field is one in | |
158 * which the workstation operator has begun entering data.) If the | |
159 * requirements of the field have not been satisfied, an error occurs. | |
160 * | |
161 * @return | |
162 * | |
163 */ | |
164 public boolean isCanSendAid() { | |
165 | |
166 // We also have to check if we are still in the field. | |
167 if (currentField != null && | |
168 (currentField.getAdjustment() > 0 || currentField.isSignedNumeric()) | |
169 && currentModified && isInField() | |
170 && !currentField.isCanSend()) | |
171 | |
172 return false; | |
173 else | |
174 return true; | |
175 | |
176 } | |
177 | |
178 protected void saveCurrentField() { | |
179 saveCurrent = currentField; | |
180 } | |
181 | |
182 protected void restoreCurrentField() { | |
183 currentField = saveCurrent; | |
184 } | |
185 | |
186 protected void setCurrentField(ScreenField sf) { | |
187 currentField = sf; | |
188 } | |
189 | |
190 protected void setCurrentFieldMDT() { | |
191 currentField.setMDT(); | |
192 currentModified = true; | |
193 masterMDT = true; | |
194 } | |
195 | |
196 protected void setCurrentFieldFFWs(int ffw1, int ffw2) { | |
197 | |
198 masterMDT = currentField.setFFWs(ffw1,ffw2); | |
199 | |
200 } | |
201 | |
202 | |
203 protected ScreenField setField(int attr, int row, int col, int len, int ffw1, | |
204 int ffw2, int fcw1, int fcw2) { | |
205 | |
206 ScreenField sf = null; | |
207 screenFields[nextField] = new ScreenField(screen); | |
208 screenFields[nextField].setField(attr,row,col,len,ffw1,ffw2,fcw1,fcw2); | |
209 sf = screenFields[nextField++]; | |
210 | |
211 sizeFields++; | |
212 | |
213 | |
214 // set the field id if it is not a bypass field | |
215 // this is used for cursor progression | |
216 // changed this because of problems not allocating field id's for | |
217 // all fields. kjp 2002/10/21 | |
218 // if (!sf.isBypassField()) | |
219 sf.setFieldId(++fieldIds); | |
220 | |
221 // check if the cursor progression field flag should be set. | |
222 // if ((fcw1 & 0x88) == 0x88) | |
223 if (fcw1 == 0x88) | |
224 cpfExists = true; | |
225 | |
226 if (currentField != null) { | |
227 currentField.next = sf; | |
228 sf.prev = currentField; | |
229 } | |
230 | |
231 currentField = sf; | |
232 | |
233 // check if the Modified Data Tag was set while creating the field | |
234 if (!masterMDT) | |
235 masterMDT = currentField.mdt; | |
236 | |
237 currentModified = false; | |
238 | |
239 return currentField; | |
240 | |
241 } | |
242 | |
243 public ScreenField getField(int index) { | |
244 | |
245 return screenFields[index]; | |
246 } | |
247 | |
248 public ScreenField getCurrentField() { | |
249 return currentField; | |
250 } | |
251 | |
252 public int getCurrentFieldPos() { | |
253 return currentField.getCurrentPos(); | |
254 } | |
255 | |
256 protected int getCurrentFieldShift() { | |
257 return currentField.getFieldShift(); | |
258 } | |
259 | |
260 public String getCurrentFieldText() { | |
261 | |
262 return currentField.getText(); | |
263 } | |
264 | |
265 public int getCurrentFieldHighlightedAttr(){ | |
266 return currentField.getHighlightedAttr(); | |
267 } | |
268 | |
269 public int getSize() { | |
270 | |
271 return sizeFields; | |
272 } | |
273 | |
274 public int getFieldCount() { | |
275 | |
276 return sizeFields; | |
277 } | |
278 | |
279 protected boolean isInField(int pos) { | |
280 return isInField(pos,true); | |
281 } | |
282 | |
283 protected boolean isInField() { | |
284 return isInField(screen.getLastPos(),true); | |
285 } | |
286 | |
287 protected boolean isInField(int pos, boolean chgToField) { | |
288 | |
289 ScreenField sf; | |
290 | |
291 for (int x = 0;x < sizeFields; x++) { | |
292 sf = screenFields[x]; | |
293 | |
294 if (sf.withinField(pos)) { | |
295 | |
296 if (chgToField) { | |
297 if (!currentField.equals(sf)) | |
298 currentModified = false; | |
299 currentField = sf; | |
300 } | |
301 return true; | |
302 } | |
303 } | |
304 return false; | |
305 | |
306 } | |
307 | |
308 /** | |
309 * Searches the collection for the target string and returns the iOhioField | |
310 * object containing that string. The string must be totally contained | |
311 * within the field to be considered a match. | |
312 * | |
313 * @param targetString The target string. | |
314 * @param startPos The row and column where to start the search. The position | |
315 * is inclusive (for example, row 1, col 1 means that | |
316 * position 1,1 will be used as the starting location and | |
317 * 1,1 will be included in the search). | |
318 * @param length The length from startPos to include in the search. | |
319 * @param dir An OHIO_DIRECTION value: | |
320 * | |
321 * <table BORDER COLS=3 WIDTH="50%" > | |
322 * <tr><th>Constant </th><th>Value</th> | |
323 * <th>Description</th></tr> | |
324 * <tr><td>OS_OHIO_DIRECTION_FORWARD </td><td>0</td> | |
325 * <td>Forward (beginning towards end)</td></tr> | |
326 * <tr><td>OS_OHIO_DIRECTION_BACKWARD </td><td>1</td> | |
327 * <td>Backward (end towards beginning)</td></tr> | |
328 * </table> | |
329 * Constant Value Description | |
330 * ignoreCase - Indicates whether the search is case sensitive. | |
331 * True means that case will be ignored. False means the search will | |
332 * be case sensitive. | |
333 * @return If found, an iOhioField object containing the target string. If | |
334 * not found, returns a null. | |
335 */ | |
336 public ScreenField findByString (String targetString, | |
337 int startPos, | |
338 int length, | |
339 int dir, | |
340 boolean ignoreCase) { | |
341 | |
342 // first lets check if the string exists in the screen space | |
343 // iOhioPosition pos = screen.findString(targetString, startPos, length, | |
344 // dir, ignoreCase); | |
345 | |
346 // if it does exist then lets search the fields by the position that | |
347 // was found and return the results of that search. | |
348 // if (pos != null) { | |
349 return findByPosition(startPos); | |
350 // } | |
351 | |
352 //return null; | |
353 | |
354 } | |
355 | |
356 /** | |
357 * Searches the collection for the target position and returns the ScreenField | |
358 * object containing that position. | |
359 * | |
360 * @param targetPosition The target row and column expressed as a linear | |
361 * position within the presentation space. | |
362 * | |
363 * @return If found, a ScreenField object containing the target position. | |
364 * If not found, returns a null. | |
365 */ | |
366 public ScreenField findByPosition(int targetPosition) { | |
367 | |
368 ScreenField sf = null; | |
369 | |
370 for (int x = 0;x < sizeFields; x++) { | |
371 | |
372 sf = screenFields[x]; | |
373 | |
374 if (sf.withinField(targetPosition)) { | |
375 return sf; | |
376 } | |
377 | |
378 } | |
379 | |
380 return null; | |
381 } | |
382 | |
383 /** | |
384 * Searches the collection for the target position and returns the ScreenField | |
385 * object containing that position. | |
386 * | |
387 * @param row The beginning row to start search with in the presentation space. | |
388 * @param col The beginning column to start search with in the presentation space. | |
389 * | |
390 * @return If found, a ScreenField object containing the target position. | |
391 * If not found, returns a null. | |
392 */ | |
393 public ScreenField findByPosition(int row, int col) { | |
394 | |
395 return findByPosition(screen.getPos(row,col)); | |
396 } | |
397 | |
398 public ScreenField[] getFields () { | |
399 | |
400 ScreenField[] fields = new ScreenField[sizeFields]; | |
401 for (int x = 0; x < sizeFields; x++) { | |
402 | |
403 fields[x] = screenFields[x]; | |
404 } | |
405 | |
406 return fields; | |
407 } | |
408 | |
409 public ScreenField getFirstInputField() { | |
410 | |
411 if (sizeFields <= 0) | |
412 return null; | |
413 | |
414 int f = 0; | |
415 ScreenField sf = screenFields[f]; | |
416 | |
417 while (sf.isBypassField() && f++ < sizeFields) { | |
418 sf = screenFields[f]; | |
419 } | |
420 | |
421 if (sf.isBypassField()) | |
422 return null; | |
423 else | |
424 return sf; | |
425 | |
426 } | |
427 | |
428 public void gotoFieldNext() { | |
429 | |
430 // sanity check - we were getting null pointers after a restore of screen | |
431 // and cursor was not positioned on a field when returned | |
432 // *** Note *** to myself | |
433 // maybe this is fixed I will have to check this some time | |
434 int lastPos = screen.getLastPos(); | |
435 | |
436 if (currentField == null && (sizeFields != 0) && !isInField(lastPos,true)) { | |
437 int pos = lastPos; | |
438 screen.setCursorOff(); | |
439 screen.advancePos(); | |
440 lastPos = screen.getLastPos(); | |
441 while (!isInField() && pos != lastPos) { | |
442 screen.advancePos(); | |
443 } | |
444 screen.setCursorOn(); | |
445 } | |
446 | |
447 // if we are still null do nothing | |
448 if (currentField == null) | |
449 return; | |
450 | |
451 ScreenField sf = currentField; | |
452 | |
453 if (!sf.withinField(lastPos)) { | |
454 screen.setCursorOff(); | |
455 | |
456 if (sizeFields > 0) { | |
457 | |
458 // lets get the current position so we can test if we have looped | |
459 // the screen and not found a valid field. | |
460 int pos = lastPos; | |
461 int savPos = lastPos; | |
462 boolean done = false; | |
463 do { | |
464 screen.advancePos(); | |
465 lastPos = screen.getLastPos(); | |
466 if (isInField(lastPos) | |
467 || pos==lastPos) { | |
468 if (!currentField.isBypassField()) { | |
469 screen.gotoField(currentField); | |
470 done = true; | |
471 } | |
472 } | |
473 } while ( !done && lastPos != savPos); | |
474 } | |
475 currentModified = false; | |
476 screen.setCursorOn(); | |
477 | |
478 } | |
479 else { | |
480 if (!cpfExists) { | |
481 do { | |
482 | |
483 sf = sf.next; | |
484 } | |
485 while ( sf != null && sf.isBypassField()); | |
486 | |
487 } | |
488 else { | |
489 int f = 0; | |
490 int cp = sf.getCursorProgression(); | |
491 | |
492 if (cp == 0) { | |
493 do { | |
494 | |
495 sf = sf.next; | |
496 } | |
497 while ( sf != null && sf.isBypassField()); | |
498 | |
499 } | |
500 else { | |
501 ScreenField sf1 = null; | |
502 boolean found = false; | |
503 while (!found && f < sizeFields) { | |
504 | |
505 sf1 = screenFields[f++]; | |
506 if (sf1.getFieldId() == cp) | |
507 found = true; | |
508 } | |
509 if (found) | |
510 sf = sf1; | |
511 else { | |
512 do { | |
513 sf = sf.next; | |
514 } | |
515 while ( sf != null && sf.isBypassField()); | |
516 | |
517 } | |
518 sf1 = null; | |
519 } | |
520 } | |
521 if (sf == null) | |
522 screen.gotoField(1); | |
523 else { | |
524 currentField = sf; | |
525 screen.gotoField(currentField); | 579 screen.gotoField(currentField); |
526 } | 580 } |
527 | 581 } |
528 currentModified = false; | 582 |
529 | 583 protected void readFormatTable(ByteArrayOutputStream baosp, int readType, ICodePage codePage) { |
530 } | 584 ScreenField sf; |
531 } | 585 boolean isSigned = false; |
532 | 586 char c; |
533 public void gotoFieldPrev() { | 587 |
534 | 588 if (masterMDT) { |
535 ScreenField sf = currentField; | 589 StringBuffer sb = new StringBuffer(); |
536 int lastPos = screen.getLastPos(); | 590 |
537 | 591 for (int x = 0; x < sizeFields; x++) { |
538 if (!sf.withinField(lastPos)) { | 592 isSigned = false; |
539 screen.setCursorOff(); | 593 sf = screenFields[x]; |
540 | 594 |
541 if (sizeFields > 0) { | 595 if (sf.mdt || (readType == CMD_READ_INPUT_FIELDS)) { |
542 // lets get the current position so we can test if we have looped | 596 sb.setLength(0); |
543 // the screen and not found a valid field. | 597 sb.append(sf.getText()); |
544 int pos = lastPos; | 598 |
545 int savPos = lastPos; | 599 if (readType == CMD_READ_MDT_FIELDS || |
546 boolean done = false; | 600 readType == CMD_READ_MDT_IMMEDIATE_ALT) { |
547 | 601 int len = sb.length() - 1; |
548 do { | 602 |
549 screen.changePos(-1); | 603 // we strip out all '\u0020' and less |
550 lastPos = screen.getLastPos(); | 604 while (len >= 0 && |
551 | |
552 if (isInField(lastPos) | |
553 || (pos == lastPos)) { | |
554 | |
555 if (!currentField.isBypassField()) { | |
556 screen.gotoField(currentField); | |
557 done = true; | |
558 } | |
559 } | |
560 } while ( !done && lastPos != savPos); | |
561 } | |
562 screen.setCursorOn(); | |
563 | |
564 } | |
565 else { | |
566 | |
567 if (sf.startPos() == lastPos) { | |
568 if (!cpfExists) { | |
569 | |
570 do { | |
571 sf = sf.prev; | |
572 } | |
573 while ( sf != null && sf.isBypassField()); | |
574 } | |
575 else { | |
576 | |
577 int f = 0; | |
578 int cp = sf.getFieldId(); | |
579 ScreenField sf1 = null; | |
580 boolean found = false; | |
581 while (!found && f < sizeFields) { | |
582 | |
583 sf1 = screenFields[f++]; | |
584 if (sf1.getCursorProgression() == cp) | |
585 found = true; | |
586 } | |
587 if (found) | |
588 sf = sf1; | |
589 else { | |
590 do { | |
591 sf = sf.prev; | |
592 } | |
593 while ( sf != null && sf.isBypassField()); | |
594 } | |
595 sf1 = null; | |
596 } | |
597 } | |
598 | |
599 if (sf == null) { | |
600 int size = sizeFields; | |
601 sf = screenFields[size - 1]; | |
602 | |
603 while (sf.isBypassField() && size-- > 0) { | |
604 sf = screenFields[size]; | |
605 | |
606 } | |
607 } | |
608 currentField = sf; | |
609 currentModified = false; | |
610 screen.gotoField(currentField); | |
611 } | |
612 } | |
613 | |
614 protected void readFormatTable(ByteArrayOutputStream baosp,int readType, ICodePage codePage) { | |
615 | |
616 ScreenField sf; | |
617 boolean isSigned = false; | |
618 char c; | |
619 | |
620 if (masterMDT) { | |
621 | |
622 StringBuffer sb = new StringBuffer(); | |
623 for (int x = 0; x < sizeFields; x++) { | |
624 isSigned = false; | |
625 | |
626 sf = screenFields[x]; | |
627 | |
628 if (sf.mdt || (readType == CMD_READ_INPUT_FIELDS)) { | |
629 | |
630 sb.setLength(0); | |
631 sb.append(sf.getText()); | |
632 | |
633 | |
634 if (readType == CMD_READ_MDT_FIELDS || | |
635 readType == CMD_READ_MDT_IMMEDIATE_ALT) { | |
636 int len = sb.length() - 1; | |
637 | |
638 // we strip out all '\u0020' and less | |
639 while (len >= 0 && | |
640 // (sb.charAt(len) <= ' ' || sb.charAt(len) >= '\uff20' )) { | 605 // (sb.charAt(len) <= ' ' || sb.charAt(len) >= '\uff20' )) { |
641 (sb.charAt(len) < ' ' || sb.charAt(len) >= '\uff20')) { | 606 (sb.charAt(len) < ' ' || sb.charAt(len) >= '\uff20')) { |
642 | 607 // if we have the dup character and dup is enabled then we |
643 // if we have the dup character and dup is enabled then we | 608 // stop here |
644 // stop here | 609 if (sb.charAt(len) == 0x1C && sf.isDupEnabled()) |
645 if (sb.charAt(len) == 0x1C && sf.isDupEnabled()) | 610 break; |
646 break; | 611 |
647 | 612 sb.deleteCharAt(len--); |
648 sb.deleteCharAt(len--); | 613 } |
649 } | 614 } |
650 | |
651 } | |
652 | 615 |
653 // System.out.println("field " + sf.toString()); | 616 // System.out.println("field " + sf.toString()); |
654 // System.out.println(">" + sb.toString() + "<"); | 617 // System.out.println(">" + sb.toString() + "<"); |
655 // System.out.println(" field is all nulls"); | 618 // System.out.println(" field is all nulls"); |
656 if (sf.isSignedNumeric() && sb.length() > 0 && sb.charAt(sb.length() - 1) == '-') { | 619 if (sf.isSignedNumeric() && sb.length() > 0 && sb.charAt(sb.length() - 1) == '-') { |
657 isSigned = true; | 620 isSigned = true; |
658 sb.setLength(sb.length() - 1); | 621 sb.setLength(sb.length() - 1); |
659 } | 622 } |
660 | 623 |
661 int len3 = sb.length(); | 624 int len3 = sb.length(); |
662 | 625 |
663 if (len3 > 0 || (readType == CMD_READ_MDT_FIELDS || | 626 if (len3 > 0 || (readType == CMD_READ_MDT_FIELDS || |
664 readType == CMD_READ_MDT_IMMEDIATE_ALT)) { | 627 readType == CMD_READ_MDT_IMMEDIATE_ALT)) { |
665 | 628 if ((readType == CMD_READ_MDT_FIELDS || |
666 if ((readType == CMD_READ_MDT_FIELDS || | 629 readType == CMD_READ_MDT_IMMEDIATE_ALT)) { |
667 readType == CMD_READ_MDT_IMMEDIATE_ALT)) { | 630 baosp.write(17); // start of field data |
668 | 631 |
669 baosp.write(17); // start of field data | 632 if (sf.isSelectionField()) { |
670 if (sf.isSelectionField()) { | 633 baosp.write(screen.getRow(sf.selectionPos) + 1); |
671 baosp.write(screen.getRow(sf.selectionPos)+1); | 634 baosp.write(screen.getCol(sf.selectionPos) + 1); |
672 baosp.write(screen.getCol(sf.selectionPos)+1); | 635 } |
673 } | 636 else { |
674 else { | 637 baosp.write(sf.startRow() + 1); |
675 baosp.write(sf.startRow()+1); | 638 baosp.write(sf.startCol() + 1); |
676 baosp.write(sf.startCol()+1); | 639 } |
677 } | 640 } |
678 | 641 |
679 } | |
680 // int len = sb.length(); | 642 // int len = sb.length(); |
681 if (sf.isSelectionField()) { | 643 if (sf.isSelectionField()) { |
682 baosp.write(0); | 644 baosp.write(0); |
683 baosp.write(sf.selectionIndex + 0x1F); | 645 baosp.write(sf.selectionIndex + 0x1F); |
684 | 646 } |
685 } | 647 else { |
686 else { | 648 for (int k = 0; k < len3; k++) { |
687 for (int k = 0; k < len3; k++) { | 649 c = sb.charAt(k); |
688 c = sb.charAt(k); | 650 |
689 // here we have to check for special instances of the | 651 // here we have to check for special instances of the |
690 // characters in the string field. Attribute bytes | 652 // characters in the string field. Attribute bytes |
691 // are encoded with an offset of \uff00 | 653 // are encoded with an offset of \uff00 |
692 // This is a hack !!!!!!!!!!! | 654 // This is a hack !!!!!!!!!!! |
693 // See ScreenField object for a description | 655 // See ScreenField object for a description |
694 if (c < ' ' || c >= '\uff20') { | 656 if (c < ' ' || c >= '\uff20') { |
695 | 657 // if it is an offset attribute byte we just pass |
696 // if it is an offset attribute byte we just pass | 658 // it straight on to the output stream |
697 // it straight on to the output stream | 659 if (c >= '\uff20' && c <= '\uff3f') { |
698 if (c >= '\uff20' && c <= '\uff3f') { | 660 baosp.write(c - '\uff00'); |
699 baosp.write(c - '\uff00'); | 661 } |
700 } | 662 else |
701 else | 663 |
702 // check for dup character | 664 // check for dup character |
703 if (c == 0x1C) | 665 if (c == 0x1C) |
704 baosp.write(c); | 666 baosp.write(c); |
705 else | 667 else |
706 baosp.write(codePage.uni2ebcdic(' ')); | 668 baosp.write(codePage.uni2ebcdic(' ')); |
707 } | 669 } |
708 else { | 670 else { |
709 if (isSigned && k == len3 - 1) { | 671 if (isSigned && k == len3 - 1) { |
710 baosp.write(0xd0 | (0x0f & c)); | 672 baosp.write(0xd0 | (0x0f & c)); |
711 } | 673 } |
712 else | 674 else |
713 baosp.write(codePage.uni2ebcdic(c)); | 675 baosp.write(codePage.uni2ebcdic(c)); |
714 | 676 } |
715 } | 677 } |
716 } | 678 } |
717 } | 679 } |
718 } | 680 } |
719 } | 681 } |
720 } | 682 } |
721 } | 683 } |
722 } | |
723 | 684 |
724 } | 685 } |