Mercurial > 510Connectbot
annotate src/org/tn5250j/framework/tn5250/ScreenPlanes.java @ 106:12425771714d
setField() needs to dirty the modified screen positions
author | Carl Byington <carl@five-ten-sg.com> |
---|---|
date | Wed, 18 Jun 2014 10:38:46 -0700 |
parents | 044b1a951925 |
children | 77ac18bc1b2f |
rev | line source |
---|---|
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 | |
75
bf01d1eec5c6
convert 5250 to vt320 attributes
Carl Byington <carl@five-ten-sg.com>
parents:
6
diff
changeset
|
215 protected final char getCharColor(int pos) { |
bf01d1eec5c6
convert 5250 to vt320 attributes
Carl Byington <carl@five-ten-sg.com>
parents:
6
diff
changeset
|
216 return screenColor[pos]; |
bf01d1eec5c6
convert 5250 to vt320 attributes
Carl Byington <carl@five-ten-sg.com>
parents:
6
diff
changeset
|
217 } |
bf01d1eec5c6
convert 5250 to vt320 attributes
Carl Byington <carl@five-ten-sg.com>
parents:
6
diff
changeset
|
218 |
3 | 219 protected final int getCharAttr(int pos) { |
220 return screenAttr[pos]; | |
221 } | |
222 | |
78
044b1a951925
convert 5250 to vt320 attributes
Carl Byington <carl@five-ten-sg.com>
parents:
75
diff
changeset
|
223 protected final char getCharExtended(int pos) { |
75
bf01d1eec5c6
convert 5250 to vt320 attributes
Carl Byington <carl@five-ten-sg.com>
parents:
6
diff
changeset
|
224 return screenExtended[pos]; |
bf01d1eec5c6
convert 5250 to vt320 attributes
Carl Byington <carl@five-ten-sg.com>
parents:
6
diff
changeset
|
225 } |
bf01d1eec5c6
convert 5250 to vt320 attributes
Carl Byington <carl@five-ten-sg.com>
parents:
6
diff
changeset
|
226 |
3 | 227 protected final boolean isAttributePlace(int pos) { |
228 return screenIsAttr[pos] == 1 ? true : false; | |
229 } | |
230 | |
231 public final void setUseGUI(int pos, int which) { | |
232 | |
233 screenIsChanged[pos] = screenGUI[pos] == which ? '0' : '1'; | |
234 screenGUI[pos] = (char)which; | |
235 } | |
236 | |
237 private void disperseAttribute(int pos, int attr) { | |
238 | |
239 char c = 0; | |
240 char cs = 0; | |
241 char ul = 0; | |
242 char nd = 0; | |
243 | |
244 if(attr == 0) | |
245 return; | |
246 | |
247 switch(attr) { | |
248 case 32: // green normal | |
249 c = ATTR_32; | |
250 break; | |
251 | |
252 case 33: // green/revers | |
253 c = ATTR_33; | |
254 break; | |
255 | |
256 case 34: // white normal | |
257 c = ATTR_34; | |
258 break; | |
259 | |
260 case 35: // white/reverse | |
261 c = ATTR_35; | |
262 break; | |
263 | |
264 case 36: // green/underline | |
265 c = ATTR_36; | |
266 ul = EXTENDED_5250_UNDERLINE; | |
267 break; | |
268 | |
269 case 37: // green/reverse/underline | |
270 c = ATTR_37; | |
271 ul = EXTENDED_5250_UNDERLINE; | |
272 break; | |
273 | |
274 case 38: // white/underline | |
275 c = ATTR_38; | |
276 ul = EXTENDED_5250_UNDERLINE; | |
277 break; | |
278 | |
279 case 39: | |
280 nd = EXTENDED_5250_NON_DSP; | |
281 break; | |
282 | |
283 case 40: | |
284 case 42: // red/normal | |
285 c = ATTR_40; | |
286 break; | |
287 | |
288 case 41: | |
289 case 43: // red/reverse | |
290 c = ATTR_41; | |
291 break; | |
292 | |
293 case 44: | |
294 case 46: // red/underline | |
295 c = ATTR_44; | |
296 ul = EXTENDED_5250_UNDERLINE; | |
297 break; | |
298 | |
299 case 45: // red/reverse/underline | |
300 c = ATTR_45; | |
301 ul = EXTENDED_5250_UNDERLINE; | |
302 break; | |
303 | |
304 case 47: | |
305 nd = EXTENDED_5250_NON_DSP; | |
306 break; | |
307 | |
308 case 48: | |
309 c = ATTR_48; | |
310 cs = EXTENDED_5250_COL_SEP; | |
311 break; | |
312 | |
313 case 49: | |
314 c = ATTR_49; | |
315 cs = EXTENDED_5250_COL_SEP; | |
316 break; | |
317 | |
318 case 50: | |
319 c = ATTR_50; | |
320 cs = EXTENDED_5250_COL_SEP; | |
321 break; | |
322 | |
323 case 51: | |
324 c = ATTR_51; | |
325 cs = EXTENDED_5250_COL_SEP; | |
326 break; | |
327 | |
328 case 52: | |
329 c = ATTR_52; | |
330 // colSep = true; | |
331 ul = EXTENDED_5250_UNDERLINE; | |
332 break; | |
333 | |
334 case 53: | |
335 c = ATTR_53; | |
336 // colSep = true; | |
337 ul = EXTENDED_5250_UNDERLINE; | |
338 break; | |
339 | |
340 case 54: | |
341 c = ATTR_54; | |
342 // colSep = true; | |
343 ul = EXTENDED_5250_UNDERLINE; | |
344 break; | |
345 | |
346 case 55: | |
347 nd = EXTENDED_5250_NON_DSP; | |
348 break; | |
349 | |
350 case 56: // pink | |
351 c = ATTR_56; | |
352 break; | |
353 | |
354 case 57: // pink/reverse | |
355 c = ATTR_57; | |
356 break; | |
357 | |
358 case 58: // blue/reverse | |
359 c = ATTR_58; | |
360 break; | |
361 | |
362 case 59: // blue | |
363 c = ATTR_59; | |
364 break; | |
365 | |
366 case 60: // pink/underline | |
367 c = ATTR_60; | |
368 ul = EXTENDED_5250_UNDERLINE; | |
369 break; | |
370 | |
371 case 61: // pink/reverse/underline | |
372 c = ATTR_61; | |
373 ul = EXTENDED_5250_UNDERLINE; | |
374 break; | |
375 | |
376 case 62: // blue/underline | |
377 c = ATTR_62; | |
378 ul = EXTENDED_5250_UNDERLINE; | |
379 break; | |
380 | |
381 case 63: // nondisplay | |
382 nd = EXTENDED_5250_NON_DSP; | |
383 cs = EXTENDED_5250_COL_SEP; | |
384 break; | |
385 default: | |
386 c = ( COLOR_BG_BLACK << 8 & 0xff00) | | |
387 ( COLOR_FG_YELLOW & 0xff); | |
388 break; | |
389 | |
390 } | |
391 | |
392 screenColor[pos] = c; | |
393 screenExtended[pos] = (char)(ul | cs | nd); | |
394 } | |
395 | |
396 protected void initalizePlanes () { | |
397 | |
398 char c = (COLOR_BG_BLACK << 8 & 0xff00) | | |
399 (COLOR_FG_GREEN & 0xff); | |
400 | |
401 for (int y = 0;y < screenSize; y++) { | |
402 | |
403 screenAttr[y] = initAttr; | |
404 screenColor[y] = c; | |
405 | |
406 } | |
407 | |
408 // here we will just copy the initialized plane onto the other planes | |
409 // using arraycopy which will be faster. I hope. | |
410 | |
411 System.arraycopy(initArray,0,screen,0,screenSize); | |
412 System.arraycopy(initArray,0,screenGUI,0,screenSize); | |
413 System.arraycopy(initArray,0,screenIsAttr,0,screenSize); | |
414 System.arraycopy(initArray,0,screenExtended,0,screenSize); | |
415 System.arraycopy(initArray,0,fieldExtended,0,screenSize); | |
416 System.arraycopy(initArray,0,screenField,0,screenSize); | |
417 } | |
418 | |
419 protected void initalizeFieldPlanes () { | |
420 System.arraycopy(initArray,0,fieldExtended,0,screenSize); | |
421 System.arraycopy(initArray,0,screenField,0,screenSize); | |
422 } | |
423 | |
424 protected final int getWhichGUI(int pos) { | |
425 | |
426 return screenGUI[pos]; | |
427 } | |
428 | |
429 protected final boolean isChanged(int pos) { | |
430 return screenIsChanged[pos] == 0 ? false : true; | |
431 } | |
432 | |
433 protected final boolean isUseGui(int pos) { | |
434 return screenGUI[pos] == NO_GUI ? false : true; | |
435 } | |
436 | |
437 /** | |
438 * Return the data associated with the plane that is passed. | |
439 * | |
440 * @param from Position from which to start | |
441 * @param to Position to end | |
442 * @param plane From which plane to obtain the data | |
443 * @return Character array containing the data requested | |
444 */ | |
445 protected synchronized char[] getPlaneData(int from, int to, int plane) { | |
446 | |
447 int len = (to - from); | |
448 | |
449 char[] planeChars = new char[len + 1]; | |
450 | |
451 switch (plane) { | |
452 case PLANE_TEXT: | |
453 System.arraycopy(screen, from, planeChars, 0, len); | |
454 break; | |
455 case PLANE_ATTR: | |
456 System.arraycopy(screenAttr, from, planeChars, 0, len); | |
457 break; | |
458 case PLANE_COLOR: | |
459 System.arraycopy(screenColor, from, planeChars, 0, len); | |
460 break; | |
461 case PLANE_EXTENDED: | |
462 System.arraycopy(screenExtended, from, planeChars, 0, len); | |
463 break; | |
464 case PLANE_EXTENDED_GRAPHIC: | |
465 System.arraycopy(screenGUI, from, planeChars, 0, len); | |
466 break; | |
467 case PLANE_FIELD: | |
468 System.arraycopy(screenField, from, planeChars, 0, len); | |
469 break; | |
470 case PLANE_IS_ATTR_PLACE: | |
471 System.arraycopy(screenIsAttr, from, planeChars, 0, len); | |
472 break; | |
473 default: | |
474 System.arraycopy(screen, from, planeChars, 0, len); | |
475 | |
476 } | |
477 return planeChars; | |
478 | |
479 } | |
480 | |
481 /** | |
482 * Converts a linear presentation space position to its corresponding row. | |
483 * | |
484 * @param pos The position to be converted | |
485 * @return The row which corresponds to the position given | |
486 * @throws OhioException | |
487 */ | |
488 private int convertPosToRow(int pos) { | |
489 | |
490 return (pos / numCols) + 1; | |
491 | |
492 } | |
493 | |
494 /** | |
495 * Converts a linear presentation space position to its corresponding column. | |
496 * | |
497 * @param pos The position to be converted | |
498 * @return The column which corresponds to the position given | |
499 * @throws OhioException | |
500 */ | |
501 private int convertPosToColumn(int pos) { | |
502 | |
503 return (pos % numCols) + 1; | |
504 | |
505 } | |
506 | |
507 /** | |
508 * | |
509 * Converts a row and column coordinate to its corresponding linear position. | |
510 * | |
511 * @param row - The row of the coordinate | |
512 * @param col - The column of the coordinate | |
513 * @return The linear position which corresponds to the coordinate given. | |
514 * @throws OhioException | |
515 */ | |
516 private int convertRowColToPos(int row, int col) { | |
517 | |
518 | |
519 return (row - 1) * numCols + col -1; | |
520 | |
521 } | |
522 | |
523 | |
524 /** | |
525 * <p> | |
526 * GetScreen retrieves the various planes associated with the presentation | |
527 * space. The data is returned as a linear array of character values in the | |
528 * array provided. The array is not terminated by a null character except | |
529 * when data is retrieved from the text plane, in which case a single null | |
530 * character is appended. | |
531 * </p> | |
532 * <p> | |
533 * The application must supply a buffer for the returned data and the length | |
534 * of the buffer. Data is returned starting from the beginning of the | |
535 * presentation space and continuing until the buffer is full or the entire | |
536 * plane has been copied. For text plane data, the buffer must include one | |
537 * extra position for the terminating null character. | |
538 * <p> | |
539 * | |
540 * @param buffer | |
541 * @param bufferLength | |
542 * @param plane | |
543 * @return The number of characters copied to the buffer | |
544 * @throws OhioException | |
545 */ | |
546 public synchronized int GetScreen(char buffer[], int bufferLength, int plane) { | |
547 | |
548 return GetScreen(buffer,bufferLength,0,screenSize,plane); | |
549 | |
550 } | |
551 | |
552 /** | |
553 * <p> | |
554 * GetScreen retrieves the various planes associated with the presentation | |
555 * space. The data is returned as a linear array of character values in the | |
556 * array provided. The array is not terminated by a null character except | |
557 * when data is retrieved from the text plane, in which case a single null | |
558 * character is appended. | |
559 * </p> | |
560 * <p> | |
561 * The application must supply a buffer for the returned data and the length | |
562 * of the buffer. Data is returned starting from the given position and | |
563 * continuing until the specified number of characters have been copied, the | |
564 * buffer is full or the entire plane has been copied. For text plane data, | |
565 * the buffer must include one extra position for the terminating null character. | |
566 * </p> | |
567 * | |
568 * @param buffer | |
569 * @param bufferLength | |
570 * @param from | |
571 * @param length | |
572 * @param plane | |
573 * @return The number of characters copied to the buffer | |
574 * @throws OhioException | |
575 */ | |
576 public synchronized int GetScreen(char buffer[], int bufferLength, int from, | |
577 int length, int plane) | |
578 { | |
579 // if(buffer == null) | |
580 // throw new OhioException(sessionVT.getSessionConfiguration(), | |
581 // OhioScreen.class.getName(), "osohio.screen.ohio00300", 1); | |
582 if(buffer == null) | |
583 return 0; | |
584 | |
585 int min = Math.min(Math.min(buffer.length, bufferLength), screenSize); | |
586 if ((from + min) > screenSize) { | |
587 min = screenSize - from; | |
588 } | |
589 | |
590 char[] pd = getPlaneData(from,from + min,plane); | |
591 if(pd != null) { | |
592 System.arraycopy(pd, 0, buffer, 0, min); | |
593 return pd.length; | |
594 } | |
595 | |
596 return 0; | |
597 } | |
598 | |
599 /** | |
600 * <p> | |
601 * GetScreen retrieves the various planes associated with the presentation | |
602 * space. The data is returned as a linear array of character values in the | |
603 * array provided. The array is not terminated by a null character except | |
604 * when data is retrieved from the text plane, in which case a single null | |
605 * character is appended. | |
606 * </p> | |
607 * <p> | |
608 * The application must supply a buffer for the returned data and the length | |
609 * of the buffer. Data is returned starting from the given coordinates and | |
610 * continuing until the specified number of characters have been copied, | |
611 * the buffer is full, or the entire plane has been copied. For text plane | |
612 * data, the buffer must include one extra position for the terminating null | |
613 * character. | |
614 * </p> | |
615 * | |
616 * @param buffer | |
617 * @param bufferLength | |
618 * @param row | |
619 * @param col | |
620 * @param length | |
621 * @param plane | |
622 * @return The number of characters copied to the buffer. | |
623 * @throws OhioException | |
624 */ | |
625 public synchronized int GetScreen(char buffer[], int bufferLength, int row, | |
626 int col, int length, int plane) | |
627 // throws OhioException { | |
628 { | |
629 // Call GetScreen function after converting row and column to | |
630 // a position. | |
631 return GetScreen(buffer,bufferLength, convertRowColToPos(row,col), | |
632 length, plane); | |
633 } | |
634 | |
635 /** | |
636 * <p> | |
637 * GetScreenRect retrieves data from the various planes associated with the | |
638 * presentation space. The data is returned as a linear array of character | |
639 * values in the buffer provided. | |
640 * </p> | |
641 * | |
642 * <p> | |
643 * The application supplies two positions that represent opposing corners of | |
644 * a rectangle within the presentation space. The starting and ending | |
645 * positions can have any spatial relationship to each other. The data | |
646 * returned starts from the row containing the upper-most point to the row | |
647 * containing the lower-most point, and from the left-most column to the | |
648 * right-most column. | |
649 * </p> | |
650 * <p> | |
651 * The specified buffer must be at least large enough to contain the number | |
652 * of characters in the rectangle. If the buffer is too small, no data is | |
653 * copied and zero is returned by the method. Otherwise, the method returns | |
654 * the number of characters copied. | |
655 * </p> | |
656 * | |
657 * @param buffer | |
658 * @param bufferLength | |
659 * @param startPos | |
660 * @param endPos | |
661 * @param plane | |
662 * @return The number of characters copied to the buffer | |
663 * @throws OhioException | |
664 */ | |
665 protected int GetScreenRect(char buffer[], int bufferLength, | |
666 int startPos, int endPos, int plane) | |
667 // throws OhioException { | |
668 { | |
669 // We will use the row,col routine here because it is easier to use | |
670 // row colum than it is for position since I wrote the other first and | |
671 // am to lazy to implement it here | |
672 // Maybe it would be faster to do it the other way? | |
673 int startRow = convertPosToRow(startPos); | |
674 int startCol = convertPosToColumn(startPos); | |
675 int endRow = convertPosToRow(endPos); | |
676 int endCol = convertPosToColumn(endPos); | |
677 return GetScreenRect(buffer, bufferLength, startRow, startCol, | |
678 endRow, endCol, plane); | |
679 | |
680 } | |
681 | |
682 /** | |
683 * <p> | |
684 * GetScreenRect retrieves data from the various planes associated with the | |
685 * presentation space. The data is returned as a linear array of character | |
686 * values in the buffer provided. The buffer is not terminated by a null | |
687 * character. | |
688 * </p> | |
689 * <p> | |
690 * The application supplies two coordinates that represent opposing corners | |
691 * of a rectangle within the presentation space. The starting and ending | |
692 * coordinates can have any spatial relationship to each other. The data | |
693 * returned starts from the row containing the upper-most point to the row | |
694 * containing the lower-most point, and from the left-most column to the | |
695 * right-most column. | |
696 * </p> | |
697 * <p> | |
698 * The specified buffer must be at least large enough to contain the number | |
699 * of characters in the rectangle. If the buffer is too small, no data is | |
700 * copied and zero is returned by the method. Otherwise, the method returns | |
701 * the number of characters copied. | |
702 * </p> | |
703 * | |
704 * @param buffer | |
705 * @param bufferLength | |
706 * @param startRow | |
707 * @param startCol | |
708 * @param endRow | |
709 * @param endCol | |
710 * @param plane | |
711 * @return The number characters copied to the buffer | |
712 * @throws OhioException | |
713 */ | |
714 protected int GetScreenRect(char buffer[], int bufferLength, | |
715 int startRow, int startCol, | |
716 int endRow, int endCol, int plane) | |
717 // throws OhioException { | |
718 { | |
719 // number of bytes obtained | |
720 int numBytes = 0; | |
721 | |
722 // lets check the row range. If they are reversed then we need to | |
723 // place them in the correct order. | |
724 if(startRow > endRow) { | |
725 int r = startRow; | |
726 startRow = endRow; | |
727 endRow = r; | |
728 } | |
729 // lets check the column range. If they are reversed then we need to | |
730 // place them in the correct order. | |
731 if(startCol > endCol) { | |
732 int c = startCol; | |
733 startCol = endCol; | |
734 endCol = c; | |
735 } | |
736 int numCols = (endCol - startCol) + 1; | |
737 int numRows = (endRow - startRow) + 1; | |
738 | |
739 // lets make sure it is within the bounds of the character array passed | |
740 // if not the return as zero bytes where read as per documentation. | |
741 if(numCols * numRows <= bufferLength) { | |
742 | |
743 // make sure it is one larger. I guess for other languanges to | |
744 // reference like in C which is terminated by a zero byte at the end | |
745 // of strings. | |
746 char cb[] = new char[numCols + 1]; | |
747 int charOffset = 0; | |
748 int bytes = 0; | |
749 | |
750 // now let's loop through and get the screen information for | |
751 // each row; | |
752 for(int row = startRow; row <= endRow;) { | |
753 if((bytes = GetScreen(cb, cb.length, row, startCol, numCols, plane)) != 0) { | |
754 System.arraycopy(cb, 0, buffer, charOffset, numCols); | |
755 } | |
756 row++; | |
757 charOffset += numCols; | |
758 // make sure we count the number of bytes returned | |
759 numBytes += bytes; | |
760 } | |
761 | |
762 } | |
763 | |
764 return numBytes; | |
765 } | |
766 | |
767 private int isOption(char[] screen, | |
768 int x, | |
769 int lenScreen, | |
770 int numPref, | |
771 int numSuff, | |
772 char suff) { | |
773 boolean hs =true; | |
774 int sp = x; | |
775 int os = 0; | |
776 // check to the left for option | |
777 while (--sp >=0 && screen[sp] <= ' ' ) { | |
778 | |
779 if (x - sp > numPref || screen[sp] == suff|| | |
780 screen[sp] == '.' || | |
781 screen[sp] == '*') { | |
782 hs =false; | |
783 break; | |
784 } | |
785 } | |
786 | |
787 // now lets check for how long the option is it has to be numPref or less | |
788 os = sp; | |
789 while (hs && --os > 0 && screen[os] > ' ' ) { | |
790 | |
791 if (sp - os >= numPref || screen[os] == suff || | |
792 screen[os] == '.' || | |
793 screen[os] == '*') { | |
794 hs = false; | |
795 break; | |
796 } | |
797 } | |
798 if (sp - os > 1 && !Character.isDigit(screen[os+1])) { | |
799 hs = false; | |
800 } | |
801 | |
802 sp = x; | |
803 | |
804 if (Character.isDigit(screen[sp+1])) | |
805 hs = false; | |
806 // now lets make sure there are no more than numSuff spaces after option | |
807 while (hs && (++sp < lenScreen && screen[sp] <= ' ' | |
808 || screen[sp] == suff )) { | |
809 if (sp - x >= numSuff || screen[sp] == suff || | |
810 screen[sp] == '.' || | |
811 screen[sp] == '*') { | |
812 hs =false; | |
813 break; | |
814 } | |
815 } | |
816 if (hs && !Character.isLetterOrDigit(screen[sp])) | |
817 hs = false; | |
818 if (hs) { | |
819 return os; | |
820 } | |
821 return -1; | |
822 } | |
823 | |
824 } |