19f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li/* 29f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * This file is part of "JTA - Telnet/SSH for the JAVA(tm) platform". 39f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * 49f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * (c) Matthias L. Jugel, Marcus Mei�ner 1996-2005. All Rights Reserved. 59f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * 69f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * Please visit http://javatelnet.org/ for updates and contact. 79f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * 89f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * --LICENSE NOTICE-- 99f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * This program is free software; you can redistribute it and/or 109f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * modify it under the terms of the GNU General Public License 119f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * as published by the Free Software Foundation; either version 2 129f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * of the License, or (at your option) any later version. 139f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * 149f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * This program is distributed in the hope that it will be useful, 159f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * but WITHOUT ANY WARRANTY; without even the implied warranty of 169f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 179f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * GNU General Public License for more details. 189f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * 199f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * You should have received a copy of the GNU General Public License 209f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * along with this program; if not, write to the Free Software 219f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 229f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * --LICENSE NOTICE-- 239f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * 249f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li */ 259f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li 269f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Lipackage de.mud.terminal; 279f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li 289f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Liimport java.util.Arrays; 299f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li 309f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li/** 319f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * Implementation of a Video Display Unit (VDU) buffer. This class contains all methods to 329f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * manipulate the buffer that stores characters and their attributes as well as the regions 339f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * displayed. 349f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * 359f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * @version $Id: VDUBuffer.java 503 2005-10-24 07:34:13Z marcus $ 369f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li */ 379f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Lipublic class VDUBuffer { 389f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li 399f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li /** The current version id tag */ 409f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li public final static String ID = "$Id: VDUBuffer.java 503 2005-10-24 07:34:13Z marcus $"; 419f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li 429f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li /** Enable debug messages. */ 439f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li public final static int debug = 0; 449f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li 459f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li public int height, width; /* rows and columns */ 469f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li public boolean[] update; /* contains the lines that need update */ 479f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li public char[][] charArray; /* contains the characters */ 489f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li public int[][] charAttributes; /* contains character attrs */ 499f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li public int bufSize; 509f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li public int maxBufSize; /* buffer sizes */ 519f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li public int screenBase; /* the actual screen start */ 529f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li public int windowBase; /* where the start displaying */ 539f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li public int scrollMarker; /* marks the last line inserted */ 549f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li 559f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li private int topMargin; /* top scroll margin */ 569f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li private int bottomMargin; /* bottom scroll margin */ 579f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li 589f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li // cursor variables 599f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li protected boolean showcursor = true; 609f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li protected int cursorX, cursorY; 619f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li 629f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li /** Scroll up when inserting a line. */ 639f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li public final static boolean SCROLL_UP = false; 649f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li /** Scroll down when inserting a line. */ 659f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li public final static boolean SCROLL_DOWN = true; 669f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li 679f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li /* 689f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * Attributes bit-field usage: 699f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * 709f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * 8421 8421 8421 8421 8421 8421 8421 8421 |||| |||| |||| |||| |||| |||| |||| |||`- Bold |||| |||| 719f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * |||| |||| |||| |||| |||| ||`-- Underline |||| |||| |||| |||| |||| |||| |||| |`--- Invert |||| 729f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * |||| |||| |||| |||| |||| |||| `---- Low |||| |||| |||| |||| |||| |||| |||`------ Invisible |||| 739f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * |||| |||| |||| ||`+-++++-+++------- Foreground Color |||| |||| |`++-++++-++------------------ 749f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * Background Color |||| |||| `----------------------------- Fullwidth character 759f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * `+++-++++------------------------------- Reserved for future use 769f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li */ 779f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li 789f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li /** Make character normal. */ 799f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li public final static int NORMAL = 0x00; 809f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li /** Make character bold. */ 819f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li public final static int BOLD = 0x01; 829f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li /** Underline character. */ 839f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li public final static int UNDERLINE = 0x02; 849f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li /** Invert character. */ 859f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li public final static int INVERT = 0x04; 869f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li /** Lower intensity character. */ 879f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li public final static int LOW = 0x08; 889f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li /** Invisible character. */ 899f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li public final static int INVISIBLE = 0x10; 909f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li /** Unicode full-width character (CJK, et al.) */ 919f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li public final static int FULLWIDTH = 0x8000000; 929f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li 939f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li /** how much to left shift the foreground color */ 949f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li public final static int COLOR_FG_SHIFT = 5; 959f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li /** how much to left shift the background color */ 969f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li public final static int COLOR_BG_SHIFT = 14; 979f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li /** color mask */ 989f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li public final static int COLOR = 0x7fffe0; /* 0000 0000 0111 1111 1111 1111 1110 0000 */ 999f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li /** foreground color mask */ 1009f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li public final static int COLOR_FG = 0x3fe0; /* 0000 0000 0000 0000 0011 1111 1110 0000 */ 1019f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li /** background color mask */ 1029f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li public final static int COLOR_BG = 0x7fc000; /* 0000 0000 0111 1111 1100 0000 0000 0000 */ 1039f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li 1049f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li /** 1059f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * Create a new video display buffer with the passed width and height in characters. 1069f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * 1079f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * @param width 1089f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * the length of the character lines 1099f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * @param height 1109f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * the amount of lines on the screen 1119f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li */ 1129f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li public VDUBuffer(int width, int height) { 1139f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li // set the display screen size 1149f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li setScreenSize(width, height, false); 1159f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li } 1169f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li 1179f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li /** 1189f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * Create a standard video display buffer with 80 columns and 24 lines. 1199f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li */ 1209f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li public VDUBuffer() { 1219f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li this(80, 24); 1229f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li } 1239f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li 1249f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li /** 1259f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * Put a character on the screen with normal font and outline. The character previously on that 1269f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * position will be overwritten. You need to call redraw() to update the screen. 1279f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * 1289f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * @param c 1299f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * x-coordinate (column) 1309f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * @param l 1319f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * y-coordinate (line) 1329f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * @param ch 1339f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * the character to show on the screen 1349f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * @see #insertChar 1359f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * @see #deleteChar 1369f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * @see #redraw 1379f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li */ 1389f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li public void putChar(int c, int l, char ch) { 1399f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li putChar(c, l, ch, NORMAL); 1409f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li } 1419f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li 1429f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li /** 1439f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * Put a character on the screen with specific font and outline. The character previously on that 1449f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * position will be overwritten. You need to call redraw() to update the screen. 1459f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * 1469f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * @param c 1479f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * x-coordinate (column) 1489f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * @param l 1499f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * y-coordinate (line) 1509f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * @param ch 1519f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * the character to show on the screen 1529f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * @param attributes 1539f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * the character attributes 1549f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * @see #BOLD 1559f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * @see #UNDERLINE 1569f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * @see #INVERT 1579f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * @see #INVISIBLE 1589f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * @see #NORMAL 1599f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * @see #LOW 1609f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * @see #insertChar 1619f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * @see #deleteChar 1629f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * @see #redraw 1639f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li */ 1649f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li 1659f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li public void putChar(int c, int l, char ch, int attributes) { 1669f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li charArray[screenBase + l][c] = ch; 1679f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li charAttributes[screenBase + l][c] = attributes; 1689f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li if (l < height) { 1699f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li update[l + 1] = true; 1709f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li } 1719f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li } 1729f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li 1739f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li /** 1749f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * Get the character at the specified position. 1759f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * 1769f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * @param c 1779f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * x-coordinate (column) 1789f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * @param l 1799f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * y-coordinate (line) 1809f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * @see #putChar 1819f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li */ 1829f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li public char getChar(int c, int l) { 1839f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li return charArray[screenBase + l][c]; 1849f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li } 1859f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li 1869f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li /** 1879f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * Get the attributes for the specified position. 1889f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * 1899f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * @param c 1909f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * x-coordinate (column) 1919f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * @param l 1929f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * y-coordinate (line) 1939f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * @see #putChar 1949f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li */ 1959f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li public int getAttributes(int c, int l) { 1969f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li return charAttributes[screenBase + l][c]; 1979f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li } 1989f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li 1999f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li /** 2009f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * Insert a character at a specific position on the screen. All character right to from this 2019f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * position will be moved one to the right. You need to call redraw() to update the screen. 2029f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * 2039f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * @param c 2049f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * x-coordinate (column) 2059f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * @param l 2069f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * y-coordinate (line) 2079f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * @param ch 2089f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * the character to insert 2099f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * @param attributes 2109f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * the character attributes 2119f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * @see #BOLD 2129f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * @see #UNDERLINE 2139f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * @see #INVERT 2149f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * @see #INVISIBLE 2159f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * @see #NORMAL 2169f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * @see #LOW 2179f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * @see #putChar 2189f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * @see #deleteChar 2199f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * @see #redraw 2209f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li */ 2219f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li public void insertChar(int c, int l, char ch, int attributes) { 2229f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li System.arraycopy(charArray[screenBase + l], c, charArray[screenBase + l], c + 1, width - c - 1); 2239f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li System.arraycopy(charAttributes[screenBase + l], c, charAttributes[screenBase + l], c + 1, 2249f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li width - c - 1); 2259f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li putChar(c, l, ch, attributes); 2269f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li } 2279f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li 2289f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li /** 2299f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * Delete a character at a given position on the screen. All characters right to the position will 2309f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * be moved one to the left. You need to call redraw() to update the screen. 2319f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * 2329f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * @param c 2339f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * x-coordinate (column) 2349f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * @param l 2359f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * y-coordinate (line) 2369f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * @see #putChar 2379f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * @see #insertChar 2389f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * @see #redraw 2399f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li */ 2409f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li public void deleteChar(int c, int l) { 2419f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li if (c < width - 1) { 2429f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li System.arraycopy(charArray[screenBase + l], c + 1, charArray[screenBase + l], c, width - c 2439f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li - 1); 2449f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li System.arraycopy(charAttributes[screenBase + l], c + 1, charAttributes[screenBase + l], c, 2459f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li width - c - 1); 2469f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li } 2479f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li putChar(width - 1, l, (char) 0); 2489f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li } 2499f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li 2509f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li /** 2519f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * Put a String at a specific position. Any characters previously on that position will be 2529f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * overwritten. You need to call redraw() for screen update. 2539f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * 2549f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * @param c 2559f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * x-coordinate (column) 2569f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * @param l 2579f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * y-coordinate (line) 2589f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * @param s 2599f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * the string to be shown on the screen 2609f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * @see #BOLD 2619f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * @see #UNDERLINE 2629f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * @see #INVERT 2639f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * @see #INVISIBLE 2649f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * @see #NORMAL 2659f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * @see #LOW 2669f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * @see #putChar 2679f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * @see #insertLine 2689f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * @see #deleteLine 2699f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * @see #redraw 2709f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li */ 2719f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li public void putString(int c, int l, String s) { 2729f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li putString(c, l, s, NORMAL); 2739f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li } 2749f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li 2759f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li /** 2769f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * Put a String at a specific position giving all characters the same attributes. Any characters 2779f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * previously on that position will be overwritten. You need to call redraw() to update the 2789f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * screen. 2799f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * 2809f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * @param c 2819f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * x-coordinate (column) 2829f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * @param l 2839f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * y-coordinate (line) 2849f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * @param s 2859f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * the string to be shown on the screen 2869f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * @param attributes 2879f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * character attributes 2889f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * @see #BOLD 2899f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * @see #UNDERLINE 2909f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * @see #INVERT 2919f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * @see #INVISIBLE 2929f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * @see #NORMAL 2939f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * @see #LOW 2949f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * @see #putChar 2959f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * @see #insertLine 2969f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * @see #deleteLine 2979f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * @see #redraw 2989f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li */ 2999f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li public void putString(int c, int l, String s, int attributes) { 3009f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li for (int i = 0; i < s.length() && c + i < width; i++) { 3019f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li putChar(c + i, l, s.charAt(i), attributes); 3029f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li } 3039f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li } 3049f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li 3059f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li /** 3069f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * Insert a blank line at a specific position. The current line and all previous lines are 3079f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * scrolled one line up. The top line is lost. You need to call redraw() to update the screen. 3089f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * 3099f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * @param l 3109f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * the y-coordinate to insert the line 3119f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * @see #deleteLine 3129f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * @see #redraw 3139f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li */ 3149f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li public void insertLine(int l) { 3159f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li insertLine(l, 1, SCROLL_UP); 3169f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li } 3179f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li 3189f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li /** 3199f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * Insert blank lines at a specific position. You need to call redraw() to update the screen 3209f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * 3219f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * @param l 3229f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * the y-coordinate to insert the line 3239f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * @param n 3249f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * amount of lines to be inserted 3259f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * @see #deleteLine 3269f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * @see #redraw 3279f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li */ 3289f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li public void insertLine(int l, int n) { 3299f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li insertLine(l, n, SCROLL_UP); 3309f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li } 3319f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li 3329f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li /** 3339f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * Insert a blank line at a specific position. Scroll text according to the argument. You need to 3349f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * call redraw() to update the screen 3359f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * 3369f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * @param l 3379f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * the y-coordinate to insert the line 3389f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * @param scrollDown 3399f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * scroll down 3409f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * @see #deleteLine 3419f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * @see #SCROLL_UP 3429f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * @see #SCROLL_DOWN 3439f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * @see #redraw 3449f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li */ 3459f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li public void insertLine(int l, boolean scrollDown) { 3469f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li insertLine(l, 1, scrollDown); 3479f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li } 3489f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li 3499f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li /** 3509f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * Insert blank lines at a specific position. The current line and all previous lines are scrolled 3519f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * one line up. The top line is lost. You need to call redraw() to update the screen. 3529f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * 3539f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * @param l 3549f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * the y-coordinate to insert the line 3559f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * @param n 3569f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * number of lines to be inserted 3579f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * @param scrollDown 3589f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * scroll down 3599f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * @see #deleteLine 3609f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * @see #SCROLL_UP 3619f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * @see #SCROLL_DOWN 3629f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * @see #redraw 3639f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li */ 3649f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li public synchronized void insertLine(int l, int n, boolean scrollDown) { 3659f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li char cbuf[][] = null; 3669f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li int abuf[][] = null; 3679f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li int offset = 0; 3689f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li int oldBase = screenBase; 3699f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li 3709f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li int newScreenBase = screenBase; 3719f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li int newWindowBase = windowBase; 3729f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li int newBufSize = bufSize; 3739f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li 3749f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li if (l > bottomMargin) { 3759f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li return; 3769f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li } 3779f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li int top = 3789f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li (l < topMargin ? 0 : (l > bottomMargin ? (bottomMargin + 1 < height ? bottomMargin + 1 3799f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li : height - 1) : topMargin)); 3809f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li int bottom = 3819f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li (l > bottomMargin ? height - 1 : (l < topMargin ? (topMargin > 0 ? topMargin - 1 : 0) 3829f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li : bottomMargin)); 3839f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li 3849f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li // System.out.println("l is "+l+", top is "+top+", bottom is "+bottom+", bottomargin is "+bottomMargin+", topMargin is "+topMargin); 3859f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li 3869f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li if (scrollDown) { 3879f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li if (n > (bottom - top)) { 3889f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li n = (bottom - top); 3899f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li } 3909f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li int size = bottom - l - (n - 1); 3919f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li if (size < 0) { 3929f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li size = 0; 3939f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li } 3949f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li cbuf = new char[size][]; 3959f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li abuf = new int[size][]; 3969f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li 3979f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li System.arraycopy(charArray, oldBase + l, cbuf, 0, bottom - l - (n - 1)); 3989f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li System.arraycopy(charAttributes, oldBase + l, abuf, 0, bottom - l - (n - 1)); 3999f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li System.arraycopy(cbuf, 0, charArray, oldBase + l + n, bottom - l - (n - 1)); 4009f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li System.arraycopy(abuf, 0, charAttributes, oldBase + l + n, bottom - l - (n - 1)); 4019f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li cbuf = charArray; 4029f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li abuf = charAttributes; 4039f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li } else { 4049f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li try { 4059f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li if (n > (bottom - top) + 1) { 4069f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li n = (bottom - top) + 1; 4079f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li } 4089f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li if (bufSize < maxBufSize) { 4099f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li if (bufSize + n > maxBufSize) { 4109f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li offset = n - (maxBufSize - bufSize); 4119f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li scrollMarker += offset; 4129f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li newBufSize = maxBufSize; 4139f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li newScreenBase = maxBufSize - height - 1; 4149f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li newWindowBase = screenBase; 4159f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li } else { 4169f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li scrollMarker += n; 4179f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li newScreenBase += n; 4189f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li newWindowBase += n; 4199f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li newBufSize += n; 4209f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li } 4219f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li 4229f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li cbuf = new char[newBufSize][]; 4239f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li abuf = new int[newBufSize][]; 4249f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li } else { 4259f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li offset = n; 4269f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li cbuf = charArray; 4279f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li abuf = charAttributes; 4289f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li } 4299f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li // copy anything from the top of the buffer (+offset) to the new top 4309f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li // up to the screenBase. 4319f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li if (oldBase > 0) { 4329f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li System.arraycopy(charArray, offset, cbuf, 0, oldBase - offset); 4339f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li System.arraycopy(charAttributes, offset, abuf, 0, oldBase - offset); 4349f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li } 4359f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li // copy anything from the top of the screen (screenBase) up to the 4369f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li // topMargin to the new screen 4379f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li if (top > 0) { 4389f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li System.arraycopy(charArray, oldBase, cbuf, newScreenBase, top); 4399f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li System.arraycopy(charAttributes, oldBase, abuf, newScreenBase, top); 4409f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li } 4419f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li // copy anything from the topMargin up to the amount of lines inserted 4429f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li // to the gap left over between scrollback buffer and screenBase 4439f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li if (oldBase >= 0) { 4449f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li System.arraycopy(charArray, oldBase + top, cbuf, oldBase - offset, n); 4459f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li System.arraycopy(charAttributes, oldBase + top, abuf, oldBase - offset, n); 4469f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li } 4479f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li // copy anything from topMargin + n up to the line linserted to the 4489f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li // topMargin 4499f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li System 4509f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li .arraycopy(charArray, oldBase + top + n, cbuf, newScreenBase + top, l - top - (n - 1)); 4519f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li System.arraycopy(charAttributes, oldBase + top + n, abuf, newScreenBase + top, l - top 4529f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li - (n - 1)); 4539f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li // 4549f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li // copy the all lines next to the inserted to the new buffer 4559f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li if (l < height - 1) { 4569f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li System.arraycopy(charArray, oldBase + l + 1, cbuf, newScreenBase + l + 1, (height - 1) 4579f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li - l); 4589f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li System.arraycopy(charAttributes, oldBase + l + 1, abuf, newScreenBase + l + 1, 4599f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li (height - 1) - l); 4609f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li } 4619f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li } catch (ArrayIndexOutOfBoundsException e) { 4629f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li // this should not happen anymore, but I will leave the code 4639f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li // here in case something happens anyway. That code above is 4649f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li // so complex I always have a hard time understanding what 4659f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li // I did, even though there are comments 4669f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li System.err.println("*** Error while scrolling up:"); 4679f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li System.err.println("--- BEGIN STACK TRACE ---"); 4689f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li e.printStackTrace(); 4699f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li System.err.println("--- END STACK TRACE ---"); 4709f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li System.err.println("bufSize=" + bufSize + ", maxBufSize=" + maxBufSize); 4719f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li System.err.println("top=" + top + ", bottom=" + bottom); 4729f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li System.err.println("n=" + n + ", l=" + l); 4739f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li System.err.println("screenBase=" + screenBase + ", windowBase=" + windowBase); 4749f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li System.err.println("newScreenBase=" + newScreenBase + ", newWindowBase=" + newWindowBase); 4759f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li System.err.println("oldBase=" + oldBase); 4769f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li System.err.println("size.width=" + width + ", size.height=" + height); 4779f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li System.err.println("abuf.length=" + abuf.length + ", cbuf.length=" + cbuf.length); 4789f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li System.err.println("*** done dumping debug information"); 4799f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li } 4809f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li } 4819f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li 4829f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li // this is a little helper to mark the scrolling 4839f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li scrollMarker -= n; 4849f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li 4859f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li for (int i = 0; i < n; i++) { 4869f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li cbuf[(newScreenBase + l) + (scrollDown ? i : -i)] = new char[width]; 4879f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li Arrays.fill(cbuf[(newScreenBase + l) + (scrollDown ? i : -i)], ' '); 4889f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li abuf[(newScreenBase + l) + (scrollDown ? i : -i)] = new int[width]; 4899f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li } 4909f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li 4919f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li charArray = cbuf; 4929f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li charAttributes = abuf; 4939f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li screenBase = newScreenBase; 4949f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li windowBase = newWindowBase; 4959f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li bufSize = newBufSize; 4969f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li 4979f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li if (scrollDown) { 4989f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li markLine(l, bottom - l + 1); 4999f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li } else { 5009f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li markLine(top, l - top + 1); 5019f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li } 5029f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li 5039f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li display.updateScrollBar(); 5049f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li } 5059f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li 5069f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li /** 5079f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * Delete a line at a specific position. Subsequent lines will be scrolled up to fill the space 5089f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * and a blank line is inserted at the end of the screen. 5099f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * 5109f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * @param l 5119f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * the y-coordinate to insert the line 5129f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * @see #deleteLine 5139f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li */ 5149f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li public void deleteLine(int l) { 5159f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li int bottom = (l > bottomMargin ? height - 1 : (l < topMargin ? topMargin : bottomMargin + 1)); 5169f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li int numRows = bottom - l - 1; 5179f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li 5189f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li char[] discardedChars = charArray[screenBase + l]; 5199f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li int[] discardedAttributes = charAttributes[screenBase + l]; 5209f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li 5219f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li if (numRows > 0) { 5229f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li System.arraycopy(charArray, screenBase + l + 1, charArray, screenBase + l, numRows); 5239f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li System.arraycopy(charAttributes, screenBase + l + 1, charAttributes, screenBase + l, numRows); 5249f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li } 5259f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li 5269f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li int newBottomRow = screenBase + bottom - 1; 5279f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li charArray[newBottomRow] = discardedChars; 5289f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li charAttributes[newBottomRow] = discardedAttributes; 5299f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li Arrays.fill(charArray[newBottomRow], ' '); 5309f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li Arrays.fill(charAttributes[newBottomRow], 0); 5319f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li 5329f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li markLine(l, bottom - l); 5339f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li } 5349f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li 5359f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li /** 5369f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * Delete a rectangular portion of the screen. You need to call redraw() to update the screen. 5379f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * 5389f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * @param c 5399f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * x-coordinate (column) 5409f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * @param l 5419f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * y-coordinate (row) 5429f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * @param w 5439f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * with of the area in characters 5449f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * @param h 5459f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * height of the area in characters 5469f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * @param curAttr 5479f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * attribute to fill 5489f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * @see #deleteChar 5499f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * @see #deleteLine 5509f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * @see #redraw 5519f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li */ 5529f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li public void deleteArea(int c, int l, int w, int h, int curAttr) { 5539f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li int endColumn = c + w; 5549f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li int targetRow = screenBase + l; 5559f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li for (int i = 0; i < h && l + i < height; i++) { 5569f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li Arrays.fill(charAttributes[targetRow], c, endColumn, curAttr); 5579f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li Arrays.fill(charArray[targetRow], c, endColumn, ' '); 5589f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li targetRow++; 5599f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li } 5609f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li markLine(l, h); 5619f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li } 5629f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li 5639f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li /** 5649f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * Delete a rectangular portion of the screen. You need to call redraw() to update the screen. 5659f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * 5669f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * @param c 5679f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * x-coordinate (column) 5689f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * @param l 5699f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * y-coordinate (row) 5709f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * @param w 5719f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * with of the area in characters 5729f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * @param h 5739f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * height of the area in characters 5749f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * @see #deleteChar 5759f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * @see #deleteLine 5769f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * @see #redraw 5779f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li */ 5789f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li public void deleteArea(int c, int l, int w, int h) { 5799f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li deleteArea(c, l, w, h, 0); 5809f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li } 5819f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li 5829f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li /** 5839f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * Sets whether the cursor is visible or not. 5849f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * 5859f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * @param doshow 5869f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li */ 5879f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li public void showCursor(boolean doshow) { 5889f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li showcursor = doshow; 5899f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li } 5909f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li 5919f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li /** 5929f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * Check whether the cursor is currently visible. 5939f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * 5949f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * @return visibility 5959f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li */ 5969f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li public boolean isCursorVisible() { 5979f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li return showcursor; 5989f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li } 5999f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li 6009f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li /** 6019f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * Puts the cursor at the specified position. 6029f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * 6039f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * @param c 6049f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * column 6059f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * @param l 6069f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * line 6079f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li */ 6089f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li public void setCursorPosition(int c, int l) { 6099f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li cursorX = c; 6109f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li cursorY = l; 6119f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li } 6129f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li 6139f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li /** 6149f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * Get the current column of the cursor position. 6159f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li */ 6169f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li public int getCursorColumn() { 6179f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li return cursorX; 6189f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li } 6199f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li 6209f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li /** 6219f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * Get the current line of the cursor position. 6229f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li */ 6239f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li public int getCursorRow() { 6249f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li return cursorY; 6259f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li } 6269f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li 6279f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li /** 6289f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * Set the current window base. This allows to view the scrollback buffer. 6299f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * 6309f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * @param line 6319f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * the line where the screen window starts 6329f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * @see #setBufferSize 6339f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * @see #getBufferSize 6349f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li */ 6359f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li public void setWindowBase(int line) { 6369f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li if (line > screenBase) { 6379f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li line = screenBase; 6389f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li } else if (line < 0) { 6399f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li line = 0; 6409f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li } 6419f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li windowBase = line; 6429f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li update[0] = true; 6439f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li redraw(); 6449f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li } 6459f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li 6469f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li /** 6479f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * Get the current window base. 6489f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * 6499f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * @see #setWindowBase 6509f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li */ 6519f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li public int getWindowBase() { 6529f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li return windowBase; 6539f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li } 6549f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li 6559f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li /** 6569f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * Set the scroll margins simultaneously. If they're out of bounds, trim them. 6579f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * 6589f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * @param l1 6599f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * line that is the top 6609f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * @param l2 6619f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * line that is the bottom 6629f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li */ 6639f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li public void setMargins(int l1, int l2) { 6649f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li if (l1 > l2) { 6659f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li return; 6669f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li } 6679f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li 6689f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li if (l1 < 0) { 6699f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li l1 = 0; 6709f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li } 6719f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li if (l2 >= height) { 6729f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li l2 = height - 1; 6739f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li } 6749f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li 6759f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li topMargin = l1; 6769f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li bottomMargin = l2; 6779f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li } 6789f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li 6799f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li /** 6809f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * Set the top scroll margin for the screen. If the current bottom margin is smaller it will 6819f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * become the top margin and the line will become the bottom margin. 6829f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * 6839f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * @param l 6849f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * line that is the margin 6859f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li */ 6869f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li public void setTopMargin(int l) { 6879f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li if (l > bottomMargin) { 6889f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li topMargin = bottomMargin; 6899f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li bottomMargin = l; 6909f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li } else { 6919f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li topMargin = l; 6929f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li } 6939f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li if (topMargin < 0) { 6949f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li topMargin = 0; 6959f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li } 6969f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li if (bottomMargin >= height) { 6979f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li bottomMargin = height - 1; 6989f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li } 6999f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li } 7009f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li 7019f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li /** 7029f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * Get the top scroll margin. 7039f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li */ 7049f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li public int getTopMargin() { 7059f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li return topMargin; 7069f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li } 7079f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li 7089f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li /** 7099f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * Set the bottom scroll margin for the screen. If the current top margin is bigger it will become 7109f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * the bottom margin and the line will become the top margin. 7119f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * 7129f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * @param l 7139f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * line that is the margin 7149f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li */ 7159f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li public void setBottomMargin(int l) { 7169f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li if (l < topMargin) { 7179f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li bottomMargin = topMargin; 7189f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li topMargin = l; 7199f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li } else { 7209f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li bottomMargin = l; 7219f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li } 7229f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li if (topMargin < 0) { 7239f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li topMargin = 0; 7249f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li } 7259f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li if (bottomMargin >= height) { 7269f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li bottomMargin = height - 1; 7279f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li } 7289f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li } 7299f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li 7309f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li /** 7319f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * Get the bottom scroll margin. 7329f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li */ 7339f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li public int getBottomMargin() { 7349f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li return bottomMargin; 7359f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li } 7369f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li 7379f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li /** 7389f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * Set scrollback buffer size. 7399f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * 7409f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * @param amount 7419f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * new size of the buffer 7429f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li */ 7439f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li public void setBufferSize(int amount) { 7449f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li if (amount < height) { 7459f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li amount = height; 7469f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li } 7479f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li if (amount < maxBufSize) { 7489f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li char cbuf[][] = new char[amount][width]; 7499f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li int abuf[][] = new int[amount][width]; 7509f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li int copyStart = bufSize - amount < 0 ? 0 : bufSize - amount; 7519f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li int copyCount = bufSize - amount < 0 ? bufSize : amount; 7529f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li if (charArray != null) { 7539f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li System.arraycopy(charArray, copyStart, cbuf, 0, copyCount); 7549f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li } 7559f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li if (charAttributes != null) { 7569f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li System.arraycopy(charAttributes, copyStart, abuf, 0, copyCount); 7579f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li } 7589f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li charArray = cbuf; 7599f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li charAttributes = abuf; 7609f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li bufSize = copyCount; 7619f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li screenBase = bufSize - height; 7629f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li windowBase = screenBase; 7639f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li } 7649f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li maxBufSize = amount; 7659f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li 7669f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li update[0] = true; 7679f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li redraw(); 7689f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li } 7699f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li 7709f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li /** 7719f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * Retrieve current scrollback buffer size. 7729f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * 7739f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * @see #setBufferSize 7749f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li */ 7759f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li public int getBufferSize() { 7769f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li return bufSize; 7779f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li } 7789f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li 7799f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li /** 7809f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * Retrieve maximum buffer Size. 7819f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * 7829f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * @see #getBufferSize 7839f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li */ 7849f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li public int getMaxBufferSize() { 7859f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li return maxBufSize; 7869f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li } 7879f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li 7889f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li /** 7899f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * Change the size of the screen. This will include adjustment of the scrollback buffer. 7909f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * 7919f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * @param w 7929f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * of the screen 7939f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * @param h 7949f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * of the screen 7959f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li */ 7969f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li @SuppressWarnings("unused") 7979f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li public void setScreenSize(int w, int h, boolean broadcast) { 7989f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li char cbuf[][]; 7999f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li int abuf[][]; 8009f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li int maxSize = bufSize; 8019f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li 8029f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li if (w < 1 || h < 1) { 8039f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li return; 8049f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li } 8059f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li 8069f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li if (debug > 0) { 8079f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li System.err.println("VDU: screen size [" + w + "," + h + "]"); 8089f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li } 8099f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li 8109f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li if (h > maxBufSize) { 8119f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li maxBufSize = h; 8129f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li } 8139f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li 8149f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li if (h > bufSize) { 8159f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li bufSize = h; 8169f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li screenBase = 0; 8179f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li windowBase = 0; 8189f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li } 8199f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li 8209f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li if (windowBase + h >= bufSize) { 8219f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li windowBase = bufSize - h; 8229f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li } 8239f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li 8249f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li if (screenBase + h >= bufSize) { 8259f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li screenBase = bufSize - h; 8269f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li } 8279f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li 8289f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li cbuf = new char[bufSize][w]; 8299f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li abuf = new int[bufSize][w]; 8309f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li 8319f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li for (int i = 0; i < bufSize; i++) { 8329f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li Arrays.fill(cbuf[i], ' '); 8339f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li } 8349f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li 8359f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li if (bufSize < maxSize) { 8369f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li maxSize = bufSize; 8379f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li } 8389f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li 8399f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li int rowLength; 8409f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li if (charArray != null && charAttributes != null) { 8419f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li for (int i = 0; i < maxSize && charArray[i] != null; i++) { 8429f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li rowLength = charArray[i].length; 8439f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li System.arraycopy(charArray[i], 0, cbuf[i], 0, w < rowLength ? w : rowLength); 8449f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li System.arraycopy(charAttributes[i], 0, abuf[i], 0, w < rowLength ? w : rowLength); 8459f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li } 8469f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li } 8479f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li 8489f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li int C = getCursorColumn(); 8499f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li if (C < 0) { 8509f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li C = 0; 8519f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li } else if (C >= width) { 8529f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li C = width - 1; 8539f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li } 8549f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li 8559f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li int R = getCursorRow(); 8569f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li if (R < 0) { 8579f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li R = 0; 8589f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li } else if (R >= height) { 8599f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li R = height - 1; 8609f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li } 8619f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li 8629f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li setCursorPosition(C, R); 8639f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li 8649f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li charArray = cbuf; 8659f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li charAttributes = abuf; 8669f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li width = w; 8679f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li height = h; 8689f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li topMargin = 0; 8699f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li bottomMargin = h - 1; 8709f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li update = new boolean[h + 1]; 8719f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li update[0] = true; 8729f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li /* 8739f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * FIXME: ??? if(resizeStrategy == RESIZE_FONT) setBounds(getBounds()); 8749f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li */ 8759f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li } 8769f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li 8779f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li /** 8789f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * Get amount of rows on the screen. 8799f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li */ 8809f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li public int getRows() { 8819f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li return height; 8829f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li } 8839f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li 8849f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li /** 8859f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * Get amount of columns on the screen. 8869f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li */ 8879f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li public int getColumns() { 8889f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li return width; 8899f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li } 8909f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li 8919f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li /** 8929f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * Mark lines to be updated with redraw(). 8939f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * 8949f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * @param l 8959f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * starting line 8969f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * @param n 8979f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * amount of lines to be updated 8989f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * @see #redraw 8999f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li */ 9009f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li public void markLine(int l, int n) { 9019f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li for (int i = 0; (i < n) && (l + i < height); i++) { 9029f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li update[l + i + 1] = true; 9039f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li } 9049f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li } 9059f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li 9069f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li // private static int checkBounds(int value, int lower, int upper) { 9079f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li // if (value < lower) 9089f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li // return lower; 9099f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li // else if (value > upper) 9109f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li // return upper; 9119f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li // else 9129f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li // return value; 9139f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li // } 9149f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li 9159f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li /** a generic display that should redraw on demand */ 9169f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li protected VDUDisplay display; 9179f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li 9189f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li public void setDisplay(VDUDisplay display) { 9199f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li this.display = display; 9209f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li } 9219f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li 9229f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li /** 9239f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li * Trigger a redraw on the display. 9249f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li */ 9259f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li protected void redraw() { 9269f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li if (display != null) { 9279f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li display.redraw(); 9289f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li } 9299f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li } 9309f32db87b486c93a0ea71eb1781ee45676b8bf8bXin Li} 931