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

📄 terminalmenuhandlerfull.java

📁 一个非常好的ssh客户端实现
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
	if(caseSens) {	    if(chars[idx] != firstChar)		return false;	    cmpStr = new String(chars, idx, len);	    if(cmpStr.equals(findStr))		return true;	} else {	    if(Character.toLowerCase(chars[idx]) != firstChar)		return false;	    cmpStr = new String(chars, idx, len);	    if(cmpStr.equalsIgnoreCase(findStr))		return true;	}	return false;    }    int curFindRow = 0;    int curFindCol = 0;    int findLen    = 0;    void doFind() {	String  findStr = findText.getText();	int     len = findStr.length();	boolean caseSens = caseCheck.getState();	boolean revFind  = dirCheck.getState();	int     lastRow  = term.saveVisTop + term.curRow;	int     startCol;	boolean found    = false;	int     i, j = 0;	char    firstChar = (caseSens ? findStr.charAt(0) : Character.toLowerCase(findStr.charAt(0)));	if(findLen > 0) {	    term.clearSelection(curFindRow, curFindCol, curFindRow, curFindCol + findLen - 1);	}    	if(revFind) {	    if(findLen > 0) {		startCol = curFindCol - 1;	    } else {		curFindRow = lastRow;		startCol   = term.cols - len;	    }	foundItRev:	    for(i = curFindRow; i >= 0; i--) {		for(j = startCol; j >= 0; j--) {		    if(term.screen[i][j] == 0)			continue;		    if(doMatch(findStr, firstChar, term.screen[i], j, caseSens, len))			break foundItRev;		}		startCol = term.cols - len;	    }	    if(i >= 0)		found = true;	} else {	    startCol = curFindCol + findLen;	foundIt:	    for(i = curFindRow; i < lastRow; i++) {		for(j = startCol; j < term.cols - len; j++) {		    if(term.screen[i][j] == 0)			continue;		    if(doMatch(findStr, firstChar, term.screen[i], j, caseSens, len))			break foundIt;		}		startCol = 0;	    }	    if(i < lastRow)		found = true;	}	if(found) {	    findLen = len;	    if(term.saveVisTop < i)		term.visTop = term.saveVisTop;	    else if(term.visTop > i || (i - term.visTop > term.rows))		term.visTop = i;	    term.updateScrollbarValues();	    term.makeAllDirty(false);	    term.makeSelection(i, j, i, j + len - 1);	    curFindRow = i;	    curFindCol = j;	    findLen    = len;	} else {	    term.doBell();	    curFindRow = 0;	    curFindCol = 0;	    findLen    = 0;	}    }    FileDialog sendFileDialog = null;    public final void sendFileDialog() {	if(sendFileDialog == null) {	    sendFileDialog = new FileDialog(term.ownerFrame, titleName +					    " - Select ASCII-file to send", FileDialog.LOAD);	}	sendFileDialog.setVisible(true);        if (com.mindbright.util.Util.isNetscapeJava()) {            try {                netscape.security.PrivilegeManager.enablePrivilege("UniversalFileAccess");            } catch (netscape.security.ForbiddenTargetException e) {            }        }        	String fileName = sendFileDialog.getFile();	String dirName  = sendFileDialog.getDirectory();	if(fileName != null && fileName.length() > 0) {	    try {		FileInputStream fileIn = new FileInputStream(dirName + fileName);		byte[] bytes = new byte[fileIn.available()];		fileIn.read(bytes);		term.sendBytes(bytes);	    } catch (Throwable t) {		AlertDialog.show(titleName + " - Alert", t.getMessage(),				 term.ownerFrame);	    }	}    }    FileDialog captureToFileDialog = null;    public final FileOutputStream chooseFileDialog(String title) {        if (com.mindbright.util.Util.isNetscapeJava()) {            try {                netscape.security.PrivilegeManager.enablePrivilege("UniversalFileAccess");            } catch (netscape.security.ForbiddenTargetException e) {            }        }        	if(captureToFileDialog == null) {	    captureToFileDialog = new FileDialog(term.ownerFrame,						 titleName + " - " + title,						 FileDialog.SAVE);	}	captureToFileDialog.setVisible(true);	String fileName = captureToFileDialog.getFile();	String dirName  = captureToFileDialog.getDirectory();	if(fileName != null && fileName.length() > 0) {	    try {		if(!dirName.endsWith(File.separator)) {		    dirName += File.separator;		}		File file = new File(dirName + fileName);		boolean append = false;		if(file.exists()) {		    append =			ConfirmDialog.show(titleName + " - File exists",					   "File exists, overwrite or append?",					   0, 0, "Append", "Overwrite",					   true, term.ownerFrame, false);		}		FileOutputStream fileOut =		    new FileOutputStream(dirName + fileName, append);		return fileOut;	    } catch (Throwable t) {		AlertDialog.show(titleName + " - Alert", t.getMessage(),				 term.ownerFrame);	    }	}	return null;    }    TerminalCapture termCapture;    public final boolean captureToFileDialog() {        if (com.mindbright.util.Util.isNetscapeJava()) {            try {                netscape.security.PrivilegeManager.enablePrivilege("UniversalFileAccess");            } catch (netscape.security.ForbiddenTargetException e) {            }        }	FileOutputStream fileOut =	    chooseFileDialog("Select file to capture to");	if(fileOut != null) {	    termCapture = new TerminalCapture(fileOut);	    termCapture.startCapture(term);	    return true;	}	return false;    }    public void endCapture() {	if(termCapture != null) {	    termCapture.endCapture();	    try {		termCapture.getTarget().close();	    } catch (IOException e) {		AlertDialog.show(titleName + " - Alert", e.getMessage(),				 term.ownerFrame);	    }	}    }    public void setEnabledOpt(int opt, boolean val) {	((CheckboxMenuItem)menuItems[MENU_OPTIONS][opt + 1]).setEnabled(val);    }    public void setStateOpt(int opt, boolean val) {	((CheckboxMenuItem)menuItems[MENU_OPTIONS][opt + 1]).setState(val);    }    public Menu getMenu(int idx) {	Menu m = new Menu(menuTexts[idx][0]);	int len = menuTexts[idx].length;	MenuItem mi;	String   t;	if(menuItems == null)	    menuItems = new Object[menuTexts.length][];	if(menuItems[idx] == null)	    menuItems[idx] = new Object[menuTexts[idx].length];	for(int i = 1; i < len; i++) {	    t = menuTexts[idx][i];	    if(t == null) {		m.addSeparator();		continue;	    }	    if(t.charAt(0) == '_') {		t = t.substring(1);		mi = new CheckboxMenuItem(t);		((CheckboxMenuItem)mi).addItemListener(this);	    } else {		mi = new MenuItem(t);		mi.addActionListener(this);	    }	    if(menuShortCuts[idx][i] != NO_SHORTCUT) {		mi.setShortcut(new MenuShortcut(menuShortCuts[idx][i], true));	    }	    menuItems[idx][i] = mi;	    m.add(mi);	}	return m;    }    int[] mapAction(String action) {	int[] id = new int[2];	int i = 0, j = 0;	for(i = 0; i < menuTexts.length; i++) {	    for(j = 1; j < menuTexts[i].length; j++) {		String mt = menuTexts[i][j];		if(mt != null && action.equals(mt)) {		    id[0] = i;		    id[1] = j;		    i = menuTexts.length;		    break;		}	    }	}	return id;    }    public void actionPerformed(ActionEvent e) {	int[] id = mapAction(((MenuItem)(e.getSource())).getLabel());	handleMenuAction(id);    }    public void itemStateChanged(ItemEvent e) {	int[] id = mapAction("_" + (String)e.getItem());	handleMenuAction(id);    }    public void handleMenuAction(int[] id) {	switch(id[0]) {	case MENU_FILE:	    switch(id[1]) {	    case M_FILE_CAPTURE:		if(((CheckboxMenuItem)		    menuItems[MENU_FILE][M_FILE_CAPTURE]).getState()) {		    if(!captureToFileDialog()) {			((CheckboxMenuItem)			 menuItems[MENU_FILE][M_FILE_CAPTURE]).setState(false);		    }		} else {		    endCapture();		}		break;	    case M_FILE_SEND:		((TerminalMenuHandlerFull)term.getMenus()).sendFileDialog();		break;	    case M_FILE_CLOSE:		if(listener != null) {		    listener.close(this);		}		break;	    }	    break;	case MENU_EDIT:	    switch(id[1]) {	    case M_EDIT_COPY:		term.doCopy();		break;	    case M_EDIT_PASTE:		term.doPaste();		break;	    case M_EDIT_CPPASTE:		term.doCopy();		term.doPaste();		break;	    case M_EDIT_SELALL:		term.selectAll();		break;	    case M_EDIT_FIND:		findDialog();		break;	    case M_EDIT_CLS:		term.clearScreen();		term.cursorSetPos(0, 0, false);		break;	    case M_EDIT_CLEARSB:		term.clearSaveLines();		break;	    case M_EDIT_VTRESET:		term.resetInterpreter();		break;	    }	    break;	case MENU_SETTINGS:	    switch(id[1]) {	    case M_SET_TERM:		termSettingsDialog();		break;	    case M_SET_TERM_MSC:		termSettingsDialog2();		break;	    case M_SET_TERM_COL:		termColorsDialog();		break;	    }	    break;	case MENU_OPTIONS:	    int i = id[1] - 1;	    term.setProperty(TerminalDefProps.defaultPropDesc[i]			     [TerminalDefProps.PROP_NAME],			     String.valueOf(!term.termOptions[i]));	    break;	}    }    FileOutputStream printerOut;    public void write(char c) {	if(printerOut != null) {	    try {		printerOut.write((int)c);	    } catch (IOException e) {		AlertDialog.show(titleName + " - Alert", e.getMessage(),				 term.ownerFrame);	    }	}    }    public void printScreen() {	/* !!! TODO */    }    public void startPrinter() {	printerOut = chooseFileDialog("Passthrough print to file");    }    public void stopPrinter() {	if(printerOut != null) {	    try { printerOut.close(); }	    catch (IOException e) { /* don't care... */ }	    printerOut = null;	    AlertDialog.show(titleName + " - Alert",			     "Passthrough printing ended, file saved.",			     term.ownerFrame);	}    }}

⌨️ 快捷键说明

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