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

📄 terminalwin.java

📁 一个非常好的ssh客户端实现
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
	int    virtKey = e.getKeyCode();	if(DEBUGKEYEVENT) {	    char c = e.getKeyChar();	    System.out.println("released: " + c + " (" + ((int)c) + ") code=" + virtKey);	}	switch(virtKey) {	case KeyEvent.VK_ALT:	    metaKeyKludge = false;	    break;	case KeyEvent.VK_CONTROL:	    ctrlKeyKludge = false;	    break;	}    }    final boolean specialKeyHandler(int c, int virtKey, int mod) {	boolean keyProcessed = true;	switch(virtKey) {	case KeyEvent.VK_ALT:	    if(ctrlKeyKludge)		ctrlKeyKludge = false; // !!! Seems that MS-lost sends ctrl+alt for right ALT !!!	    else		metaKeyKludge = true;	    break;	case KeyEvent.VK_CONTROL:	    ctrlKeyKludge = true;	    break;	case KeyEvent.VK_BACK_SPACE:	    typedChar(bsCharacter);	    break;	case KeyEvent.VK_DELETE:	    typedChar(delCharacter);	    break;	case KeyEvent.VK_PAGE_UP:	case KeyEvent.VK_PAGE_DOWN:	case KeyEvent.VK_HOME:	case KeyEvent.VK_END:	    if(((mod & InputEvent.SHIFT_MASK) != 0) ||	       termOptions[OPT_LOCAL_PGKEYS]) {		localPageCtrlKeys(virtKey);	    } else {		keyProcessed = false;	    }	    break;	case KeyEvent.VK_INSERT:	    if((mod & InputEvent.SHIFT_MASK) != 0) {		doPaste();	    } else if((mod & InputEvent.CTRL_MASK) != 0) {		doCopy();	    } else {		keyProcessed = false;	    }	    break;	case KeyEvent.VK_SHIFT:	case KeyEvent.VK_CAPS_LOCK:	    // For some reason there seems to be characters in keyevents with	    // shift/caps, better filter them out	    //	    break;	default:	    keyProcessed = false;	    break;	}	return keyProcessed;    }    final int keyKludgeFilter(char c, int virtKey, int mod) {	//	// The KeyEvent content seems to be confusing (to say the least...)	// in some situations given different locale's and especially different	// platforms... This is not very funny, but then again who said	// anything about terminal-stuff beeing some kind of amusement...	//	// !!!	int transC = (int)c;	if(virtKey == KeyEvent.VK_SHIFT ||	   virtKey == KeyEvent.VK_CONTROL ||	   virtKey == KeyEvent.VK_CAPS_LOCK ||	   virtKey == KeyEvent.VK_ALT) {	    // !!! Swallow keypress for these, seems to contain key chars on	    // some combinations of JVM/OS/national keyboard	    //	    return -1;	} else if ((mod & InputEvent.CTRL_MASK) != 0		   && (mod & InputEvent.ALT_MASK) != 0) {	    return -1;	} else if ((mod & InputEvent.CTRL_MASK) != 0) {	    switch(virtKey) {	    case KeyEvent.VK_M: // Bug in MRJ (sent 0x0a on ^M, should be ^J)		transC = 0x0d;		break;	    case KeyEvent.VK_SPACE: // To do ctrl-space (for emacs of course)		if(termOptions[OPT_MAP_CTRLSP])		    transC = 0;		break;	    default:		if(((mod & InputEvent.ALT_MASK) == 0) &&		   virtKey >= KeyEvent.VK_A && virtKey <= KeyEvent.VK_Z) {		    // This is just to be sure that ctrl+<alphabetic-key> ends		    // up generating the right 'ascii'		    //		    transC = ctrlAlphaKey(virtKey);		    /* !!! TEMPORARILY DISABLED DUE TO CONFLICTS WITH NATIONAL CHARS		       } else if(c == '@') {		       transC = 0x00;		       } else if(c == '[') {		       transC = 0x1b;		       } else if(c == '\\') {		       transC = 0x1c;		       } else if(c == ']') {		       transC = 0x1d;		       } else if(c == '^') {		       transC = 0x1e;		       SEE ABOVE REMOVE !!! */		} else if(c == '_') {		    transC = 0x1f;		}		break;	    }	} else {	    // We always send 0x0d ^M on ENTER no matter where we are...	    //	    if (transC == 0x0a && virtKey == KeyEvent.VK_ENTER && !ctrlKeyKludge) {		transC = 0x0d;		/* !!! REMOVE	    } else if(c == '~') {		// !!! OUCH		// We MIGHT process the sly tilde character here, Hazeltine warning...		// (whomever gets the first tilde snatches further processing of it)		//		if(!tildeTypedKludge) {		    tildePressedKludge = true;		} else {		    transC = -1;		}		*/	    } else if(c == 65535) {		// OUCH, JDK 1.2 generates this on the Shift and Caps keys(!)		//		transC = -1;	    } else if(c == 65406) {		// OUCH, IBM JDK 1.1.6 on Linux generates this on right alt		// (alt_gr) (swedish-keyboard)		//		transC = -1;	    }	    // To be able to do meta-<key> in emacs with <left alt>	    //	    if(transC != -1 && metaKeyKludge) {		typedChar((char)27);	    }	}	return transC;    }    final int ctrlAlphaKey(int virtKey) {	int ctrlC = 0;	switch(virtKey) {	case KeyEvent.VK_A:	    ctrlC = 0x01;	    break;	case KeyEvent.VK_B:	    ctrlC = 0x02;	    break;	case KeyEvent.VK_C:	    ctrlC = 0x03;	    break;	case KeyEvent.VK_D:	    ctrlC = 0x04;	    break;	case KeyEvent.VK_E:	    ctrlC = 0x05;	    break;	case KeyEvent.VK_F:	    ctrlC = 0x06;	    break;	case KeyEvent.VK_G:	    ctrlC = 0x07;	    break;	case KeyEvent.VK_H:	    ctrlC = 0x08;	    break;	case KeyEvent.VK_I:	    ctrlC = 0x09;	    break;	case KeyEvent.VK_J:	    ctrlC = 0x0A;	    break;	case KeyEvent.VK_K:	    ctrlC = 0x0B;	    break;	case KeyEvent.VK_L:	    ctrlC = 0x0C;	    break;	case KeyEvent.VK_M:	    ctrlC = 0x0D;	    break;	case KeyEvent.VK_N:	    ctrlC = 0x0E;	    break;	case KeyEvent.VK_O:	    ctrlC = 0x0F;	    break;	case KeyEvent.VK_P:	    ctrlC = 0x10;	    break;	case KeyEvent.VK_Q:	    ctrlC = 0x11;	    break;	case KeyEvent.VK_R:	    ctrlC = 0x12;	    break;	case KeyEvent.VK_S:	    ctrlC = 0x13;	    break;	case KeyEvent.VK_T:	    ctrlC = 0x14;	    break;	case KeyEvent.VK_U:	    ctrlC = 0x15;	    break;	case KeyEvent.VK_V:	    ctrlC = 0x16;	    break;	case KeyEvent.VK_W:	    ctrlC = 0x17;	    break;	case KeyEvent.VK_X:	    ctrlC = 0x18;	    break;	case KeyEvent.VK_Y:	    ctrlC = 0x19;	    break;	case KeyEvent.VK_Z:	    ctrlC = 0x1A;	    break;	}	return ctrlC;    }    public final void localPageCtrlKeys(int virtKey) {	switch(virtKey) {	case KeyEvent.VK_PAGE_UP:	    visTop -= rows;	    if(visTop < 0)		visTop = 0;	    updateScrollbarValues();	    makeAllDirty(true);	    break;	case KeyEvent.VK_PAGE_DOWN:	    visTop += rows;	    if(visTop > saveVisTop)		visTop = saveVisTop;	    updateScrollbarValues();	    makeAllDirty(true);	    break;	case KeyEvent.VK_HOME:	    visTop = 0;	    updateScrollbarValues();	    makeAllDirty(true);	    break;	case KeyEvent.VK_END:	    visTop = saveVisTop;	    updateScrollbarValues();	    makeAllDirty(true);	    break;	}    }    //    // FocusListener, AdjustmentListener, MouseListener, MouseMotionListener, ComponentListener    //    public void focusGained(FocusEvent e) {	setCursor(Cursor.getPredefinedCursor(Cursor.TEXT_CURSOR));	haveFocus = true;	updateFocusCursor();    }    public void focusLost(FocusEvent e) {	metaKeyKludge  = false;	ctrlKeyKludge  = false;	setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));	haveFocus = false;	updateFocusCursor();    }    final synchronized void updateFocusCursor() {	Graphics g = getGraphics();	if(g != null) {	    hideCursor(g);	    showCursor(g);	}    }    public boolean isFocusTraversable() {	return true;    }    // !!! Since the realization of the window is very different on different    // platforms (w.r.t. generated events etc.) we don't listen to    // componentResized event until window is shown, in that instance we also    // do the pending setGeometry.    //    public void componentMoved(ComponentEvent e) {	// !!! TODO: Do we want to save absolute positions???    }    public void emulateComponentShown() {	componentShown(new ComponentEvent(ownerFrame, 0));    }    public synchronized void componentShown(ComponentEvent e) {	if(e.getComponent() == ownerFrame && pendingShow) {	    // !!! Ad-hoc wait to let AWT thread in, seems to prevent it from	    // sending a componentResized when getSize() returns bad value	    // AFTER we have done setSize(), this only occurs on Linux (as far	    // as I have seen) due to thread-scheduler lag ?!?	    try {		this.wait(100);	    } catch(InterruptedException ee) {	    }	    pendingShow = false;	    setGeometry(getProperty("gm"), true);	}    }    public void componentHidden(ComponentEvent e) {    }    public synchronized void componentResized(ComponentEvent e) {	Dimension dim = getSize();	int newCols = (dim.width  - (2 * borderWidth))  / charWidth;	int newRows = (dim.height - (2 * borderHeight)) / charHeight;	int oldCols = cols;	int oldRows = rows;	char[][]  oldScreen     = screen;	int[][]   oldAttributes = attributes;	boolean[] oldAutowraps  = autowraps;	if(DEBUG) System.out.println("componentResized: " + newCols + "x" + newRows + "(" +				     dim.width + "." + dim.height + ")");	if(pendingShow ||	   (e != null && e.getComponent() != this) ||	   (newCols <= 0 || newRows <= 0)) {	    return;	}	vpixels = dim.height;	hpixels = dim.width;	if(newCols != oldCols)	    clearSelection();	// We only want to reallocate and do all this work if the component	// REALLY has changed size, since we seem to get lot's of call-backs	// here we better check this...	//	if(newRows != rows || newCols != cols) {	    setWindowSize(newRows, newCols);	    resetWindow(); // !!! Is this right?	    clearScreen();	    oldCols = (oldCols < newCols ? oldCols : newCols);	    if(resizeGravity == GRAVITY_NORTHWEST) {		int copyRows = (oldRows < newRows ? oldRows : newRows) + saveVisTop;		for(int i = 0; i < copyRows; i++) {		    System.arraycopy(oldScreen[i], 0, screen[i], 0, oldCols);		    System.arraycopy(oldAttributes[i], 0, attributes[i], 0, oldCols);		    autowraps[i] = oldAutowraps[i];		}	    } else {		if(hasSelection) {		    selectRowAnchor += newRows - oldRows;		    selectRowLast   += newRows - oldRows;		}		int i, copyRows, fromTop, toTop;		if(oldRows < newRows) {		    int linesAdd = newRows - oldRows;		    copyRows    = oldRows + saveVisTop;		    fromTop     = 0;		    curRow     += linesAdd;		    if(saveVisTop - linesAdd < 0) {			toTop       = linesAdd;		    } else {			toTop       = 0;			visTop     -= linesAdd;			saveVisTop -= linesAdd;		    }		} else {		    int linesLost = oldRows - newRows;		    toTop       = 0;		    curRow     -= linesLost;		    if(curRow < 0)			curRow = 0;		    if(saveVisTop + linesLost > saveLines) {			copyRows    = newRows + saveVisTop;			fromTop     = linesLost;		    } else {			copyRows    = oldRows + saveVisTop;			fromTop     = 0;			visTop     += linesLost;			saveVisTop += linesLost;		    }		}		for(i = 0; i < copyRows; i++) {		    System.arraycopy(oldScreen[i + fromTop], 0, screen[i + toTop], 0, oldCols);		    System.arraycopy(oldAttributes[i + fromTop], 0, attributes[i + toTop], 0, oldCols);		    autowraps[i + toTop] = oldAutowraps[i + fromTop];		}	    }	    if(curRow >= newRows)		curRow = newRows - 1;	    if(curCol >= newCols)		curCol = newCols - 1;	    if(lastCursorRow >= newRows || lastCursorCol >= newCols) {		cursorDrawn  = false;		cursorHollow = false;	    }	    updateScrollbarValues();	    signalWindowChanged(rows, cols, vpixels, hpixels);	    memGraphics = null;	    String newGM = (cols + "x" + rows + savedGeomPos);	    propsChanged = true;	    props.put("geometry", newGM);	    updateMenus();	    makeAllDirty(false);	    requestFocus();	}    }    public synchronized void adjustmentValueChanged(AdjustmentEvent e) {	int adjValue = e.getValue();	if(adjValue >= 0 && adjValue <= saveVisTop) {	    visTop = adjValue;	    makeAllDirty(false);	}    }    public void selectAll() {	selectRowAnchor = 0;	selectColAnchor = 0;	selectRowLast   = saveVisTop + curRow;	selectColLast   = curCol;	selectReverse   = false;	makeSelection(selectRowAnchor, selectColAnchor, selectRowLast, selectColLast);	hasSelection = true;	if(termOptions[OPT_COPY_SEL])	    doCopy();    }    public void makeSelection(int startRow, int startCol, int endRow, int endCol) {	int i, j;	if(startRow != endRow) {	    for(i = startCol; i < cols; i++)		attributes[startRow][i] |= ATTR_SELECTED;	    for(i = startRow + 1; i < endRow; i++)		for(j = 0; j < c

⌨️ 快捷键说明

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