Mercurial > 510Connectbot
annotate src/org/tn5250j/framework/tn5250/Screen5250.java @ 25:5949eb469a79 tn5250
adding tn5250 files, native android logging
author | Carl Byington <carl@five-ten-sg.com> |
---|---|
date | Tue, 03 Jun 2014 12:10:21 -0700 |
parents | e773d0952613 |
children | 9ae1c889a64c |
rev | line source |
---|---|
3 | 1 /** |
2 * Title: Screen5250.java | |
3 * Copyright: Copyright (c) 2001 - 2004 | |
4 * Company: | |
5 * @author Kenneth J. Pouncey | |
6 * @version 0.5 | |
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 import static org.tn5250j.TN5250jConstants.*; | |
29 | |
30 import java.text.DecimalFormat; | |
31 import java.text.DecimalFormatSymbols; | |
32 import java.text.NumberFormat; | |
33 import java.text.ParseException; | |
34 import java.util.Vector; | |
35 | |
36 import org.tn5250j.TN5250jConstants; | |
37 import org.tn5250j.event.ScreenListener; | |
25
5949eb469a79
adding tn5250 files, native android logging
Carl Byington <carl@five-ten-sg.com>
parents:
10
diff
changeset
|
38 import android.util.Log; |
5949eb469a79
adding tn5250 files, native android logging
Carl Byington <carl@five-ten-sg.com>
parents:
10
diff
changeset
|
39 |
3 | 40 |
41 public class Screen5250 { | |
42 | |
43 private ScreenFields screenFields; | |
44 private int lastAttr; | |
45 private int lastPos; | |
46 private int lenScreen; | |
47 private KeyStrokenizer strokenizer; | |
48 private tnvt sessionVT; | |
49 private int numRows = 0; | |
50 private int numCols = 0; | |
51 protected static final int initAttr = 32; | |
52 protected static final char initChar = 0; | |
53 public boolean cursorActive = false; | |
54 public boolean cursorShown = false; | |
55 protected boolean insertMode = false; | |
56 private boolean keyProcessed = false; | |
57 private Rect dirtyScreen = new Rect(); | |
58 | |
59 public int homePos = 0; | |
60 public int saveHomePos = 0; | |
61 private String bufferedKeys; | |
62 public boolean pendingInsert = false; | |
63 | |
64 public final static byte STATUS_SYSTEM = 1; | |
65 public final static byte STATUS_ERROR_CODE = 2; | |
66 public final static byte STATUS_VALUE_ON = 1; | |
67 public final static byte STATUS_VALUE_OFF = 2; | |
68 | |
69 private StringBuffer hsMore = new StringBuffer("More..."); | |
70 private StringBuffer hsBottom = new StringBuffer("Bottom"); | |
71 | |
72 // error codes to be sent to the host on an error | |
73 private final static int ERR_CURSOR_PROTECTED = 0x05; | |
74 private final static int ERR_INVALID_SIGN = 0x11; | |
75 private final static int ERR_NO_ROOM_INSERT = 0x12; | |
76 private final static int ERR_NUMERIC_ONLY = 0x09; | |
77 private final static int ERR_DUP_KEY_NOT_ALLOWED = 0x19; | |
78 private final static int ERR_NUMERIC_09 = 0x10; | |
79 private final static int ERR_FIELD_MINUS = 0x16; | |
80 private final static int ERR_FIELD_EXIT_INVALID = 0x18; | |
81 private final static int ERR_ENTER_NO_ALLOWED = 0x20; | |
82 private final static int ERR_MANDITORY_ENTER = 0x21; | |
83 | |
84 private boolean guiInterface = false; | |
85 private boolean resetRequired = true; | |
86 private boolean backspaceError = true; | |
87 private boolean feError; | |
88 | |
89 // vector of listeners for changes to the screen. | |
90 Vector<ScreenListener> listeners = null; | |
91 | |
92 // Operator Information Area | |
93 private ScreenOIA oia; | |
94 | |
95 // screen planes | |
96 protected ScreenPlanes planes; | |
97 | |
98 //Added by Barry | |
99 private StringBuffer keybuf; | |
100 | |
25
5949eb469a79
adding tn5250 files, native android logging
Carl Byington <carl@five-ten-sg.com>
parents:
10
diff
changeset
|
101 |
3 | 102 |
103 public Screen5250() { | |
104 | |
105 //Added by Barry | |
106 this.keybuf = new StringBuffer(); | |
107 | |
108 try { | |
109 jbInit(); | |
110 } catch (Exception ex) { | |
25
5949eb469a79
adding tn5250 files, native android logging
Carl Byington <carl@five-ten-sg.com>
parents:
10
diff
changeset
|
111 Log.w(TAG,"In constructor: ", ex); |
3 | 112 } |
113 } | |
114 | |
115 void jbInit() throws Exception { | |
116 | |
117 lastAttr = 32; | |
118 | |
119 // default number of rows and columns | |
120 numRows = 24; | |
121 numCols = 80; | |
122 | |
123 setCursor(1, 1); // set initial cursor position | |
124 | |
125 oia = new ScreenOIA(this); | |
126 oia.setKeyBoardLocked(true); | |
127 | |
128 lenScreen = numRows * numCols; | |
129 | |
130 planes = new ScreenPlanes(this,numRows); | |
131 | |
132 screenFields = new ScreenFields(this); | |
133 strokenizer = new KeyStrokenizer(); | |
134 } | |
135 | |
136 protected ScreenPlanes getPlanes() { | |
137 return planes; | |
138 } | |
139 | |
140 public final ScreenOIA getOIA() { | |
141 return oia; | |
142 } | |
143 | |
144 protected final void setRowsCols(int rows, int cols) { | |
145 | |
146 int oldRows = numRows; | |
147 int oldCols = numCols; | |
148 | |
149 // default number of rows and columns | |
150 numRows = rows; | |
151 numCols = cols; | |
152 | |
153 lenScreen = numRows * numCols; | |
154 | |
155 planes.setSize(rows); | |
156 | |
157 // If they are not the same then we need to inform the listeners that | |
158 // the size changed. | |
159 if (oldRows != numRows || oldCols != numCols) | |
160 fireScreenSizeChanged(); | |
161 | |
162 } | |
163 | |
164 | |
165 public boolean isCursorActive() { | |
166 return cursorActive; | |
167 | |
168 } | |
169 | |
170 public boolean isCursorShown() { | |
171 return cursorShown; | |
172 } | |
173 | |
174 public void setUseGUIInterface(boolean gui) { | |
175 guiInterface = gui; | |
176 } | |
177 | |
178 public void toggleGUIInterface() { | |
179 guiInterface = !guiInterface; | |
180 } | |
181 | |
182 public void setResetRequired(boolean reset) { | |
183 resetRequired = reset; | |
184 } | |
185 | |
186 public void setBackspaceError(boolean onError) { | |
187 backspaceError = onError; | |
188 } | |
189 | |
190 /** | |
191 * Copy & Paste support | |
7 | 192 * |
3 | 193 * @see {@link #pasteText(String, boolean)} |
194 * @see {@link #copyTextField(int)} | |
195 */ | |
196 public final String copyText(Rect area) { | |
197 StringBuilder sb = new StringBuilder(); | |
198 Rect workR = new Rect(); | |
199 workR.setBounds(area); | |
25
5949eb469a79
adding tn5250 files, native android logging
Carl Byington <carl@five-ten-sg.com>
parents:
10
diff
changeset
|
200 Log.d(TAG,"Copying " + workR); |
3 | 201 |
202 // loop through all the screen characters to send them to the clip board | |
203 int m = workR.x; | |
204 int i = 0; | |
205 int t = 0; | |
206 | |
207 while (workR.height-- > 0) { | |
208 t = workR.width; | |
209 i = workR.y; | |
210 while (t-- > 0) { | |
211 // only copy printable characters (in this case >= ' ') | |
212 char c = planes.getChar(getPos(m - 1, i - 1)); | |
213 if (c >= ' ' && (planes.screenExtended[getPos(m - 1, i - 1)] & EXTENDED_5250_NON_DSP) | |
214 == 0) | |
215 sb.append(c); | |
216 else | |
217 sb.append(' '); | |
218 | |
219 i++; | |
220 } | |
221 sb.append('\n'); | |
222 m++; | |
223 } | |
224 return sb.toString(); | |
225 } | |
226 | |
227 /** | |
228 * Copy & Paste support | |
7 | 229 * |
3 | 230 * @param content |
231 * @see {@link #copyText(Rectangle)} | |
232 */ | |
233 public final void pasteText(String content, boolean special) { | |
25
5949eb469a79
adding tn5250 files, native android logging
Carl Byington <carl@five-ten-sg.com>
parents:
10
diff
changeset
|
234 Log.d(TAG,"Pasting, special:"+special); |
3 | 235 setCursorActive(false); |
236 | |
237 StringBuilder sb = new StringBuilder(content); | |
238 StringBuilder pd = new StringBuilder(); | |
239 | |
240 // character counters within the string to be pasted. | |
241 int nextChar = 0; | |
242 int nChars = sb.length(); | |
243 | |
244 int lr = getRow(lastPos); | |
245 int lc = getCol(lastPos); | |
246 resetDirty(lastPos); | |
247 | |
248 int cpos = lastPos; | |
249 int length = getScreenLength(); | |
250 | |
251 char c = 0; | |
252 boolean setIt; | |
253 | |
254 // save our current place within the FFT. | |
255 screenFields.saveCurrentField(); | |
256 | |
257 for (int x = nextChar; x < nChars; x++) { | |
258 | |
259 c = sb.charAt(x); | |
260 | |
261 if ((c == '\n') || (c == '\r')) { | |
262 | |
25
5949eb469a79
adding tn5250 files, native android logging
Carl Byington <carl@five-ten-sg.com>
parents:
10
diff
changeset
|
263 Log.i(TAG,"pasted cr-lf>" + pd + "<"); |
3 | 264 pd.setLength(0); |
265 // if we read in a cr lf in the data stream we need to go | |
266 // to the starting column of the next row and start from there | |
267 cpos = getPos(getRow(cpos)+1,lc); | |
268 | |
269 // If we go paste the end of the screen then let's start over from | |
270 // the beginning of the screen space. | |
271 if (cpos > length) | |
272 cpos = 0; | |
273 } | |
274 else { | |
275 | |
276 // we will default to set the character always. | |
277 setIt = true; | |
278 | |
279 // If we are in a special paste scenario then we check for valid | |
280 // characters to paste. | |
281 if (special && (!Character.isLetter(c) && !Character.isDigit(c))) | |
282 setIt = false; | |
283 | |
284 // we will only push a character to the screen space if we are in | |
285 // a field | |
286 if (isInField(cpos) && setIt) { | |
287 planes.setChar(cpos, c); | |
288 setDirty(cpos); | |
289 screenFields.setCurrentFieldMDT(); | |
290 } | |
291 // If we placed a character then we go to the next position. | |
292 if (setIt) | |
293 cpos++; | |
294 // we will append the information to our debug buffer. | |
295 pd.append(c); | |
296 } | |
297 } | |
298 | |
299 // if we have anything else not logged then log it out. | |
300 if (pd.length() > 0) | |
25
5949eb469a79
adding tn5250 files, native android logging
Carl Byington <carl@five-ten-sg.com>
parents:
10
diff
changeset
|
301 Log.i(TAG,"pasted >" + pd + "<"); |
3 | 302 |
303 // restore out position within the FFT. | |
304 screenFields.restoreCurrentField(); | |
305 updateDirty(); | |
306 | |
307 // restore our cursor position. | |
308 setCursor(lr + 1, lc + 1); | |
309 | |
310 setCursorActive(true); | |
311 | |
312 } | |
313 | |
314 /** | |
315 * Copy & Paste support | |
7 | 316 * |
3 | 317 * @param position |
318 * @return | |
319 * @see {@link #copyText(int)} | |
320 */ | |
321 public final String copyTextField(int position) { | |
322 screenFields.saveCurrentField(); | |
323 isInField(position); | |
324 String result = screenFields.getCurrentFieldText(); | |
325 screenFields.restoreCurrentField(); | |
326 return result; | |
327 } | |
328 | |
329 /** | |
330 * | |
331 * Copy & Paste end code | |
332 * | |
333 */ | |
334 | |
335 /** | |
336 * Sum them | |
337 * | |
338 * @param which | |
339 * formatting option to use | |
340 * @return vector string of numberic values | |
341 */ | |
342 public final Vector<Double> sumThem(boolean which, Rect area) { | |
343 | |
344 StringBuilder sb = new StringBuilder(); | |
345 Rect workR = new Rect(); | |
346 workR.setBounds(area); | |
347 | |
348 // gui.rubberband.reset(); | |
349 // gui.repaint(); | |
350 | |
25
5949eb469a79
adding tn5250 files, native android logging
Carl Byington <carl@five-ten-sg.com>
parents:
10
diff
changeset
|
351 Log.d(TAG,"Summing"); |
3 | 352 |
353 // obtain the decimal format for parsing | |
354 DecimalFormat df = (DecimalFormat) NumberFormat.getInstance(); | |
355 | |
356 DecimalFormatSymbols dfs = df.getDecimalFormatSymbols(); | |
357 | |
358 if (which) { | |
359 dfs.setDecimalSeparator('.'); | |
360 dfs.setGroupingSeparator(','); | |
361 } else { | |
362 dfs.setDecimalSeparator(','); | |
363 dfs.setGroupingSeparator('.'); | |
364 } | |
365 | |
366 df.setDecimalFormatSymbols(dfs); | |
367 | |
368 Vector<Double> sumVector = new Vector<Double>(); | |
369 | |
370 // loop through all the screen characters to send them to the clip board | |
371 int m = workR.x; | |
372 int i = 0; | |
373 int t = 0; | |
374 | |
375 double sum = 0.0; | |
376 | |
377 while (workR.height-- > 0) { | |
378 t = workR.width; | |
379 i = workR.y; | |
380 while (t-- > 0) { | |
381 | |
382 // only copy printable numeric characters (in this case >= ' ') | |
383 // char c = screen[getPos(m - 1, i - 1)].getChar(); | |
384 char c = planes.getChar(getPos(m - 1, i - 1)); | |
385 // if (((c >= '0' && c <= '9') || c == '.' || c == ',' || c == '-') | |
386 // && !screen[getPos(m - 1, i - 1)].nonDisplay) { | |
387 | |
388 // TODO: update me here to implement the nonDisplay check as well | |
389 if (((c >= '0' && c <= '9') || c == '.' || c == ',' || c == '-')) { | |
390 sb.append(c); | |
391 } | |
392 i++; | |
393 } | |
394 | |
395 if (sb.length() > 0) { | |
396 if (sb.charAt(sb.length() - 1) == '-') { | |
397 sb.insert(0, '-'); | |
398 sb.deleteCharAt(sb.length() - 1); | |
399 } | |
400 try { | |
401 Number n = df.parse(sb.toString()); | |
402 // System.out.println(s + " " + n.doubleValue()); | |
403 | |
404 sumVector.add(new Double(n.doubleValue())); | |
405 sum += n.doubleValue(); | |
406 } catch (ParseException pe) { | |
25
5949eb469a79
adding tn5250 files, native android logging
Carl Byington <carl@five-ten-sg.com>
parents:
10
diff
changeset
|
407 Log.w(TAG,pe.getMessage() + " at " |
3 | 408 + pe.getErrorOffset()); |
409 } | |
410 } | |
411 sb.setLength(0); | |
412 m++; | |
413 } | |
25
5949eb469a79
adding tn5250 files, native android logging
Carl Byington <carl@five-ten-sg.com>
parents:
10
diff
changeset
|
414 Log.d(TAG,"" + sum); |
3 | 415 return sumVector; |
416 } | |
417 | |
418 /** | |
419 * This will move the screen cursor based on the mouse event. | |
420 * | |
421 * I do not think the checks here for the gui characters should be here but | |
422 * will leave them here for now until we work out the interaction. This | |
423 * should be up to the gui frontend in my opinion. | |
424 * | |
425 * @param pos | |
426 */ | |
427 public boolean moveCursor(int pos) { | |
428 | |
429 if (!oia.isKeyBoardLocked()) { | |
430 | |
431 if (pos < 0) | |
432 return false; | |
433 // because getRowColFromPoint returns offset of 1,1 we need to | |
434 // translate to offset 0,0 | |
435 // pos -= (numCols + 1); | |
436 | |
437 int g = planes.getWhichGUI(pos); | |
438 | |
439 // lets check for hot spots | |
440 if (g >= BUTTON_LEFT && g <= BUTTON_LAST) { | |
441 StringBuffer aid = new StringBuffer(); | |
442 boolean aidFlag = true; | |
443 switch (g) { | |
444 case BUTTON_RIGHT: | |
445 case BUTTON_MIDDLE: | |
446 while (planes.getWhichGUI(--pos) != BUTTON_LEFT) { | |
447 } | |
448 case BUTTON_LEFT: | |
449 if (planes.getChar(pos) == 'F') { | |
450 pos++; | |
451 } else | |
452 aidFlag = false; | |
453 | |
454 if (planes.getChar(pos + 1) != '=' | |
455 && planes.getChar(pos + 1) != '.' | |
456 && planes.getChar(pos + 1) != '/') { | |
25
5949eb469a79
adding tn5250 files, native android logging
Carl Byington <carl@five-ten-sg.com>
parents:
10
diff
changeset
|
457 Log.d(TAG," Hotspot clicked!!! we will send characters " |
7 | 458 + planes.getChar(pos) + " " + planes.getChar(pos+1)); |
3 | 459 aid.append(planes.getChar(pos)); |
460 aid.append(planes.getChar(pos + 1)); | |
461 } else { | |
25
5949eb469a79
adding tn5250 files, native android logging
Carl Byington <carl@five-ten-sg.com>
parents:
10
diff
changeset
|
462 Log.d(TAG," Hotspot clicked!!! we will send character " |
3 | 463 + planes.getChar(pos)); |
464 aid.append(planes.getChar(pos)); | |
465 } | |
466 break; | |
467 | |
468 } | |
469 if (aidFlag) { | |
470 switch (g) { | |
471 | |
472 case BUTTON_LEFT_UP: | |
473 case BUTTON_MIDDLE_UP: | |
474 case BUTTON_RIGHT_UP: | |
475 case BUTTON_ONE_UP: | |
476 case BUTTON_SB_UP: | |
477 case BUTTON_SB_GUIDE: | |
478 sessionVT.sendAidKey(AID_ROLL_UP); | |
479 break; | |
480 | |
481 case BUTTON_LEFT_DN: | |
482 case BUTTON_MIDDLE_DN: | |
483 case BUTTON_RIGHT_DN: | |
484 case BUTTON_ONE_DN: | |
485 case BUTTON_SB_DN: | |
486 case BUTTON_SB_THUMB: | |
487 | |
488 sessionVT.sendAidKey(AID_ROLL_DOWN); | |
489 break; | |
490 case BUTTON_LEFT_EB: | |
491 case BUTTON_MIDDLE_EB: | |
492 case BUTTON_RIGHT_EB: | |
493 StringBuffer eb = new StringBuffer(); | |
494 while (planes.getWhichGUI(pos--) != BUTTON_LEFT_EB) | |
495 ; | |
496 while (planes.getWhichGUI(pos++) != BUTTON_RIGHT_EB) { | |
497 eb.append(planes.getChar(pos)); | |
498 } | |
10 | 499 sessionVT.showURL(eb.toString()); |
3 | 500 // take out the log statement when we are sure it is |
501 // working | |
25
5949eb469a79
adding tn5250 files, native android logging
Carl Byington <carl@five-ten-sg.com>
parents:
10
diff
changeset
|
502 Log.i(TAG,"Send to external Browser: " + eb.toString()); |
3 | 503 break; |
504 | |
505 default: | |
506 int aidKey = Integer.parseInt(aid.toString()); | |
507 if (aidKey >= 1 && aidKey <= 12) | |
508 sessionVT.sendAidKey(0x30 + aidKey); | |
509 if (aidKey >= 13 && aidKey <= 24) | |
510 sessionVT.sendAidKey(0xB0 + (aidKey - 12)); | |
511 } | |
512 } else { | |
513 if (screenFields.getCurrentField() != null) { | |
514 int xPos = screenFields.getCurrentField().startPos(); | |
515 for (int x = 0; x < aid.length(); x++) { | |
516 // System.out.println(sr + "," + (sc + x) + " " + | |
517 // aid.charAt(x)); | |
518 planes.setChar(xPos + x , aid.charAt(x)); | |
519 } | |
520 // System.out.println(aid); | |
521 screenFields.setCurrentFieldMDT(); | |
522 sessionVT.sendAidKey(AID_ENTER); | |
523 } | |
524 | |
525 } | |
526 // return back to the calling routine that the cursor was not moved | |
527 // but something else here was done like aid keys or the such | |
528 return false; | |
529 } | |
530 // this is a note to not execute this code here when we | |
531 // implement | |
532 // the remain after edit function option. | |
533 // if (gui.rubberband.isAreaSelected()) { | |
534 // gui.rubberband.reset(); | |
535 // gui.repaint(); | |
536 // } else { | |
537 goto_XY(pos); | |
538 isInField(lastPos); | |
539 | |
540 // return back to the calling object that the cursor was indeed | |
541 // moved with in the screen object | |
542 return true; | |
543 // } | |
544 } | |
545 return false; | |
546 } | |
547 | |
548 public void setVT(tnvt v) { | |
549 | |
550 sessionVT = v; | |
551 } | |
552 | |
553 /** | |
554 * Searches the mnemonicData array looking for the specified string. If it | |
555 * is found it will return the value associated from the mnemonicValue | |
556 * | |
557 * @see #sendKeys | |
558 * @param mnem | |
559 * string mnemonic value | |
560 * @return key value of Mnemonic | |
561 */ | |
562 private int getMnemonicValue(String mnem) { | |
563 | |
564 for (int x = 0; x < mnemonicData.length; x++) { | |
565 | |
566 if (mnemonicData[x].equals(mnem)) | |
567 return mnemonicValue[x]; | |
568 } | |
569 return 0; | |
570 | |
571 } | |
572 | |
573 protected void setPrehelpState(boolean setErrorCode, boolean lockKeyboard, | |
574 boolean unlockIfLocked) { | |
575 if (oia.isKeyBoardLocked() && unlockIfLocked) | |
576 oia.setKeyBoardLocked(false); | |
577 else | |
578 oia.setKeyBoardLocked(lockKeyboard); | |
579 bufferedKeys = null; | |
580 oia.setKeysBuffered(false); | |
581 | |
582 | |
583 } | |
584 | |
585 /** | |
586 * Activate the cursor on screen | |
587 * | |
588 * @param activate | |
589 */ | |
590 public void setCursorActive(boolean activate) { | |
591 | |
592 // System.out.println("cursor active " + updateCursorLoc + " " + | |
593 // cursorActive + " " + activate); | |
594 if (cursorActive && !activate) { | |
595 setCursorOff(); | |
596 cursorActive = activate; | |
597 } else { | |
598 if (!cursorActive && activate) { | |
599 cursorActive = activate; | |
600 setCursorOn(); | |
601 } | |
602 } | |
603 } | |
604 | |
605 /** | |
606 * Set the cursor on | |
607 */ | |
608 public void setCursorOn() { | |
609 cursorShown = true; | |
610 updateCursorLoc(); | |
611 } | |
612 | |
613 /** | |
614 * Set the cursor off | |
615 */ | |
616 public void setCursorOff() { | |
617 | |
618 cursorShown = false; | |
619 updateCursorLoc(); | |
620 // System.out.println("cursor off " + updateCursorLoc + " " + | |
621 // cursorActive); | |
622 | |
623 } | |
624 | |
625 /** | |
626 * | |
627 */ | |
628 private void updateCursorLoc() { | |
629 | |
630 if (cursorActive) { | |
631 | |
632 fireCursorChanged(3); | |
633 | |
634 } | |
635 } | |
636 | |
637 //Added by Barry | |
638 public String getKeys() { | |
639 String result = this.keybuf.toString(); | |
640 this.keybuf = new StringBuffer(); | |
641 return result; | |
642 } | |
643 | |
644 /** | |
645 * The sendKeys method sends a string of keys to the virtual screen. This | |
646 * method acts as if keystrokes were being typed from the keyboard. The | |
647 * keystrokes will be sent to the location given. The string being passed | |
648 * can also contain mnemonic values such as [enter] enter key,[tab] tab key, | |
649 * [pf1] pf1 etc... | |
650 * | |
651 * These will be processed as if you had pressed these keys from the | |
652 * keyboard. All the valid special key values are contained in the MNEMONIC | |
653 * enumeration: | |
654 * | |
655 * <table BORDER COLS=2 WIDTH="50%" > | |
656 * | |
657 * <tr> | |
658 * <td>MNEMONIC_CLEAR</td> | |
659 * <td>[clear]</td> | |
660 * </tr> | |
661 * <tr> | |
662 * <td>MNEMONIC_ENTER</td> | |
663 * <td>[enter]</td> | |
664 * </tr> | |
665 * <tr> | |
666 * <td>MNEMONIC_HELP</td> | |
667 * <td>[help]</td> | |
668 * </tr> | |
669 * <tr> | |
670 * <td>MNEMONIC_PAGE_DOWN</td> | |
671 * <td>[pgdown]</td> | |
672 * </tr> | |
673 * <tr> | |
674 * <td>MNEMONIC_PAGE_UP</td> | |
675 * <td>[pgup]</td> | |
676 * </tr> | |
677 * <tr> | |
678 * <td>MNEMONIC_PRINT</td> | |
679 * <td>[print]</td> | |
680 * </tr> | |
681 * <tr> | |
682 * <td>MNEMONIC_PF1</td> | |
683 * <td>[pf1]</td> | |
684 * </tr> | |
685 * <tr> | |
686 * <td>MNEMONIC_PF2</td> | |
687 * <td>[pf2]</td> | |
688 * </tr> | |
689 * <tr> | |
690 * <td>MNEMONIC_PF3</td> | |
691 * <td>[pf3]</td> | |
692 * </tr> | |
693 * <tr> | |
694 * <td>MNEMONIC_PF4</td> | |
695 * <td>[pf4]</td> | |
696 * </tr> | |
697 * <tr> | |
698 * <td>MNEMONIC_PF5</td> | |
699 * <td>[pf5]</td> | |
700 * </tr> | |
701 * <tr> | |
702 * <td>MNEMONIC_PF6</td> | |
703 * <td>[pf6]</td> | |
704 * </tr> | |
705 * <tr> | |
706 * <td>MNEMONIC_PF7</td> | |
707 * <td>[pf7]</td> | |
708 * </tr> | |
709 * <tr> | |
710 * <td>MNEMONIC_PF8</td> | |
711 * <td>[pf8]</td> | |
712 * </tr> | |
713 * <tr> | |
714 * <td>MNEMONIC_PF9</td> | |
715 * <td>[pf9]</td> | |
716 * </tr> | |
717 * <tr> | |
718 * <td>MNEMONIC_PF10</td> | |
719 * <td>[pf10]</td> | |
720 * </tr> | |
721 * <tr> | |
722 * <td>MNEMONIC_PF11</td> | |
723 * <td>[pf11]</td> | |
724 * </tr> | |
725 * <tr> | |
726 * <td>MNEMONIC_PF12</td> | |
727 * <td>[pf12]</td> | |
728 * </tr> | |
729 * <tr> | |
730 * <td>MNEMONIC_PF13</td> | |
731 * <td>[pf13]</td> | |
732 * </tr> | |
733 * <tr> | |
734 * <td>MNEMONIC_PF14</td> | |
735 * <td>[pf14]</td> | |
736 * </tr> | |
737 * <tr> | |
738 * <td>MNEMONIC_PF15</td> | |
739 * <td>[pf15]</td> | |
740 * </tr> | |
741 * <tr> | |
742 * <td>MNEMONIC_PF16</td> | |
743 * <td>[pf16]</td> | |
744 * </tr> | |
745 * <tr> | |
746 * <td>MNEMONIC_PF17</td> | |
747 * <td>[pf17]</td> | |
748 * </tr> | |
749 * <tr> | |
750 * <td>MNEMONIC_PF18</td> | |
751 * <td>[pf18]</td> | |
752 * </tr> | |
753 * <tr> | |
754 * <td>MNEMONIC_PF19</td> | |
755 * <td>[pf19]</td> | |
756 * </tr> | |
757 * <tr> | |
758 * <td>MNEMONIC_PF20</td> | |
759 * <td>[pf20]</td> | |
760 * </tr> | |
761 * <tr> | |
762 * <td>MNEMONIC_PF21</td> | |
763 * <td>[pf21]</td> | |
764 * </tr> | |
765 * <tr> | |
766 * <td>MNEMONIC_PF22</td> | |
767 * <td>[pf22]</td> | |
768 * </tr> | |
769 * <tr> | |
770 * <td>MNEMONIC_PF23</td> | |
771 * <td>[pf23]</td> | |
772 * </tr> | |
773 * <tr> | |
774 * <td>MNEMONIC_PF24</td> | |
775 * <td>[pf24]</td> | |
776 * </tr> | |
777 * <tr> | |
778 * <td>MNEMONIC_BACK_SPACE</td> | |
779 * <td>[backspace]</td> | |
780 * </tr> | |
781 * <tr> | |
782 * <td>MNEMONIC_BACK_TAB</td> | |
783 * <td>[backtab]</td> | |
784 * </tr> | |
785 * <tr> | |
786 * <td>MNEMONIC_UP</td> | |
787 * <td>[up]</td> | |
788 * </tr> | |
789 * <tr> | |
790 * <td>MNEMONIC_DOWN</td> | |
791 * <td>[down]</td> | |
792 * </tr> | |
793 * <tr> | |
794 * <td>MNEMONIC_LEFT</td> | |
795 * <td>[left]</td> | |
796 * </tr> | |
797 * <tr> | |
798 * <td>MNEMONIC_RIGHT</td> | |
799 * <td>[right]</td> | |
800 * </tr> | |
801 * <tr> | |
802 * <td>MNEMONIC_DELETE</td> | |
803 * <td>[delete]</td> | |
804 * </tr> | |
805 * <tr> | |
806 * <td>MNEMONIC_TAB</td> | |
807 * <td>"[tab]</td> | |
808 * </tr> | |
809 * <tr> | |
810 * <td>MNEMONIC_END_OF_FIELD</td> | |
811 * <td>[eof]</td> | |
812 * </tr> | |
813 * <tr> | |
814 * <td>MNEMONIC_ERASE_EOF</td> | |
815 * <td>[eraseeof]</td> | |
816 * </tr> | |
817 * <tr> | |
818 * <td>MNEMONIC_ERASE_FIELD</td> | |
819 * <td>[erasefld]</td> | |
820 * </tr> | |
821 * <tr> | |
822 * <td>MNEMONIC_INSERT</td> | |
823 * <td>[insert]</td> | |
824 * </tr> | |
825 * <tr> | |
826 * <td>MNEMONIC_HOME</td> | |
827 * <td>[home]</td> | |
828 * </tr> | |
829 * <tr> | |
830 * <td>MNEMONIC_KEYPAD0</td> | |
831 * <td>[keypad0]</td> | |
832 * </tr> | |
833 * <tr> | |
834 * <td>MNEMONIC_KEYPAD1</td> | |
835 * <td>[keypad1]</td> | |
836 * </tr> | |
837 * <tr> | |
838 * <td>MNEMONIC_KEYPAD2</td> | |
839 * <td>[keypad2]</td> | |
840 * </tr> | |
841 * <tr> | |
842 * <td>MNEMONIC_KEYPAD3</td> | |
843 * <td>[keypad3]</td> | |
844 * </tr> | |
845 * <tr> | |
846 * <td>MNEMONIC_KEYPAD4</td> | |
847 * <td>[keypad4]</td> | |
848 * </tr> | |
849 * <tr> | |
850 * <td>MNEMONIC_KEYPAD5</td> | |
851 * <td>[keypad5]</td> | |
852 * </tr> | |
853 * <tr> | |
854 * <td>MNEMONIC_KEYPAD6</td> | |
855 * <td>[keypad6]</td> | |
856 * </tr> | |
857 * <tr> | |
858 * <td>MNEMONIC_KEYPAD7</td> | |
859 * <td>[keypad7]</td> | |
860 * </tr> | |
861 * <tr> | |
862 * <td>MNEMONIC_KEYPAD8</td> | |
863 * <td>[keypad8]</td> | |
864 * </tr> | |
865 * <tr> | |
866 * <td>MNEMONIC_KEYPAD9</td> | |
867 * <td>[keypad9]</td> | |
868 * </tr> | |
869 * <tr> | |
870 * <td>MNEMONIC_KEYPAD_PERIOD</td> | |
871 * <td>[keypad.]</td> | |
872 * </tr> | |
873 * <tr> | |
874 * <td>MNEMONIC_KEYPAD_COMMA</td> | |
875 * <td>[keypad,]</td> | |
876 * </tr> | |
877 * <tr> | |
878 * <td>MNEMONIC_KEYPAD_MINUS</td> | |
879 * <td>[keypad-]</td> | |
880 * </tr> | |
881 * <tr> | |
882 * <td>MNEMONIC_FIELD_EXIT</td> | |
883 * <td>[fldext]</td> | |
884 * </tr> | |
885 * <tr> | |
886 * <td>MNEMONIC_FIELD_PLUS</td> | |
887 * <td>[field+]</td> | |
888 * </tr> | |
889 * <tr> | |
890 * <td>MNEMONIC_FIELD_MINUS</td> | |
891 * <td>[field-]</td> | |
892 * </tr> | |
893 * <tr> | |
894 * <td>MNEMONIC_BEGIN_OF_FIELD</td> | |
895 * <td>[bof]</td> | |
896 * </tr> | |
897 * <tr> | |
898 * <td>MNEMONIC_PA1</td> | |
899 * <td>[pa1]</td> | |
900 * </tr> | |
901 * <tr> | |
902 * <td>MNEMONIC_PA2</td> | |
903 * <td>[pa2]</td> | |
904 * </tr> | |
905 * <tr> | |
906 * <td>MNEMONIC_PA3</td> | |
907 * <td>[pa3]</td> | |
908 * </tr> | |
909 * <tr> | |
910 * <td>MNEMONIC_SYSREQ</td> | |
911 * <td>[sysreq]</td> | |
912 * </tr> | |
913 * <tr> | |
914 * <td>MNEMONIC_RESET</td> | |
915 * <td>[reset]</td> | |
916 * </tr> | |
917 * <tr> | |
918 * <td>MNEMONIC_ATTN</td> | |
919 * <td>[attn]</td> | |
920 * </tr> | |
921 * <tr> | |
922 * <td>MNEMONIC_MARK_LEFT</td> | |
923 * <td>[markleft]</td> | |
924 * </tr> | |
925 * <tr> | |
926 * <td>MNEMONIC_MARK_RIGHT</td> | |
927 * <td>[markright]</td> | |
928 * </tr> | |
929 * <tr> | |
930 * <td>MNEMONIC_MARK_UP</td> | |
931 * <td>[markup]</td> | |
932 * </tr> | |
933 * <tr> | |
934 * <td>MNEMONIC_MARK_DOWN</td> | |
935 * <td>[markdown]</td> | |
936 * </tr> | |
937 * | |
938 * </table> | |
939 * | |
940 * @param text | |
941 * The string of characters to be sent | |
942 * | |
943 * @see #sendAid | |
944 * | |
945 * Added synchronized to fix a StringOutOfBounds error - Luc Gorren LDC | |
946 */ | |
947 public synchronized void sendKeys(String text) { | |
948 | |
949 // if (text == null) { | |
950 // return; | |
951 // } | |
952 this.keybuf.append(text); | |
953 | |
954 if (isStatusErrorCode() && !resetRequired) { | |
955 setCursorActive(false); | |
956 simulateMnemonic(getMnemonicValue("[reset]")); | |
957 setCursorActive(true); | |
958 } | |
959 | |
960 if (oia.isKeyBoardLocked()) { | |
961 if (text.equals("[reset]") || text.equals("[sysreq]") | |
962 || text.equals("[attn]")) { | |
963 setCursorActive(false); | |
964 simulateMnemonic(getMnemonicValue(text)); | |
965 setCursorActive(true); | |
966 | |
967 } else { | |
968 if (isStatusErrorCode()) { | |
969 sessionVT.signalBell(); | |
970 return; | |
971 } | |
972 | |
973 oia.setKeysBuffered(true); | |
974 | |
975 if (bufferedKeys == null) { | |
976 bufferedKeys = text; | |
977 return; | |
978 } | |
979 bufferedKeys += text; | |
980 return; | |
981 } | |
982 | |
983 } else { | |
984 | |
985 if (oia.isKeysBuffered()) { | |
986 if (bufferedKeys != null) { | |
987 text = bufferedKeys + text; | |
988 } | |
989 // if (text.length() == 0) { | |
990 oia.setKeysBuffered(false); | |
991 // } | |
992 bufferedKeys = null; | |
993 | |
994 } | |
995 // check to see if position is in a field and if it is then change | |
996 // current field to that field | |
997 isInField(lastPos, true); | |
998 if (text.length() == 1 && !text.equals("[") && !text.equals("]")) { | |
999 // setCursorOff2(); | |
1000 setCursorActive(false); | |
1001 simulateKeyStroke(text.charAt(0)); | |
1002 setCursorActive(true); | |
1003 // setCursorOn2(); | |
1004 // System.out.println(" text one"); | |
1005 | |
1006 } else { | |
1007 | |
1008 strokenizer.setKeyStrokes(text); | |
1009 String s; | |
1010 boolean done = false; | |
1011 | |
1012 // setCursorOff2(); | |
1013 setCursorActive(false); | |
1014 while (!done) { | |
1015 // while (strokenizer.hasMoreKeyStrokes() && !keyboardLocked | |
1016 // && | |
1017 // !isStatusErrorCode() && !done) { | |
1018 if (strokenizer.hasMoreKeyStrokes()) { | |
1019 | |
1020 // check to see if position is in a field and if it is | |
1021 // then change | |
1022 // current field to that field | |
1023 isInField(lastPos, true); | |
1024 s = strokenizer.nextKeyStroke(); | |
1025 if (s.length() == 1) { | |
1026 // setCursorOn(); | |
1027 // if (!keysBuffered) { | |
1028 // System.out.println(" s two" + s); | |
1029 // setCursorOn(); | |
1030 // } | |
1031 | |
1032 // try { new Thread().sleep(400);} catch | |
1033 // (InterruptedException ie) {} | |
1034 simulateKeyStroke(s.charAt(0)); | |
1035 // System.out.println(" s two " + s + " " + | |
1036 // cursorActive); | |
1037 // if (cursorActive && !keysBuffered) { | |
1038 // System.out.println(" s two" + s); | |
1039 // setCursorOn(); | |
1040 // } | |
1041 } else { | |
1042 simulateMnemonic(getMnemonicValue(s)); | |
1043 // if (!cursorActive && !keysBuffered) { | |
1044 // System.out.println(" m one"); | |
1045 // setCursorOn(); | |
1046 // } | |
1047 } | |
1048 | |
1049 if (oia.isKeyBoardLocked()) { | |
1050 | |
1051 bufferedKeys = strokenizer | |
1052 .getUnprocessedKeyStroked(); | |
1053 if (bufferedKeys != null) { | |
1054 oia.setKeysBuffered(true); | |
1055 | |
1056 } | |
1057 done = true; | |
1058 } | |
1059 | |
1060 } | |
1061 | |
1062 else { | |
1063 // setCursorActive(true); | |
1064 // setCursorOn(); | |
1065 done = true; | |
1066 } | |
1067 } | |
1068 setCursorActive(true); | |
1069 } | |
1070 } | |
1071 } | |
1072 | |
1073 /** | |
1074 * The sendAid method sends an "aid" keystroke to the virtual screen. These | |
1075 * aid keys can be thought of as special keystrokes, like the Enter key, | |
1076 * PF1-24 keys or the Page Up key. All the valid special key values are | |
1077 * contained in the AID_ enumeration: | |
1078 * | |
1079 * @param aidKey | |
1080 * The aid key to be sent to the host | |
1081 * | |
1082 * @see #sendKeys | |
1083 * @see TN5250jConstants#AID_CLEAR | |
1084 * @see #AID_ENTER | |
1085 * @see #AID_HELP | |
1086 * @see #AID_ROLL_UP | |
1087 * @see #AID_ROLL_DOWN | |
1088 * @see #AID_ROLL_LEFT | |
1089 * @see #AID_ROLL_RIGHT | |
1090 * @see #AID_PRINT | |
1091 * @see #AID_PF1 | |
1092 * @see #AID_PF2 | |
1093 * @see #AID_PF3 | |
1094 * @see #AID_PF4 | |
1095 * @see #AID_PF5 | |
1096 * @see #AID_PF6 | |
1097 * @see #AID_PF7 | |
1098 * @see #AID_PF8 | |
1099 * @see #AID_PF9 | |
1100 * @see #AID_PF10 | |
1101 * @see #AID_PF11 | |
1102 * @see #AID_PF12 | |
1103 * @see #AID_PF13 | |
1104 * @see #AID_PF14 | |
1105 * @see #AID_PF15 | |
1106 * @see #AID_PF16 | |
1107 * @see #AID_PF17 | |
1108 * @see #AID_PF18 | |
1109 * @see #AID_PF19 | |
1110 * @see #AID_PF20 | |
1111 * @see #AID_PF21 | |
1112 * @see #AID_PF22 | |
1113 * @see #AID_PF23 | |
1114 * @see #AID_PF24 | |
1115 */ | |
1116 public void sendAid(int aidKey) { | |
1117 | |
1118 sessionVT.sendAidKey(aidKey); | |
1119 } | |
1120 | |
1121 /** | |
1122 * Restores the error line and sets the error mode off. | |
1123 * | |
1124 */ | |
1125 protected void resetError() { | |
1126 | |
1127 restoreErrorLine(); | |
1128 setStatus(STATUS_ERROR_CODE, STATUS_VALUE_OFF, ""); | |
1129 | |
1130 } | |
1131 | |
1132 protected boolean simulateMnemonic(int mnem) { | |
1133 | |
1134 boolean simulated = false; | |
1135 | |
1136 switch (mnem) { | |
1137 | |
1138 case AID_CLEAR: | |
1139 case AID_ENTER: | |
1140 case AID_PF1: | |
1141 case AID_PF2: | |
1142 case AID_PF3: | |
1143 case AID_PF4: | |
1144 case AID_PF5: | |
1145 case AID_PF6: | |
1146 case AID_PF7: | |
1147 case AID_PF8: | |
1148 case AID_PF9: | |
1149 case AID_PF10: | |
1150 case AID_PF11: | |
1151 case AID_PF12: | |
1152 case AID_PF13: | |
1153 case AID_PF14: | |
1154 case AID_PF15: | |
1155 case AID_PF16: | |
1156 case AID_PF17: | |
1157 case AID_PF18: | |
1158 case AID_PF19: | |
1159 case AID_PF20: | |
1160 case AID_PF21: | |
1161 case AID_PF22: | |
1162 case AID_PF23: | |
1163 case AID_PF24: | |
1164 case AID_ROLL_DOWN: | |
1165 case AID_ROLL_UP: | |
1166 case AID_ROLL_LEFT: | |
1167 case AID_ROLL_RIGHT: | |
1168 | |
1169 if (!screenFields.isCanSendAid()) { | |
1170 displayError(ERR_ENTER_NO_ALLOWED); | |
1171 } else | |
1172 sendAid(mnem); | |
1173 simulated = true; | |
1174 | |
1175 break; | |
1176 case AID_HELP: | |
1177 sessionVT.sendHelpRequest(); | |
1178 simulated = true; | |
1179 break; | |
1180 | |
1181 case AID_PRINT: | |
1182 sessionVT.hostPrint(1); | |
1183 simulated = true; | |
1184 break; | |
1185 | |
1186 case BACK_SPACE: | |
1187 if (screenFields.getCurrentField() != null | |
1188 && screenFields.withinCurrentField(lastPos) | |
1189 && !screenFields.isCurrentFieldBypassField()) { | |
1190 | |
1191 if (screenFields.getCurrentField().startPos() == lastPos) { | |
1192 if (backspaceError) | |
1193 displayError(ERR_CURSOR_PROTECTED); | |
1194 else { | |
1195 gotoFieldPrev(); | |
1196 goto_XY(screenFields.getCurrentField().endPos()); | |
1197 updateDirty(); | |
1198 } | |
1199 } | |
1200 else { | |
1201 screenFields.getCurrentField().getKeyPos(lastPos); | |
1202 screenFields.getCurrentField().changePos(-1); | |
1203 resetDirty(screenFields.getCurrentField().getCurrentPos()); | |
1204 shiftLeft(screenFields.getCurrentField().getCurrentPos()); | |
1205 updateDirty(); | |
1206 screenFields.setCurrentFieldMDT(); | |
1207 | |
1208 simulated = true; | |
1209 } | |
1210 } else { | |
1211 displayError(ERR_CURSOR_PROTECTED); | |
1212 | |
1213 } | |
1214 break; | |
1215 case BACK_TAB: | |
1216 | |
1217 if (screenFields.getCurrentField() != null | |
1218 && screenFields.isCurrentFieldHighlightedEntry()) { | |
1219 resetDirty(screenFields.getCurrentField().startPos); | |
1220 gotoFieldPrev(); | |
1221 updateDirty(); | |
1222 } else | |
1223 gotoFieldPrev(); | |
1224 | |
1225 if (screenFields.isCurrentFieldContinued()) { | |
1226 do { | |
1227 gotoFieldPrev(); | |
1228 } while (screenFields.isCurrentFieldContinuedMiddle() | |
1229 || screenFields.isCurrentFieldContinuedLast()); | |
1230 } | |
1231 isInField(lastPos); | |
1232 simulated = true; | |
1233 break; | |
1234 case UP: | |
1235 case MARK_UP: | |
1236 process_XY(lastPos - numCols); | |
1237 simulated = true; | |
1238 break; | |
1239 case DOWN: | |
1240 case MARK_DOWN: | |
1241 process_XY(lastPos + numCols); | |
1242 simulated = true; | |
1243 break; | |
1244 case LEFT: | |
1245 case MARK_LEFT: | |
1246 process_XY(lastPos - 1); | |
1247 simulated = true; | |
1248 break; | |
1249 case RIGHT: | |
1250 case MARK_RIGHT: | |
1251 process_XY(lastPos + 1); | |
1252 simulated = true; | |
1253 break; | |
1254 case NEXTWORD: | |
1255 gotoNextWord(); | |
1256 simulated = true; | |
1257 break; | |
1258 case PREVWORD: | |
1259 gotoPrevWord(); | |
1260 simulated = true; | |
1261 break; | |
1262 case DELETE: | |
1263 if (screenFields.getCurrentField() != null | |
1264 && screenFields.withinCurrentField(lastPos) | |
1265 && !screenFields.isCurrentFieldBypassField()) { | |
1266 | |
1267 resetDirty(lastPos); | |
1268 screenFields.getCurrentField().getKeyPos(lastPos); | |
1269 shiftLeft(screenFields.getCurrentFieldPos()); | |
1270 screenFields.setCurrentFieldMDT(); | |
1271 updateDirty(); | |
1272 simulated = true; | |
1273 } else { | |
1274 displayError(ERR_CURSOR_PROTECTED); | |
1275 } | |
1276 | |
1277 break; | |
1278 case TAB: | |
1279 | |
1280 if (screenFields.getCurrentField() != null | |
1281 && !screenFields.isCurrentFieldContinued()) { | |
1282 if (screenFields.isCurrentFieldHighlightedEntry()) { | |
1283 resetDirty(screenFields.getCurrentField().startPos); | |
1284 gotoFieldNext(); | |
1285 updateDirty(); | |
1286 } else | |
1287 gotoFieldNext(); | |
1288 } else { | |
1289 do { | |
1290 gotoFieldNext(); | |
1291 } while (screenFields.getCurrentField() != null | |
1292 && (screenFields.isCurrentFieldContinuedMiddle() || screenFields | |
1293 .isCurrentFieldContinuedLast())); | |
1294 } | |
1295 | |
1296 isInField(lastPos); | |
1297 simulated = true; | |
1298 | |
1299 break; | |
1300 case EOF: | |
1301 if (screenFields.getCurrentField() != null | |
1302 && screenFields.withinCurrentField(lastPos) | |
1303 && !screenFields.isCurrentFieldBypassField()) { | |
1304 int where = endOfField(screenFields.getCurrentField() | |
1305 .startPos(), true); | |
1306 if (where > 0) { | |
1307 setCursor((where / numCols) + 1, (where % numCols) + 1); | |
1308 } | |
1309 simulated = true; | |
1310 } else { | |
1311 displayError(ERR_CURSOR_PROTECTED); | |
1312 } | |
1313 resetDirty(lastPos); | |
1314 | |
1315 break; | |
1316 case ERASE_EOF: | |
1317 if (screenFields.getCurrentField() != null | |
1318 && screenFields.withinCurrentField(lastPos) | |
1319 && !screenFields.isCurrentFieldBypassField()) { | |
1320 | |
1321 int where = lastPos; | |
1322 resetDirty(lastPos); | |
1323 if (fieldExit()) { | |
1324 screenFields.setCurrentFieldMDT(); | |
1325 if (!screenFields.isCurrentFieldContinued()) { | |
1326 gotoFieldNext(); | |
1327 } else { | |
1328 do { | |
1329 gotoFieldNext(); | |
1330 if (screenFields.isCurrentFieldContinued()) | |
1331 fieldExit(); | |
1332 } while (screenFields.isCurrentFieldContinuedMiddle() | |
1333 || screenFields.isCurrentFieldContinuedLast()); | |
1334 } | |
1335 } | |
1336 updateDirty(); | |
1337 goto_XY(where); | |
1338 simulated = true; | |
1339 | |
1340 } else { | |
1341 displayError(ERR_CURSOR_PROTECTED); | |
1342 } | |
1343 | |
1344 break; | |
1345 case ERASE_FIELD: | |
1346 if (screenFields.getCurrentField() != null | |
1347 && screenFields.withinCurrentField(lastPos) | |
1348 && !screenFields.isCurrentFieldBypassField()) { | |
1349 | |
1350 int where = lastPos; | |
1351 lastPos = screenFields.getCurrentField().startPos(); | |
1352 resetDirty(lastPos); | |
1353 if (fieldExit()) { | |
1354 screenFields.setCurrentFieldMDT(); | |
1355 if (!screenFields.isCurrentFieldContinued()) { | |
1356 gotoFieldNext(); | |
1357 } else { | |
1358 do { | |
1359 gotoFieldNext(); | |
1360 if (screenFields.isCurrentFieldContinued()) | |
1361 fieldExit(); | |
1362 } while (screenFields.isCurrentFieldContinuedMiddle() | |
1363 || screenFields.isCurrentFieldContinuedLast()); | |
1364 } | |
1365 } | |
1366 updateDirty(); | |
1367 goto_XY(where); | |
1368 simulated = true; | |
1369 | |
1370 } else { | |
1371 displayError(ERR_CURSOR_PROTECTED); | |
1372 } | |
1373 | |
1374 break; | |
1375 case INSERT: | |
1376 // we toggle it | |
1377 oia.setInsertMode(oia.isInsertMode() ? false : true); | |
1378 break; | |
1379 case HOME: | |
1380 // position to the home position set | |
1381 if (lastPos + numCols + 1 != homePos) { | |
1382 goto_XY(homePos - numCols - 1); | |
1383 // now check if we are in a field | |
1384 isInField(lastPos); | |
1385 } else | |
1386 gotoField(1); | |
1387 break; | |
1388 case KEYPAD_0: | |
1389 simulated = simulateKeyStroke('0'); | |
1390 break; | |
1391 case KEYPAD_1: | |
1392 simulated = simulateKeyStroke('1'); | |
1393 break; | |
1394 case KEYPAD_2: | |
1395 simulated = simulateKeyStroke('2'); | |
1396 break; | |
1397 case KEYPAD_3: | |
1398 simulated = simulateKeyStroke('3'); | |
1399 break; | |
1400 case KEYPAD_4: | |
1401 simulated = simulateKeyStroke('4'); | |
1402 break; | |
1403 case KEYPAD_5: | |
1404 simulated = simulateKeyStroke('5'); | |
1405 break; | |
1406 case KEYPAD_6: | |
1407 simulated = simulateKeyStroke('6'); | |
1408 break; | |
1409 case KEYPAD_7: | |
1410 simulated = simulateKeyStroke('7'); | |
1411 break; | |
1412 case KEYPAD_8: | |
1413 simulated = simulateKeyStroke('8'); | |
1414 break; | |
1415 case KEYPAD_9: | |
1416 simulated = simulateKeyStroke('9'); | |
1417 break; | |
1418 case KEYPAD_PERIOD: | |
1419 simulated = simulateKeyStroke('.'); | |
1420 break; | |
1421 case KEYPAD_COMMA: | |
1422 simulated = simulateKeyStroke(','); | |
1423 break; | |
1424 case KEYPAD_MINUS: | |
1425 if (screenFields.getCurrentField() != null | |
1426 && screenFields.withinCurrentField(lastPos) | |
1427 && !screenFields.isCurrentFieldBypassField()) { | |
1428 | |
1429 int s = screenFields.getCurrentField().getFieldShift(); | |
1430 if (s == 3 || s == 5 || s == 7) { | |
1431 planes.setChar(lastPos,'-'); | |
1432 | |
1433 resetDirty(lastPos); | |
1434 advancePos(); | |
1435 if (fieldExit()) { | |
1436 screenFields.setCurrentFieldMDT(); | |
1437 if (!screenFields.isCurrentFieldContinued()) { | |
1438 gotoFieldNext(); | |
1439 } else { | |
1440 do { | |
1441 gotoFieldNext(); | |
1442 } while (screenFields | |
1443 .isCurrentFieldContinuedMiddle() | |
1444 || screenFields | |
1445 .isCurrentFieldContinuedLast()); | |
1446 } | |
1447 simulated = true; | |
1448 updateDirty(); | |
1449 if (screenFields.isCurrentFieldAutoEnter()) | |
1450 sendAid(AID_ENTER); | |
1451 | |
1452 } | |
1453 } else { | |
1454 displayError(ERR_FIELD_MINUS); | |
1455 | |
1456 } | |
1457 } else { | |
1458 displayError(ERR_CURSOR_PROTECTED); | |
1459 } | |
1460 | |
1461 break; | |
1462 case FIELD_EXIT: | |
1463 if (screenFields.getCurrentField() != null | |
1464 && screenFields.withinCurrentField(lastPos) | |
1465 && !screenFields.isCurrentFieldBypassField()) { | |
1466 | |
1467 resetDirty(lastPos); | |
1468 | |
1469 boolean autoFE = screenFields.isCurrentFieldAutoEnter(); | |
1470 | |
1471 if (fieldExit()) { | |
1472 screenFields.setCurrentFieldMDT(); | |
1473 if (!screenFields.isCurrentFieldContinued() && | |
1474 !screenFields.isCurrentFieldAutoEnter()) { | |
1475 gotoFieldNext(); | |
1476 } else { | |
1477 do { | |
1478 gotoFieldNext(); | |
1479 if (screenFields.isCurrentFieldContinued()) | |
1480 fieldExit(); | |
1481 } while (screenFields.isCurrentFieldContinuedMiddle() | |
1482 || screenFields.isCurrentFieldContinuedLast()); | |
1483 } | |
1484 } | |
1485 | |
1486 updateDirty(); | |
1487 simulated = true; | |
1488 if (autoFE) | |
1489 sendAid(AID_ENTER); | |
1490 | |
1491 } else { | |
1492 displayError(ERR_CURSOR_PROTECTED); | |
1493 } | |
1494 | |
1495 break; | |
1496 case FIELD_PLUS: | |
1497 if (screenFields.getCurrentField() != null | |
1498 && screenFields.withinCurrentField(lastPos) | |
1499 && !screenFields.isCurrentFieldBypassField()) { | |
1500 | |
1501 resetDirty(lastPos); | |
1502 | |
1503 boolean autoFE = screenFields.isCurrentFieldAutoEnter(); | |
1504 if (fieldExit()) { | |
1505 screenFields.setCurrentFieldMDT(); | |
1506 if (!screenFields.isCurrentFieldContinued() && | |
1507 !screenFields.isCurrentFieldAutoEnter()) { | |
1508 gotoFieldNext(); | |
1509 } else { | |
1510 do { | |
1511 gotoFieldNext(); | |
1512 } while (screenFields.isCurrentFieldContinuedMiddle() | |
1513 || screenFields.isCurrentFieldContinuedLast()); | |
1514 } | |
1515 } | |
1516 updateDirty(); | |
1517 simulated = true; | |
1518 | |
1519 if (autoFE) | |
1520 sendAid(AID_ENTER); | |
1521 | |
1522 } else { | |
1523 displayError(ERR_CURSOR_PROTECTED); | |
1524 } | |
1525 | |
1526 break; | |
1527 case FIELD_MINUS: | |
1528 if (screenFields.getCurrentField() != null | |
1529 && screenFields.withinCurrentField(lastPos) | |
1530 && !screenFields.isCurrentFieldBypassField()) { | |
1531 | |
1532 int s = screenFields.getCurrentField().getFieldShift(); | |
1533 if (s == 3 || s == 5 || s == 7) { | |
1534 planes.setChar(lastPos, '-'); | |
1535 | |
1536 resetDirty(lastPos); | |
1537 advancePos(); | |
1538 | |
1539 boolean autoFE = screenFields.isCurrentFieldAutoEnter(); | |
1540 | |
1541 if (fieldExit()) { | |
1542 screenFields.setCurrentFieldMDT(); | |
1543 if (!screenFields.isCurrentFieldContinued() | |
1544 && !screenFields.isCurrentFieldAutoEnter()) { | |
1545 gotoFieldNext(); | |
1546 } | |
1547 else { | |
1548 do { | |
1549 gotoFieldNext(); | |
1550 } | |
1551 while (screenFields.isCurrentFieldContinuedMiddle() | |
1552 || screenFields.isCurrentFieldContinuedLast()); | |
1553 } | |
1554 } | |
1555 updateDirty(); | |
1556 simulated = true; | |
1557 if (autoFE) | |
1558 sendAid(AID_ENTER); | |
1559 | |
1560 } | |
1561 else { | |
1562 displayError(ERR_FIELD_MINUS); | |
1563 | |
1564 } | |
1565 } | |
1566 else { | |
1567 displayError(ERR_CURSOR_PROTECTED); | |
1568 } | |
1569 | |
1570 break; | |
1571 case BOF: | |
1572 if (screenFields.getCurrentField() != null | |
1573 && screenFields.withinCurrentField(lastPos) | |
1574 && !screenFields.isCurrentFieldBypassField()) { | |
1575 int where = screenFields.getCurrentField().startPos(); | |
1576 if (where > 0) { | |
1577 goto_XY(where); | |
1578 } | |
1579 simulated = true; | |
1580 } else { | |
1581 displayError(ERR_CURSOR_PROTECTED); | |
1582 } | |
1583 resetDirty(lastPos); | |
1584 | |
1585 break; | |
1586 case SYSREQ: | |
1587 sessionVT.systemRequest(); | |
1588 simulated = true; | |
1589 break; | |
1590 case RESET: | |
1591 if (isStatusErrorCode()) { | |
1592 resetError(); | |
1593 isInField(lastPos); | |
1594 updateDirty(); | |
1595 } else { | |
1596 setPrehelpState(false, oia.isKeyBoardLocked(), false); | |
1597 } | |
1598 simulated = true; | |
1599 break; | |
1600 case ATTN: | |
1601 sessionVT.sendAttentionKey(); | |
1602 simulated = true; | |
1603 break; | |
1604 case DUP_FIELD: | |
1605 if (screenFields.getCurrentField() != null | |
1606 && screenFields.withinCurrentField(lastPos) | |
1607 && !screenFields.isCurrentFieldBypassField()) { | |
1608 | |
1609 if (screenFields.isCurrentFieldDupEnabled()) { | |
1610 resetDirty(lastPos); | |
1611 screenFields.getCurrentField().setFieldChar(lastPos, | |
1612 (char) 0x1C); | |
1613 screenFields.setCurrentFieldMDT(); | |
1614 gotoFieldNext(); | |
1615 updateDirty(); | |
1616 simulated = true; | |
1617 } else { | |
1618 displayError(ERR_DUP_KEY_NOT_ALLOWED); | |
1619 } | |
1620 } else { | |
1621 displayError(ERR_CURSOR_PROTECTED); | |
1622 } | |
1623 | |
1624 break; | |
1625 case NEW_LINE: | |
1626 if (screenFields.getSize() > 0) { | |
1627 int startRow = getRow(lastPos) + 1; | |
1628 int startPos = lastPos; | |
1629 | |
1630 if (startRow == getRows()) | |
1631 startRow = 0; | |
1632 | |
1633 setCursor(++startRow, 1); | |
1634 | |
1635 if (!isInField() && screenFields.getCurrentField() != null | |
1636 && !screenFields.isCurrentFieldBypassField()) { | |
1637 while (!isInField() | |
1638 && screenFields.getCurrentField() != null | |
1639 && !screenFields.isCurrentFieldBypassField()) { | |
1640 | |
1641 // lets keep going | |
1642 advancePos(); | |
1643 | |
1644 // Have we looped the screen? | |
1645 if (lastPos == startPos) { | |
1646 // if so then go back to starting point | |
1647 goto_XY(startPos); | |
1648 break; | |
1649 } | |
1650 } | |
1651 } | |
1652 } | |
1653 simulated = true; | |
1654 break; | |
1655 case FAST_CURSOR_DOWN: | |
1656 int rowNow = (getCurrentRow()-1) + 3; | |
1657 if (rowNow > getRows()-1) | |
1658 rowNow = rowNow - getRows(); | |
1659 this.goto_XY(getPos(rowNow,getCurrentCol()-1)); | |
1660 simulated = true; | |
1661 break; | |
1662 case FAST_CURSOR_UP: | |
1663 rowNow = (getCurrentRow()-1) - 3; | |
1664 if (rowNow < 0) | |
1665 rowNow = (getRows()) + rowNow; | |
1666 this.goto_XY(getPos(rowNow,getCurrentCol()-1)); | |
1667 simulated = true; | |
1668 break; | |
1669 case FAST_CURSOR_LEFT: | |
1670 int colNow = (getCurrentCol()-1) - 3; | |
1671 rowNow = getCurrentRow()-1; | |
1672 if (colNow <= 0) { | |
1673 colNow = getColumns() + colNow; | |
1674 rowNow--; | |
1675 } | |
1676 if (rowNow < 0) | |
1677 rowNow = getRows() - 1; | |
1678 | |
1679 process_XY(getPos(rowNow,colNow)); | |
1680 simulated = true; | |
1681 break; | |
1682 case FAST_CURSOR_RIGHT: | |
1683 colNow = (getCurrentCol()-1) + 3; | |
1684 rowNow = getCurrentRow()-1; | |
1685 if (colNow >= getColumns()) { | |
1686 colNow = colNow - getColumns(); | |
1687 rowNow++; | |
1688 } | |
1689 if (rowNow > getRows() - 1) | |
1690 rowNow = getRows() - rowNow; | |
1691 | |
1692 process_XY(getPos(rowNow,colNow)); | |
1693 simulated = true; | |
1694 break; | |
1695 default: | |
25
5949eb469a79
adding tn5250 files, native android logging
Carl Byington <carl@five-ten-sg.com>
parents:
10
diff
changeset
|
1696 Log.i(TAG," Mnemonic not supported " + mnem); |
3 | 1697 break; |
1698 | |
1699 } | |
1700 | |
1701 return simulated; | |
1702 } | |
1703 | |
1704 protected boolean simulateKeyStroke(char c) { | |
1705 | |
1706 if (isStatusErrorCode() && !Character.isISOControl(c) && !keyProcessed) { | |
1707 if (resetRequired) return false; | |
1708 resetError(); | |
1709 } | |
1710 | |
1711 boolean updateField = false; | |
1712 boolean numericError = false; | |
1713 boolean updatePos = false; | |
1714 boolean autoEnter = false; | |
1715 | |
1716 if (!Character.isISOControl(c)) { | |
1717 | |
1718 if (screenFields.getCurrentField() != null | |
1719 && screenFields.withinCurrentField(lastPos) | |
1720 && !screenFields.isCurrentFieldBypassField()) { | |
1721 | |
1722 if (screenFields.isCurrentFieldFER() | |
1723 && !screenFields.withinCurrentField(screenFields | |
1724 .getCurrentFieldPos()) | |
1725 && lastPos == screenFields.getCurrentField().endPos() | |
1726 && screenFields.getCurrentFieldPos() > screenFields | |
1727 .getCurrentField().endPos()) { | |
1728 | |
1729 displayError(ERR_FIELD_EXIT_INVALID); | |
1730 feError = true; | |
1731 return false; | |
1732 } | |
1733 | |
1734 switch (screenFields.getCurrentFieldShift()) { | |
1735 case 0: // Alpha shift | |
1736 case 2: // Numeric Shift | |
1737 case 4: // Kakana Shift | |
1738 updateField = true; | |
1739 break; | |
1740 case 1: // Alpha Only | |
1741 if (Character.isLetter(c) || c == ',' || c == '-' | |
1742 || c == '.' || c == ' ') | |
1743 updateField = true; | |
1744 break; | |
1745 case 3: // Numeric only | |
1746 if (Character.isDigit(c) || c == '+' || c == ',' | |
1747 || c == '-' || c == '.' || c == ' ') | |
1748 updateField = true; | |
1749 else | |
1750 numericError = true; | |
1751 break; | |
1752 case 5: // Digits only | |
1753 if (Character.isDigit(c)) | |
1754 updateField = true; | |
1755 else | |
1756 displayError(ERR_NUMERIC_09); | |
1757 break; | |
1758 case 7: // Signed numeric | |
1759 if (Character.isDigit(c) || c == '+' || c == '-') | |
1760 if (lastPos == screenFields.getCurrentField().endPos() | |
1761 && (c != '+' && c != '-')) | |
1762 displayError(ERR_INVALID_SIGN); | |
1763 else | |
1764 updateField = true; | |
1765 else | |
1766 displayError(ERR_NUMERIC_09); | |
1767 break; | |
1768 } | |
1769 | |
1770 if (updateField) { | |
1771 if (screenFields.isCurrentFieldToUpper()) | |
1772 c = Character.toUpperCase(c); | |
1773 | |
1774 updatePos = true; | |
1775 resetDirty(lastPos); | |
1776 | |
1777 if (oia.isInsertMode()) { | |
1778 if (endOfField(false) != screenFields.getCurrentField() | |
1779 .endPos()) | |
1780 shiftRight(lastPos); | |
1781 else { | |
1782 | |
1783 displayError(ERR_NO_ROOM_INSERT); | |
1784 updatePos = false; | |
1785 } | |
1786 | |
1787 } | |
1788 | |
1789 if (updatePos) { | |
1790 screenFields.getCurrentField().getKeyPos( | |
1791 getRow(lastPos), getCol(lastPos)); | |
1792 screenFields.getCurrentField().changePos(1); | |
1793 | |
1794 planes.setChar(lastPos,c); | |
1795 | |
1796 screenFields.setCurrentFieldMDT(); | |
1797 | |
1798 // if we have gone passed the end of the field then goto | |
1799 // the next field | |
1800 if (!screenFields.withinCurrentField(screenFields | |
1801 .getCurrentFieldPos())) { | |
1802 if (screenFields.isCurrentFieldAutoEnter()) { | |
1803 autoEnter = true; | |
1804 } else if (!screenFields.isCurrentFieldFER()) | |
1805 gotoFieldNext(); | |
1806 else { | |
1807 // screenFields.getCurrentField().changePos(1); | |
1808 // | |
1809 // if (screenFields. | |
1810 // cursorPos == endPos) | |
1811 // System.out.println("end of field"); | |
1812 // | |
1813 // feError != feError; | |
1814 // if (feError) | |
1815 // displayError(ERR_FIELD_EXIT_INVALID); | |
1816 } | |
1817 | |
1818 } else | |
1819 setCursor(screenFields.getCurrentField() | |
1820 .getCursorRow() + 1, screenFields | |
1821 .getCurrentField().getCursorCol() + 1); | |
1822 | |
1823 } | |
1824 | |
1825 fireScreenChanged(1); | |
1826 | |
1827 if (autoEnter) | |
1828 sendAid(AID_ENTER); | |
1829 } else { | |
1830 if (numericError) { | |
1831 displayError(ERR_NUMERIC_ONLY); | |
1832 } | |
1833 } | |
1834 } else { | |
1835 displayError(ERR_CURSOR_PROTECTED); | |
1836 } | |
1837 | |
1838 } | |
1839 return updatePos; | |
1840 } | |
1841 | |
1842 /** | |
1843 * Method: endOfField | |
1844 * <p> | |
1845 * | |
1846 * convenience method that call endOfField with lastRow lastCol and passes | |
1847 * the posSpace to that method | |
1848 * | |
1849 * @param posSpace | |
1850 * value of type boolean - specifying to return the position of | |
1851 * the the last space or not | |
1852 * @return a value of type int - the screen postion (row * columns) + col | |
1853 * | |
1854 */ | |
1855 private int endOfField(boolean posSpace) { | |
1856 return endOfField(lastPos, posSpace); | |
1857 } | |
1858 | |
1859 /** | |
1860 * Method: endOfField | |
1861 * <p> | |
1862 * | |
1863 * gets the position of the last character of the current field posSpace | |
1864 * parameter tells the routine whether to return the position of the last | |
1865 * space ( <= ' ') or the last non space posSpace == true last occurrence of | |
1866 * char <= ' ' posSpace == false last occurrence of char > ' ' | |
1867 * | |
1868 * @param pos | |
1869 * value of type int - position to start from | |
1870 * @param posSpace | |
1871 * value of type boolean - specifying to return the position of | |
1872 * the the last space or not | |
1873 * @return a value of type int - the screen postion (row * columns) + col | |
1874 * | |
1875 */ | |
1876 private int endOfField(int pos, boolean posSpace) { | |
1877 | |
1878 int endPos = screenFields.getCurrentField().endPos(); | |
1879 int fePos = endPos; | |
1880 // get the number of characters to the right | |
1881 int count = endPos - pos; | |
1882 | |
1883 // first lets get the real ending point without spaces and the such | |
1884 while (planes.getChar(endPos) <= ' ' && count-- > 0) { | |
1885 | |
1886 endPos--; | |
1887 } | |
1888 | |
1889 if (endPos == fePos) { | |
1890 | |
1891 return endPos; | |
1892 | |
7 | 1893 } |
3 | 1894 screenFields.getCurrentField().getKeyPos(endPos); |
1895 if (posSpace) screenFields.getCurrentField().changePos(+1); | |
1896 return screenFields.getCurrentFieldPos(); | |
1897 | |
1898 } | |
1899 | |
1900 private boolean fieldExit() { | |
1901 | |
1902 int pos = lastPos; | |
1903 boolean mdt = false; | |
1904 int end = endOfField(false); // get the ending position of the first | |
1905 // non blank character in field | |
1906 | |
1907 ScreenField sf = screenFields.getCurrentField(); | |
1908 | |
1909 if (sf.isMandatoryEnter() && end == sf.startPos()) { | |
1910 displayError(ERR_MANDITORY_ENTER); | |
1911 return false; | |
1912 } | |
1913 | |
1914 // save off the current pos of the field for checking field exit required | |
1915 // positioning. the getKeyPos resets this information so it is useless | |
1916 // for comparing if we are positioned passed the end of field. | |
1917 // Maybe this should be changed to not update the current cursor position | |
1918 // of the field. | |
1919 int currentPos = sf.getCurrentPos(); | |
1920 | |
1921 // get the number of characters to the right | |
1922 int count = (end - sf.startPos()) - sf.getKeyPos(pos); | |
1923 | |
1924 if (count == 0 && sf.isFER()) { | |
1925 if (currentPos > sf.endPos()) { | |
1926 mdt = true; | |
1927 return mdt; | |
1928 } | |
1929 } | |
1930 | |
1931 for (; count >= 0; count--) { | |
1932 planes.setChar(pos, initChar); | |
1933 setDirty(pos); | |
1934 pos++; | |
1935 mdt = true; | |
1936 } | |
1937 | |
1938 // This checks for a field minus because a field minus places | |
1939 // a negative sign and then advances a position. If it is the | |
1940 // end of the field where the minus is placed then this offset will | |
1941 // place the count as -1. | |
1942 if (count == -1) { | |
1943 int s = sf.getFieldShift(); | |
1944 if (s == 3 || s == 5 || s == 7) { | |
1945 mdt = true; | |
1946 } | |
1947 } | |
1948 | |
1949 int adj = sf.getAdjustment(); | |
1950 | |
1951 if (adj != 0) { | |
1952 | |
1953 switch (adj) { | |
1954 | |
1955 case 5: | |
1956 rightAdjustField('0'); | |
1957 sf.setRightAdjusted(); | |
1958 break; | |
1959 case 6: | |
1960 rightAdjustField(' '); | |
1961 sf.setRightAdjusted(); | |
1962 | |
1963 break; | |
1964 case 7: | |
1965 sf.setManditoryEntered(); | |
1966 break; | |
1967 | |
1968 } | |
1969 } | |
1970 else { | |
1971 | |
1972 // we need to right adjust signed numeric fields as well. | |
1973 if (sf.isSignedNumeric()) { | |
1974 rightAdjustField(' '); | |
1975 } | |
1976 } | |
1977 | |
1978 return mdt; | |
1979 } | |
1980 | |
1981 private void rightAdjustField(char fill) { | |
1982 | |
1983 int end = endOfField(false); // get the ending position of the first | |
1984 // non blank character in field | |
1985 | |
1986 // get the number of characters to the right | |
1987 int count = screenFields.getCurrentField().endPos() - end; | |
1988 | |
1989 // subtract 1 from count for signed numeric - note for later | |
1990 if (screenFields.getCurrentField().isSignedNumeric()) { | |
1991 if (planes.getChar(end -1) != '-') | |
1992 count--; | |
1993 } | |
1994 | |
1995 int pos = screenFields.getCurrentField().startPos(); | |
1996 | |
1997 while (count-- >= 0) { | |
1998 | |
1999 shiftRight(pos); | |
2000 planes.setChar(pos,fill); | |
2001 | |
2002 setDirty(pos); | |
2003 | |
2004 } | |
2005 | |
2006 } | |
2007 | |
2008 private void shiftLeft(int sPos) { | |
2009 | |
2010 int endPos = 0; | |
2011 | |
2012 int pos = sPos; | |
2013 int pPos = sPos; | |
2014 | |
2015 ScreenField sf = screenFields.getCurrentField(); | |
2016 int end; | |
2017 int count; | |
2018 do { | |
2019 end = endOfField(pPos, false); // get the ending position of the | |
2020 // first | |
2021 // non blank character in field | |
2022 | |
2023 count = (end - screenFields.getCurrentField().startPos()) | |
2024 - screenFields.getCurrentField().getKeyPos(pPos); | |
2025 | |
2026 // now we loop through and shift the remaining characters to the | |
2027 // left | |
2028 while (count-- > 0) { | |
2029 pos++; | |
2030 planes.setChar(pPos,planes.getChar(pos)); | |
2031 setDirty(pPos); | |
2032 pPos = pos; | |
2033 | |
2034 } | |
2035 | |
2036 if (screenFields.isCurrentFieldContinued()) { | |
2037 gotoFieldNext(); | |
2038 if (screenFields.getCurrentField().isContinuedFirst()) | |
2039 break; | |
2040 | |
2041 pos = screenFields.getCurrentField().startPos(); | |
2042 planes.setChar(pPos,planes.getChar(pos)); | |
2043 setDirty(pPos); | |
2044 | |
2045 pPos = pos; | |
2046 | |
2047 } | |
2048 } while (screenFields.isCurrentFieldContinued() | |
2049 && !screenFields.getCurrentField().isContinuedFirst()); | |
2050 | |
2051 if (end >= 0 && count >= -1) { | |
2052 | |
2053 endPos = end; | |
2054 } else { | |
2055 endPos = sPos; | |
2056 | |
2057 } | |
2058 | |
2059 screenFields.setCurrentField(sf); | |
2060 planes.setChar(endPos,initChar); | |
2061 setDirty(endPos); | |
2062 goto_XY(screenFields.getCurrentFieldPos()); | |
2063 sf = null; | |
2064 | |
2065 } | |
2066 | |
2067 private void shiftRight(int sPos) { | |
2068 | |
2069 int end = endOfField(true); // get the ending position of the first | |
2070 // non blank character in field | |
2071 int pos = end; | |
2072 int pPos = end; | |
2073 | |
2074 int count = end - sPos; | |
2075 | |
2076 // now we loop through and shift the remaining characters to the right | |
2077 while (count-- > 0) { | |
2078 | |
2079 pos--; | |
2080 planes.setChar(pPos, planes.getChar(pos)); | |
2081 setDirty(pPos); | |
2082 | |
2083 pPos = pos; | |
2084 } | |
2085 } | |
2086 | |
2087 public int getRow(int pos) { | |
2088 | |
2089 // if (pos == 0) | |
2090 // return 1; | |
2091 | |
2092 int row = pos / numCols; | |
2093 | |
2094 if (row < 0) { | |
2095 | |
2096 row = lastPos / numCols; | |
2097 } | |
2098 if (row > (lenScreen / numCols) - 1) | |
2099 row = (lenScreen / numCols) - 1; | |
2100 | |
2101 return row; | |
2102 | |
2103 } | |
2104 | |
2105 public int getCol(int pos) { | |
2106 int col = pos % (getColumns()); | |
2107 if (col > 0) return col; | |
2108 return 0; | |
2109 } | |
2110 | |
2111 /** | |
2112 * This routine is 0 based offset. So to get row 20,1 then pass row 19,0 | |
2113 * | |
2114 * @param row | |
2115 * @param col | |
2116 * @return | |
2117 */ | |
2118 public int getPos(int row, int col) { | |
2119 | |
2120 return (row * numCols) + col; | |
2121 } | |
2122 | |
2123 /** | |
2124 * Current position is based on offsets of 1,1 not 0,0 of the current | |
2125 * position of the screen | |
2126 * | |
2127 * @return int | |
2128 */ | |
2129 public int getCurrentPos() { | |
2130 | |
2131 // return lastPos + numCols + 1; | |
2132 return lastPos + 1; | |
2133 | |
2134 } | |
2135 | |
2136 /** | |
2137 * I got this information from a tcp trace of each error. I could not find | |
2138 * any documenation for this. Maybe there is but I could not find it. If | |
2139 * anybody finds this documention could you please send me a copy. Please | |
2140 * note that I did not look that hard either. | |
2141 * <p> | |
2142 * 0000: 00 50 73 1D 89 81 00 50 DA 44 C8 45 08 00 45 00 .Ps....P.D.E..E. | |
2143 * </p> | |
2144 * <p> | |
2145 * 0010: 00 36 E9 1C 40 00 80 06 9B F9 C1 A8 33 58 C0 A8 .6..@...k....3X.. | |
2146 * </p> | |
2147 * <p> | |
2148 * 0020: C0 02 06 0E 00 17 00 52 6E 88 73 40 DE CB 50 18 .......Rn.s@..P. | |
2149 * </p> | |
2150 * <p> | |
2151 * 0030: 20 12 3C 53 00 00 00 0C 12 A0 00 00 04 01 00 00 . <S............ | |
2152 * </p> | |
2153 * <p> | |
2154 * 0040: 00 05 FF EF .... ----------|| The 00 XX is the code to be sent. I | |
2155 * found the following <table BORDER COLS=2 WIDTH="50%" > | |
2156 * <tr> | |
2157 * <td>ERR_CURSOR_PROTECTED</td> | |
2158 * <td>0x05</td> | |
2159 * </tr> | |
2160 * <tr> | |
2161 * <td>ERR_INVALID_SIGN</td> | |
2162 * <td>0x11</td> | |
2163 * </tr> | |
2164 * <tr> | |
2165 * <td>ERR_NO_ROOM_INSERT</td> | |
2166 * <td>0x12</td> | |
2167 * </tr> | |
2168 * <tr> | |
2169 * <td>ERR_NUMERIC_ONLY</td> | |
2170 * <td>0x09</td> | |
2171 * </tr> | |
2172 * <tr> | |
2173 * <td>ERR_NUMERIC_09</td> | |
2174 * <td>0x10</td> | |
2175 * </tr> | |
2176 * <tr> | |
2177 * <td>ERR_FIELD_MINUS</td> | |
2178 * <td>0x16</td> | |
2179 * </tr> | |
2180 * <tr> | |
2181 * <td>ERR_ENTER_NOT_ALLOWED</td> | |
2182 * <td>0x20</td> | |
2183 * </tr> | |
2184 * <tr> | |
2185 * <td>ERR_MANDITORY_ENTER</td> | |
2186 * <td>0x21</td> | |
2187 * </tr> | |
2188 * <tr> | |
2189 * <td>ERR_ENTER_NOT_ALLOWED</td> | |
2190 * <td>0x20</td> | |
2191 * </tr> | |
2192 * </table> I am tired of typing and they should be self explanitory. Finding | |
2193 * them in the first place was the pain. | |
2194 * </p> | |
2195 * | |
2196 * @param ec error code | |
2197 */ | |
2198 private void displayError(int ec) { | |
2199 saveHomePos = homePos; | |
2200 homePos = lastPos + numCols + 1; | |
2201 pendingInsert = true; | |
2202 sessionVT.sendNegResponse2(ec); | |
2203 | |
2204 } | |
2205 | |
2206 private void process_XY(int pos) { | |
2207 | |
2208 if (pos < 0) | |
2209 pos = lenScreen + pos; | |
2210 if (pos > lenScreen - 1) | |
2211 pos = pos - lenScreen; | |
2212 | |
2213 // if there was a field exit error then we need to treat the movement | |
2214 // of the cursor in a special way that equals that of Client Access. | |
2215 // If the cursor is moved from the field then we need to reset the | |
2216 // position within the field so that the last character can be typed | |
2217 // over again instead of sending the field exit error again. | |
2218 // We also need to reset the field exit error flag. | |
2219 // | |
2220 // How we know we have a field exit error is when the field position is | |
2221 // set beyond the end of the field and a character is then typed we can | |
2222 // not position that character. To reset this we need to set the next | |
2223 // position of the field to not be beyond the end of field but to the | |
2224 // last character. | |
2225 // | |
2226 // Now to make it work like Client Access if the cursor is a back space | |
2227 // then do not move the cursor but place it on the last field. All | |
2228 // other keys will reset the field position so that entering over the | |
2229 // last character will not cause an error but replace that character or | |
2230 // just plain move the cursor if the key was to do that. | |
2231 | |
2232 ScreenField sf = screenFields.getCurrentField(); | |
2233 if (feError) { | |
2234 feError = false; | |
2235 sf.changePos(-1); | |
2236 } else { | |
2237 if (sf != null&& sf.isFER()){ | |
2238 if ((sf.getCurrentPos() | |
2239 > sf.endPos())) { | |
2240 if (sf.withinField(pos)) { | |
2241 sf.getKeyPos(pos); | |
2242 return; | |
2243 } | |
2244 sf.getKeyPos(sf.endPos()); | |
2245 } | |
2246 } | |
2247 | |
2248 goto_XY(pos); | |
2249 } | |
2250 } | |
2251 | |
2252 public boolean isUsingGuiInterface() { | |
2253 | |
2254 return guiInterface; | |
2255 } | |
2256 | |
2257 /** | |
2258 * Convinience class to return if the cursor is in a field or not. | |
2259 * | |
2260 * @return true or false | |
2261 */ | |
2262 | |
2263 protected boolean isInField() { | |
2264 | |
2265 return isInField(lastPos, true); | |
2266 } | |
2267 | |
2268 /** | |
2269 * | |
2270 * Convinience class to return if the position that is passed is in a field | |
2271 * or not. If it is then the chgToField parameter will change the current | |
2272 * field to this field where the position indicates | |
2273 * | |
2274 * @param pos | |
2275 * @param chgToField | |
2276 * @return true or false | |
2277 */ | |
2278 public boolean isInField(int pos, boolean chgToField) { | |
2279 | |
2280 return screenFields.isInField(pos, chgToField); | |
2281 } | |
2282 | |
2283 /** | |
2284 * | |
2285 * Convinience class to return if the position that is passed is in a field | |
2286 * or not. If it is then the field at this position becomes the current | |
2287 * working field | |
2288 * | |
2289 * @param pos | |
2290 * @return true or false | |
2291 */ | |
2292 public boolean isInField(int pos) { | |
2293 | |
2294 return screenFields.isInField(pos, true); | |
2295 } | |
2296 | |
2297 /** | |
2298 * Convinience class to return if the position at row and column that is | |
2299 * passed is in a field or not. If it is then the field at this position | |
2300 * becomes the current working field. | |
2301 * | |
2302 * @param row | |
2303 * @param col | |
2304 * @return true or false | |
2305 */ | |
2306 public boolean isInField(int row, int col) { | |
2307 | |
2308 return isInField(row, col, true); | |
2309 } | |
2310 | |
2311 /** | |
2312 * | |
2313 * Convinience class to return if the position at row and column that is | |
2314 * passed is in a field or not. If it is then the chgToField parameter will | |
2315 * change the current field to this field where the row and column | |
2316 * indicates. | |
2317 * | |
2318 * @param row | |
2319 * @param col | |
2320 * @param chgToField | |
2321 * @return true or false | |
2322 */ | |
2323 public boolean isInField(int row, int col, boolean chgToField) { | |
2324 return screenFields.isInField((row * numCols) + col, chgToField); | |
2325 } | |
2326 | |
2327 /** | |
2328 * Gets the length of the screen - number of rows times number of columns | |
2329 * | |
2330 * @return int value of screen length | |
2331 */ | |
2332 public int getScreenLength() { | |
2333 | |
2334 return lenScreen; | |
2335 } | |
2336 | |
2337 /** | |
2338 * Get the number or rows available. | |
2339 * | |
2340 * @return number of rows | |
2341 */ | |
2342 public int getRows() { | |
2343 | |
2344 return numRows; | |
2345 | |
2346 } | |
2347 | |
2348 /** | |
2349 * Get the number of columns available. | |
2350 * | |
2351 * @return number of columns | |
2352 */ | |
2353 public int getColumns() { | |
2354 | |
2355 return numCols; | |
2356 | |
2357 } | |
2358 | |
2359 /** | |
2360 * Get the current row where the cursor is | |
2361 * | |
2362 * @return the cursor current row position 1,1 based | |
2363 */ | |
2364 public int getCurrentRow() { | |
2365 | |
2366 return (lastPos / numCols) + 1; | |
2367 | |
2368 } | |
2369 | |
2370 /** | |
2371 * Get the current column where the cursor is | |
2372 * | |
2373 * @return the cursor current column position 1,1 based | |
2374 */ | |
2375 public int getCurrentCol() { | |
2376 | |
2377 return (lastPos % numCols) + 1; | |
2378 | |
2379 } | |
2380 | |
2381 /** | |
2382 * The last position of the cursor on the screen - Note - position is based | |
2383 * 0,0 | |
2384 * | |
2385 * @return last position | |
2386 */ | |
2387 protected int getLastPos() { | |
2388 | |
2389 return lastPos; | |
2390 | |
2391 } | |
2392 | |
2393 /** | |
2394 * Hotspot More... string | |
2395 * | |
2396 * @return string literal of More... | |
2397 */ | |
2398 public StringBuffer getHSMore() { | |
2399 return hsMore; | |
2400 } | |
2401 | |
2402 /** | |
2403 * Hotspot Bottom string | |
2404 * | |
2405 * @return string literal of Bottom | |
2406 */ | |
2407 public StringBuffer getHSBottom() { | |
2408 return hsBottom; | |
2409 } | |
2410 | |
2411 /** | |
2412 * Return the whole screen represented as a character array | |
2413 * | |
2414 * @return character array containing the text | |
2415 * | |
2416 * Added by Luc - LDC | |
2417 * | |
2418 * Note to KJP - Have to ask what the difference is between this method and | |
2419 * the other | |
2420 */ | |
2421 public char[] getScreenAsAllChars() { | |
2422 char[] sac = new char[lenScreen]; | |
2423 char c; | |
2424 | |
2425 for (int x = 0; x < lenScreen; x++) { | |
2426 c = planes.getChar(x); | |
2427 // only draw printable characters (in this case >= ' ') | |
2428 if ((c >= ' ') && (!planes.isAttributePlace(x))) { | |
2429 sac[x] = c; | |
2430 // TODO: implement the underline check here | |
2431 // if (screen[x].underLine && c <= ' ') | |
2432 // sac[x] = '_'; | |
2433 } else | |
2434 sac[x] = ' '; | |
2435 } | |
2436 | |
2437 return sac; | |
2438 } | |
2439 | |
2440 /** | |
2441 * | |
2442 * Return the screen represented as a character array | |
2443 * | |
2444 * @return character array containing the text | |
2445 */ | |
2446 public char[] getScreenAsChars() { | |
2447 char[] sac = new char[lenScreen]; | |
2448 char c; | |
2449 | |
2450 for (int x = 0; x < lenScreen; x++) { | |
2451 c = planes.getChar(x); | |
2452 // only draw printable characters (in this case >= ' ') | |
2453 if ((c >= ' ') && (!planes.isAttributePlace(x))) { | |
2454 sac[x] = c; | |
2455 // TODO: implement the underline check here | |
2456 // if (screen[x].underLine && c <= ' ') | |
2457 // sac[x] = '_'; | |
2458 } else | |
2459 sac[x] = ' '; | |
2460 } | |
2461 | |
2462 return sac; | |
2463 } | |
2464 | |
2465 public char[] getData(int startRow, int startCol, int endRow, int endCol, int plane) { | |
2466 try { | |
2467 int from = getPos(startRow,startCol); | |
2468 int to = getPos(endRow,endCol); | |
2469 if (from > to) { | |
2470 | |
2471 int f = from; | |
2472 to = f; | |
2473 from = f; | |
2474 } | |
2475 return planes.getPlaneData(from,to,plane); | |
2476 } | |
2477 catch (Exception oe) { | |
2478 return null; | |
2479 } | |
2480 | |
2481 } | |
2482 | |
2483 /** | |
2484 * <p> | |
2485 * GetScreen retrieves the various planes associated with the presentation | |
2486 * space. The data is returned as a linear array of character values in the | |
2487 * array provided. The array is not terminated by a null character except | |
2488 * when data is retrieved from the text plane, in which case a single null | |
2489 * character is appended. | |
2490 * </p> | |
2491 * <p> | |
2492 * The application must supply a buffer for the returned data and the length | |
2493 * of the buffer. Data is returned starting from the beginning of the | |
2494 * presentation space and continuing until the buffer is full or the entire | |
2495 * plane has been copied. For text plane data, the buffer must include one | |
2496 * extra position for the terminating null character. | |
2497 * <p> | |
2498 * | |
2499 * @param buffer | |
2500 * @param bufferLength | |
2501 * @param plane | |
2502 * @return The number of characters copied to the buffer | |
2503 * @throws OhioException | |
2504 */ | |
2505 public synchronized int GetScreen(char buffer[], int bufferLength, int plane) | |
2506 // throws OhioException { | |
2507 { | |
2508 return GetScreen(buffer,bufferLength,0,lenScreen,plane); | |
2509 | |
2510 } | |
2511 | |
2512 /** | |
2513 * <p> | |
2514 * GetScreen retrieves the various planes associated with the presentation | |
2515 * space. The data is returned as a linear array of character values in the | |
2516 * array provided. The array is not terminated by a null character except | |
2517 * when data is retrieved from the text plane, in which case a single null | |
2518 * character is appended. | |
2519 * </p> | |
2520 * <p> | |
2521 * The application must supply a buffer for the returned data and the length | |
2522 * of the buffer. Data is returned starting from the given position and | |
2523 * continuing until the specified number of characters have been copied, the | |
2524 * buffer is full or the entire plane has been copied. For text plane data, | |
2525 * the buffer must include one extra position for the terminating null character. | |
2526 * </p> | |
2527 * | |
2528 * @param buffer | |
2529 * @param bufferLength | |
2530 * @param from | |
2531 * @param length | |
2532 * @param plane | |
2533 * @return The number of characters copied to the buffer | |
2534 * @throws OhioException | |
2535 */ | |
2536 public synchronized int GetScreen(char buffer[], int bufferLength, int from, | |
2537 int length, int plane) | |
2538 // throws OhioException { | |
2539 { | |
2540 | |
2541 return planes.GetScreen(buffer,bufferLength, from, length, plane); | |
2542 } | |
2543 | |
2544 /** | |
2545 * <p> | |
2546 * GetScreen retrieves the various planes associated with the presentation | |
2547 * space. The data is returned as a linear array of character values in the | |
2548 * array provided. The array is not terminated by a null character except | |
2549 * when data is retrieved from the text plane, in which case a single null | |
2550 * character is appended. | |
2551 * </p> | |
2552 * <p> | |
2553 * The application must supply a buffer for the returned data and the length | |
2554 * of the buffer. Data is returned starting from the given coordinates and | |
2555 * continuing until the specified number of characters have been copied, | |
2556 * the buffer is full, or the entire plane has been copied. For text plane | |
2557 * data, the buffer must include one extra position for the terminating null | |
2558 * character. | |
2559 * </p> | |
2560 * | |
2561 * @param buffer | |
2562 * @param bufferLength | |
2563 * @param row | |
2564 * @param col | |
2565 * @param length | |
2566 * @param plane | |
2567 * @return The number of characters copied to the buffer. | |
2568 * @throws OhioException | |
2569 */ | |
2570 public synchronized int GetScreen(char buffer[], int bufferLength, int row, | |
2571 int col, int length, int plane) | |
2572 // throws OhioException { | |
2573 { | |
2574 // Call GetScreen function after converting row and column to | |
2575 // a position. | |
2576 return planes.GetScreen(buffer,bufferLength, row, col, length, plane); | |
2577 } | |
2578 | |
2579 /** | |
2580 * <p> | |
2581 * GetScreenRect retrieves data from the various planes associated with the | |
2582 * presentation space. The data is returned as a linear array of character | |
2583 * values in the buffer provided. | |
2584 * </p> | |
2585 * | |
2586 * <p> | |
2587 * The application supplies two positions that represent opposing corners of | |
2588 * a rectangle within the presentation space. The starting and ending | |
2589 * positions can have any spatial relationship to each other. The data | |
2590 * returned starts from the row containing the upper-most point to the row | |
2591 * containing the lower-most point, and from the left-most column to the | |
2592 * right-most column. | |
2593 * </p> | |
2594 * <p> | |
2595 * The specified buffer must be at least large enough to contain the number | |
2596 * of characters in the rectangle. If the buffer is too small, no data is | |
2597 * copied and zero is returned by the method. Otherwise, the method returns | |
2598 * the number of characters copied. | |
2599 * </p> | |
2600 * | |
2601 * @param buffer | |
2602 * @param bufferLength | |
2603 * @param startPos | |
2604 * @param endPos | |
2605 * @param plane | |
2606 * @return The number of characters copied to the buffer | |
2607 * @throws OhioException | |
2608 */ | |
2609 public synchronized int GetScreenRect(char buffer[], int bufferLength, | |
2610 int startPos, int endPos, int plane) | |
2611 // throws OhioException { | |
2612 { | |
2613 return planes.GetScreenRect(buffer, bufferLength, startPos, endPos, plane); | |
2614 | |
2615 } | |
2616 | |
2617 /** | |
2618 * <p> | |
2619 * GetScreenRect retrieves data from the various planes associated with the | |
2620 * presentation space. The data is returned as a linear array of character | |
2621 * values in the buffer provided. The buffer is not terminated by a null | |
2622 * character. | |
2623 * </p> | |
2624 * <p> | |
2625 * The application supplies two coordinates that represent opposing corners | |
2626 * of a rectangle within the presentation space. The starting and ending | |
2627 * coordinates can have any spatial relationship to each other. The data | |
2628 * returned starts from the row containing the upper-most point to the row | |
2629 * containing the lower-most point, and from the left-most column to the | |
2630 * right-most column. | |
2631 * </p> | |
2632 * <p> | |
2633 * The specified buffer must be at least large enough to contain the number | |
2634 * of characters in the rectangle. If the buffer is too small, no data is | |
2635 * copied and zero is returned by the method. Otherwise, the method returns | |
2636 * the number of characters copied. | |
2637 * </p> | |
2638 * | |
2639 * @param buffer | |
2640 * @param bufferLength | |
2641 * @param startRow | |
2642 * @param startCol | |
2643 * @param endRow | |
2644 * @param endCol | |
2645 * @param plane | |
2646 * @return The number characters copied to the buffer | |
2647 * @throws OhioException | |
2648 */ | |
2649 public synchronized int GetScreenRect(char buffer[], int bufferLength, | |
2650 int startRow, int startCol, | |
2651 int endRow, int endCol, int plane) | |
2652 // throws OhioException { | |
2653 { | |
2654 | |
2655 return planes.GetScreenRect(buffer, bufferLength, startRow, startCol, endRow, | |
2656 endCol, plane); | |
2657 } | |
2658 | |
2659 public synchronized boolean[] getActiveAidKeys() { | |
2660 return sessionVT.getActiveAidKeys(); | |
2661 } | |
2662 | |
2663 protected synchronized void setScreenData(String text, int location) { | |
2664 // throws OhioException { | |
2665 | |
2666 if (location < 0 || location > lenScreen) { | |
2667 return; | |
2668 // throw new OhioException(sessionVT.getSessionConfiguration(), | |
2669 // OhioScreen5250.class.getName(), "osohio.screen.ohio00300", 1); | |
2670 } | |
2671 | |
2672 int pos = location; | |
2673 | |
2674 int l = text.length(); | |
2675 boolean updated = false; | |
2676 boolean flag = false; | |
2677 int x =0; | |
2678 for (; x < l; x++) { | |
2679 if (isInField(pos + x,true)) { | |
2680 if (!screenFields.getCurrentField().isBypassField()) { | |
2681 if (!flag) { | |
2682 screenFields.getCurrentField().setMDT(); | |
2683 updated = true; | |
2684 resetDirty(pos + x); | |
2685 screenFields.setMasterMDT(); | |
2686 flag = true; | |
2687 } | |
2688 | |
2689 planes.screen[pos + x] = text.charAt(x); | |
2690 setDirty(pos + x); | |
2691 } | |
2692 } | |
2693 | |
2694 } | |
2695 lastPos = pos + x; | |
2696 if (updated) { | |
2697 fireScreenChanged(1); | |
2698 } | |
2699 | |
2700 } | |
2701 | |
2702 /** | |
2703 * This routine is based on offset 1,1 not 0,0 it will translate to offset | |
2704 * 0,0 and call the goto_XY(int pos) it is mostly used from external classes | |
2705 * that use the 1,1 offset | |
2706 * | |
2707 * @param row | |
2708 * @param col | |
2709 */ | |
2710 public void setCursor(int row, int col) { | |
2711 goto_XY(((row - 1) * numCols) + (col - 1)); | |
2712 } | |
2713 | |
2714 // this routine is based on offset 0,0 not 1,1 | |
2715 protected void goto_XY(int pos) { | |
2716 // setCursorOff(); | |
2717 updateCursorLoc(); | |
2718 lastPos = pos; | |
2719 // setCursorOn(); | |
2720 updateCursorLoc(); | |
2721 } | |
2722 | |
2723 /** | |
2724 * Set the current working field to the field number specified. | |
2725 * | |
2726 * @param f - | |
2727 * numeric field number on the screen | |
2728 * @return true or false whether it was sucessful | |
2729 */ | |
2730 public boolean gotoField(int f) { | |
2731 | |
2732 int sizeFields = screenFields.getSize(); | |
2733 | |
2734 if (f > sizeFields || f <= 0) | |
2735 return false; | |
2736 | |
2737 screenFields.setCurrentField(screenFields.getField(f - 1)); | |
2738 | |
2739 while (screenFields.isCurrentFieldBypassField() && f < sizeFields) { | |
2740 | |
2741 screenFields.setCurrentField(screenFields.getField(f++)); | |
2742 | |
2743 } | |
2744 return gotoField(screenFields.getCurrentField()); | |
2745 } | |
2746 | |
2747 /** | |
2748 * Convenience method to set the field object passed as the currect working | |
2749 * screen field | |
2750 * | |
2751 * @param f | |
2752 * @return true or false whether it was sucessful | |
2753 * @see org.tn5250j.ScreenField | |
2754 */ | |
2755 protected boolean gotoField(ScreenField f) { | |
2756 if (f != null) { | |
2757 goto_XY(f.startPos()); | |
2758 return true; | |
2759 } | |
2760 return false; | |
2761 } | |
2762 | |
2763 /** | |
2764 * Convenience class to position the cursor to the next word on the screen | |
2765 * | |
2766 */ | |
2767 private void gotoNextWord() { | |
2768 | |
2769 int pos = lastPos; | |
2770 | |
2771 if (planes.getChar(lastPos) > ' ') { | |
2772 advancePos(); | |
2773 // get the next space character | |
2774 while (planes.getChar(lastPos) > ' ' && pos != lastPos) { | |
2775 advancePos(); | |
2776 } | |
2777 } else | |
2778 advancePos(); | |
2779 | |
2780 // now that we are positioned on the next space character get the | |
2781 // next none space character | |
2782 while (planes.getChar(lastPos) <= ' ' && pos != lastPos) { | |
2783 advancePos(); | |
2784 } | |
2785 | |
2786 } | |
2787 | |
2788 /** | |
2789 * Convenience class to position the cursor to the previous word on the | |
2790 * screen | |
2791 * | |
2792 */ | |
2793 private void gotoPrevWord() { | |
2794 | |
2795 int pos = lastPos; | |
2796 | |
2797 changePos(-1); | |
2798 | |
2799 // position previous white space character | |
2800 while (planes.getChar(lastPos) <= ' ') { | |
2801 changePos(-1); | |
2802 if (pos == lastPos) | |
2803 break; | |
2804 } | |
2805 | |
2806 changePos(-1); | |
2807 // get the previous space character | |
2808 while (planes.getChar(lastPos) > ' ' && pos != lastPos) { | |
2809 changePos(-1); | |
2810 } | |
2811 | |
2812 // and position one position more should give us the beginning of word | |
2813 advancePos(); | |
2814 | |
2815 } | |
2816 | |
2817 /** | |
2818 * Convinience class to position to the next field on the screen. | |
2819 * | |
2820 * @see org.tn5250j.ScreenFields | |
2821 */ | |
2822 private void gotoFieldNext() { | |
2823 | |
2824 if (screenFields.isCurrentFieldHighlightedEntry()) | |
2825 unsetFieldHighlighted(screenFields.getCurrentField()); | |
2826 | |
2827 screenFields.gotoFieldNext(); | |
2828 | |
2829 if (screenFields.isCurrentFieldHighlightedEntry()) | |
2830 setFieldHighlighted(screenFields.getCurrentField()); | |
2831 } | |
2832 | |
2833 /** | |
2834 * Convinience class to position to the previous field on the screen. | |
2835 * | |
2836 * @see org.tn5250j.ScreenFields | |
2837 */ | |
2838 private void gotoFieldPrev() { | |
2839 | |
2840 if (screenFields.isCurrentFieldHighlightedEntry()) | |
2841 unsetFieldHighlighted(screenFields.getCurrentField()); | |
2842 | |
2843 screenFields.gotoFieldPrev(); | |
2844 | |
2845 if (screenFields.isCurrentFieldHighlightedEntry()) | |
2846 setFieldHighlighted(screenFields.getCurrentField()); | |
2847 | |
2848 } | |
2849 | |
2850 /* *** NEVER USED LOCALLY ************************************************** */ | |
2851 // /** | |
2852 // * Used to restrict the cursor to a particular position on the screen. Used | |
2853 // * in combination with windows to restrict the cursor to the active window | |
2854 // * show on the screen. | |
2855 // * | |
2856 // * Not supported yet. Please implement me :-( | |
2857 // * | |
2858 // * @param depth | |
2859 // * @param width | |
2860 // */ | |
2861 // protected void setRestrictCursor(int depth, int width) { | |
2862 // | |
2863 // restrictCursor = true; | |
2864 // // restriction | |
2865 // | |
2866 // } | |
2867 | |
2868 /** | |
2869 * Creates a window on the screen | |
2870 * | |
2871 * @param depth | |
2872 * @param width | |
2873 * @param type | |
2874 * @param gui | |
2875 * @param monoAttr | |
2876 * @param colorAttr | |
2877 * @param ul | |
2878 * @param upper | |
2879 * @param ur | |
2880 * @param left | |
2881 * @param right | |
2882 * @param ll | |
2883 * @param bottom | |
2884 * @param lr | |
2885 */ | |
2886 protected void createWindow(int depth, int width, int type, boolean gui, | |
2887 int monoAttr, int colorAttr, int ul, int upper, int ur, int left, | |
2888 int right, int ll, int bottom, int lr) { | |
2889 | |
2890 int c = getCol(lastPos); | |
2891 int w = 0; | |
2892 width++; | |
2893 | |
2894 w = width; | |
2895 // set leading attribute byte | |
2896 // screen[lastPos].setCharAndAttr(initChar, initAttr, true); | |
2897 planes.setScreenCharAndAttr(lastPos, initChar, initAttr, true); | |
2898 setDirty(lastPos); | |
2899 | |
2900 advancePos(); | |
2901 // set upper left | |
2902 // screen[lastPos].setCharAndAttr((char) ul, colorAttr, false); | |
2903 planes.setScreenCharAndAttr(lastPos, (char) ul, colorAttr, false); | |
2904 if (gui) { | |
2905 // screen[lastPos].setUseGUI(UPPER_LEFT); | |
2906 planes.setUseGUI(lastPos, UPPER_LEFT); | |
2907 } | |
2908 setDirty(lastPos); | |
2909 | |
2910 advancePos(); | |
2911 | |
2912 // draw top row | |
2913 | |
2914 while (w-- >= 0) { | |
2915 // screen[lastPos].setCharAndAttr((char) upper, colorAttr, false); | |
2916 planes.setScreenCharAndAttr(lastPos, (char) upper, colorAttr, false); | |
2917 if (gui) { | |
2918 // screen[lastPos].setUseGUI(UPPER); | |
2919 planes.setUseGUI(lastPos,UPPER); | |
2920 } | |
2921 setDirty(lastPos); | |
2922 advancePos(); | |
2923 } | |
2924 | |
2925 // set upper right | |
2926 // screen[lastPos].setCharAndAttr((char) ur, colorAttr, false); | |
2927 planes.setScreenCharAndAttr(lastPos,(char) ur, colorAttr, false); | |
2928 | |
2929 if (gui) { | |
2930 // screen[lastPos].setUseGUI(UPPER_RIGHT); | |
2931 planes.setUseGUI(lastPos, UPPER_RIGHT); | |
2932 } | |
2933 setDirty(lastPos); | |
2934 advancePos(); | |
2935 | |
2936 // set ending attribute byte | |
2937 planes.setScreenCharAndAttr(lastPos,initChar, initAttr, true); | |
2938 | |
2939 setDirty(lastPos); | |
2940 | |
2941 lastPos = ((getRow(lastPos) + 1) * numCols) + c; | |
2942 | |
2943 // now handle body of window | |
2944 while (depth-- > 0) { | |
2945 | |
2946 // set leading attribute byte | |
2947 planes.setScreenCharAndAttr(lastPos,initChar, initAttr, true); | |
2948 setDirty(lastPos); | |
2949 advancePos(); | |
2950 | |
2951 // set left | |
2952 planes.setScreenCharAndAttr(lastPos, (char) left, colorAttr, false); | |
2953 | |
2954 if (gui) { | |
2955 planes.setUseGUI(lastPos,GUI_LEFT); | |
2956 } | |
2957 setDirty(lastPos); | |
2958 advancePos(); | |
2959 | |
2960 w = width; | |
2961 // fill it in | |
2962 while (w-- >= 0) { | |
2963 // screen[lastPos].setCharAndAttr(initChar, initAttr, true); | |
2964 planes.setScreenCharAndAttr(lastPos,initChar, initAttr, true); | |
2965 // screen[lastPos].setUseGUI(NO_GUI); | |
2966 planes.setUseGUI(lastPos,NO_GUI); | |
2967 setDirty(lastPos); | |
2968 advancePos(); | |
2969 } | |
2970 | |
2971 // set right | |
2972 // screen[lastPos].setCharAndAttr((char) right, colorAttr, false); | |
2973 planes.setScreenCharAndAttr(lastPos,(char) right, colorAttr, false); | |
2974 if (gui) { | |
2975 // screen[lastPos].setUseGUI(RIGHT); | |
2976 planes.setUseGUI(lastPos,GUI_RIGHT); | |
2977 } | |
2978 | |
2979 setDirty(lastPos); | |
2980 advancePos(); | |
2981 | |
2982 // set ending attribute byte | |
2983 // screen[lastPos].setCharAndAttr(initChar, initAttr, true); | |
2984 planes.setScreenCharAndAttr(lastPos,initChar, initAttr, true); | |
2985 setDirty(lastPos); | |
2986 | |
2987 lastPos = ((getRow(lastPos) + 1) * numCols) + c; | |
2988 } | |
2989 | |
2990 // set leading attribute byte | |
2991 // screen[lastPos].setCharAndAttr(initChar, initAttr, true); | |
2992 planes.setScreenCharAndAttr(lastPos,initChar, initAttr, true); | |
2993 setDirty(lastPos); | |
2994 advancePos(); | |
2995 | |
2996 // set lower left | |
2997 // screen[lastPos].setCharAndAttr((char) ll, colorAttr, false); | |
2998 planes.setScreenCharAndAttr(lastPos,(char) ll, colorAttr, false); | |
2999 if (gui) { | |
3000 // screen[lastPos].setUseGUI(LOWER_LEFT); | |
3001 planes.setUseGUI(lastPos,LOWER_LEFT); | |
3002 } | |
3003 setDirty(lastPos); | |
3004 advancePos(); | |
3005 | |
3006 w = width; | |
3007 | |
3008 // draw bottom row | |
3009 while (w-- >= 0) { | |
3010 planes.setScreenCharAndAttr(lastPos,(char) bottom, colorAttr, false); | |
3011 if (gui) { | |
3012 planes.setUseGUI(lastPos,BOTTOM); | |
3013 } | |
3014 setDirty(lastPos); | |
3015 advancePos(); | |
3016 } | |
3017 | |
3018 // set lower right | |
3019 planes.setScreenCharAndAttr(lastPos, (char) lr, colorAttr, false); | |
3020 if (gui) { | |
3021 planes.setUseGUI(lastPos,LOWER_RIGHT); | |
3022 } | |
3023 | |
3024 setDirty(lastPos); | |
3025 advancePos(); | |
3026 | |
3027 // set ending attribute byte | |
3028 planes.setScreenCharAndAttr(lastPos,initChar, initAttr, true); | |
3029 setDirty(lastPos); | |
3030 | |
3031 } | |
3032 | |
3033 /** | |
3034 * Creates a scroll bar on the screen using the parameters provided. | |
3035 * ** we only support vertical scroll bars at the time. | |
3036 * | |
3037 * @param flag - | |
3038 * type to draw - vertical or horizontal | |
3039 * @param totalRowScrollable | |
3040 * @param totalColScrollable | |
3041 * @param sliderRowPos | |
3042 * @param sliderColPos | |
3043 * @param sbSize | |
3044 */ | |
3045 protected void createScrollBar(int flag, int totalRowScrollable, | |
3046 int totalColScrollable, int sliderRowPos, int sliderColPos, | |
3047 int sbSize) { | |
3048 | |
3049 // System.out.println("Scrollbar flag: " + flag + | |
3050 // " scrollable Rows: " + totalRowScrollable + | |
3051 // " scrollable Cols: " + totalColScrollable + | |
3052 // " thumb Row: " + sliderRowPos + | |
3053 // " thumb Col: " + sliderColPos + | |
3054 // " size: " + sbSize + | |
3055 // " row: " + getRow(lastPos) + | |
3056 // " col: " + getCol(lastPos)); | |
3057 | |
3058 int sp = lastPos; | |
3059 int size = sbSize - 2; | |
3060 | |
3061 int thumbPos = (int) (size * ((float) sliderColPos / (float) totalColScrollable)); | |
3062 // System.out.println(thumbPos); | |
3063 planes.setScreenCharAndAttr(sp,' ', 32, false); | |
3064 planes.setUseGUI(sp,BUTTON_SB_UP); | |
3065 | |
3066 int ctr = 0; | |
3067 while (ctr < size) { | |
3068 sp += numCols; | |
3069 planes.setScreenCharAndAttr(sp,' ', 32, false); | |
3070 if (ctr == thumbPos) | |
3071 planes.setUseGUI(sp,BUTTON_SB_THUMB); | |
3072 else | |
3073 planes.setUseGUI(sp, BUTTON_SB_GUIDE); | |
3074 ctr++; | |
3075 } | |
3076 sp += numCols; | |
3077 | |
3078 | |
3079 planes.setScreenCharAndAttr(sp, ' ', 32, false); | |
3080 planes.setUseGUI(sp, BUTTON_SB_DN); | |
3081 } | |
3082 | |
3083 /** | |
3084 * Write the title of the window that is on the screen | |
3085 * | |
3086 * @param pos | |
3087 * @param depth | |
3088 * @param width | |
3089 * @param orientation | |
3090 * @param monoAttr | |
3091 * @param colorAttr | |
3092 * @param title | |
3093 */ | |
3094 protected void writeWindowTitle(int pos, int depth, int width, | |
3095 byte orientation, int monoAttr, int colorAttr, StringBuffer title) { | |
3096 | |
3097 int len = title.length(); | |
3098 | |
3099 // get bit 0 and 1 for interrogation | |
3100 switch (orientation & 0xc0) { | |
3101 case 0x40: // right | |
3102 pos += (4 + width - len); | |
3103 break; | |
3104 case 0x80: // left | |
3105 pos += 2; | |
3106 break; | |
3107 default: // center | |
3108 // this is to place the position to the first text position of the | |
3109 // window | |
3110 // the position passed in is the first attribute position, the next | |
3111 // is the border character and then there is another attribute after | |
3112 // that. | |
3113 pos += (3 + ((width / 2) - (len / 2))); | |
3114 break; | |
3115 | |
3116 } | |
3117 | |
3118 // if bit 2 is on then this is a footer | |
3119 if ((orientation & 0x20) == 0x20) | |
3120 pos += ((depth + 1) * numCols); | |
3121 | |
3122 // System.out.println(pos + "," + width + "," + len+ "," + getRow(pos) | |
3123 // + "," + getCol(pos) + "," + ((orientation >> 6) & 0xf0)); | |
3124 | |
3125 for (int x = 0; x < len; x++) { | |
3126 planes.setChar(pos, title.charAt(x)); | |
3127 planes.setUseGUI(pos++, NO_GUI); | |
3128 | |
3129 } | |
3130 } | |
3131 | |
3132 /** | |
3133 * Roll the screen up or down. | |
3134 * | |
3135 * Byte 1: Bit 0 0 = Roll up 1 = Roll down Bits 1-2 Reserved Bits 3-7 Number | |
3136 * of lines that the designated area is to be rolled Byte 2: Bits 0-7 Line | |
3137 * number defining the top line of the area that will participate in the | |
3138 * roll. Byte 3: Bits 0-7 Line number defining the bottom line of the area | |
3139 * that will participate in the roll. | |
3140 * | |
3141 * @param direction | |
3142 * @param topLine | |
3143 * @param bottomLine | |
3144 */ | |
3145 protected void rollScreen(int direction, int topLine, int bottomLine) { | |
3146 | |
3147 // get the number of lines which are the last 5 bits | |
3148 /* int lines = direction & 0x7F; */ | |
3149 // get the direction of the roll which is the first bit | |
3150 // 0 - up | |
3151 // 1 - down | |
3152 int updown = direction & 0x80; | |
7 | 3153 final int lines = direction & 0x7F; |
3 | 3154 |
3155 // calculate the reference points for the move. | |
3156 int start = this.getPos(topLine - 1, 0); | |
3157 int end = this.getPos(bottomLine - 1, numCols - 1); | |
3158 int len = end - start; | |
3159 | |
3160 // System.out.println(" starting roll"); | |
3161 // dumpScreen(); | |
3162 switch (updown) { | |
3163 case 0: | |
3164 // Now round em up and head em UP. | |
3165 for (int x = start; x < end + numCols; x++) { | |
3166 if (x + lines * numCols >= lenScreen) { | |
3167 //Clear at the end | |
3168 planes.setChar(x, ' '); | |
3169 } else { | |
3170 planes.setChar(x, planes.getChar(x + lines * numCols )); | |
3171 } | |
3172 } | |
3173 break; | |
3174 case 1: | |
3175 // Now round em up and head em DOWN. | |
3176 for (int x = end + numCols; x > 0; x--) { | |
3177 if ((x - lines * numCols ) < 0 ) { | |
3178 //Do nothing ... tooo small!!! | |
3179 } else { | |
3180 planes.setChar(x - lines * numCols, planes.getChar(x)); | |
7 | 3181 //and clear |
3 | 3182 planes.setChar(x, ' '); |
3183 } | |
3184 } | |
3185 break; | |
3186 default: | |
25
5949eb469a79
adding tn5250 files, native android logging
Carl Byington <carl@five-ten-sg.com>
parents:
10
diff
changeset
|
3187 Log.w(TAG," Invalid roll parameter - please report this"); |
3 | 3188 } |
3189 // System.out.println(" end roll"); | |
3190 // dumpScreen(); | |
3191 | |
3192 } | |
3193 | |
3194 public void dumpScreen() { | |
3195 | |
3196 StringBuffer sb = new StringBuffer(); | |
3197 char[] s = getScreenAsChars(); | |
3198 int c = getColumns(); | |
3199 int l = getRows() * c; | |
3200 int col = 0; | |
3201 for (int x = 0; x < l; x++, col++) { | |
3202 sb.append(s[x]); | |
3203 if (col == c) { | |
3204 sb.append('\n'); | |
3205 col = 0; | |
3206 } | |
3207 } | |
25
5949eb469a79
adding tn5250 files, native android logging
Carl Byington <carl@five-ten-sg.com>
parents:
10
diff
changeset
|
3208 Log.i(TAG,sb.toString()); |
3 | 3209 |
3210 } | |
3211 | |
3212 /** | |
3213 * Add a field to the field format table. | |
3214 * | |
3215 * @param attr - Field attribute | |
3216 * @param len - length of field | |
3217 * @param ffw1 - Field format word 1 | |
3218 * @param ffw2 - Field format word 2 | |
3219 * @param fcw1 - Field control word 1 | |
3220 * @param fcw2 - Field control word 2 | |
3221 */ | |
3222 protected void addField(int attr, int len, int ffw1, int ffw2, int fcw1, | |
3223 int fcw2) { | |
3224 | |
3225 lastAttr = attr; | |
3226 | |
3227 planes.setScreenCharAndAttr(lastPos, initChar, lastAttr, true); | |
3228 | |
3229 setDirty(lastPos); | |
3230 | |
3231 advancePos(); | |
3232 | |
3233 ScreenField sf = null; | |
3234 | |
3235 // from 14.6.12 for Start of Field Order 5940 function manual | |
3236 // examine the format table for an entry that begins at the current | |
3237 // starting address plus 1. | |
3238 if (screenFields.existsAtPos(lastPos)) { | |
3239 screenFields.setCurrentFieldFFWs(ffw1, ffw2); | |
3240 } else { | |
3241 sf = screenFields.setField(attr, getRow(lastPos), getCol(lastPos), | |
3242 len, ffw1, ffw2, fcw1, fcw2); | |
3243 lastPos = sf.startPos(); | |
3244 int x = len; | |
3245 | |
3246 boolean gui = guiInterface; | |
3247 if (sf.isBypassField()) | |
3248 gui = false; | |
3249 | |
3250 while (x-- > 0) { | |
3251 | |
3252 if (planes.getChar(lastPos) == 0) | |
3253 planes.setScreenCharAndAttr(lastPos, ' ', lastAttr, false); | |
3254 else | |
3255 planes.setScreenAttr(lastPos,lastAttr); | |
3256 | |
3257 if (gui) { | |
3258 planes.setUseGUI(lastPos,FIELD_MIDDLE); | |
3259 } | |
3260 | |
3261 // now we set the field plane attributes | |
3262 planes.setScreenFieldAttr(lastPos,ffw1); | |
3263 | |
3264 advancePos(); | |
3265 | |
3266 } | |
3267 | |
3268 if (gui) | |
3269 if (len > 1) { | |
3270 planes.setUseGUI(sf.startPos(), FIELD_LEFT); | |
3271 | |
3272 if (lastPos > 0) | |
3273 planes.setUseGUI(lastPos - 1, FIELD_RIGHT); | |
3274 else | |
3275 planes.setUseGUI(lastPos,FIELD_RIGHT); | |
3276 | |
3277 } | |
3278 else { | |
3279 planes.setUseGUI(lastPos - 1,FIELD_ONE); | |
3280 } | |
3281 | |
3282 // screen[lastPos].setCharAndAttr(initChar,initAttr,true); | |
3283 setEndingAttr(initAttr); | |
3284 | |
3285 lastPos = sf.startPos(); | |
3286 } | |
3287 | |
3288 // if (fcw1 != 0 || fcw2 != 0) { | |
3289 | |
3290 // System.out.println("lr = " + lastRow + " lc = " + lastCol + " " + | |
3291 // sf.toString()); | |
3292 // } | |
3293 sf = null; | |
3294 | |
3295 } | |
3296 | |
3297 | |
3298 // public void addChoiceField(int attr, int len, int ffw1, int ffw2, int | |
3299 // fcw1, int fcw2) { | |
3300 // | |
3301 // lastAttr = attr; | |
3302 // | |
3303 // screen[lastPos].setCharAndAttr(initChar,lastAttr,true); | |
3304 // setDirty(lastPos); | |
3305 // | |
3306 // advancePos(); | |
3307 // | |
3308 // boolean found = false; | |
3309 // ScreenField sf = null; | |
3310 // | |
3311 // // from 14.6.12 for Start of Field Order 5940 function manual | |
3312 // // examine the format table for an entry that begins at the current | |
3313 // // starting address plus 1. | |
3314 // for (int x = 0;x < sizeFields; x++) { | |
3315 // sf = screenFields[x]; | |
3316 // | |
3317 // if (lastPos == sf.startPos()) { | |
3318 // screenFields.getCurrentField() = sf; | |
3319 // screenFields.getCurrentField().setFFWs(ffw1,ffw2); | |
3320 // found = true; | |
3321 // } | |
3322 // | |
3323 // } | |
3324 // | |
3325 // if (!found) { | |
3326 // sf = | |
3327 // setField(attr,getRow(lastPos),getCol(lastPos),len,ffw1,ffw2,fcw1,fcw2); | |
3328 // | |
3329 // lastPos = sf.startPos(); | |
3330 // int x = len; | |
3331 // | |
3332 // boolean gui = guiInterface; | |
3333 // if (sf.isBypassField()) | |
3334 // gui = false; | |
3335 // | |
3336 // while (x-- > 0) { | |
3337 // | |
3338 // if (screen[lastPos].getChar() == 0) | |
3339 // screen[lastPos].setCharAndAttr(' ',lastAttr,false); | |
3340 // else | |
3341 // screen[lastPos].setAttribute(lastAttr); | |
3342 // | |
3343 // if (gui) | |
3344 // screen[lastPos].setUseGUI(FIELD_MIDDLE); | |
3345 // | |
3346 // advancePos(); | |
3347 // | |
3348 // } | |
3349 // | |
3350 // if (gui) | |
3351 // if (len > 1) { | |
3352 // screen[sf.startPos()].setUseGUI(FIELD_LEFT); | |
3353 // if (lastPos > 0) | |
3354 // screen[lastPos-1].setUseGUI(FIELD_RIGHT); | |
3355 // else | |
3356 // screen[lastPos].setUseGUI(FIELD_RIGHT); | |
3357 // | |
3358 // } | |
3359 // else | |
3360 // screen[lastPos-1].setUseGUI(FIELD_ONE); | |
3361 // | |
3362 // setEndingAttr(initAttr); | |
3363 // | |
3364 // lastPos = sf.startPos(); | |
3365 // } | |
3366 // | |
3367 // // if (fcw1 != 0 || fcw2 != 0) { | |
3368 // // | |
3369 // // System.out.println("lr = " + lastRow + " lc = " + lastCol + " " + | |
3370 // sf.toString()); | |
3371 // // } | |
3372 // sf = null; | |
3373 // | |
3374 // } | |
3375 | |
3376 /** | |
3377 * Return the fields that are contained in the Field Format Table | |
3378 * | |
3379 * @return ScreenFields object | |
3380 * @see org.tn5250j.ScreenFields | |
3381 */ | |
3382 public ScreenFields getScreenFields() { | |
3383 return screenFields; | |
3384 } | |
3385 | |
3386 /** | |
3387 * Redraw the fields on the screen. Used for gui enhancement to redraw the | |
3388 * fields when toggling | |
3389 * | |
3390 */ | |
3391 protected void drawFields() { | |
3392 | |
3393 ScreenField sf; | |
3394 | |
3395 int sizeFields = screenFields.getSize(); | |
3396 for (int x = 0; x < sizeFields; x++) { | |
3397 | |
3398 sf = screenFields.getField(x); | |
3399 | |
3400 if (!sf.isBypassField()) { | |
3401 int pos = sf.startPos(); | |
3402 | |
3403 int l = sf.length; | |
3404 | |
3405 boolean f = true; | |
3406 | |
3407 if (l >= lenScreen) | |
3408 l = lenScreen - 1; | |
3409 | |
3410 if (l > 1) { | |
3411 while (l-- > 0) { | |
3412 | |
3413 if (guiInterface && f) { | |
3414 planes.setUseGUI(pos,FIELD_LEFT); | |
3415 f = false; | |
3416 } else { | |
3417 | |
3418 planes.setUseGUI(pos,FIELD_MIDDLE); | |
3419 | |
3420 } | |
3421 | |
3422 if (guiInterface && l == 0) { | |
3423 planes.setUseGUI(pos,FIELD_RIGHT); | |
3424 } | |
3425 | |
3426 setDirty(pos++); | |
3427 } | |
3428 } else { | |
3429 planes.setUseGUI(pos,FIELD_ONE); | |
3430 } | |
3431 } | |
3432 } | |
3433 | |
3434 //updateDirty(); | |
3435 } | |
3436 | |
3437 /** | |
3438 * Draws the field on the screen. Used to redraw or change the attributes of | |
3439 * the field. | |
3440 * | |
3441 * @param sf - | |
3442 * Field to be redrawn | |
3443 * @see org.tn5250j.ScreenField.java | |
3444 */ | |
3445 protected void drawField(ScreenField sf) { | |
3446 | |
3447 int pos = sf.startPos(); | |
3448 | |
3449 int x = sf.length; | |
3450 | |
3451 while (x-- > 0) { | |
3452 setDirty(pos++); | |
3453 } | |
3454 | |
3455 updateDirty(); | |
3456 | |
3457 } | |
3458 | |
3459 /** | |
3460 * Set the field to be displayed as highlighted. | |
3461 * | |
3462 * @param sf - | |
3463 * Field to be highlighted | |
3464 */ | |
3465 protected void setFieldHighlighted(ScreenField sf) { | |
3466 | |
3467 int pos = sf.startPos(); | |
3468 | |
3469 int x = sf.length; | |
3470 int na = sf.getHighlightedAttr(); | |
3471 | |
3472 while (x-- > 0) { | |
3473 planes.setScreenAttr(pos,na); | |
3474 setDirty(pos++); | |
3475 } | |
3476 fireScreenChanged(1); | |
3477 | |
3478 } | |
3479 | |
3480 /** | |
3481 * Draw the field as un higlighted. This is used to reset the field | |
3482 * presentation on the screen after the field is exited. | |
3483 * | |
3484 * @param sf - | |
3485 * Field to be unhighlighted | |
3486 */ | |
3487 protected void unsetFieldHighlighted(ScreenField sf) { | |
3488 | |
3489 int pos = sf.startPos(); | |
3490 | |
3491 int x = sf.length; | |
3492 int na = sf.getAttr(); | |
3493 | |
3494 while (x-- > 0) { | |
3495 planes.setScreenAttr(pos,na); | |
3496 setDirty(pos++); | |
3497 } | |
3498 fireScreenChanged(1); | |
3499 | |
3500 } | |
3501 | |
3502 protected void setChar(int cByte) { | |
3503 if (lastPos > 0) { | |
3504 lastAttr = planes.getCharAttr(lastPos - 1); | |
3505 } | |
3506 if (cByte > 0 && (char)cByte < ' ') { | |
3507 planes.setScreenCharAndAttr(lastPos, (char) 0x00, 33, false); | |
3508 setDirty(lastPos); | |
3509 advancePos(); | |
3510 } else { | |
3511 planes.setScreenCharAndAttr(lastPos, (char) cByte, lastAttr, false); | |
3512 setDirty(lastPos); | |
3513 if (guiInterface && !isInField(lastPos, false)) { | |
3514 planes.setUseGUI(lastPos, NO_GUI); | |
3515 } | |
3516 advancePos(); | |
3517 } | |
3518 } | |
3519 | |
3520 protected void setEndingAttr(int cByte) { | |
3521 int attr = lastAttr; | |
3522 setAttr(cByte); | |
3523 lastAttr = attr; | |
3524 } | |
3525 | |
3526 protected void setAttr(int cByte) { | |
3527 lastAttr = cByte; | |
3528 | |
3529 // int sattr = screen[lastPos].getCharAttr(); | |
3530 // System.out.println("changing from " + sattr + " to attr " + lastAttr | |
3531 // + | |
3532 // " at " + (this.getRow(lastPos) + 1) + "," + (this.getCol(lastPos) + | |
3533 // 1)); | |
3534 planes.setScreenCharAndAttr(lastPos, initChar, lastAttr, true); | |
3535 setDirty(lastPos); | |
3536 | |
3537 advancePos(); | |
3538 int pos = lastPos; | |
3539 | |
3540 int times = 0; | |
3541 // sattr = screen[lastPos].getCharAttr(); | |
3542 // System.out.println(" next position after change " + sattr + " last | |
3543 // attr " + lastAttr + | |
3544 // " at " + (this.getRow(lastPos) + 1) + "," + (this.getCol(lastPos) + | |
3545 // 1) + | |
3546 // " attr place " + screen[lastPos].isAttributePlace()); | |
3547 | |
3548 while (planes.getCharAttr(lastPos) != lastAttr | |
3549 && !planes.isAttributePlace(lastPos)) { | |
3550 | |
3551 planes.setScreenAttr(lastPos, lastAttr); | |
3552 if (guiInterface && !isInField(lastPos, false)) { | |
3553 int g = planes.getWhichGUI(lastPos); | |
3554 if (g >= FIELD_LEFT && g <= FIELD_ONE) | |
3555 planes.setUseGUI(lastPos,NO_GUI); | |
3556 } | |
3557 setDirty(lastPos); | |
3558 | |
3559 times++; | |
3560 advancePos(); | |
3561 } | |
3562 | |
3563 // sanity check for right now | |
3564 // if (times > 200) | |
3565 // System.out.println(" setAttr = " + times + " start = " + (sr + 1) + | |
3566 // "," + (sc + 1)); | |
3567 | |
3568 lastPos = pos; | |
3569 } | |
3570 | |
3571 protected void setScreenCharAndAttr(char right, int colorAttr, boolean isAttr) { | |
3572 | |
3573 planes.setScreenCharAndAttr(lastPos,right, colorAttr, isAttr); | |
3574 setDirty(lastPos); | |
3575 advancePos(); | |
3576 | |
3577 } | |
3578 | |
3579 protected void setScreenCharAndAttr(char right, int colorAttr, | |
3580 int whichGui, boolean isAttr) { | |
3581 | |
3582 planes.setScreenCharAndAttr(lastPos,right, colorAttr, isAttr); | |
3583 planes.setUseGUI(lastPos,whichGui); | |
3584 | |
3585 setDirty(lastPos); | |
3586 advancePos(); | |
3587 | |
3588 } | |
3589 | |
3590 /** | |
3591 * Draw or redraw the dirty parts of the screen and display them. | |
3592 * | |
3593 * Rectangle dirty holds the dirty area of the screen to be updated. | |
3594 * | |
3595 * If you want to change the screen in anyway you need to set the screen | |
3596 * attributes before calling this routine. | |
3597 */ | |
3598 protected void updateDirty() { | |
3599 | |
3600 fireScreenChanged(1); | |
3601 | |
3602 } | |
3603 | |
3604 protected void setDirty(int pos) { | |
3605 | |
3606 int minr = Math.min(getRow(pos),getRow(dirtyScreen.x)); | |
3607 int minc = Math.min(getCol(pos),getCol(dirtyScreen.x)); | |
3608 | |
3609 int maxr = Math.max(getRow(pos),getRow(dirtyScreen.y)); | |
3610 int maxc = Math.max(getCol(pos),getCol(dirtyScreen.y)); | |
3611 | |
3612 int x1 = getPos(minr,minc); | |
3613 int x2 = getPos(maxr,maxc); | |
3614 | |
3615 dirtyScreen.setBounds(x1,x2,0,0); | |
3616 | |
3617 } | |
3618 | |
3619 /* *** NEVER USED LOCALLY ************************************************** */ | |
3620 // private void setDirty(int row, int col) { | |
3621 // | |
3622 // setDirty(getPos(row, col)); | |
3623 // | |
3624 // } | |
3625 | |
3626 private void resetDirty(int pos) { | |
3627 | |
3628 dirtyScreen.setBounds(pos,pos,0,0); | |
3629 | |
3630 } | |
3631 | |
3632 /** | |
3633 * Change the screen position by one column | |
3634 */ | |
3635 protected void advancePos() { | |
3636 changePos(1); | |
3637 } | |
3638 | |
3639 /** | |
3640 * Change position of the screen by the increment of parameter passed. | |
3641 * | |
3642 * If the position change is under the minimum of the first screen position | |
3643 * then the position is moved to the last row and column of the screen. | |
3644 * | |
3645 * If the position change is over the last row and column of the screen then | |
3646 * cursor is moved to first position of the screen. | |
3647 * | |
3648 * @param i | |
3649 */ | |
3650 protected void changePos(int i) { | |
3651 | |
3652 lastPos += i; | |
3653 if (lastPos < 0) | |
3654 lastPos = lenScreen + lastPos; | |
3655 if (lastPos > lenScreen - 1) | |
3656 lastPos = lastPos - lenScreen; | |
3657 | |
3658 // System.out.println(lastRow + "," + ((lastPos) / numCols) + "," + | |
3659 // lastCol + "," + ((lastPos) % numCols) + "," + | |
3660 // ((lastRow * numCols) + lastCol) + "," + | |
3661 // (lastPos)); | |
3662 | |
3663 } | |
3664 | |
3665 protected void goHome() { | |
3666 | |
3667 // now we try to move to first input field according to | |
3668 // 14.6 WRITE TO DISPLAY Command | |
3669 // ? If the WTD command is valid, after the command is processed, | |
3670 // the cursor moves to one of three locations: | |
3671 // - The location set by an insert cursor order (unless control | |
3672 // character byte 1, bit 1 is equal to B'1'.) | |
3673 // - The start of the first non-bypass input field defined in the | |
3674 // format table | |
3675 // - A default starting address of row 1 column 1. | |
3676 | |
3677 if (pendingInsert && homePos > 0) { | |
3678 setCursor(getRow(homePos), getCol(homePos)); | |
3679 isInField(); // we now check if we are in a field | |
3680 } else { | |
3681 if (!gotoField(1)) { | |
3682 homePos = getPos(1, 1); | |
3683 setCursor(1, 1); | |
3684 isInField(0, 0); // we now check if we are in a field | |
3685 } else { | |
3686 homePos = getPos(getCurrentRow(), getCurrentCol()); | |
3687 } | |
3688 } | |
3689 } | |
3690 | |
3691 protected void setPendingInsert(boolean flag, int icX, int icY) { | |
3692 pendingInsert = flag; | |
3693 if (pendingInsert) { | |
3694 homePos = getPos(icX, icY); | |
3695 } | |
3696 | |
3697 if (!isStatusErrorCode()) { | |
3698 setCursor(icX, icY); | |
3699 } | |
3700 } | |
3701 | |
3702 protected void setPendingInsert(boolean flag) { | |
3703 if (homePos != -1) | |
3704 pendingInsert = flag; | |
3705 } | |
3706 | |
3707 /** | |
3708 * Set the error line number to that of number passed. | |
3709 * | |
3710 * @param line | |
3711 */ | |
3712 protected void setErrorLine(int line) { | |
3713 | |
3714 planes.setErrorLine(line); | |
3715 } | |
3716 | |
3717 /** | |
3718 * Returns the current error line number | |
3719 * | |
3720 * @return current error line number | |
3721 */ | |
3722 protected int getErrorLine() { | |
3723 return planes.getErrorLine(); | |
3724 } | |
3725 | |
3726 /** | |
3727 * Saves off the current error line characters to be used later. | |
3728 * | |
3729 */ | |
3730 protected void saveErrorLine() { | |
3731 planes.saveErrorLine(); | |
3732 } | |
3733 | |
3734 /** | |
3735 * Restores the error line characters from the save buffer. | |
3736 * | |
3737 * @see #saveErrorLine() | |
3738 */ | |
3739 protected void restoreErrorLine() { | |
3740 | |
3741 if (planes.isErrorLineSaved()) { | |
3742 planes.restoreErrorLine(); | |
3743 fireScreenChanged(1,planes.getErrorLine()-1,0,planes.getErrorLine()-1,numCols - 1); | |
3744 } | |
3745 } | |
3746 | |
3747 protected void setStatus(byte attr, byte value, String s) { | |
3748 | |
3749 // set the status area | |
3750 switch (attr) { | |
3751 | |
3752 case STATUS_SYSTEM: | |
3753 if (value == STATUS_VALUE_ON) { | |
3754 oia.setInputInhibited(ScreenOIA.INPUTINHIBITED_SYSTEM_WAIT,ScreenOIA.OIA_LEVEL_INPUT_INHIBITED, s); | |
3755 } | |
3756 else { | |
3757 oia.setInputInhibited(ScreenOIA.INPUTINHIBITED_NOTINHIBITED,ScreenOIA.OIA_LEVEL_NOT_INHIBITED,s); | |
3758 } | |
3759 break; | |
3760 | |
3761 case STATUS_ERROR_CODE: | |
3762 if (value == STATUS_VALUE_ON) { | |
3763 setPrehelpState(true, true, false); | |
3764 oia.setInputInhibited(ScreenOIA.INPUTINHIBITED_SYSTEM_WAIT, | |
3765 ScreenOIA.OIA_LEVEL_INPUT_ERROR,s); | |
3766 | |
3767 sessionVT.signalBell(); | |
3768 } else { | |
3769 oia.setInputInhibited(ScreenOIA.INPUTINHIBITED_NOTINHIBITED, | |
3770 ScreenOIA.OIA_LEVEL_NOT_INHIBITED); | |
3771 setPrehelpState(false, true, true); | |
3772 homePos = saveHomePos; | |
3773 saveHomePos = 0; | |
3774 pendingInsert = false; | |
3775 } | |
3776 break; | |
3777 | |
3778 } | |
3779 } | |
3780 | |
3781 protected boolean isStatusErrorCode() { | |
3782 | |
3783 return oia.getLevel() == ScreenOIA.OIA_LEVEL_INPUT_ERROR; | |
3784 | |
3785 } | |
3786 | |
3787 /** | |
3788 * This routine clears the screen, resets row and column to 0, resets the | |
3789 * last attribute to 32, clears the fields, turns insert mode off, | |
3790 * clears/initializes the screen character array. | |
3791 */ | |
3792 protected void clearAll() { | |
3793 | |
3794 lastAttr = 32; | |
3795 lastPos = 0; | |
3796 | |
3797 clearTable(); | |
3798 clearScreen(); | |
3799 planes.setScreenAttr(0, initAttr); | |
3800 oia.setInsertMode(false); | |
3801 } | |
3802 | |
3803 /** | |
3804 * Clear the fields table | |
3805 */ | |
3806 protected void clearTable() { | |
3807 | |
3808 oia.setKeyBoardLocked(true); | |
3809 screenFields.clearFFT(); | |
3810 planes.initalizeFieldPlanes(); | |
3811 pendingInsert = false; | |
3812 homePos = -1; | |
3813 } | |
3814 | |
3815 /** | |
3816 * Clear the gui constructs | |
3817 * | |
3818 */ | |
3819 protected void clearGuiStuff() { | |
3820 | |
3821 for (int x = 0; x < lenScreen; x++) { | |
3822 planes.setUseGUI(x,NO_GUI); | |
3823 } | |
3824 dirtyScreen.setBounds(0,lenScreen - 1,0,0); | |
3825 } | |
3826 | |
3827 /** | |
3828 * Clear the screen by setting the initial character and initial attribute | |
3829 * to all the positions on the screen | |
3830 */ | |
3831 protected void clearScreen() { | |
3832 | |
3833 planes.initalizePlanes(); | |
3834 | |
3835 dirtyScreen.setBounds(0,lenScreen - 1,0,0); | |
3836 | |
3837 oia.clearScreen(); | |
3838 | |
3839 } | |
3840 | |
3841 protected void restoreScreen() { | |
3842 | |
3843 lastAttr = 32; | |
3844 dirtyScreen.setBounds(0,lenScreen - 1,0,0); | |
3845 updateDirty(); | |
3846 } | |
3847 | |
3848 /** | |
3849 * Notify all registered listeners of the onScreenChanged event. | |
3850 * | |
3851 */ | |
3852 private void fireScreenChanged(int which, int startRow, int startCol, | |
3853 int endRow, int endCol) { | |
3854 if (listeners != null) { | |
3855 // Patch below contributed by Mitch Blevins | |
3856 //int size = listeners.size(); | |
3857 Vector<ScreenListener> lc = new Vector<ScreenListener>(listeners); | |
3858 int size = lc.size(); | |
3859 for (int i = 0; i < size; i++) { | |
3860 //ScreenListener target = | |
3861 // (ScreenListener)listeners.elementAt(i); | |
3862 ScreenListener target = lc.elementAt(i); | |
3863 target.onScreenChanged(1,startRow,startCol,endRow,endCol); | |
3864 } | |
3865 } | |
3866 dirtyScreen.setBounds(lenScreen,0,0,0); | |
3867 } | |
3868 | |
3869 /** | |
3870 * Notify all registered listeners of the onScreenChanged event. | |
3871 * | |
3872 */ | |
3873 private synchronized void fireScreenChanged(int update) { | |
3874 if (dirtyScreen.x > dirtyScreen.y) { | |
25
5949eb469a79
adding tn5250 files, native android logging
Carl Byington <carl@five-ten-sg.com>
parents:
10
diff
changeset
|
3875 // Log.i(TAG," x < y " + dirtyScreen); |
3 | 3876 return; |
3877 } | |
3878 | |
3879 fireScreenChanged(update, getRow(dirtyScreen.x), getCol(dirtyScreen.x), | |
3880 getRow(dirtyScreen.y), getCol(dirtyScreen.y)); | |
3881 | |
3882 } | |
3883 | |
3884 /** | |
3885 * Notify all registered listeners of the onScreenChanged event. | |
3886 * | |
3887 */ | |
3888 private synchronized void fireCursorChanged(int update) { | |
3889 int startRow = getRow(lastPos); | |
3890 int startCol = getCol(lastPos); | |
3891 | |
3892 if (listeners != null) { | |
3893 Vector<ScreenListener> lc = new Vector<ScreenListener>(listeners); | |
3894 //int size = listeners.size(); | |
3895 int size = lc.size(); | |
3896 for (int i = 0; i < size; i++) { | |
3897 ScreenListener target = | |
3898 lc.elementAt(i); | |
3899 target.onScreenChanged(update,startRow,startCol,startRow,startCol); | |
3900 } | |
3901 } | |
3902 } | |
3903 | |
3904 /** | |
3905 * Notify all registered listeners of the onScreenSizeChanged event. | |
3906 * | |
3907 */ | |
3908 private void fireScreenSizeChanged() { | |
3909 | |
3910 if (listeners != null) { | |
3911 Vector<ScreenListener> lc = new Vector<ScreenListener>(listeners); | |
3912 //int size = listeners.size(); | |
3913 int size = lc.size(); | |
3914 for (int i = 0; i < size; i++) { | |
3915 ScreenListener target = | |
3916 lc.elementAt(i); | |
3917 target.onScreenSizeChanged(numRows,numCols); | |
3918 } | |
3919 } | |
3920 } | |
3921 | |
3922 /** | |
3923 * This method does a complete refresh of the screen. | |
3924 */ | |
3925 public final void updateScreen() { | |
3926 repaintScreen(); | |
3927 setCursorActive(false); | |
3928 setCursorActive(true); | |
3929 } | |
3930 | |
3931 /** | |
3932 * Add a ScreenListener to the listener list. | |
3933 * | |
3934 * @param listener The ScreenListener to be added | |
3935 */ | |
3936 public void addScreenListener(ScreenListener listener) { | |
3937 | |
3938 if (listeners == null) { | |
3939 listeners = new java.util.Vector<ScreenListener>(3); | |
3940 } | |
3941 listeners.addElement(listener); | |
3942 | |
3943 } | |
3944 | |
3945 /** | |
3946 * Remove a ScreenListener from the listener list. | |
3947 * | |
3948 * @param listener The ScreenListener to be removed | |
3949 */ | |
3950 public void removeScreenListener(ScreenListener listener) { | |
3951 | |
3952 if (listeners == null) { | |
3953 return; | |
3954 } | |
3955 listeners.removeElement(listener); | |
3956 } | |
3957 | |
3958 /** | |
3959 * Utility method to share the repaint behaviour between setBounds() and | |
3960 * updateScreen. | |
3961 */ | |
3962 public void repaintScreen() { | |
3963 | |
3964 setCursorOff(); | |
3965 dirtyScreen.setBounds(0,lenScreen - 1,0,0); | |
3966 updateDirty(); | |
3967 // restore statuses that were on the screen before resize | |
3968 if (oia.getLevel() == ScreenOIA.OIA_LEVEL_INPUT_ERROR) { | |
3969 oia.setInputInhibited(ScreenOIA.INPUTINHIBITED_SYSTEM_WAIT, | |
3970 ScreenOIA.OIA_LEVEL_INPUT_ERROR); | |
3971 } | |
3972 | |
3973 if (oia.getLevel() == ScreenOIA.OIA_LEVEL_INPUT_INHIBITED) { | |
3974 oia.setInputInhibited(ScreenOIA.INPUTINHIBITED_SYSTEM_WAIT, | |
3975 ScreenOIA.OIA_LEVEL_INPUT_INHIBITED); | |
3976 } | |
3977 | |
3978 if (oia.isMessageWait()) | |
3979 oia.setMessageLightOn(); | |
3980 setCursorOn(); | |
3981 } | |
3982 | |
3983 // ADDED BY BARRY - changed by Kenneth to use the character plane | |
3984 // This should be replaced with the getPlane methods when they are implemented | |
3985 public char[] getCharacters() { | |
3986 return planes.screen; | |
3987 } | |
3988 | |
3989 } |