⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vdubuffer.java

📁 The Javatm Telnet Application/Applet 很好用的
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        // copy anything from the topMargin up to the amount of lines inserted        // to the gap left over between scrollback buffer and screenBase        if (oldBase > 0) {          System.arraycopy(charArray, oldBase + top,                           cbuf, oldBase - offset,                           n);          System.arraycopy(charAttributes, oldBase + top,                           abuf, oldBase - offset,                           n);        }        // copy anything from topMargin + n up to the line linserted to the        // topMargin        System.arraycopy(charArray, oldBase + top + n,                         cbuf, screenBase + top,                         l - top - (n - 1));        System.arraycopy(charAttributes, oldBase + top + n,                         abuf, screenBase + top,                         l - top - (n - 1));        //        // copy the all lines next to the inserted to the new buffer        if (l < height - 1) {          System.arraycopy(charArray, oldBase + l + 1,                           cbuf, screenBase + l + 1,                           (height - 1) - l);          System.arraycopy(charAttributes, oldBase + l + 1,                           abuf, screenBase + l + 1,                           (height - 1) - l);        }      } catch (ArrayIndexOutOfBoundsException e) {        // this should not happen anymore, but I will leave the code        // here in case something happens anyway. That code above is        // so complex I always have a hard time understanding what        // I did, even though there are comments        System.err.println("*** Error while scrolling up:");        System.err.println("--- BEGIN STACK TRACE ---");        e.printStackTrace();        System.err.println("--- END STACK TRACE ---");        System.err.println("bufSize=" + bufSize + ", maxBufSize=" + maxBufSize);        System.err.println("top=" + top + ", bottom=" + bottom);        System.err.println("n=" + n + ", l=" + l);        System.err.println("screenBase=" + screenBase + ", windowBase=" + windowBase);        System.err.println("oldBase=" + oldBase);        System.err.println("size.width=" + width + ", size.height=" + height);        System.err.println("abuf.length=" + abuf.length + ", cbuf.length=" + cbuf.length);        System.err.println("*** done dumping debug information");      }    }    // this is a little helper to mark the scrolling    scrollMarker -= n;    for (int i = 0; i < n; i++) {      cbuf[(screenBase + l) + (scrollDown ? i : -i)] = new char[width];      abuf[(screenBase + l) + (scrollDown ? i : -i)] = new int[width];    }    charArray = cbuf;    charAttributes = abuf;    if (scrollDown)      markLine(l, bottom - l + 1);    else      markLine(top, l - top + 1);/*  FIXME: needs to be in VDU    if(scrollBar != null)      scrollBar.setValues(windowBase, height, 0, bufSize);*/  }  /**   * Delete a line at a specific position. Subsequent lines will be scrolled   * up to fill the space and a blank line is inserted at the end of the   * screen.   * @param l the y-coordinate to insert the line   * @see #deleteLine   */  public void deleteLine(int l) {    l = checkBounds(l, 0, height - 1);    int bottom = (l > bottomMargin ? height - 1:            (l < topMargin?topMargin:bottomMargin + 1));    System.arraycopy(charArray, screenBase + l + 1,                     charArray, screenBase + l, bottom - l - 1);    System.arraycopy(charAttributes, screenBase + l + 1,                     charAttributes, screenBase + l, bottom - l - 1);    charArray[screenBase + bottom - 1] = new char[width];    charAttributes[screenBase + bottom - 1] = new int[width];    markLine(l, bottom - l);  }  /**   * Delete a rectangular portion of the screen.   * You need to call redraw() to update the screen.   * @param c x-coordinate (column)   * @param l y-coordinate (row)   * @param w with of the area in characters   * @param h height of the area in characters   * @param curAttr attribute to fill   * @see #deleteChar   * @see #deleteLine   * @see #redraw   */  public void deleteArea(int c, int l, int w, int h, int curAttr) {    c = checkBounds(c, 0, width - 1);    l = checkBounds(l, 0, height - 1);    char cbuf[] = new char[w];    int abuf[] = new int[w];    for (int i = 0; i < w; i++) abuf[i] = curAttr;    for (int i = 0; i < h && l + i < height; i++) {      System.arraycopy(cbuf, 0, charArray[screenBase + l + i], c, w);      System.arraycopy(abuf, 0, charAttributes[screenBase + l + i], c, w);    }    markLine(l, h);  }  /**   * Delete a rectangular portion of the screen.   * You need to call redraw() to update the screen.   * @param c x-coordinate (column)   * @param l y-coordinate (row)   * @param w with of the area in characters   * @param h height of the area in characters   * @see #deleteChar   * @see #deleteLine   * @see #redraw   */  public void deleteArea(int c, int l, int w, int h) {    c = checkBounds(c, 0, width - 1);    l = checkBounds(l, 0, height - 1);    char cbuf[] = new char[w];    int abuf[] = new int[w];    for (int i = 0; i < h && l + i < height; i++) {      System.arraycopy(cbuf, 0, charArray[screenBase + l + i], c, w);      System.arraycopy(abuf, 0, charAttributes[screenBase + l + i], c, w);    }    markLine(l, h);  }  /**   * Sets whether the cursor is visible or not.   * @param doshow   */  public void showCursor(boolean doshow) {    if (doshow != showcursor)      markLine(cursorY, 1);    showcursor = doshow;  }  /**   * Puts the cursor at the specified position.   * @param c column   * @param l line   */  public void setCursorPosition(int c, int l) {    cursorX = checkBounds(c, 0, width - 1);    cursorY = checkBounds(l, 0, height - 1);    markLine(cursorY, 1);  }  /**   * Get the current column of the cursor position.   */  public int getCursorColumn() {    return cursorX;  }  /**   * Get the current line of the cursor position.   */  public int getCursorRow() {    return cursorY;  }  /**   * Set the current window base. This allows to view the scrollback buffer.   * @param line the line where the screen window starts   * @see #setBufferSize   * @see #getBufferSize   */  public void setWindowBase(int line) {    if (line > screenBase)      line = screenBase;    else if (line < 0) line = 0;    windowBase = line;    update[0] = true;    redraw();  }  /**   * Get the current window base.   * @see #setWindowBase   */  public int getWindowBase() {    return windowBase;  }  /**   * Set the top scroll margin for the screen. If the current bottom margin   * is smaller it will become the top margin and the line will become the   * bottom margin.   * @param l line that is the margin   */  public void setTopMargin(int l) {    if (l > bottomMargin) {      topMargin = bottomMargin;      bottomMargin = l;    } else      topMargin = l;    if (topMargin < 0) topMargin = 0;    if (bottomMargin > height - 1) bottomMargin = height - 1;  }  /**   * Get the top scroll margin.   */  public int getTopMargin() {    return topMargin;  }  /**   * Set the bottom scroll margin for the screen. If the current top margin   * is bigger it will become the bottom margin and the line will become the   * top margin.   * @param l line that is the margin   */  public void setBottomMargin(int l) {    if (l < topMargin) {      bottomMargin = topMargin;      topMargin = l;    } else      bottomMargin = l;    if (topMargin < 0) topMargin = 0;    if (bottomMargin > height - 1) bottomMargin = height - 1;  }  /**   * Get the bottom scroll margin.   */  public int getBottomMargin() {    return bottomMargin;  }  /**   * Set scrollback buffer size.   * @param amount new size of the buffer   */  public void setBufferSize(int amount) {    if (amount < height) amount = height;    if (amount < maxBufSize) {      char cbuf[][] = new char[amount][width];      int abuf[][] = new int[amount][width];      int copyStart = bufSize - amount < 0 ? 0 : bufSize - amount;      int copyCount = bufSize - amount < 0 ? bufSize : amount;      if (charArray != null)        System.arraycopy(charArray, copyStart, cbuf, 0, copyCount);      if (charAttributes != null)        System.arraycopy(charAttributes, copyStart, abuf, 0, copyCount);      charArray = cbuf;      charAttributes = abuf;      bufSize = copyCount;      screenBase = bufSize - height;      windowBase = screenBase;    }    maxBufSize = amount;    update[0] = true;    redraw();  }  /**   * Retrieve current scrollback buffer size.   * @see #setBufferSize   */  public int getBufferSize() {    return bufSize;  }  /**   * Retrieve maximum buffer Size.   * @see #getBufferSize   */  public int getMaxBufferSize() {    return maxBufSize;  }  /**   * Change the size of the screen. This will include adjustment of the   * scrollback buffer.   * @param w of the screen   * @param h of the screen   */  public void setScreenSize(int w, int h) {    char cbuf[][];    int abuf[][];    int bsize = bufSize;    if (w < 1 || h < 1) return;    if (debug > 0)      System.err.println("VDU: screen size [" + w + "," + h + "]");    if (h > maxBufSize)      maxBufSize = h;    if (h > bufSize) {      bufSize = h;      screenBase = 0;      windowBase = 0;    }    if (windowBase + h >= bufSize)      windowBase = bufSize - h;    if (screenBase + h >= bufSize)      screenBase = bufSize - h;    cbuf = new char[bufSize][w];    abuf = new int[bufSize][w];    if (charArray != null && charAttributes != null) {      for (int i = 0; i < bsize && i < bufSize; i++) {        System.arraycopy(charArray[i], 0, cbuf[i], 0,                         w < width ? w : width);        System.arraycopy(charAttributes[i], 0, abuf[i], 0,                         w < width ? w : width);      }    }    charArray = cbuf;    charAttributes = abuf;    width = w;    height = h;    topMargin = 0;    bottomMargin = h - 1;    update = new boolean[h + 1];    update[0] = true;    /*  FIXME: ???    if(resizeStrategy == RESIZE_FONT)      setBounds(getBounds());    */  }  /**   * Get amount of rows on the screen.   */  public int getRows() {    return height;  }  /**   * Get amount of columns on the screen.   */  public int getColumns() {    return width;  }  /**   * Mark lines to be updated with redraw().   * @param l starting line   * @param n amount of lines to be updated   * @see #redraw   */  public void markLine(int l, int n) {    l = checkBounds(l, 0, height - 1);    for (int i = 0; (i < n) && (l + i < height); i++)      update[l + i + 1] = true;  }  private int checkBounds(int value, int lower, int upper) {    if (value < lower) return lower;    if (value > upper) return upper;    return value;  }  /** a generic display that should redraw on demand */  protected VDUDisplay display;  public void setDisplay(VDUDisplay display) {    this.display = display;  }  /**   * Trigger a redraw on the display.   */  protected void redraw() {    if (display != null)      display.redraw();  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -