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 public class ScreenPlanes {
|
|
33
|
|
34 private final Screen5250 scr;
|
|
35 private int screenSize;
|
|
36 private int numRows;
|
|
37 private int numCols;
|
|
38 private int errorLineNum;
|
|
39
|
|
40 private static final int initAttr = 32;
|
|
41 private static final char initChar = 0;
|
|
42
|
|
43 protected char[] screen; // text plane
|
|
44 private char[] screenAttr; // attribute plane
|
|
45 private char[] screenGUI; // gui plane
|
|
46 private char[] screenIsAttr;
|
|
47 private char[] fieldExtended;
|
|
48 private char[] screenField;
|
|
49 private char[] screenColor; // color plane
|
|
50 protected char[] screenExtended; // extended plane
|
|
51 private char[] screenIsChanged;
|
|
52
|
|
53 private char[] initArray;
|
|
54
|
|
55 private char[] errorLine;
|
|
56 private char[] errorLineAttr;
|
|
57 private char[] errorLineIsAttr;
|
|
58 private char[] errorLineGui;
|
|
59
|
|
60 public ScreenPlanes(Screen5250 s5250, int size) {
|
|
61
|
|
62 scr = s5250;
|
|
63 setSize(size);
|
|
64 }
|
|
65
|
|
66 protected void setSize(int newSize) {
|
|
67
|
|
68 screenSize = newSize;
|
|
69
|
|
70 numCols = 80;
|
|
71 switch (newSize) {
|
|
72 case 24:
|
|
73 numRows = 24;
|
|
74 break;
|
|
75 case 27:
|
|
76 numRows = 27;
|
|
77 numCols = 132;
|
|
78 break;
|
|
79
|
|
80 }
|
|
81
|
|
82 // this is used here when size changes
|
|
83 setErrorLine(numRows);
|
|
84
|
|
85 screenSize = numRows * numCols;
|
|
86 screen = new char[screenSize];
|
|
87 screenAttr = new char[screenSize];
|
|
88 screenIsAttr = new char[screenSize];
|
|
89 screenGUI = new char[screenSize];
|
|
90 screenColor = new char[screenSize];
|
|
91 screenExtended = new char[screenSize];
|
|
92 fieldExtended = new char[screenSize];
|
|
93 screenIsChanged = new char[screenSize];
|
|
94 screenField = new char[screenSize];
|
|
95
|
|
96 initArray = new char[screenSize];
|
|
97
|
|
98 initalizePlanes();
|
|
99 }
|
|
100
|
|
101 protected void setErrorLine (int line) {
|
|
102
|
|
103 // * NOTE * for developers I have changed the send qry to pass different
|
|
104 // parameters to the host so check setsize for setting error line as well.
|
|
105 //
|
|
106 if (line == 0 || line > numRows)
|
|
107 errorLineNum = numRows;
|
|
108 else
|
|
109 errorLineNum = line;
|
|
110 }
|
|
111
|
|
112 /**
|
|
113 * Returns the current error line number
|
|
114 *
|
|
115 * @return current error line number
|
|
116 */
|
|
117 protected int getErrorLine() {
|
|
118 return errorLineNum;
|
|
119 }
|
|
120
|
|
121 protected void saveErrorLine() {
|
|
122
|
|
123 // if there is already an error line saved then do not save it again
|
|
124 // This signifies that there was a previous error and the original error
|
|
125 // line was not restored yet.
|
|
126 if (errorLine == null) {
|
|
127 errorLine = new char[numCols];
|
|
128 errorLineAttr = new char[numCols];
|
|
129 errorLineIsAttr = new char[numCols];
|
|
130 errorLineGui = new char[numCols];
|
|
131
|
|
132 int r = scr.getPos(errorLineNum-1,0);
|
|
133
|
|
134 for (int x = 0;x < numCols; x++) {
|
|
135 errorLine[x] = screen[r+x];
|
|
136 errorLineAttr[x] = screenAttr[r+x];
|
|
137 errorLineIsAttr[x] = screenIsAttr[r+x];
|
|
138 errorLineGui[x] = screenGUI[r+x];
|
|
139 }
|
|
140 }
|
|
141 }
|
|
142
|
|
143 /**
|
|
144 * Restores the error line characters from the save buffer.
|
|
145 *
|
|
146 * @see #saveErrorLine()
|
|
147 */
|
|
148 protected void restoreErrorLine() {
|
|
149
|
|
150 if (errorLine != null) {
|
|
151 int r = scr.getPos(errorLineNum - 1, 0);
|
|
152
|
|
153 for (int x = 0; x < numCols - 1; x++) {
|
|
154 setScreenCharAndAttr(r+x,errorLine[x],errorLineAttr[x],
|
|
155 (errorLineIsAttr[x] == '1' ? true : false));
|
|
156 screenGUI[x] = errorLineGui[x];
|
|
157 }
|
|
158
|
|
159 errorLine = null;
|
|
160 errorLineAttr = null;
|
|
161 errorLineIsAttr = null;
|
|
162 errorLineGui = null;
|
|
163 }
|
|
164 }
|
|
165
|
|
166 protected boolean isErrorLineSaved() {
|
|
167 return errorLine == null ? false : true;
|
|
168 }
|
|
169
|
|
170 protected void setScreenCharAndAttr(int pos, char c, int attr, boolean isAttr) {
|
|
171
|
|
172 screen[pos] = c;
|
|
173 screenAttr[pos] = (char)attr;
|
|
174 disperseAttribute(pos,attr);
|
|
175 screenIsAttr[pos] = (isAttr ? (char)1 : (char)0);
|
|
176 screenGUI[pos] = NO_GUI;
|
|
177
|
|
178 }
|
|
179
|
|
180 protected void setScreenAttr(int pos, int attr, boolean isAttr) {
|
|
181
|
|
182 screenAttr[pos] = (char)attr;
|
|
183 screenIsAttr[pos] = isAttr ? (char)1 : (char)0;
|
|
184 disperseAttribute(pos,attr);
|
|
185 screenGUI[pos] = initChar;
|
|
186
|
|
187 }
|
|
188
|
|
189 protected void setScreenAttr(int pos, int attr) {
|
|
190
|
|
191 screenAttr[pos] = (char)attr;
|
|
192 //screenGUI[pos] = initChar;
|
|
193 disperseAttribute(pos,attr);
|
|
194
|
|
195 }
|
|
196
|
|
197 protected void setScreenFieldAttr(int pos, int attr) {
|
|
198
|
|
199 screenField[pos] = (char)attr;
|
|
200
|
|
201 }
|
|
202
|
|
203 protected final void setChar(int pos, char c) {
|
|
204 screenIsChanged[pos] = screen[pos] == c ? '0' : '1';
|
|
205 screen[pos] = c;
|
|
206 if (screenIsAttr[pos] == 1)
|
|
207 setScreenCharAndAttr(pos,c,32,false);
|
|
208
|
|
209 }
|
|
210
|
|
211 protected final char getChar(int pos) {
|
|
212 return screen[pos];
|
|
213 }
|
|
214
|
|
215 protected final int getCharAttr(int pos) {
|
|
216 return screenAttr[pos];
|
|
217 }
|
|
218
|
|
219 protected final boolean isAttributePlace(int pos) {
|
|
220 return screenIsAttr[pos] == 1 ? true : false;
|
|
221 }
|
|
222
|
|
223 public final void setUseGUI(int pos, int which) {
|
|
224
|
|
225 screenIsChanged[pos] = screenGUI[pos] == which ? '0' : '1';
|
|
226 screenGUI[pos] = (char)which;
|
|
227 }
|
|
228
|
|
229 private void disperseAttribute(int pos, int attr) {
|
|
230
|
|
231 char c = 0;
|
|
232 char cs = 0;
|
|
233 char ul = 0;
|
|
234 char nd = 0;
|
|
235
|
|
236 if(attr == 0)
|
|
237 return;
|
|
238
|
|
239 switch(attr) {
|
|
240 case 32: // green normal
|
|
241 c = ATTR_32;
|
|
242 break;
|
|
243
|
|
244 case 33: // green/revers
|
|
245 c = ATTR_33;
|
|
246 break;
|
|
247
|
|
248 case 34: // white normal
|
|
249 c = ATTR_34;
|
|
250 break;
|
|
251
|
|
252 case 35: // white/reverse
|
|
253 c = ATTR_35;
|
|
254 break;
|
|
255
|
|
256 case 36: // green/underline
|
|
257 c = ATTR_36;
|
|
258 ul = EXTENDED_5250_UNDERLINE;
|
|
259 break;
|
|
260
|
|
261 case 37: // green/reverse/underline
|
|
262 c = ATTR_37;
|
|
263 ul = EXTENDED_5250_UNDERLINE;
|
|
264 break;
|
|
265
|
|
266 case 38: // white/underline
|
|
267 c = ATTR_38;
|
|
268 ul = EXTENDED_5250_UNDERLINE;
|
|
269 break;
|
|
270
|
|
271 case 39:
|
|
272 nd = EXTENDED_5250_NON_DSP;
|
|
273 break;
|
|
274
|
|
275 case 40:
|
|
276 case 42: // red/normal
|
|
277 c = ATTR_40;
|
|
278 break;
|
|
279
|
|
280 case 41:
|
|
281 case 43: // red/reverse
|
|
282 c = ATTR_41;
|
|
283 break;
|
|
284
|
|
285 case 44:
|
|
286 case 46: // red/underline
|
|
287 c = ATTR_44;
|
|
288 ul = EXTENDED_5250_UNDERLINE;
|
|
289 break;
|
|
290
|
|
291 case 45: // red/reverse/underline
|
|
292 c = ATTR_45;
|
|
293 ul = EXTENDED_5250_UNDERLINE;
|
|
294 break;
|
|
295
|
|
296 case 47:
|
|
297 nd = EXTENDED_5250_NON_DSP;
|
|
298 break;
|
|
299
|
|
300 case 48:
|
|
301 c = ATTR_48;
|
|
302 cs = EXTENDED_5250_COL_SEP;
|
|
303 break;
|
|
304
|
|
305 case 49:
|
|
306 c = ATTR_49;
|
|
307 cs = EXTENDED_5250_COL_SEP;
|
|
308 break;
|
|
309
|
|
310 case 50:
|
|
311 c = ATTR_50;
|
|
312 cs = EXTENDED_5250_COL_SEP;
|
|
313 break;
|
|
314
|
|
315 case 51:
|
|
316 c = ATTR_51;
|
|
317 cs = EXTENDED_5250_COL_SEP;
|
|
318 break;
|
|
319
|
|
320 case 52:
|
|
321 c = ATTR_52;
|
|
322 // colSep = true;
|
|
323 ul = EXTENDED_5250_UNDERLINE;
|
|
324 break;
|
|
325
|
|
326 case 53:
|
|
327 c = ATTR_53;
|
|
328 // colSep = true;
|
|
329 ul = EXTENDED_5250_UNDERLINE;
|
|
330 break;
|
|
331
|
|
332 case 54:
|
|
333 c = ATTR_54;
|
|
334 // colSep = true;
|
|
335 ul = EXTENDED_5250_UNDERLINE;
|
|
336 break;
|
|
337
|
|
338 case 55:
|
|
339 nd = EXTENDED_5250_NON_DSP;
|
|
340 break;
|
|
341
|
|
342 case 56: // pink
|
|
343 c = ATTR_56;
|
|
344 break;
|
|
345
|
|
346 case 57: // pink/reverse
|
|
347 c = ATTR_57;
|
|
348 break;
|
|
349
|
|
350 case 58: // blue/reverse
|
|
351 c = ATTR_58;
|
|
352 break;
|
|
353
|
|
354 case 59: // blue
|
|
355 c = ATTR_59;
|
|
356 break;
|
|
357
|
|
358 case 60: // pink/underline
|
|
359 c = ATTR_60;
|
|
360 ul = EXTENDED_5250_UNDERLINE;
|
|
361 break;
|
|
362
|
|
363 case 61: // pink/reverse/underline
|
|
364 c = ATTR_61;
|
|
365 ul = EXTENDED_5250_UNDERLINE;
|
|
366 break;
|
|
367
|
|
368 case 62: // blue/underline
|
|
369 c = ATTR_62;
|
|
370 ul = EXTENDED_5250_UNDERLINE;
|
|
371 break;
|
|
372
|
|
373 case 63: // nondisplay
|
|
374 nd = EXTENDED_5250_NON_DSP;
|
|
375 cs = EXTENDED_5250_COL_SEP;
|
|
376 break;
|
|
377 default:
|
|
378 c = ( COLOR_BG_BLACK << 8 & 0xff00) |
|
|
379 ( COLOR_FG_YELLOW & 0xff);
|
|
380 break;
|
|
381
|
|
382 }
|
|
383
|
|
384 screenColor[pos] = c;
|
|
385 screenExtended[pos] = (char)(ul | cs | nd);
|
|
386 }
|
|
387
|
|
388 protected void initalizePlanes () {
|
|
389
|
|
390 char c = (COLOR_BG_BLACK << 8 & 0xff00) |
|
|
391 (COLOR_FG_GREEN & 0xff);
|
|
392
|
|
393 for (int y = 0;y < screenSize; y++) {
|
|
394
|
|
395 screenAttr[y] = initAttr;
|
|
396 screenColor[y] = c;
|
|
397
|
|
398 }
|
|
399
|
|
400 // here we will just copy the initialized plane onto the other planes
|
|
401 // using arraycopy which will be faster. I hope.
|
|
402
|
|
403 System.arraycopy(initArray,0,screen,0,screenSize);
|
|
404 System.arraycopy(initArray,0,screenGUI,0,screenSize);
|
|
405 System.arraycopy(initArray,0,screenIsAttr,0,screenSize);
|
|
406 System.arraycopy(initArray,0,screenExtended,0,screenSize);
|
|
407 System.arraycopy(initArray,0,fieldExtended,0,screenSize);
|
|
408 System.arraycopy(initArray,0,screenField,0,screenSize);
|
|
409 }
|
|
410
|
|
411 protected void initalizeFieldPlanes () {
|
|
412 System.arraycopy(initArray,0,fieldExtended,0,screenSize);
|
|
413 System.arraycopy(initArray,0,screenField,0,screenSize);
|
|
414 }
|
|
415
|
|
416 protected final int getWhichGUI(int pos) {
|
|
417
|
|
418 return screenGUI[pos];
|
|
419 }
|
|
420
|
|
421 protected final boolean isChanged(int pos) {
|
|
422 return screenIsChanged[pos] == 0 ? false : true;
|
|
423 }
|
|
424
|
|
425 protected final boolean isUseGui(int pos) {
|
|
426 return screenGUI[pos] == NO_GUI ? false : true;
|
|
427 }
|
|
428
|
|
429 /**
|
|
430 * Return the data associated with the plane that is passed.
|
|
431 *
|
|
432 * @param from Position from which to start
|
|
433 * @param to Position to end
|
|
434 * @param plane From which plane to obtain the data
|
|
435 * @return Character array containing the data requested
|
|
436 */
|
|
437 protected synchronized char[] getPlaneData(int from, int to, int plane) {
|
|
438
|
|
439 int len = (to - from);
|
|
440
|
|
441 char[] planeChars = new char[len + 1];
|
|
442
|
|
443 switch (plane) {
|
|
444 case PLANE_TEXT:
|
|
445 System.arraycopy(screen, from, planeChars, 0, len);
|
|
446 break;
|
|
447 case PLANE_ATTR:
|
|
448 System.arraycopy(screenAttr, from, planeChars, 0, len);
|
|
449 break;
|
|
450 case PLANE_COLOR:
|
|
451 System.arraycopy(screenColor, from, planeChars, 0, len);
|
|
452 break;
|
|
453 case PLANE_EXTENDED:
|
|
454 System.arraycopy(screenExtended, from, planeChars, 0, len);
|
|
455 break;
|
|
456 case PLANE_EXTENDED_GRAPHIC:
|
|
457 System.arraycopy(screenGUI, from, planeChars, 0, len);
|
|
458 break;
|
|
459 case PLANE_FIELD:
|
|
460 System.arraycopy(screenField, from, planeChars, 0, len);
|
|
461 break;
|
|
462 case PLANE_IS_ATTR_PLACE:
|
|
463 System.arraycopy(screenIsAttr, from, planeChars, 0, len);
|
|
464 break;
|
|
465 default:
|
|
466 System.arraycopy(screen, from, planeChars, 0, len);
|
|
467
|
|
468 }
|
|
469 return planeChars;
|
|
470
|
|
471 }
|
|
472
|
|
473 /**
|
|
474 * Converts a linear presentation space position to its corresponding row.
|
|
475 *
|
|
476 * @param pos The position to be converted
|
|
477 * @return The row which corresponds to the position given
|
|
478 * @throws OhioException
|
|
479 */
|
|
480 private int convertPosToRow(int pos) {
|
|
481
|
|
482 return (pos / numCols) + 1;
|
|
483
|
|
484 }
|
|
485
|
|
486 /**
|
|
487 * Converts a linear presentation space position to its corresponding column.
|
|
488 *
|
|
489 * @param pos The position to be converted
|
|
490 * @return The column which corresponds to the position given
|
|
491 * @throws OhioException
|
|
492 */
|
|
493 private int convertPosToColumn(int pos) {
|
|
494
|
|
495 return (pos % numCols) + 1;
|
|
496
|
|
497 }
|
|
498
|
|
499 /**
|
|
500 *
|
|
501 * Converts a row and column coordinate to its corresponding linear position.
|
|
502 *
|
|
503 * @param row - The row of the coordinate
|
|
504 * @param col - The column of the coordinate
|
|
505 * @return The linear position which corresponds to the coordinate given.
|
|
506 * @throws OhioException
|
|
507 */
|
|
508 private int convertRowColToPos(int row, int col) {
|
|
509
|
|
510
|
|
511 return (row - 1) * numCols + col -1;
|
|
512
|
|
513 }
|
|
514
|
|
515
|
|
516 /**
|
|
517 * <p>
|
|
518 * GetScreen retrieves the various planes associated with the presentation
|
|
519 * space. The data is returned as a linear array of character values in the
|
|
520 * array provided. The array is not terminated by a null character except
|
|
521 * when data is retrieved from the text plane, in which case a single null
|
|
522 * character is appended.
|
|
523 * </p>
|
|
524 * <p>
|
|
525 * The application must supply a buffer for the returned data and the length
|
|
526 * of the buffer. Data is returned starting from the beginning of the
|
|
527 * presentation space and continuing until the buffer is full or the entire
|
|
528 * plane has been copied. For text plane data, the buffer must include one
|
|
529 * extra position for the terminating null character.
|
|
530 * <p>
|
|
531 *
|
|
532 * @param buffer
|
|
533 * @param bufferLength
|
|
534 * @param plane
|
|
535 * @return The number of characters copied to the buffer
|
|
536 * @throws OhioException
|
|
537 */
|
|
538 public synchronized int GetScreen(char buffer[], int bufferLength, int plane) {
|
|
539
|
|
540 return GetScreen(buffer,bufferLength,0,screenSize,plane);
|
|
541
|
|
542 }
|
|
543
|
|
544 /**
|
|
545 * <p>
|
|
546 * GetScreen retrieves the various planes associated with the presentation
|
|
547 * space. The data is returned as a linear array of character values in the
|
|
548 * array provided. The array is not terminated by a null character except
|
|
549 * when data is retrieved from the text plane, in which case a single null
|
|
550 * character is appended.
|
|
551 * </p>
|
|
552 * <p>
|
|
553 * The application must supply a buffer for the returned data and the length
|
|
554 * of the buffer. Data is returned starting from the given position and
|
|
555 * continuing until the specified number of characters have been copied, the
|
|
556 * buffer is full or the entire plane has been copied. For text plane data,
|
|
557 * the buffer must include one extra position for the terminating null character.
|
|
558 * </p>
|
|
559 *
|
|
560 * @param buffer
|
|
561 * @param bufferLength
|
|
562 * @param from
|
|
563 * @param length
|
|
564 * @param plane
|
|
565 * @return The number of characters copied to the buffer
|
|
566 * @throws OhioException
|
|
567 */
|
|
568 public synchronized int GetScreen(char buffer[], int bufferLength, int from,
|
|
569 int length, int plane)
|
|
570 {
|
|
571 // if(buffer == null)
|
|
572 // throw new OhioException(sessionVT.getSessionConfiguration(),
|
|
573 // OhioScreen.class.getName(), "osohio.screen.ohio00300", 1);
|
|
574 if(buffer == null)
|
|
575 return 0;
|
|
576
|
|
577 int min = Math.min(Math.min(buffer.length, bufferLength), screenSize);
|
|
578 if ((from + min) > screenSize) {
|
|
579 min = screenSize - from;
|
|
580 }
|
|
581
|
|
582 char[] pd = getPlaneData(from,from + min,plane);
|
|
583 if(pd != null) {
|
|
584 System.arraycopy(pd, 0, buffer, 0, min);
|
|
585 return pd.length;
|
|
586 }
|
|
587
|
|
588 return 0;
|
|
589 }
|
|
590
|
|
591 /**
|
|
592 * <p>
|
|
593 * GetScreen retrieves the various planes associated with the presentation
|
|
594 * space. The data is returned as a linear array of character values in the
|
|
595 * array provided. The array is not terminated by a null character except
|
|
596 * when data is retrieved from the text plane, in which case a single null
|
|
597 * character is appended.
|
|
598 * </p>
|
|
599 * <p>
|
|
600 * The application must supply a buffer for the returned data and the length
|
|
601 * of the buffer. Data is returned starting from the given coordinates and
|
|
602 * continuing until the specified number of characters have been copied,
|
|
603 * the buffer is full, or the entire plane has been copied. For text plane
|
|
604 * data, the buffer must include one extra position for the terminating null
|
|
605 * character.
|
|
606 * </p>
|
|
607 *
|
|
608 * @param buffer
|
|
609 * @param bufferLength
|
|
610 * @param row
|
|
611 * @param col
|
|
612 * @param length
|
|
613 * @param plane
|
|
614 * @return The number of characters copied to the buffer.
|
|
615 * @throws OhioException
|
|
616 */
|
|
617 public synchronized int GetScreen(char buffer[], int bufferLength, int row,
|
|
618 int col, int length, int plane)
|
|
619 // throws OhioException {
|
|
620 {
|
|
621 // Call GetScreen function after converting row and column to
|
|
622 // a position.
|
|
623 return GetScreen(buffer,bufferLength, convertRowColToPos(row,col),
|
|
624 length, plane);
|
|
625 }
|
|
626
|
|
627 /**
|
|
628 * <p>
|
|
629 * GetScreenRect retrieves data from the various planes associated with the
|
|
630 * presentation space. The data is returned as a linear array of character
|
|
631 * values in the buffer provided.
|
|
632 * </p>
|
|
633 *
|
|
634 * <p>
|
|
635 * The application supplies two positions that represent opposing corners of
|
|
636 * a rectangle within the presentation space. The starting and ending
|
|
637 * positions can have any spatial relationship to each other. The data
|
|
638 * returned starts from the row containing the upper-most point to the row
|
|
639 * containing the lower-most point, and from the left-most column to the
|
|
640 * right-most column.
|
|
641 * </p>
|
|
642 * <p>
|
|
643 * The specified buffer must be at least large enough to contain the number
|
|
644 * of characters in the rectangle. If the buffer is too small, no data is
|
|
645 * copied and zero is returned by the method. Otherwise, the method returns
|
|
646 * the number of characters copied.
|
|
647 * </p>
|
|
648 *
|
|
649 * @param buffer
|
|
650 * @param bufferLength
|
|
651 * @param startPos
|
|
652 * @param endPos
|
|
653 * @param plane
|
|
654 * @return The number of characters copied to the buffer
|
|
655 * @throws OhioException
|
|
656 */
|
|
657 protected int GetScreenRect(char buffer[], int bufferLength,
|
|
658 int startPos, int endPos, int plane)
|
|
659 // throws OhioException {
|
|
660 {
|
|
661 // We will use the row,col routine here because it is easier to use
|
|
662 // row colum than it is for position since I wrote the other first and
|
|
663 // am to lazy to implement it here
|
|
664 // Maybe it would be faster to do it the other way?
|
|
665 int startRow = convertPosToRow(startPos);
|
|
666 int startCol = convertPosToColumn(startPos);
|
|
667 int endRow = convertPosToRow(endPos);
|
|
668 int endCol = convertPosToColumn(endPos);
|
|
669 return GetScreenRect(buffer, bufferLength, startRow, startCol,
|
|
670 endRow, endCol, plane);
|
|
671
|
|
672 }
|
|
673
|
|
674 /**
|
|
675 * <p>
|
|
676 * GetScreenRect retrieves data from the various planes associated with the
|
|
677 * presentation space. The data is returned as a linear array of character
|
|
678 * values in the buffer provided. The buffer is not terminated by a null
|
|
679 * character.
|
|
680 * </p>
|
|
681 * <p>
|
|
682 * The application supplies two coordinates that represent opposing corners
|
|
683 * of a rectangle within the presentation space. The starting and ending
|
|
684 * coordinates can have any spatial relationship to each other. The data
|
|
685 * returned starts from the row containing the upper-most point to the row
|
|
686 * containing the lower-most point, and from the left-most column to the
|
|
687 * right-most column.
|
|
688 * </p>
|
|
689 * <p>
|
|
690 * The specified buffer must be at least large enough to contain the number
|
|
691 * of characters in the rectangle. If the buffer is too small, no data is
|
|
692 * copied and zero is returned by the method. Otherwise, the method returns
|
|
693 * the number of characters copied.
|
|
694 * </p>
|
|
695 *
|
|
696 * @param buffer
|
|
697 * @param bufferLength
|
|
698 * @param startRow
|
|
699 * @param startCol
|
|
700 * @param endRow
|
|
701 * @param endCol
|
|
702 * @param plane
|
|
703 * @return The number characters copied to the buffer
|
|
704 * @throws OhioException
|
|
705 */
|
|
706 protected int GetScreenRect(char buffer[], int bufferLength,
|
|
707 int startRow, int startCol,
|
|
708 int endRow, int endCol, int plane)
|
|
709 // throws OhioException {
|
|
710 {
|
|
711 // number of bytes obtained
|
|
712 int numBytes = 0;
|
|
713
|
|
714 // lets check the row range. If they are reversed then we need to
|
|
715 // place them in the correct order.
|
|
716 if(startRow > endRow) {
|
|
717 int r = startRow;
|
|
718 startRow = endRow;
|
|
719 endRow = r;
|
|
720 }
|
|
721 // lets check the column range. If they are reversed then we need to
|
|
722 // place them in the correct order.
|
|
723 if(startCol > endCol) {
|
|
724 int c = startCol;
|
|
725 startCol = endCol;
|
|
726 endCol = c;
|
|
727 }
|
|
728 int numCols = (endCol - startCol) + 1;
|
|
729 int numRows = (endRow - startRow) + 1;
|
|
730
|
|
731 // lets make sure it is within the bounds of the character array passed
|
|
732 // if not the return as zero bytes where read as per documentation.
|
|
733 if(numCols * numRows <= bufferLength) {
|
|
734
|
|
735 // make sure it is one larger. I guess for other languanges to
|
|
736 // reference like in C which is terminated by a zero byte at the end
|
|
737 // of strings.
|
|
738 char cb[] = new char[numCols + 1];
|
|
739 int charOffset = 0;
|
|
740 int bytes = 0;
|
|
741
|
|
742 // now let's loop through and get the screen information for
|
|
743 // each row;
|
|
744 for(int row = startRow; row <= endRow;) {
|
|
745 if((bytes = GetScreen(cb, cb.length, row, startCol, numCols, plane)) != 0) {
|
|
746 System.arraycopy(cb, 0, buffer, charOffset, numCols);
|
|
747 }
|
|
748 row++;
|
|
749 charOffset += numCols;
|
|
750 // make sure we count the number of bytes returned
|
|
751 numBytes += bytes;
|
|
752 }
|
|
753
|
|
754 }
|
|
755
|
|
756 return numBytes;
|
|
757 }
|
|
758
|
|
759 private int isOption(char[] screen,
|
|
760 int x,
|
|
761 int lenScreen,
|
|
762 int numPref,
|
|
763 int numSuff,
|
|
764 char suff) {
|
|
765 boolean hs =true;
|
|
766 int sp = x;
|
|
767 int os = 0;
|
|
768 // check to the left for option
|
|
769 while (--sp >=0 && screen[sp] <= ' ' ) {
|
|
770
|
|
771 if (x - sp > numPref || screen[sp] == suff||
|
|
772 screen[sp] == '.' ||
|
|
773 screen[sp] == '*') {
|
|
774 hs =false;
|
|
775 break;
|
|
776 }
|
|
777 }
|
|
778
|
|
779 // now lets check for how long the option is it has to be numPref or less
|
|
780 os = sp;
|
|
781 while (hs && --os > 0 && screen[os] > ' ' ) {
|
|
782
|
|
783 if (sp - os >= numPref || screen[os] == suff ||
|
|
784 screen[os] == '.' ||
|
|
785 screen[os] == '*') {
|
|
786 hs = false;
|
|
787 break;
|
|
788 }
|
|
789 }
|
|
790 if (sp - os > 1 && !Character.isDigit(screen[os+1])) {
|
|
791 hs = false;
|
|
792 }
|
|
793
|
|
794 sp = x;
|
|
795
|
|
796 if (Character.isDigit(screen[sp+1]))
|
|
797 hs = false;
|
|
798 // now lets make sure there are no more than numSuff spaces after option
|
|
799 while (hs && (++sp < lenScreen && screen[sp] <= ' '
|
|
800 || screen[sp] == suff )) {
|
|
801 if (sp - x >= numSuff || screen[sp] == suff ||
|
|
802 screen[sp] == '.' ||
|
|
803 screen[sp] == '*') {
|
|
804 hs =false;
|
|
805 break;
|
|
806 }
|
|
807 }
|
|
808 if (hs && !Character.isLetterOrDigit(screen[sp]))
|
|
809 hs = false;
|
|
810 if (hs) {
|
|
811 return os;
|
|
812 }
|
|
813 return -1;
|
|
814 }
|
|
815
|
|
816 } |