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

📄 vt320.java

📁 The Javatm Telnet Application/Applet 很好用的
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
   * A small conveniance method thar converts the string to a byte array   * for sending.   * @param s the string to be sent   */  private boolean write(String s, boolean doecho) {    if (debug > 2) System.out.println("write(|" + s + "|," + doecho);    if (s == null) // aka the empty string.      return true;    /* NOTE: getBytes() honours some locale, it *CONVERTS* the string.     * However, we output only 7bit stuff towards the target, and *some*     * 8 bit control codes. We must not mess up the latter, so we do hand     * by hand copy.     */    byte arr[] = new byte[s.length()];    for (int i = 0; i < s.length(); i++) {      arr[i] = (byte) s.charAt(i);    }    write(arr);    if (doecho)      putString(s);    return true;  }  private boolean write(String s) {    return write(s, localecho);  }  // ===================================================================  // the actual terminal emulation code comes here:  // ===================================================================  private String terminalID = "vt320";  private String answerBack = "Use Terminal.answerback to set ...\n";  // X - COLUMNS, Y - ROWS  int R,C;  int attributes = 0;  int Sc,Sr,Sa,Stm,Sbm;  char Sgr,Sgl;  char Sgx[];  int insertmode = 0;  int statusmode = 0;  boolean vt52mode = false;  boolean keypadmode = false; /* false - numeric, true - application */  boolean output8bit = false;  int normalcursor = 0;  boolean moveoutsidemargins = true;  boolean wraparound = true;  boolean sendcrlf = true;  boolean capslock = false;  boolean numlock = false;  int mouserpt = 0;  byte mousebut = 0;  boolean useibmcharset = false;  int lastwaslf = 0;  boolean usedcharsets = false;  private final static char ESC = 27;  private final static char IND = 132;  private final static char NEL = 133;  private final static char RI = 141;  private final static char SS2 = 142;  private final static char SS3 = 143;  private final static char DCS = 144;  private final static char HTS = 136;  private final static char CSI = 155;  private final static char OSC = 157;  private final static int TSTATE_DATA = 0;  private final static int TSTATE_ESC = 1; /* ESC */  private final static int TSTATE_CSI = 2; /* ESC [ */  private final static int TSTATE_DCS = 3; /* ESC P */  private final static int TSTATE_DCEQ = 4; /* ESC [? */  private final static int TSTATE_ESCSQUARE = 5; /* ESC # */  private final static int TSTATE_OSC = 6;       /* ESC ] */  private final static int TSTATE_SETG0 = 7;     /* ESC (? */  private final static int TSTATE_SETG1 = 8;     /* ESC )? */  private final static int TSTATE_SETG2 = 9;     /* ESC *? */  private final static int TSTATE_SETG3 = 10;    /* ESC +? */  private final static int TSTATE_CSI_DOLLAR = 11; /* ESC [ Pn $ */  private final static int TSTATE_CSI_EX = 12; /* ESC [ ! */  private final static int TSTATE_ESCSPACE = 13; /* ESC <space> */  private final static int TSTATE_VT52X = 14;  private final static int TSTATE_VT52Y = 15;  private final static int TSTATE_CSI_TICKS = 16;  private final static int TSTATE_CSI_EQUAL = 17; /* ESC [ = */  /* The graphics charsets   * B - default ASCII   * A - ISO Latin 1   * 0 - DEC SPECIAL   * < - User defined   * ....   */  char gx[] = {// same initial set as in XTERM.    'B', // g0    '0', // g1    'B', // g2    'B', // g3  };  char gl = 0;		// default GL to G0  char gr = 2;		// default GR to G2  int onegl = -1;	// single shift override for GL.  // Map from scoansi linedrawing to DEC _and_ unicode (for the stuff which  // is not in linedrawing). Got from experimenting with scoadmin.  private final static String scoansi_acs = "Tm7k3x4u?kZl@mYjEnB\u2566DqCtAvM\u2550:\u2551N\u2557I\u2554;\u2557H\u255a0a<\u255d";  // array to store DEC Special -> Unicode mapping  //  Unicode   DEC  Unicode name    (DEC name)  private static char DECSPECIAL[] = {    '\u0040', //5f blank    '\u2666', //60 black diamond    '\u2592', //61 grey square    '\u2409', //62 Horizontal tab  (ht) pict. for control    '\u240c', //63 Form Feed       (ff) pict. for control    '\u240d', //64 Carriage Return (cr) pict. for control    '\u240a', //65 Line Feed       (lf) pict. for control    '\u00ba', //66 Masculine ordinal indicator    '\u00b1', //67 Plus or minus sign    '\u2424', //68 New Line        (nl) pict. for control    '\u240b', //69 Vertical Tab    (vt) pict. for control    '\u2518', //6a Forms light up   and left    '\u2510', //6b Forms light down and left    '\u250c', //6c Forms light down and right    '\u2514', //6d Forms light up   and right    '\u253c', //6e Forms light vertical and horizontal    '\u2594', //6f Upper 1/8 block                        (Scan 1)    '\u2580', //70 Upper 1/2 block                        (Scan 3)    '\u2500', //71 Forms light horizontal or ?em dash?    (Scan 5)    '\u25ac', //72 \u25ac black rect. or \u2582 lower 1/4 (Scan 7)    '\u005f', //73 \u005f underscore  or \u2581 lower 1/8 (Scan 9)    '\u251c', //74 Forms light vertical and right    '\u2524', //75 Forms light vertical and left    '\u2534', //76 Forms light up   and horizontal    '\u252c', //77 Forms light down and horizontal    '\u2502', //78 vertical bar    '\u2264', //79 less than or equal    '\u2265', //7a greater than or equal    '\u00b6', //7b paragraph    '\u2260', //7c not equal    '\u00a3', //7d Pound Sign (british)    '\u00b7'  //7e Middle Dot  };  /** Strings to send on function key pressing */  private String Numpad[];  private String FunctionKey[];  private String FunctionKeyShift[];  private String FunctionKeyCtrl[];  private String FunctionKeyAlt[];  private String TabKey[];  private String KeyUp[],KeyDown[],KeyLeft[],KeyRight[];  private String KPMinus, KPComma, KPPeriod, KPEnter;  private String PF1, PF2, PF3, PF4;  private String Help, Do, Find, Select;  private String KeyHome[], KeyEnd[], Insert[], Remove[], PrevScn[], NextScn[];  private String Escape[], BackSpace[], NUMDot[], NUMPlus[];  private String osc,dcs;  /* to memorize OSC & DCS control sequence */  /** vt320 state variable (internal) */  private int term_state = TSTATE_DATA;  /** in vms mode, set by Terminal.VMS property */  private boolean vms = false;  /** Tabulators */  private byte[] Tabs;  /** The list of integers as used by CSI */  private int[] DCEvars = new int[30];  private int DCEvar;  /**   * Replace escape code characters (backslash + identifier) with their   * respective codes.   * @param tmp the string to be parsed   * @return a unescaped string   */  static String unEscape(String tmp) {    int idx = 0, oldidx = 0;    String cmd;    // System.err.println("unescape("+tmp+")");    cmd = "";    while ((idx = tmp.indexOf('\\', oldidx)) >= 0 &&            ++idx <= tmp.length()) {      cmd += tmp.substring(oldidx, idx - 1);      if (idx == tmp.length()) return cmd;      switch (tmp.charAt(idx)) {        case 'b':          cmd += "\b";          break;        case 'e':          cmd += "\u001b";          break;        case 'n':          cmd += "\n";          break;        case 'r':          cmd += "\r";          break;        case 't':          cmd += "\t";          break;        case 'v':          cmd += "\u000b";          break;        case 'a':          cmd += "\u0012";          break;        default :          if ((tmp.charAt(idx) >= '0') && (tmp.charAt(idx) <= '9')) {            int i;            for (i = idx; i < tmp.length(); i++)              if ((tmp.charAt(i) < '0') || (tmp.charAt(i) > '9'))                break;            cmd += (char) Integer.parseInt(tmp.substring(idx, i));            idx = i - 1;          } else            cmd += tmp.substring(idx, ++idx);          break;      }      oldidx = ++idx;    }    if (oldidx <= tmp.length()) cmd += tmp.substring(oldidx);    return cmd;  }  /**   * A small conveniance method thar converts a 7bit string to the 8bit   * version depending on VT52/Output8Bit mode.   *   * @param s the string to be sent   */  private boolean writeSpecial(String s) {    if (s == null)      return true;    if (((s.length() >= 3) && (s.charAt(0) == 27) && (s.charAt(1) == 'O'))) {      if (vt52mode) {        if ((s.charAt(2) >= 'P') && (s.charAt(2) <= 'S')) {          s = "\u001b" + s.substring(2); /* ESC x */        } else {          s = "\u001b?" + s.substring(2); /* ESC ? x */        }      } else {        if (output8bit) {          s = "\u008f" + s.substring(2);  /* SS3 x */        } /* else keep string as it is */      }    }    if (((s.length() >= 3) && (s.charAt(0) == 27) && (s.charAt(1) == '['))) {      if (output8bit) {        s = "\u009b" + s.substring(2); /* CSI ... */      } /* else keep */    }    return write(s, false);  }  /**   * main keytyping event handler...   */  public void keyPressed(int keyCode, char keyChar, int modifiers) {    boolean control = (modifiers & VDUInput.KEY_CONTROL) != 0;    boolean shift = (modifiers & VDUInput.KEY_SHIFT) != 0;    boolean alt = (modifiers & VDUInput.KEY_ALT) != 0;    if (debug > 1) System.out.println("keyPressed("+keyCode+", "+(int)keyChar+", "+modifiers+")");    int xind;    String fmap[];    xind = 0;    fmap = FunctionKey;    if (shift) {      fmap = FunctionKeyShift;      xind = 1;    }    if (control) {      fmap = FunctionKeyCtrl;      xind = 2;    }    if (alt) {      fmap = FunctionKeyAlt;      xind = 3;    }    switch (keyCode) {      case KeyEvent.VK_PAUSE:        if (shift || control)          sendTelnetCommand((byte) 243); // BREAK        break;      case KeyEvent.VK_F1:        writeSpecial(fmap[1]);        break;      case KeyEvent.VK_F2:        writeSpecial(fmap[2]);        break;      case KeyEvent.VK_F3:        writeSpecial(fmap[3]);        break;      case KeyEvent.VK_F4:        writeSpecial(fmap[4]);        break;      case KeyEvent.VK_F5:        writeSpecial(fmap[5]);        break;      case KeyEvent.VK_F6:        writeSpecial(fmap[6]);        break;      case KeyEvent.VK_F7:        writeSpecial(fmap[7]);        break;      case KeyEvent.VK_F8:        writeSpecial(fmap[8]);        break;      case KeyEvent.VK_F9:        writeSpecial(fmap[9]);        break;      case KeyEvent.VK_F10:        writeSpecial(fmap[10]);        break;      case KeyEvent.VK_F11:        writeSpecial(fmap[11]);        break;      case KeyEvent.VK_F12:        writeSpecial(fmap[12]);        break;      case KeyEvent.VK_UP:        writeSpecial(KeyUp[xind]);        break;      case KeyEvent.VK_DOWN:        writeSpecial(KeyDown[xind]);        break;      case KeyEvent.VK_LEFT:        writeSpecial(KeyLeft[xind]);        break;      case KeyEvent.VK_RIGHT:        writeSpecial(KeyRight[xind]);        break;      case KeyEvent.VK_PAGE_DOWN:        writeSpecial(NextScn[xind]);        break;      case KeyEvent.VK_PAGE_UP:        writeSpecial(PrevScn[xind]);        break;      case KeyEvent.VK_INSERT:        writeSpecial(Insert[xind]);        break;      case KeyEvent.VK_DELETE:        writeSpecial(Remove[xind]);        break;      case KeyEvent.VK_BACK_SPACE:        writeSpecial(BackSpace[xind]);	if (localecho) {	  if (BackSpace[xind] == "\b") {	    putString("\b \b"); // make the last char 'deleted'	  } else {	    putString(BackSpace[xind]); // echo it	  }	}        break;      case KeyEvent.VK_HOME:        writeSpecial(KeyHome[xind]);        break;      case KeyEvent.VK_END:        writeSpecial(KeyEnd[xind]);        break;      case KeyEvent.VK_NUM_LOCK:        if (vms && control) {          writeSpecial(PF1);        }        if (!control)          numlock = !numlock;        break;      case KeyEvent.VK_CAPS_LOCK:        capslock = !capslock;        return;      case KeyEvent.VK_SHIFT:      case KeyEvent.VK_CONTROL:      case KeyEvent.VK_ALT:        return;      default:        break;    }  }  public void keyReleased(KeyEvent evt) {    if (debug > 1) System.out.println("keyReleased("+evt+")");    // ignore  }  /**   * Handle key Typed events for the terminal, this will get   * all normal key types, but no shift/alt/control/numlock.   */  public void keyTyped(int keyCode, char keyChar, int modifiers) {    boolean control = (modifiers & VDUInput.KEY_CONTROL) != 0;    boolean shift = (modifiers & VDUInput.KEY_SHIFT) != 0;    boolean alt = (modifiers & VDUInput.KEY_ALT) != 0;    if (debug > 1) System.out.println("keyTyped("+keyCode+", "+(int)keyChar+", "+modifiers+")");    if (keyChar == '\t') {      if (shift) {

⌨️ 快捷键说明

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