1 /* 2 * This file is part of "The Java Telnet Application". 3 * 4 * (c) Matthias L. Jugel, Marcus Meißner 1996-2002. All Rights Reserved. 5 * 6 * Please visit http://javatelnet.org/ for updates and contact. 7 * The file was changed by Radek Polak to work as midlet in MIDP 1.0 8 * 9 * --LICENSE NOTICE-- 10 * This program is free software; you can redistribute it and/or 11 * modify it under the terms of the GNU General Public License 12 * as published by the Free Software Foundation; either version 2 13 * of the License, or (at your option) 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 program; if not, write to the Free Software 22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 23 * --LICENSE NOTICE-- 24 * 25 */ 26 27 package telnet; 28 29 /** 30 * Implementation of a Video Display Unit (VDU) buffer. This class contains 31 * all methods to manipulate the buffer that stores characters and their 32 * attributes as well as the regions displayed. 33 * 34 * @author Matthias L. Jugel, Marcus Meißner 35 * @version $Id: VDUBuffer.java,v 1.2 2002/05/23 14:32:43 leo Exp $ 36 */ 37 public class VDUBuffer { 38 39 40 public int height, width; /* rows and columns */ 41 public boolean[] update; /* contains the lines that need update */ 42 public char[][] charArray; /* contains the characters */ 43 public int[][] charAttributes; /* contains character attrs */ 44 public int bufSize; 45 public int maxBufSize; /* buffer sizes */ 46 public int screenBase; /* the actual screen start */ 47 public int windowBase; /* where the start displaying */ 48 public int scrollMarker; /* marks the last line inserted */ 49 50 private int topMargin; /* top scroll margin */ 51 private int bottomMargin; /* bottom scroll margin */ 52 53 // cursor variables 54 protected boolean showcursor = true; 55 protected int cursorX, cursorY; 56 57 /** Scroll up when inserting a line. */ 58 public final static boolean SCROLL_UP = false; 59 /** Scroll down when inserting a line. */ 60 public final static boolean SCROLL_DOWN = true; 61 62 /** Make character normal. */ 63 public final static int NORMAL = 0x00; 64 /** Make character bold. */ 65 public final static int BOLD = 0x01; 66 /** Underline character. */ 67 public final static int UNDERLINE = 0x02; 68 /** Invert character. */ 69 public final static int INVERT = 0x04; 70 /** Lower intensity character. */ 71 public final static int LOW = 0x08; 72 73 public final static int COLOR = 0xff0; 74 public final static int COLOR_FG = 0xf0; 75 public final static int COLOR_BG = 0xf00; 76 77 /** 78 * Create a new video display buffer with the passed width and height in 79 * characters. 80 * @param width the length of the character lines 81 * @param height the amount of lines on the screen 82 */ 83 public VDUBuffer(int width, int height) { 84 // set the display screen size 85 setScreenSize(width, height); 86 } 87 88 /** 89 * Put a character on the screen with normal font and outline. 90 * The character previously on that position will be overwritten. 91 * You need to call redraw() to update the screen. 92 * @param c x-coordinate (column) 93 * @param l y-coordinate (line) 94 * @param ch the character to show on the screen 95 * @see #insertChar 96 * @see #deleteChar 97 * @see #redraw 98 */ 99 public void putChar(int c, int l, char ch) { 100 putChar(c, l, ch, NORMAL); 101 } 102 103 /** 104 * Put a character on the screen with specific font and outline. 105 * The character previously on that position will be overwritten. 106 * You need to call redraw() to update the screen. 107 * @param c x-coordinate (column) 108 * @param l y-coordinate (line) 109 * @param ch the character to show on the screen 110 * @param attributes the character attributes 111 * @see #BOLD 112 * @see #UNDERLINE 113 * @see #INVERT 114 * @see #NORMAL 115 * @see #insertChar 116 * @see #deleteChar 117 * @see #redraw 118 */ 119 120 public void putChar(int c, int l, char ch, int attributes) { 121 122 c = checkBounds(c, 0, width - 1); 123 l = checkBounds(l, 0, height - 1); 124 charArray[screenBase + l][c] = ch; 125 charAttributes[screenBase + l][c] = attributes; 126 markLine(l, 1); 127 } 128 129 /** 130 * Get the character at the specified position. 131 * @param c x-coordinate (column) 132 * @param l y-coordinate (line) 133 * @see #putChar 134 */ 135 public char getChar(int c, int l) { 136 c = checkBounds(c, 0, width - 1); 137 l = checkBounds(l, 0, height - 1); 138 return charArray[screenBase + l][c]; 139 } 140 141 /** 142 * Get the attributes for the specified position. 143 * @param c x-coordinate (column) 144 * @param l y-coordinate (line) 145 * @see #putChar 146 */ 147 public int getAttributes(int c, int l) { 148 c = checkBounds(c, 0, width - 1); 149 l = checkBounds(l, 0, height - 1); 150 return charAttributes[screenBase + l][c]; 151 } 152 153 /** 154 * Insert a character at a specific position on the screen. 155 * All character right to from this position will be moved one to the right. 156 * You need to call redraw() to update the screen. 157 * @param c x-coordinate (column) 158 * @param l y-coordinate (line) 159 * @param ch the character to insert 160 * @param attributes the character attributes 161 * @see #BOLD 162 * @see #UNDERLINE 163 * @see #INVERT 164 * @see #NORMAL 165 * @see #putChar 166 * @see #deleteChar 167 * @see #redraw 168 */ 169 public void insertChar(int c, int l, char ch, int attributes) { 170 c = checkBounds(c, 0, width - 1); 171 l = checkBounds(l, 0, height - 1); 172 System.arraycopy(charArray[screenBase + l], c, 173 charArray[screenBase + l], c + 1, width - c - 1); 174 System.arraycopy(charAttributes[screenBase + l], c, 175 charAttributes[screenBase + l], c + 1, width - c - 1); 176 putChar(c, l, ch, attributes); 177 } 178 179 /** 180 * Delete a character at a given position on the screen. 181 * All characters right to the position will be moved one to the left. 182 * You need to call redraw() to update the screen. 183 * @param c x-coordinate (column) 184 * @param l y-coordinate (line) 185 * @see #putChar 186 * @see #insertChar 187 * @see #redraw 188 */ 189 public void deleteChar(int c, int l) { 190 c = checkBounds(c, 0, width - 1); 191 l = checkBounds(l, 0, height - 1); 192 if (c < width - 1) { 193 System.arraycopy(charArray[screenBase + l], c + 1, 194 charArray[screenBase + l], c, width - c - 1); 195 System.arraycopy(charAttributes[screenBase + l], c + 1, 196 charAttributes[screenBase + l], c, width - c - 1); 197 } 198 putChar(width - 1, l, (char) 0); 199 } 200 201 /** 202 * Put a String at a specific position. Any characters previously on that 203 * position will be overwritten. You need to call redraw() for screen update. 204 * @param c x-coordinate (column) 205 * @param l y-coordinate (line) 206 * @param s the string to be shown on the screen 207 * @see #BOLD 208 * @see #UNDERLINE 209 * @see #INVERT 210 * @see #NORMAL 211 * @see #putChar 212 * @see #insertLine 213 * @see #deleteLine 214 * @see #redraw 215 */ 216 public void putString(int c, int l, String s) { 217 putString(c, l, s, NORMAL); 218 } 219 220 /** 221 * Put a String at a specific position giving all characters the same 222 * attributes. Any characters previously on that position will be 223 * overwritten. You need to call redraw() to update the screen. 224 * @param c x-coordinate (column) 225 * @param l y-coordinate (line) 226 * @param s the string to be shown on the screen 227 * @param attributes character attributes 228 * @see #BOLD 229 * @see #UNDERLINE 230 * @see #INVERT 231 * @see #NORMAL 232 * @see #putChar 233 * @see #insertLine 234 * @see #deleteLine 235 * @see #redraw 236 */ 237 public void putString(int c, int l, String s, int attributes) { 238 for (int i = 0; i < s.length() && c + i < width; i++) { 239 putChar(c + i, l, s.charAt(i), attributes); 240 } 241 } 242 243 /** 244 * Insert a blank line at a specific position. 245 * The current line and all previous lines are scrolled one line up. The 246 * top line is lost. You need to call redraw() to update the screen. 247 * @param l the y-coordinate to insert the line 248 * @see #deleteLine 249 * @see #redraw 250 */ 251 public void insertLine(int l) { 252 insertLine(l, 1, SCROLL_UP); 253 } 254 255 /** 256 * Insert blank lines at a specific position. 257 * You need to call redraw() to update the screen 258 * @param l the y-coordinate to insert the line 259 * @param n amount of lines to be inserted 260 * @see #deleteLine 261 * @see #redraw 262 */ 263 public void insertLine(int l, int n) { 264 insertLine(l, n, SCROLL_UP); 265 } 266 267 /** 268 * Insert a blank line at a specific position. Scroll text according to 269 * the argument. 270 * You need to call redraw() to update the screen 271 * @param l the y-coordinate to insert the line 272 * @param scrollDown scroll down 273 * @see #deleteLine 274 * @see #SCROLL_UP 275 * @see #SCROLL_DOWN 276 * @see #redraw 277 */ 278 public void insertLine(int l, boolean scrollDown) { 279 insertLine(l, 1, scrollDown); 280 } 281 282 /** 283 * Insert blank lines at a specific position. 284 * The current line and all previous lines are scrolled one line up. The 285 * top line is lost. You need to call redraw() to update the screen. 286 * @param l the y-coordinate to insert the line 287 * @param n number of lines to be inserted 288 * @param scrollDown scroll down 289 * @see #deleteLine 290 * @see #SCROLL_UP 291 * @see #SCROLL_DOWN 292 * @see #redraw 293 */ 294 public synchronized void insertLine(int l, int n, boolean scrollDown) { 295 296 l = checkBounds(l, 0, height - 1); 297 298 char cbuf[][] = null; 299 int abuf[][] = null; 300 int offset = 0; 301 int oldBase = screenBase; 302 303 if (l > 304 bottomMargin) /* We do not scroll below bottom margin (below the scrolling region). */ { 305 return; 306 } 307 int top = (l < topMargin ? 308 0 : (l > bottomMargin ? 309 (bottomMargin + 1 < height ? 310 bottomMargin + 1 : height - 1) : topMargin)); 311 int bottom = (l > bottomMargin ? 312 height - 1 : (l < topMargin ? 313 (topMargin > 0 ? 314 topMargin - 1 : 0) : bottomMargin)); 315 316 // System.out.println("l is "+l+", top is "+top+", bottom is "+bottom+", bottomargin is "+bottomMargin+", topMargin is "+topMargin); 317 318 if (scrollDown) { 319 if (n > (bottom - top)) { 320 n = (bottom - top); 321 } 322 cbuf = new char[bottom - l - (n - 1)][width]; 323 abuf = new int[bottom - l - (n - 1)][width]; 324 325 System.arraycopy(charArray, oldBase + l, cbuf, 0, bottom - l - (n - 1)); 326 System.arraycopy(charAttributes, oldBase + l, 327 abuf, 0, bottom - l - (n - 1)); 328 System.arraycopy(cbuf, 0, charArray, oldBase + l + n, 329 bottom - l - (n - 1)); 330 System.arraycopy(abuf, 0, charAttributes, oldBase + l + n, 331 bottom - l - (n - 1)); 332 cbuf = charArray; 333 abuf = charAttributes; 334 } 335 else { 336 try { 337 if (n > (bottom - top) + 1) { 338 n = (bottom - top) + 1; 339 } 340 if (bufSize < maxBufSize) { 341 if (bufSize + n > maxBufSize) { 342 offset = n - (maxBufSize - bufSize); 343 scrollMarker += offset; 344 bufSize = maxBufSize; 345 screenBase = maxBufSize - height - 1; 346 windowBase = screenBase; 347 } 348 else { 349 scrollMarker += n; 350 screenBase += n; 351 windowBase += n; 352 bufSize += n; 353 } 354 355 cbuf = new char[bufSize][width]; 356 abuf = new int[bufSize][width]; 357 } 358 else { 359 offset = n; 360 cbuf = charArray; 361 abuf = charAttributes; 362 } 363 // copy anything from the top of the buffer (+offset) to the new top 364 // up to the screenBase. 365 if (oldBase > 0) { 366 System.arraycopy(charArray, offset, 367 cbuf, 0, 368 oldBase - offset); 369 System.arraycopy(charAttributes, offset, 370 abuf, 0, 371 oldBase - offset); 372 } 373 // copy anything from the top of the screen (screenBase) up to the 374 // topMargin to the new screen 375 if (top > 0) { 376 System.arraycopy(charArray, oldBase, 377 cbuf, screenBase, 378 top); 379 System.arraycopy(charAttributes, oldBase, 380 abuf, screenBase, 381 top); 382 } 383 // copy anything from the topMargin up to the amount of lines inserted 384 // to the gap left over between scrollback buffer and screenBase 385 if (oldBase > 0) { 386 System.arraycopy(charArray, oldBase + top, 387 cbuf, oldBase - offset, 388 n); 389 System.arraycopy(charAttributes, oldBase + top, 390 abuf, oldBase - offset, 391 n); 392 } 393 // copy anything from topMargin + n up to the line linserted to the 394 // topMargin 395 // Telnet.console.println( "scrolling up line:" ); 396 // Telnet.console.println( new String( charArray[screenBase+top] )); 397 398 // ERROR for mobile phones 399 // Telnet.console.println( "arraycopy: " ); 400 // Telnet.console.println( "len:" + (l - top - (n - 1))); 401 // Telnet.console.println( "from:" + (oldBase + top + n)); 402 // Telnet.console.println( "to:" + (screenBase + top)); 403 404 /* System.arraycopy(charArray, oldBase + top + n, 405 cbuf, screenBase + top, 406 l - top - (n - 1)); 407 System.arraycopy(charAttributes, oldBase + top + n, 408 abuf, screenBase + top, 409 l - top - (n - 1)); 410 */ 411 // this works fine RADEK 412 for (int i = 0; i < l - top - (n - 1); i++) { 413 cbuf[screenBase + top + i] = charArray[oldBase + top + n + i]; 414 abuf[screenBase + top + i] = charAttributes[oldBase + top + n + i]; 415 } 416 417 // 418 // copy the all lines next to the inserted to the new buffer 419 if (l < height - 1) { 420 System.arraycopy(charArray, oldBase + l + 1, 421 cbuf, screenBase + l + 1, 422 (height - 1) - l); 423 System.arraycopy(charAttributes, oldBase + l + 1, 424 abuf, screenBase + l + 1, 425 (height - 1) - l); 426 } 427 } 428 catch (ArrayIndexOutOfBoundsException e) { 429 // this should not happen anymore, but I will leave the code 430 // here in case something happens anyway. That code above is 431 // so complex I always have a hard time understanding what 432 // I did, even though there are comments 433 System.err.println("*** Error while scrolling up:"); 434 System.err.println("--- BEGIN STACK TRACE ---"); 435 e.printStackTrace(); 436 System.err.println("--- END STACK TRACE ---"); 437 System.err.println("bufSize=" + bufSize + ", maxBufSize=" + maxBufSize); 438 System.err.println("top=" + top + ", bottom=" + bottom); 439 System.err.println("n=" + n + ", l=" + l); 440 System.err.println("screenBase=" + screenBase + ", windowBase=" + 441 windowBase); 442 System.err.println("oldBase=" + oldBase); 443 System.err.println("size.width=" + width + ", size.height=" + height); 444 System.err.println("abuf.length=" + abuf.length + ", cbuf.length=" + 445 cbuf.length); 446 System.err.println("*** done dumping debug information"); 447 } 448 } 449 450 // this is a little helper to mark the scrolling 451 scrollMarker -= n; 452 453 for (int i = 0; i < n; i++) { 454 cbuf[ (screenBase + l) + (scrollDown ? i : -i)] = new char[width]; 455 abuf[ (screenBase + l) + (scrollDown ? i : -i)] = new int[width]; 456 } 457 458 charArray = cbuf; 459 charAttributes = abuf; 460 461 if (scrollDown) { 462 markLine(l, bottom - l + 1); 463 } 464 else { 465 markLine(top, l - top + 1); 466 467 // System.out.println( "14:" + new String( charArray[14]) ); 468 // System.out.println( "15:" + new String( charArray[15]) ); 469 470 /* FIXME: needs to be in VDU 471 if(scrollBar != null) 472 scrollBar.setValues(windowBase, height, 0, bufSize); 473 */ 474 } 475 } 476 477 /** 478 * Delete a line at a specific position. Subsequent lines will be scrolled 479 * up to fill the space and a blank line is inserted at the end of the 480 * screen. 481 * @param l the y-coordinate to insert the line 482 * @see #deleteLine 483 */ 484 public void deleteLine(int l) { 485 l = checkBounds(l, 0, height - 1); 486 487 int bottom = (l > bottomMargin ? height - 1 : 488 (l < topMargin ? topMargin : bottomMargin + 1)); 489 System.arraycopy(charArray, screenBase + l + 1, 490 charArray, screenBase + l, bottom - l - 1); 491 System.arraycopy(charAttributes, screenBase + l + 1, 492 charAttributes, screenBase + l, bottom - l - 1); 493 charArray[screenBase + bottom - 1] = new char[width]; 494 charAttributes[screenBase + bottom - 1] = new int[width]; 495 markLine(l, bottom - l); 496 } 497 498 /** 499 * Delete a rectangular portion of the screen. 500 * You need to call redraw() to update the screen. 501 * @param c x-coordinate (column) 502 * @param l y-coordinate (row) 503 * @param w with of the area in characters 504 * @param h height of the area in characters 505 * @param curAttr attribute to fill 506 * @see #deleteChar 507 * @see #deleteLine 508 * @see #redraw 509 */ 510 public void deleteArea(int c, int l, int w, int h, int curAttr) { 511 c = checkBounds(c, 0, width - 1); 512 l = checkBounds(l, 0, height - 1); 513 514 char cbuf[] = new char[w]; 515 int abuf[] = new int[w]; 516 517 for (int i = 0; i < w; i++) { 518 abuf[i] = curAttr; 519 } 520 for (int i = 0; i < h && l + i < height; i++) { 521 System.arraycopy(cbuf, 0, charArray[screenBase + l + i], c, w); 522 System.arraycopy(abuf, 0, charAttributes[screenBase + l + i], c, w); 523 } 524 markLine(l, h); 525 } 526 527 /** 528 * Delete a rectangular portion of the screen. 529 * You need to call redraw() to update the screen. 530 * @param c x-coordinate (column) 531 * @param l y-coordinate (row) 532 * @param w with of the area in characters 533 * @param h height of the area in characters 534 * @see #deleteChar 535 * @see #deleteLine 536 * @see #redraw 537 */ 538 public void deleteArea(int c, int l, int w, int h) { 539 c = checkBounds(c, 0, width - 1); 540 l = checkBounds(l, 0, height - 1); 541 542 char cbuf[] = new char[w]; 543 int abuf[] = new int[w]; 544 545 for (int i = 0; i < h && l + i < height; i++) { 546 System.arraycopy(cbuf, 0, charArray[screenBase + l + i], c, w); 547 System.arraycopy(abuf, 0, charAttributes[screenBase + l + i], c, w); 548 } 549 markLine(l, h); 550 } 551 552 /** 553 * Sets whether the cursor is visible or not. 554 * @param doshow 555 */ 556 public void showCursor(boolean doshow) { 557 if (doshow != showcursor) { 558 markLine(cursorY, 1); 559 } 560 showcursor = doshow; 561 } 562 563 /** 564 * Puts the cursor at the specified position. 565 * @param c column 566 * @param l line 567 */ 568 public void setCursorPosition(int c, int l) { 569 cursorX = checkBounds(c, 0, width - 1); 570 cursorY = checkBounds(l, 0, height - 1); 571 markLine(cursorY, 1); 572 } 573 574 /** 575 * Get the current column of the cursor position. 576 */ 577 public int getCursorColumn() { 578 return cursorX; 579 } 580 581 /** 582 * Get the current line of the cursor position. 583 */ 584 public int getCursorRow() { 585 return cursorY; 586 } 587 588 /** 589 * Set the current window base. This allows to view the scrollback buffer. 590 * @param line the line where the screen window starts 591 * @see #setBufferSize 592 * @see #getBufferSize 593 */ 594 public void setWindowBase(int line) { 595 if (line > screenBase) { 596 line = screenBase; 597 } 598 else if (line < 0) { 599 line = 0; 600 } 601 windowBase = line; 602 update[0] = true; 603 redraw(); 604 } 605 606 /** 607 * Get the current window base. 608 * @see #setWindowBase 609 */ 610 public int getWindowBase() { 611 return windowBase; 612 } 613 614 /** 615 * Set the top scroll margin for the screen. If the current bottom margin 616 * is smaller it will become the top margin and the line will become the 617 * bottom margin. 618 * @param l line that is the margin 619 */ 620 public void setTopMargin(int l) { 621 if (l > bottomMargin) { 622 topMargin = bottomMargin; 623 bottomMargin = l; 624 } 625 else { 626 topMargin = l; 627 } 628 if (topMargin < 0) { 629 topMargin = 0; 630 } 631 if (bottomMargin > height - 1) { 632 bottomMargin = height - 1; 633 } 634 } 635 636 /** 637 * Get the top scroll margin. 638 */ 639 public int getTopMargin() { 640 return topMargin; 641 } 642 643 /** 644 * Set the bottom scroll margin for the screen. If the current top margin 645 * is bigger it will become the bottom margin and the line will become the 646 * top margin. 647 * @param l line that is the margin 648 */ 649 public void setBottomMargin(int l) { 650 if (l < topMargin) { 651 bottomMargin = topMargin; 652 topMargin = l; 653 } 654 else { 655 bottomMargin = l; 656 } 657 if (topMargin < 0) { 658 topMargin = 0; 659 } 660 if (bottomMargin > height - 1) { 661 bottomMargin = height - 1; 662 } 663 } 664 665 /** 666 * Get the bottom scroll margin. 667 */ 668 public int getBottomMargin() { 669 return bottomMargin; 670 } 671 672 /** 673 * Set scrollback buffer size. 674 * @param amount new size of the buffer 675 */ 676 public void setBufferSize(int amount) { 677 if (amount < height) { 678 amount = height; 679 } 680 if (amount < maxBufSize) { 681 char cbuf[][] = new char[amount][width]; 682 int abuf[][] = new int[amount][width]; 683 int copyStart = bufSize - amount < 0 ? 0 : bufSize - amount; 684 int copyCount = bufSize - amount < 0 ? bufSize : amount; 685 if (charArray != null) { 686 System.arraycopy(charArray, copyStart, cbuf, 0, copyCount); 687 } 688 if (charAttributes != null) { 689 System.arraycopy(charAttributes, copyStart, abuf, 0, copyCount); 690 } 691 charArray = cbuf; 692 charAttributes = abuf; 693 bufSize = copyCount; 694 screenBase = bufSize - height; 695 windowBase = screenBase; 696 } 697 maxBufSize = amount; 698 699 update[0] = true; 700 redraw(); 701 } 702 703 /** 704 * Retrieve current scrollback buffer size. 705 * @see #setBufferSize 706 */ 707 public int getBufferSize() { 708 return bufSize; 709 } 710 711 /** 712 * Retrieve maximum buffer Size. 713 * @see #getBufferSize 714 */ 715 public int getMaxBufferSize() { 716 return maxBufSize; 717 } 718 719 /** 720 * Change the size of the screen. This will include adjustment of the 721 * scrollback buffer. 722 * @param w of the screen 723 * @param h of the screen 724 */ 725 public void setScreenSize(int w, int h) { 726 char cbuf[][]; 727 int abuf[][]; 728 int bsize = bufSize; 729 730 if (w < 1 || h < 1) { 731 return; 732 } 733 734 if (h > maxBufSize) { 735 maxBufSize = h; 736 737 } 738 if (h > bufSize) { 739 bufSize = h; 740 screenBase = 0; 741 windowBase = 0; 742 } 743 744 if (windowBase + h >= bufSize) { 745 windowBase = bufSize - h; 746 747 } 748 if (screenBase + h >= bufSize) { 749 screenBase = bufSize - h; 750 751 } 752 753 cbuf = new char[bufSize][w]; 754 abuf = new int[bufSize][w]; 755 756 if (charArray != null && charAttributes != null) { 757 for (int i = 0; i < bsize && i < bufSize; i++) { 758 System.arraycopy(charArray[i], 0, cbuf[i], 0, 759 w < width ? w : width); 760 System.arraycopy(charAttributes[i], 0, abuf[i], 0, 761 w < width ? w : width); 762 } 763 } 764 765 charArray = cbuf; 766 charAttributes = abuf; 767 width = w; 768 height = h; 769 topMargin = 0; 770 bottomMargin = h - 1; 771 update = new boolean[h + 1]; 772 update[0] = true; 773 /* FIXME: ??? 774 if(resizeStrategy == RESIZE_FONT) 775 setBounds(getBounds()); 776 */ 777 } 778 779 780 /** 781 * Mark lines to be updated with redraw(). 782 * @param l starting line 783 * @param n amount of lines to be updated 784 * @see #redraw 785 */ 786 public void markLine(int l, int n) { 787 l = checkBounds(l, 0, height - 1); 788 for (int i = 0; (i < n) && (l + i < height); i++) { 789 update[l + i + 1] = true; 790 } 791 } 792 793 private int checkBounds(int value, int lower, int upper) { 794 if (value < lower) { 795 return lower; 796 } 797 if (value > upper) { 798 return upper; 799 } 800 return value; 801 } 802 803 /** a generic display that should redraw on demand */ 804 protected MidletTerminal display; 805 806 public void setDisplay(MidletTerminal display) { 807 this.display = display; 808 } 809 810 /** 811 * Trigger a redraw on the display. 812 */ 813 protected void redraw() { 814 if (display != null) { 815 display.redraw(); 816 } 817 } 818 } |