3
|
1 /**
|
|
2 * Title: ScreenPlanes.java
|
|
3 * Copyright: Copyright (c) 2001
|
|
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.util.Properties;
|
|
31
|
|
32 import org.tn5250j.ExternalProgramConfig;
|
|
33
|
|
34 public class ScreenPlanes {
|
|
35
|
|
36 private final Screen5250 scr;
|
|
37 private int screenSize;
|
|
38 private int numRows;
|
|
39 private int numCols;
|
|
40 private int errorLineNum;
|
|
41
|
|
42 private static final int initAttr = 32;
|
|
43 private static final char initChar = 0;
|
|
44
|
|
45 protected char[] screen; // text plane
|
|
46 private char[] screenAttr; // attribute plane
|
|
47 private char[] screenGUI; // gui plane
|
|
48 private char[] screenIsAttr;
|
|
49 private char[] fieldExtended;
|
|
50 private char[] screenField;
|
|
51 private char[] screenColor; // color plane
|
|
52 protected char[] screenExtended; // extended plane
|
|
53 private char[] screenIsChanged;
|
|
54
|
|
55 private char[] initArray;
|
|
56
|
|
57 private char[] errorLine;
|
|
58 private char[] errorLineAttr;
|
|
59 private char[] errorLineIsAttr;
|
|
60 private char[] errorLineGui;
|
|
61
|
|
62 public ScreenPlanes(Screen5250 s5250, int size) {
|
|
63
|
|
64 scr = s5250;
|
|
65 setSize(size);
|
|
66 }
|
|
67
|
|
68 protected void setSize(int newSize) {
|
|
69
|
|
70 screenSize = newSize;
|
|
71
|
|
72 numCols = 80;
|
|
73 switch (newSize) {
|
|
74 case 24:
|
|
75 numRows = 24;
|
|
76 break;
|
|
77 case 27:
|
|
78 numRows = 27;
|
|
79 numCols = 132;
|
|
80 break;
|
|
81
|
|
82 }
|
|
83
|
|
84 // this is used here when size changes
|
|
85 setErrorLine(numRows);
|
|
86
|
|
87 screenSize = numRows * numCols;
|
|
88 screen = new char[screenSize];
|
|
89 screenAttr = new char[screenSize];
|
|
90 screenIsAttr = new char[screenSize];
|
|
91 screenGUI = new char[screenSize];
|
|
92 screenColor = new char[screenSize];
|
|
93 screenExtended = new char[screenSize];
|
|
94 fieldExtended = new char[screenSize];
|
|
95 screenIsChanged = new char[screenSize];
|
|
96 screenField = new char[screenSize];
|
|
97
|
|
98 initArray = new char[screenSize];
|
|
99
|
|
100 initalizePlanes();
|
|
101 }
|
|
102
|
|
103 protected void setErrorLine (int line) {
|
|
104
|
|
105 // * NOTE * for developers I have changed the send qry to pass different
|
|
106 // parameters to the host so check setsize for setting error line as well.
|
|
107 //
|
|
108 if (line == 0 || line > numRows)
|
|
109 errorLineNum = numRows;
|
|
110 else
|
|
111 errorLineNum = line;
|
|
112 }
|
|
113
|
|
114 /**
|
|
115 * Returns the current error line number
|
|
116 *
|
|
117 * @return current error line number
|
|
118 */
|
|
119 protected int getErrorLine() {
|
|
120 return errorLineNum;
|
|
121 }
|
|
122
|
|
123 protected void saveErrorLine() {
|
|
124
|
|
125 // if there is already an error line saved then do not save it again
|
|
126 // This signifies that there was a previous error and the original error
|
|
127 // line was not restored yet.
|
|
128 if (errorLine == null) {
|
|
129 errorLine = new char[numCols];
|
|
130 errorLineAttr = new char[numCols];
|
|
131 errorLineIsAttr = new char[numCols];
|
|
132 errorLineGui = new char[numCols];
|
|
133
|
|
134 int r = scr.getPos(errorLineNum-1,0);
|
|
135
|
|
136 for (int x = 0;x < numCols; x++) {
|
|
137 errorLine[x] = screen[r+x];
|
|
138 errorLineAttr[x] = screenAttr[r+x];
|
|
139 errorLineIsAttr[x] = screenIsAttr[r+x];
|
|
140 errorLineGui[x] = screenGUI[r+x];
|
|
141 }
|
|
142 }
|
|
143 }
|
|
144
|
|
145 /**
|
|
146 * Restores the error line characters from the save buffer.
|
|
147 *
|
|
148 * @see #saveErrorLine()
|
|
149 */
|
|
150 protected void restoreErrorLine() {
|
|
151
|
|
152 if (errorLine != null) {
|
|
153 int r = scr.getPos(errorLineNum - 1, 0);
|
|
154
|
|
155 for (int x = 0; x < numCols - 1; x++) {
|
|
156 setScreenCharAndAttr(r+x,errorLine[x],errorLineAttr[x],
|
|
157 (errorLineIsAttr[x] == '1' ? true : false));
|
|
158 screenGUI[x] = errorLineGui[x];
|
|
159 }
|
|
160
|
|
161 errorLine = null;
|
|
162 errorLineAttr = null;
|
|
163 errorLineIsAttr = null;
|
|
164 errorLineGui = null;
|
|
165 }
|
|
166 }
|
|
167
|
|
168 protected boolean isErrorLineSaved() {
|
|
169 return errorLine == null ? false : true;
|
|
170 }
|
|
171
|
|
172 protected void setScreenCharAndAttr(int pos, char c, int attr, boolean isAttr) {
|
|
173
|
|
174 screen[pos] = c;
|
|
175 screenAttr[pos] = (char)attr;
|
|
176 disperseAttribute(pos,attr);
|
|
177 screenIsAttr[pos] = (isAttr ? (char)1 : (char)0);
|
|
178 screenGUI[pos] = NO_GUI;
|
|
179
|
|
180 }
|
|
181
|
|
182 protected void setScreenAttr(int pos, int attr, boolean isAttr) {
|
|
183
|
|
184 screenAttr[pos] = (char)attr;
|
|
185 screenIsAttr[pos] = isAttr ? (char)1 : (char)0;
|
|
186 disperseAttribute(pos,attr);
|
|
187 screenGUI[pos] = initChar;
|
|
188
|
|
189 }
|
|
190
|
|
191 protected void setScreenAttr(int pos, int attr) {
|
|
192
|
|
193 screenAttr[pos] = (char)attr;
|
|
194 //screenGUI[pos] = initChar;
|
|
195 disperseAttribute(pos,attr);
|
|
196
|
|
197 }
|
|
198
|
|
199 protected void setScreenFieldAttr(int pos, int attr) {
|
|
200
|
|
201 screenField[pos] = (char)attr;
|
|
202
|
|
203 }
|
|
204
|
|
205 protected final void setChar(int pos, char c) {
|
|
206 screenIsChanged[pos] = screen[pos] == c ? '0' : '1';
|
|
207 screen[pos] = c;
|
|
208 if (screenIsAttr[pos] == 1)
|
|
209 setScreenCharAndAttr(pos,c,32,false);
|
|
210
|
|
211 }
|
|
212
|
|
213 protected final char getChar(int pos) {
|
|
214 return screen[pos];
|
|
215 }
|
|
216
|
|
217 protected final int getCharAttr(int pos) {
|
|
218 return screenAttr[pos];
|
|
219 }
|
|
220
|
|
221 protected final boolean isAttributePlace(int pos) {
|
|
222 return screenIsAttr[pos] == 1 ? true : false;
|
|
223 }
|
|
224
|
|
225 public final void setUseGUI(int pos, int which) {
|
|
226
|
|
227 screenIsChanged[pos] = screenGUI[pos] == which ? '0' : '1';
|
|
228 screenGUI[pos] = (char)which;
|
|
229 }
|
|
230
|
|
231 private void disperseAttribute(int pos, int attr) {
|
|
232
|
|
233 char c = 0;
|
|
234 char cs = 0;
|
|
235 char ul = 0;
|
|
236 char nd = 0;
|
|
237
|
|
238 if(attr == 0)
|
|
239 return;
|
|
240
|
|
241 switch(attr) {
|
|
242 case 32: // green normal
|
|
243 c = ATTR_32;
|
|
244 break;
|
|
245
|
|
246 case 33: // green/revers
|
|
247 c = ATTR_33;
|
|
248 break;
|
|
249
|
|
250 case 34: // white normal
|
|
251 c = ATTR_34;
|
|
252 break;
|
|
253
|
|
254 case 35: // white/reverse
|
|
255 c = ATTR_35;
|
|
256 break;
|
|
257
|
|
258 case 36: // green/underline
|
|
259 c = ATTR_36;
|
|
260 ul = EXTENDED_5250_UNDERLINE;
|
|
261 break;
|
|
262
|
|
263 case 37: // green/reverse/underline
|
|
264 c = ATTR_37;
|
|
265 ul = EXTENDED_5250_UNDERLINE;
|
|
266 break;
|
|
267
|
|
268 case 38: // white/underline
|
|
269 c = ATTR_38;
|
|
270 ul = EXTENDED_5250_UNDERLINE;
|
|
271 break;
|
|
272
|
|
273 case 39:
|
|
274 nd = EXTENDED_5250_NON_DSP;
|
|
275 break;
|
|
276
|
|
277 case 40:
|
|
278 case 42: // red/normal
|
|
279 c = ATTR_40;
|
|
280 break;
|
|
281
|
|
282 case 41:
|
|
283 case 43: // red/reverse
|
|
284 c = ATTR_41;
|
|
285 break;
|
|
286
|
|
287 case 44:
|
|
288 case 46: // red/underline
|
|
289 c = ATTR_44;
|
|
290 ul = EXTENDED_5250_UNDERLINE;
|
|
291 break;
|
|
292
|
|
293 case 45: // red/reverse/underline
|
|
294 c = ATTR_45;
|
|
295 ul = EXTENDED_5250_UNDERLINE;
|
|
296 break;
|
|
297
|
|
298 case 47:
|
|
299 nd = EXTENDED_5250_NON_DSP;
|
|
300 break;
|
|
301
|
|
302 case 48:
|
|
303 c = ATTR_48;
|
|
304 cs = EXTENDED_5250_COL_SEP;
|
|
305 break;
|
|
306
|
|
307 case 49:
|
|
308 c = ATTR_49;
|
|
309 cs = EXTENDED_5250_COL_SEP;
|
|
310 break;
|
|
311
|
|
312 case 50:
|
|
313 c = ATTR_50;
|
|
314 cs = EXTENDED_5250_COL_SEP;
|
|
315 break;
|
|
316
|
|
317 case 51:
|
|
318 c = ATTR_51;
|
|
319 cs = EXTENDED_5250_COL_SEP;
|
|
320 break;
|
|
321
|
|
322 case 52:
|
|
323 c = ATTR_52;
|
|
324 // colSep = true;
|
|
325 ul = EXTENDED_5250_UNDERLINE;
|
|
326 break;
|
|
327
|
|
328 case 53:
|
|
329 c = ATTR_53;
|
|
330 // colSep = true;
|
|
331 ul = EXTENDED_5250_UNDERLINE;
|
|
332 break;
|
|
333
|
|
334 case 54:
|
|
335 c = ATTR_54;
|
|
336 // colSep = true;
|
|
337 ul = EXTENDED_5250_UNDERLINE;
|
|
338 break;
|
|
339
|
|
340 case 55:
|
|
341 nd = EXTENDED_5250_NON_DSP;
|
|
342 break;
|
|
343
|
|
344 case 56: // pink
|
|
345 c = ATTR_56;
|
|
346 break;
|
|
347
|
|
348 case 57: // pink/reverse
|
|
349 c = ATTR_57;
|
|
350 break;
|
|
351
|
|
352 case 58: // blue/reverse
|
|
353 c = ATTR_58;
|
|
354 break;
|
|
355
|
|
356 case 59: // blue
|
|
357 c = ATTR_59;
|
|
358 break;
|
|
359
|
|
360 case 60: // pink/underline
|
|
361 c = ATTR_60;
|
|
362 ul = EXTENDED_5250_UNDERLINE;
|
|
363 break;
|
|
364
|
|
365 case 61: // pink/reverse/underline
|
|
366 c = ATTR_61;
|
|
367 ul = EXTENDED_5250_UNDERLINE;
|
|
368 break;
|
|
369
|
|
370 case 62: // blue/underline
|
|
371 c = ATTR_62;
|
|
372 ul = EXTENDED_5250_UNDERLINE;
|
|
373 break;
|
|
374
|
|
375 case 63: // nondisplay
|
|
376 nd = EXTENDED_5250_NON_DSP;
|
|
377 cs = EXTENDED_5250_COL_SEP;
|
|
378 break;
|
|
379 default:
|
|
380 c = ( COLOR_BG_BLACK << 8 & 0xff00) |
|
|
381 ( COLOR_FG_YELLOW & 0xff);
|
|
382 break;
|
|
383
|
|
384 }
|
|
385
|
|
386 screenColor[pos] = c;
|
|
387 screenExtended[pos] = (char)(ul | cs | nd);
|
|
388 }
|
|
389
|
|
390 protected void initalizePlanes () {
|
|
391
|
|
392 char c = (COLOR_BG_BLACK << 8 & 0xff00) |
|
|
393 (COLOR_FG_GREEN & 0xff);
|
|
394
|
|
395 for (int y = 0;y < screenSize; y++) {
|
|
396
|
|
397 screenAttr[y] = initAttr;
|
|
398 screenColor[y] = c;
|
|
399
|
|
400 }
|
|
401
|
|
402 // here we will just copy the initialized plane onto the other planes
|
|
403 // using arraycopy which will be faster. I hope.
|
|
404
|
|
405 System.arraycopy(initArray,0,screen,0,screenSize);
|
|
406 System.arraycopy(initArray,0,screenGUI,0,screenSize);
|
|
407 System.arraycopy(initArray,0,screenIsAttr,0,screenSize);
|
|
408 System.arraycopy(initArray,0,screenExtended,0,screenSize);
|
|
409 System.arraycopy(initArray,0,fieldExtended,0,screenSize);
|
|
410 System.arraycopy(initArray,0,screenField,0,screenSize);
|
|
411 }
|
|
412
|
|
413 protected void initalizeFieldPlanes () {
|
|
414 System.arraycopy(initArray,0,fieldExtended,0,screenSize);
|
|
415 System.arraycopy(initArray,0,screenField,0,screenSize);
|
|
416 }
|
|
417
|
|
418 protected final int getWhichGUI(int pos) {
|
|
419
|
|
420 return screenGUI[pos];
|
|
421 }
|
|
422
|
|
423 protected final boolean isChanged(int pos) {
|
|
424 return screenIsChanged[pos] == 0 ? false : true;
|
|
425 }
|
|
426
|
|
427 protected final boolean isUseGui(int pos) {
|
|
428 return screenGUI[pos] == NO_GUI ? false : true;
|
|
429 }
|
|
430
|
|
431 /**
|
|
432 * Return the data associated with the plane that is passed.
|
|
433 *
|
|
434 * @param from Position from which to start
|
|
435 * @param to Position to end
|
|
436 * @param plane From which plane to obtain the data
|
|
437 * @return Character array containing the data requested
|
|
438 */
|
|
439 protected synchronized char[] getPlaneData(int from, int to, int plane) {
|
|
440
|
|
441 int len = (to - from);
|
|
442
|
|
443 char[] planeChars = new char[len + 1];
|
|
444
|
|
445 switch (plane) {
|
|
446 case PLANE_TEXT:
|
|
447 System.arraycopy(screen, from, planeChars, 0, len);
|
|
448 break;
|
|
449 case PLANE_ATTR:
|
|
450 System.arraycopy(screenAttr, from, planeChars, 0, len);
|
|
451 break;
|
|
452 case PLANE_COLOR:
|
|
453 System.arraycopy(screenColor, from, planeChars, 0, len);
|
|
454 break;
|
|
455 case PLANE_EXTENDED:
|
|
456 System.arraycopy(screenExtended, from, planeChars, 0, len);
|
|
457 break;
|
|
458 case PLANE_EXTENDED_GRAPHIC:
|
|
459 System.arraycopy(screenGUI, from, planeChars, 0, len);
|
|
460 break;
|
|
461 case PLANE_FIELD:
|
|
462 System.arraycopy(screenField, from, planeChars, 0, len);
|
|
463 break;
|
|
464 case PLANE_IS_ATTR_PLACE:
|
|
465 System.arraycopy(screenIsAttr, from, planeChars, 0, len);
|
|
466 break;
|
|
467 default:
|
|
468 System.arraycopy(screen, from, planeChars, 0, len);
|
|
469
|
|
470 }
|
|
471 return planeChars;
|
|
472
|
|
473 }
|
|
474
|
|
475 /**
|
|
476 * Converts a linear presentation space position to its corresponding row.
|
|
477 *
|
|
478 * @param pos The position to be converted
|
|
479 * @return The row which corresponds to the position given
|
|
480 * @throws OhioException
|
|
481 */
|
|
482 private int convertPosToRow(int pos) {
|
|
483
|
|
484 return (pos / numCols) + 1;
|
|
485
|
|
486 }
|
|
487
|
|
488 /**
|
|
489 * Converts a linear presentation space position to its corresponding column.
|
|
490 *
|
|
491 * @param pos The position to be converted
|
|
492 * @return The column which corresponds to the position given
|
|
493 * @throws OhioException
|
|
494 */
|
|
495 private int convertPosToColumn(int pos) {
|
|
496
|
|
497 return (pos % numCols) + 1;
|
|
498
|
|
499 }
|
|
500
|
|
501 /**
|
|
502 *
|
|
503 * Converts a row and column coordinate to its corresponding linear position.
|
|
504 *
|
|
505 * @param row - The row of the coordinate
|
|
506 * @param col - The column of the coordinate
|
|
507 * @return The linear position which corresponds to the coordinate given.
|
|
508 * @throws OhioException
|
|
509 */
|
|
510 private int convertRowColToPos(int row, int col) {
|
|
511
|
|
512
|
|
513 return (row - 1) * numCols + col -1;
|
|
514
|
|
515 }
|
|
516
|
|
517
|
|
518 /**
|
|
519 * <p>
|
|
520 * GetScreen retrieves the various planes associated with the presentation
|
|
521 * space. The data is returned as a linear array of character values in the
|
|
522 * array provided. The array is not terminated by a null character except
|
|
523 * when data is retrieved from the text plane, in which case a single null
|
|
524 * character is appended.
|
|
525 * </p>
|
|
526 * <p>
|
|
527 * The application must supply a buffer for the returned data and the length
|
|
528 * of the buffer. Data is returned starting from the beginning of the
|
|
529 * presentation space and continuing until the buffer is full or the entire
|
|
530 * plane has been copied. For text plane data, the buffer must include one
|
|
531 * extra position for the terminating null character.
|
|
532 * <p>
|
|
533 *
|
|
534 * @param buffer
|
|
535 * @param bufferLength
|
|
536 * @param plane
|
|
537 * @return The number of characters copied to the buffer
|
|
538 * @throws OhioException
|
|
539 */
|
|
540 public synchronized int GetScreen(char buffer[], int bufferLength, int plane) {
|
|
541
|
|
542 return GetScreen(buffer,bufferLength,0,screenSize,plane);
|
|
543
|
|
544 }
|
|
545
|
|
546 /**
|
|
547 * <p>
|
|
548 * GetScreen retrieves the various planes associated with the presentation
|
|
549 * space. The data is returned as a linear array of character values in the
|
|
550 * array provided. The array is not terminated by a null character except
|
|
551 * when data is retrieved from the text plane, in which case a single null
|
|
552 * character is appended.
|
|
553 * </p>
|
|
554 * <p>
|
|
555 * The application must supply a buffer for the returned data and the length
|
|
556 * of the buffer. Data is returned starting from the given position and
|
|
557 * continuing until the specified number of characters have been copied, the
|
|
558 * buffer is full or the entire plane has been copied. For text plane data,
|
|
559 * the buffer must include one extra position for the terminating null character.
|
|
560 * </p>
|
|
561 *
|
|
562 * @param buffer
|
|
563 * @param bufferLength
|
|
564 * @param from
|
|
565 * @param length
|
|
566 * @param plane
|
|
567 * @return The number of characters copied to the buffer
|
|
568 * @throws OhioException
|
|
569 */
|
|
570 public synchronized int GetScreen(char buffer[], int bufferLength, int from,
|
|
571 int length, int plane)
|
|
572 {
|
|
573 // if(buffer == null)
|
|
574 // throw new OhioException(sessionVT.getSessionConfiguration(),
|
|
575 // OhioScreen.class.getName(), "osohio.screen.ohio00300", 1);
|
|
576 if(buffer == null)
|
|
577 return 0;
|
|
578
|
|
579 int min = Math.min(Math.min(buffer.length, bufferLength), screenSize);
|
|
580 if ((from + min) > screenSize) {
|
|
581 min = screenSize - from;
|
|
582 }
|
|
583
|
|
584 char[] pd = getPlaneData(from,from + min,plane);
|
|
585 if(pd != null) {
|
|
586 System.arraycopy(pd, 0, buffer, 0, min);
|
|
587 return pd.length;
|
|
588 }
|
|
589
|
|
590 return 0;
|
|
591 }
|
|
592
|
|
593 /**
|
|
594 * <p>
|
|
595 * GetScreen retrieves the various planes associated with the presentation
|
|
596 * space. The data is returned as a linear array of character values in the
|
|
597 * array provided. The array is not terminated by a null character except
|
|
598 * when data is retrieved from the text plane, in which case a single null
|
|
599 * character is appended.
|
|
600 * </p>
|
|
601 * <p>
|
|
602 * The application must supply a buffer for the returned data and the length
|
|
603 * of the buffer. Data is returned starting from the given coordinates and
|
|
604 * continuing until the specified number of characters have been copied,
|
|
605 * the buffer is full, or the entire plane has been copied. For text plane
|
|
606 * data, the buffer must include one extra position for the terminating null
|
|
607 * character.
|
|
608 * </p>
|
|
609 *
|
|
610 * @param buffer
|
|
611 * @param bufferLength
|
|
612 * @param row
|
|
613 * @param col
|
|
614 * @param length
|
|
615 * @param plane
|
|
616 * @return The number of characters copied to the buffer.
|
|
617 * @throws OhioException
|
|
618 */
|
|
619 public synchronized int GetScreen(char buffer[], int bufferLength, int row,
|
|
620 int col, int length, int plane)
|
|
621 // throws OhioException {
|
|
622 {
|
|
623 // Call GetScreen function after converting row and column to
|
|
624 // a position.
|
|
625 return GetScreen(buffer,bufferLength, convertRowColToPos(row,col),
|
|
626 length, plane);
|
|
627 }
|
|
628
|
|
629 /**
|
|
630 * <p>
|
|
631 * GetScreenRect retrieves data from the various planes associated with the
|
|
632 * presentation space. The data is returned as a linear array of character
|
|
633 * values in the buffer provided.
|
|
634 * </p>
|
|
635 *
|
|
636 * <p>
|
|
637 * The application supplies two positions that represent opposing corners of
|
|
638 * a rectangle within the presentation space. The starting and ending
|
|
639 * positions can have any spatial relationship to each other. The data
|
|
640 * returned starts from the row containing the upper-most point to the row
|
|
641 * containing the lower-most point, and from the left-most column to the
|
|
642 * right-most column.
|
|
643 * </p>
|
|
644 * <p>
|
|
645 * The specified buffer must be at least large enough to contain the number
|
|
646 * of characters in the rectangle. If the buffer is too small, no data is
|
|
647 * copied and zero is returned by the method. Otherwise, the method returns
|
|
648 * the number of characters copied.
|
|
649 * </p>
|
|
650 *
|
|
651 * @param buffer
|
|
652 * @param bufferLength
|
|
653 * @param startPos
|
|
654 * @param endPos
|
|
655 * @param plane
|
|
656 * @return The number of characters copied to the buffer
|
|
657 * @throws OhioException
|
|
658 */
|
|
659 protected int GetScreenRect(char buffer[], int bufferLength,
|
|
660 int startPos, int endPos, int plane)
|
|
661 // throws OhioException {
|
|
662 {
|
|
663 // We will use the row,col routine here because it is easier to use
|
|
664 // row colum than it is for position since I wrote the other first and
|
|
665 // am to lazy to implement it here
|
|
666 // Maybe it would be faster to do it the other way?
|
|
667 int startRow = convertPosToRow(startPos);
|
|
668 int startCol = convertPosToColumn(startPos);
|
|
669 int endRow = convertPosToRow(endPos);
|
|
670 int endCol = convertPosToColumn(endPos);
|
|
671 return GetScreenRect(buffer, bufferLength, startRow, startCol,
|
|
672 endRow, endCol, plane);
|
|
673
|
|
674 }
|
|
675
|
|
676 /**
|
|
677 * <p>
|
|
678 * GetScreenRect retrieves data from the various planes associated with the
|
|
679 * presentation space. The data is returned as a linear array of character
|
|
680 * values in the buffer provided. The buffer is not terminated by a null
|
|
681 * character.
|
|
682 * </p>
|
|
683 * <p>
|
|
684 * The application supplies two coordinates that represent opposing corners
|
|
685 * of a rectangle within the presentation space. The starting and ending
|
|
686 * coordinates can have any spatial relationship to each other. The data
|
|
687 * returned starts from the row containing the upper-most point to the row
|
|
688 * containing the lower-most point, and from the left-most column to the
|
|
689 * right-most column.
|
|
690 * </p>
|
|
691 * <p>
|
|
692 * The specified buffer must be at least large enough to contain the number
|
|
693 * of characters in the rectangle. If the buffer is too small, no data is
|
|
694 * copied and zero is returned by the method. Otherwise, the method returns
|
|
695 * the number of characters copied.
|
|
696 * </p>
|
|
697 *
|
|
698 * @param buffer
|
|
699 * @param bufferLength
|
|
700 * @param startRow
|
|
701 * @param startCol
|
|
702 * @param endRow
|
|
703 * @param endCol
|
|
704 * @param plane
|
|
705 * @return The number characters copied to the buffer
|
|
706 * @throws OhioException
|
|
707 */
|
|
708 protected int GetScreenRect(char buffer[], int bufferLength,
|
|
709 int startRow, int startCol,
|
|
710 int endRow, int endCol, int plane)
|
|
711 // throws OhioException {
|
|
712 {
|
|
713 // number of bytes obtained
|
|
714 int numBytes = 0;
|
|
715
|
|
716 // lets check the row range. If they are reversed then we need to
|
|
717 // place them in the correct order.
|
|
718 if(startRow > endRow) {
|
|
719 int r = startRow;
|
|
720 startRow = endRow;
|
|
721 endRow = r;
|
|
722 }
|
|
723 // lets check the column range. If they are reversed then we need to
|
|
724 // place them in the correct order.
|
|
725 if(startCol > endCol) {
|
|
726 int c = startCol;
|
|
727 startCol = endCol;
|
|
728 endCol = c;
|
|
729 }
|
|
730 int numCols = (endCol - startCol) + 1;
|
|
731 int numRows = (endRow - startRow) + 1;
|
|
732
|
|
733 // lets make sure it is within the bounds of the character array passed
|
|
734 // if not the return as zero bytes where read as per documentation.
|
|
735 if(numCols * numRows <= bufferLength) {
|
|
736
|
|
737 // make sure it is one larger. I guess for other languanges to
|
|
738 // reference like in C which is terminated by a zero byte at the end
|
|
739 // of strings.
|
|
740 char cb[] = new char[numCols + 1];
|
|
741 int charOffset = 0;
|
|
742 int bytes = 0;
|
|
743
|
|
744 // now let's loop through and get the screen information for
|
|
745 // each row;
|
|
746 for(int row = startRow; row <= endRow;) {
|
|
747 if((bytes = GetScreen(cb, cb.length, row, startCol, numCols, plane)) != 0) {
|
|
748 System.arraycopy(cb, 0, buffer, charOffset, numCols);
|
|
749 }
|
|
750 row++;
|
|
751 charOffset += numCols;
|
|
752 // make sure we count the number of bytes returned
|
|
753 numBytes += bytes;
|
|
754 }
|
|
755
|
|
756 }
|
|
757
|
|
758 return numBytes;
|
|
759 }
|
|
760
|
|
761 protected boolean checkHotSpots () {
|
|
762
|
|
763 Screen5250 s = scr;
|
|
764 int lenScreen = scr.getScreenLength();
|
|
765 boolean hs = false;
|
|
766 boolean retHS = false;
|
|
767 StringBuffer hsMore = s.getHSMore();
|
|
768 StringBuffer hsBottom = s.getHSBottom();
|
|
769
|
|
770 for (int x = 0; x < lenScreen; x++) {
|
|
771
|
|
772 hs =false;
|
|
773 if (s.isInField(x,false))
|
|
774 continue;
|
|
775
|
|
776 // First check for PF keys
|
|
777 if (x > 0 && screen[x] == 'F') {
|
|
778 if (screen[x + 1] >= '0' &&
|
|
779 screen[x + 1] <= '9' &&
|
|
780 screen[x - 1] <= ' ' &&
|
|
781 (screenExtended[x] & EXTENDED_5250_NON_DSP) == 0) {
|
|
782
|
|
783 if (screen[x + 2] >= '0' &&
|
|
784 screen[x + 2] <= '9' &&
|
|
785 (screen[x + 3] == '=' ||
|
|
786 screen[x + 3] == '-' ||
|
|
787 screen[x + 3] == '/') )
|
|
788 hs = true;
|
|
789 else
|
|
790 if ( screen[x + 2] == '=' ||
|
|
791 screen[x + 3] == '-' ||
|
|
792 screen[x + 3] == '/')
|
|
793 hs = true;
|
|
794
|
|
795 if (hs) {
|
|
796 screenGUI[x] = BUTTON_LEFT;
|
|
797
|
|
798 int ns = 0;
|
|
799 int row = x / numCols;
|
|
800 while (ns < 2 && ++x / numCols == row) {
|
|
801 if (screen[x] <= ' ')
|
|
802 ns++;
|
|
803 else
|
|
804 ns = 0;
|
|
805 if (ns <2)
|
|
806 screenGUI[x] = BUTTON_MIDDLE;
|
|
807
|
|
808 }
|
|
809
|
|
810 // now lets go back and take out gui's that do not belong
|
|
811 while (screen[--x] <= ' ') {
|
|
812 screenGUI[x] = NO_GUI;
|
|
813 }
|
|
814 screenGUI[x] = BUTTON_RIGHT;
|
|
815
|
|
816 }
|
|
817 }
|
|
818 }
|
|
819
|
|
820 // now lets check for menus
|
|
821 if (!hs && x > 0 && x < lenScreen - 2 &&
|
|
822 screen[x] == '.' &&
|
|
823 screenGUI[x] == NO_GUI &&
|
|
824 (screenExtended[x] & EXTENDED_5250_UNDERLINE) == 0 &&
|
|
825 (screenExtended[x] & EXTENDED_5250_NON_DSP) == 0
|
|
826 ) {
|
|
827
|
|
828 int os = 0;
|
|
829 if ((os = isOption(screen,x,lenScreen,2,3,'.') )> 0) {
|
|
830 hs = true;
|
|
831
|
|
832 int stop = x;
|
|
833 int ns = 0;
|
|
834 int row = stop / numCols;
|
|
835
|
|
836 while (++stop / numCols == row &&
|
|
837 (screen[stop] >= ' ' ||
|
|
838 screen[stop] == 0x0) ) {
|
|
839
|
|
840 if (screen[stop] <= ' ') {
|
|
841 ns++;
|
|
842 }
|
|
843 else
|
|
844 ns = 0;
|
|
845
|
|
846 if (screen[stop] == '.') {
|
|
847 int io = 0;
|
|
848 if ((io = isOption(screen,stop,lenScreen,2,3,'.')) > 0) {
|
|
849
|
|
850 stop = io;
|
|
851 break;
|
|
852 }
|
|
853 }
|
|
854
|
|
855 if (ns > 3)
|
|
856 break;
|
|
857 }
|
|
858
|
|
859 screenGUI[++os] = BUTTON_LEFT;
|
|
860 s.setDirty(os);
|
|
861
|
|
862 while (++os < stop) {
|
|
863 screenGUI[os] = BUTTON_MIDDLE;
|
|
864 s.setDirty(os);
|
|
865 }
|
|
866
|
|
867 // now lets go back and take out gui's that do not belong
|
|
868 while (screen[--stop] <= ' ') {
|
|
869 screenGUI[stop] = NO_GUI;
|
|
870 s.setDirty(stop);
|
|
871 }
|
|
872 screenGUI[stop] = BUTTON_RIGHT;
|
|
873 s.setDirty(stop);
|
|
874
|
|
875 }
|
|
876 }
|
|
877
|
|
878 // now lets check for options.
|
|
879 if (!hs && x > 0 && x < lenScreen - 2 &&
|
|
880 screen[x] == '=' &&
|
|
881 screenGUI[x] == NO_GUI &&
|
|
882 (screenExtended[x] & EXTENDED_5250_UNDERLINE) == 0 &&
|
|
883 (screenExtended[x] & EXTENDED_5250_NON_DSP) == 0
|
|
884 ) {
|
|
885
|
|
886 int os = 0;
|
|
887 if ((os = isOption(screen,x,lenScreen,2,2,'=') )> 0) {
|
|
888 hs = true;
|
|
889
|
|
890 int stop = x;
|
|
891 int ns = 0;
|
|
892 int row = stop / numCols;
|
|
893
|
|
894 while (++stop / numCols == row &&
|
|
895 screen[stop] >= ' ') {
|
|
896
|
|
897 if (screen[stop] == ' ') {
|
|
898 ns++;
|
|
899 }
|
|
900 else
|
|
901 ns = 0;
|
|
902
|
|
903 if (screen[stop] == '=') {
|
|
904 int io = 0;
|
|
905 if ((io = isOption(screen,stop,lenScreen,2,2,'=')) > 0) {
|
|
906
|
|
907 stop = io;
|
|
908 break;
|
|
909 }
|
|
910 }
|
|
911
|
|
912 if (ns > 2)
|
|
913 break;
|
|
914 }
|
|
915
|
|
916 screenGUI[++os] = BUTTON_LEFT;
|
|
917 s.setDirty(os);
|
|
918
|
|
919 while (++os < stop) {
|
|
920 screenGUI[os] = BUTTON_MIDDLE;
|
|
921 s.setDirty(os);
|
|
922
|
|
923 }
|
|
924
|
|
925 // now lets go back and take out gui's that do not belong
|
|
926 while (screen[--stop] <= ' ') {
|
|
927 screenGUI[stop] = NO_GUI;
|
|
928 s.setDirty(stop);
|
|
929
|
|
930 }
|
|
931 screenGUI[stop] = BUTTON_RIGHT;
|
|
932 s.setDirty(stop);
|
|
933 }
|
|
934 }
|
|
935
|
|
936 // now lets check for More... .
|
|
937
|
|
938 if (!hs && x > 2 && x < lenScreen - hsMore.length() &&
|
|
939 screen[x] == hsMore.charAt(0) &&
|
|
940 screen[x - 1] <= ' ' &&
|
|
941 screen[x - 2] <= ' ' &&
|
|
942 screenGUI[x] == NO_GUI &&
|
|
943 (screenExtended[x] & EXTENDED_5250_NON_DSP) == 0
|
|
944 ) {
|
|
945
|
|
946 boolean mFlag = true;
|
|
947 int ms = hsMore.length();
|
|
948 int mc = 0;
|
|
949 while (++mc < ms) {
|
|
950 if (screen[x+mc] != hsMore.charAt(mc)) {
|
|
951 mFlag = false;
|
|
952 break;
|
|
953 }
|
|
954
|
|
955 }
|
|
956
|
|
957 if (mFlag) {
|
|
958 hs = true;
|
|
959
|
|
960 screenGUI[x] = BUTTON_LEFT_DN;
|
|
961
|
|
962 while (--ms > 0) {
|
|
963 screenGUI[++x] = BUTTON_MIDDLE_DN;
|
|
964
|
|
965 }
|
|
966 screenGUI[x] = BUTTON_RIGHT_DN;
|
|
967 }
|
|
968 }
|
|
969
|
|
970 // now lets check for Bottom .
|
|
971 if (!hs && x > 2 && x < lenScreen - hsBottom.length() &&
|
|
972 screen[x] == hsBottom.charAt(0) &&
|
|
973 screen[x - 1] <= ' ' &&
|
|
974 screen[x - 2] <= ' ' &&
|
|
975 screenGUI[x] == NO_GUI &&
|
|
976 (screenExtended[x] & EXTENDED_5250_NON_DSP) == 0
|
|
977 ) {
|
|
978
|
|
979 boolean mFlag = true;
|
|
980 int bs = hsBottom.length();
|
|
981 int bc = 0;
|
|
982 while (++bc < bs) {
|
|
983 if (screen[x+bc] != hsBottom.charAt(bc)) {
|
|
984 mFlag = false;
|
|
985 break;
|
|
986 }
|
|
987
|
|
988 }
|
|
989
|
|
990 if (mFlag) {
|
|
991 hs = true;
|
|
992
|
|
993 screenGUI[x] = BUTTON_LEFT_UP;
|
|
994
|
|
995 while (--bs > 0) {
|
|
996 screenGUI[++x] = BUTTON_MIDDLE_UP;
|
|
997
|
|
998 }
|
|
999 screenGUI[x] = BUTTON_RIGHT_UP;
|
|
1000 }
|
|
1001 }
|
|
1002
|
|
1003 // Submitted by Richard Houston of RLH Consulting rhouston@rlhc.net
|
|
1004 // now lets check for HTTP:// or HTTPS://.
|
|
1005 if (!hs && x > 0 && x < lenScreen - 7 &&
|
|
1006 Character.toLowerCase(screen[x]) == 'h' &&
|
|
1007 screen[x - 1] <= ' ' &&
|
|
1008 screenGUI[x] == NO_GUI &&
|
|
1009 (screenExtended[x] & EXTENDED_5250_NON_DSP) == 0
|
|
1010 ) {
|
|
1011
|
|
1012 if (Character.toLowerCase(screen[x+1]) == 't' &&
|
|
1013 Character.toLowerCase(screen[x+2]) == 't' &&
|
|
1014 Character.toLowerCase(screen[x+3]) == 'p' &&
|
|
1015 screen[x+4] == ':' &&
|
|
1016 screen[x+5] == '/' &&
|
|
1017 screen[x+6] == '/' ) {
|
|
1018
|
|
1019 hs = true;
|
|
1020
|
|
1021 screenGUI[x] = BUTTON_LEFT_EB;
|
|
1022
|
|
1023 while (screen[++x] > ' ') {
|
|
1024 screenGUI[x] = BUTTON_MIDDLE_EB;
|
|
1025
|
|
1026 }
|
|
1027
|
|
1028 screenGUI[--x] = BUTTON_RIGHT_EB;
|
|
1029 }
|
|
1030
|
|
1031 else if (Character.toLowerCase(screen[x+1]) == 't' &&
|
|
1032 Character.toLowerCase(screen[x+2]) == 't' &&
|
|
1033 Character.toLowerCase(screen[x+3]) == 'p' &&
|
|
1034 Character.toLowerCase(screen[x+4]) == 's' &&
|
|
1035 screen[x+5] == ':' &&
|
|
1036 screen[x+6] == '/' &&
|
|
1037 screen[x+7] == '/' ) {
|
|
1038
|
|
1039 hs = true;
|
|
1040
|
|
1041 screenGUI[x] = BUTTON_LEFT_EB;
|
|
1042
|
|
1043 while (screen[++x] > ' ') {
|
|
1044 screenGUI[x] = BUTTON_MIDDLE_EB;
|
|
1045
|
|
1046 }
|
|
1047
|
|
1048 screenGUI[--x] = BUTTON_RIGHT_EB;
|
|
1049 }
|
|
1050
|
|
1051 }
|
|
1052 // now lets check for MAILTO: .
|
|
1053 else if (!hs && x > 0 && x < lenScreen - 7 &&
|
|
1054 Character.toLowerCase(screen[x]) == 'm' &&
|
|
1055 screen[x - 1] <= ' ' &&
|
|
1056 screenGUI[x] == NO_GUI &&
|
|
1057 (screenExtended[x] & EXTENDED_5250_NON_DSP) == 0
|
|
1058 ) {
|
|
1059
|
|
1060 if (Character.toLowerCase(screen[x+1]) == 'a' &&
|
|
1061 Character.toLowerCase(screen[x+2]) == 'i' &&
|
|
1062 Character.toLowerCase(screen[x+3]) == 'l' &&
|
|
1063 Character.toLowerCase(screen[x+4]) == 't' &&
|
|
1064 Character.toLowerCase(screen[x+5]) == 'o' &&
|
|
1065 screen[x+6] == ':') {
|
|
1066
|
|
1067 hs = true;
|
|
1068
|
|
1069 screenGUI[x] = BUTTON_LEFT_EB;
|
|
1070
|
|
1071 while (screen[++x] > ' ') {
|
|
1072 screenGUI[x] = BUTTON_MIDDLE_EB;
|
|
1073
|
|
1074 }
|
|
1075 screenGUI[--x] = BUTTON_RIGHT_EB;
|
|
1076 }
|
|
1077 }
|
|
1078 // now lets check for External Program: .
|
|
1079 else if (!hs && x > 0 && x < lenScreen - 7 &&
|
|
1080 screen[x - 1] <= ' ' &&
|
|
1081 screenGUI[x] == NO_GUI &&
|
|
1082 (screenExtended[x] & EXTENDED_5250_NON_DSP) == 0
|
|
1083 ) {
|
|
1084 Properties etnProps = ExternalProgramConfig.getInstance().getEtnPgmProps();
|
|
1085 String count = etnProps.getProperty("etn.pgm.support.total.num");
|
|
1086 if(count != null && count.length() > 0){
|
|
1087 int total = Integer.parseInt(count);
|
|
1088 for(int i=1;i<=total;i++){
|
|
1089 String program = etnProps.getProperty("etn.pgm."+i+".command.name");
|
|
1090 String key="";
|
|
1091 if(x + program.length() >= screen.length) break;
|
|
1092 for(int j=0;j<=program.length();j++){
|
|
1093 key+=screen[x+j];
|
|
1094 }
|
|
1095 if(key.toLowerCase().equals(program.toLowerCase()+":")) {
|
|
1096 hs = true;
|
|
1097 screenGUI[x] = BUTTON_LEFT_EB;
|
|
1098 while (screen[++x] > ' ') {
|
|
1099 screenGUI[x] = BUTTON_MIDDLE_EB;
|
|
1100 }
|
|
1101 screenGUI[--x] = BUTTON_RIGHT_EB;
|
|
1102 break;
|
|
1103 }
|
|
1104 }
|
|
1105 }
|
|
1106 }
|
|
1107
|
|
1108 if (!retHS && hs)
|
|
1109 retHS = true;
|
|
1110
|
|
1111 }
|
|
1112
|
|
1113 return retHS;
|
|
1114 }
|
|
1115
|
|
1116 private int isOption(char[] screen,
|
|
1117 int x,
|
|
1118 int lenScreen,
|
|
1119 int numPref,
|
|
1120 int numSuff,
|
|
1121 char suff) {
|
|
1122 boolean hs =true;
|
|
1123 int sp = x;
|
|
1124 int os = 0;
|
|
1125 // check to the left for option
|
|
1126 while (--sp >=0 && screen[sp] <= ' ' ) {
|
|
1127
|
|
1128 if (x - sp > numPref || screen[sp] == suff||
|
|
1129 screen[sp] == '.' ||
|
|
1130 screen[sp] == '*') {
|
|
1131 hs =false;
|
|
1132 break;
|
|
1133 }
|
|
1134 }
|
|
1135
|
|
1136 // now lets check for how long the option is it has to be numPref or less
|
|
1137 os = sp;
|
|
1138 while (hs && --os > 0 && screen[os] > ' ' ) {
|
|
1139
|
|
1140 if (sp - os >= numPref || screen[os] == suff ||
|
|
1141 screen[os] == '.' ||
|
|
1142 screen[os] == '*') {
|
|
1143 hs = false;
|
|
1144 break;
|
|
1145 }
|
|
1146 }
|
|
1147 if (sp - os > 1 && !Character.isDigit(screen[os+1])) {
|
|
1148 hs = false;
|
|
1149 }
|
|
1150
|
|
1151 sp = x;
|
|
1152
|
|
1153 if (Character.isDigit(screen[sp+1]))
|
|
1154 hs = false;
|
|
1155 // now lets make sure there are no more than numSuff spaces after option
|
|
1156 while (hs && (++sp < lenScreen && screen[sp] <= ' '
|
|
1157 || screen[sp] == suff )) {
|
|
1158 if (sp - x >= numSuff || screen[sp] == suff ||
|
|
1159 screen[sp] == '.' ||
|
|
1160 screen[sp] == '*') {
|
|
1161 hs =false;
|
|
1162 break;
|
|
1163 }
|
|
1164 }
|
|
1165 if (hs && !Character.isLetterOrDigit(screen[sp]))
|
|
1166 hs = false;
|
|
1167 if (hs) {
|
|
1168 return os;
|
|
1169 }
|
|
1170 return -1;
|
|
1171 }
|
|
1172
|
|
1173 } |