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

📄 terminalmenuhandlerfull.java

📁 一个非常好的ssh客户端实现
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/****************************************************************************** * * Copyright (c) 1999-2003 AppGate Network Security AB. All Rights Reserved. *  * This file contains Original Code and/or Modifications of Original Code as * defined in and that are subject to the MindTerm Public Source License, * Version 2.0, (the 'License'). You may not use this file except in compliance * with the License. *  * You should have received a copy of the MindTerm Public Source License * along with this software; see the file LICENSE.  If not, write to * AppGate Network Security AB, Otterhallegatan 2, SE-41118 Goteborg, SWEDEN * *****************************************************************************/package com.mindbright.terminal;import java.io.File;import java.io.FileInputStream;import java.io.FileOutputStream;import java.io.IOException;import java.awt.*; import java.awt.event.*; import com.mindbright.gui.AWTConvenience;import com.mindbright.gui.AlertDialog;import com.mindbright.gui.ConfirmDialog;public final class TerminalMenuHandlerFull extends TerminalMenuHandler     implements ActionListener, ItemListener, TerminalPrinter{    protected final static int ACT_SETTINGS    = 0;    protected final static int ACT_COLORS      = 1;    protected final static int ACT_MISC        = 2;    protected final static int ACT_FIND_CANCEL = 3;    protected final static int ACT_FIND        = 4;    private class Actions implements ActionListener, ItemListener {	private int       action;	public Actions(int action) {	    this.action = action;	}	public void actionPerformed(ActionEvent e) {	    switch(action) {	    case ACT_SETTINGS:		try {		    term.setProperty("te", te[choiceTE.getSelectedIndex()]);		    term.setProperty("fn", fn[choiceFN.getSelectedIndex()]);		    term.setProperty("fs", textFS.getText());		    term.setProperty("sb", sb[choiceSB.getSelectedIndex()]);		    term.setProperty("sl", textSL.getText());		    term.setProperty("gm", textCols.getText() + "x" + textRows.getText());		    settingsDialog.setVisible(false);		} catch (Exception ee) {		    lblAlert.setText(ee.getMessage());		}		break;	    case ACT_COLORS:		try {		    term.setProperty("fg", getSelectedColor(choiceFG, textFG));		    term.setProperty("bg", getSelectedColor(choiceBG, textBG));		    term.setProperty("cc", getSelectedColor(choiceCC, textCC));		    colorsDialog.setVisible(false);		} catch (Exception ee) {		    lblAlertC.setText(ee.getMessage());		}		break;	    case ACT_MISC:		try {		    term.setProperty("pb", pb[choicePB.getSelectedIndex()]);		    term.setProperty("rg", rg[choiceRG.getSelectedIndex()]);		    term.setProperty("sd", textSD.getText());		    if(cbBS.getState())			term.setProperty("bs", "DEL");		    else			term.setProperty("bs", "BS");		    if(cbDEL.getState())			term.setProperty("de", "BS");		    else			term.setProperty("de", "DEL");		    term.setProperty("lp", String.valueOf(cbLocPG.getState()));		    term.setProperty("sc", String.valueOf(cbCpWinCR.getState()));		    term.setProperty("cs", String.valueOf(cbCpOnSel.getState()));		    term.setProperty("ad", String.valueOf(cbAsciiLD.getState()));		    settingsDialog2.setVisible(false);		} catch (Exception ee) {		    // !!! REMOVE		    // Can't happen...		    ee.printStackTrace();		    System.out.println("Fatal error in dialog: " + ee);		}		break;	    case ACT_FIND_CANCEL:		findDialog.setVisible(false);		if(findLen > 0) {		    term.clearSelection(curFindRow, curFindCol, curFindRow, curFindCol + findLen - 1);		}		curFindRow = 0;		curFindCol = 0;		findLen    = 0;		break;	    case ACT_FIND:		String txt = findText.getText();		if(txt != null && txt.length() > 0) {		    doFind();		}		break;	    }	}	public void itemStateChanged(ItemEvent e) {	    updateColors();	}    }    TerminalWin term;    String      titleName;    Object[][]  menuItems;    TerminalMenuListener listener;    final static String[] settingsMenu = { "Terminal Settings",					   "Emulation", "Resize gravity", "Font",					   "Savelines", "Scrollbar", "Colors",					   "Backspace"    };    final static int MENU_FILE     = 0;    final static int MENU_EDIT     = 1;    final static int MENU_SETTINGS = 2;    final static int MENU_OPTIONS  = 3;    final static int M_FILE_CAPTURE = 1;    final static int M_FILE_SEND    = 2;    final static int M_FILE_CLOSE   = 4;    final static int M_SET_TERM     = 1;    final static int M_SET_TERM_MSC = 2;    final static int M_SET_TERM_COL = 3;    final static int M_EDIT_COPY    = 1;    final static int M_EDIT_PASTE   = 2;    final static int M_EDIT_CPPASTE = 3;    final static int M_EDIT_SELALL  = 4;    final static int M_EDIT_FIND    = 5;    final static int M_EDIT_CLS     = 7;    final static int M_EDIT_CLEARSB = 8;    final static int M_EDIT_VTRESET = 9;    final static String[][] menuTexts = {	{ "File", 	  "_Capture To File...", "Send ASCII File...", null, "Close"	},	{ "Edit",	  "Copy Ctrl+Ins", "Paste Shift+Ins", "Copy & Paste", "Select All",	  "Find...", null,	  "Clear Screen", "Clear Scrollback", "VT Reset"	},	{ "Settings",	  "Terminal...", "Terminal Misc...", "Terminal Colors..."	},	{ "VT Options",	  "_Reverse Video", "_Auto Wraparound", "_Reverse Wraparound",	  "_Insert mode", "_Auto Linefeed",	  "_Scroll to Bottom On Key Press",	  "_Scroll to Bottom On Tty Output",	  "_Visible Cursor", "_Local Echo",	  "_Visual Bell",	"_Map <CTRL>+<SPC> To ^@",	  "_Toggle 80/132 Columns", "_Enable 80/132 Switching",	  "_Enable Passthrough Print"	}    };    final static int NO_SHORTCUT = -1;    final static int[][] menuShortCuts = {	{ NO_SHORTCUT, NO_SHORTCUT, NO_SHORTCUT, NO_SHORTCUT, KeyEvent.VK_E },	{ NO_SHORTCUT, NO_SHORTCUT, NO_SHORTCUT, NO_SHORTCUT, KeyEvent.VK_A,	  KeyEvent.VK_F, NO_SHORTCUT, NO_SHORTCUT, NO_SHORTCUT, NO_SHORTCUT },	{ NO_SHORTCUT, NO_SHORTCUT, NO_SHORTCUT, NO_SHORTCUT },	{ NO_SHORTCUT, NO_SHORTCUT, NO_SHORTCUT, NO_SHORTCUT, NO_SHORTCUT,	  NO_SHORTCUT, NO_SHORTCUT, NO_SHORTCUT, NO_SHORTCUT, NO_SHORTCUT,	  NO_SHORTCUT, NO_SHORTCUT, NO_SHORTCUT, NO_SHORTCUT, NO_SHORTCUT,	  NO_SHORTCUT, NO_SHORTCUT, NO_SHORTCUT, NO_SHORTCUT, NO_SHORTCUT },    };    // !!! OUCH    public TerminalMenuHandlerFull() {	this("MindTerm");    }    public TerminalMenuHandlerFull(String titleName) {	setTitleName(titleName);    }    public void setTitleName(String titleName) {	this.titleName = titleName;	    }    public void setTerminalWin(TerminalWin term) {	this.term = term;	term.attachPrinter(this);    }    public void setTerminalMenuListener(TerminalMenuListener listener) {	this.listener = listener;    }    public void addBasicMenus(TerminalWin terminal, Frame frame) {	MenuBar menubar = frame.getMenuBar();	setTerminalWin(terminal);	terminal.setMenus(this);	menubar.add(getMenu(0));	menubar.add(getMenu(1));	menubar.add(getMenu(2));	menubar.add(getMenu(3));	frame.addWindowListener(new AWTConvenience.	    CloseAdapter((MenuItem)menuItems[MENU_FILE][M_FILE_CLOSE]));	terminal.setClipboard(GlobalClipboard.getClipboardHandler(this));	terminal.updateMenus();    }    public void updateSelection(boolean selectionAvailable) {	((MenuItem)menuItems[MENU_EDIT][M_EDIT_COPY]).setEnabled(								 selectionAvailable);	((MenuItem)menuItems[MENU_EDIT][M_EDIT_CPPASTE]).setEnabled(								    selectionAvailable);    }    public void update() {	if(listener != null) {	    listener.update();	}    }    Dialog settingsDialog;    Choice choiceTE, choiceFN, choiceSB;    TextField textFS, textRows, textCols, textInitPos;    Label lblAlert;    final static String[] sb = { "left", "right", "none" };    final static String[] te = TerminalXTerm.getTerminalTypes();    final static String[] fn = Toolkit.getDefaultToolkit().getFontList();    public final void termSettingsDialog() {	if(settingsDialog == null) {	    settingsDialog = new Dialog(term.ownerFrame, settingsMenu[0], true);	    Label              lbl;	    GridBagLayout      grid  = new GridBagLayout();	    GridBagConstraints gridc = new GridBagConstraints();	    settingsDialog.setLayout(grid);	    gridc.insets = new Insets(4, 4, 4, 4);	    gridc.fill   = GridBagConstraints.NONE;	    gridc.anchor = GridBagConstraints.WEST;	    gridc.gridy = 0;	    gridc.gridwidth = 6;	    lbl = new Label("Terminal type:");	    grid.setConstraints(lbl, gridc);	    settingsDialog.add(lbl);	    choiceTE = AWTConvenience.newChoice(te);	    grid.setConstraints(choiceTE, gridc);	    settingsDialog.add(choiceTE);	    gridc.gridy = 1;	    gridc.gridwidth = 4;	    lbl = new Label("Columns:");	    grid.setConstraints(lbl, gridc);	    settingsDialog.add(lbl);	    gridc.gridwidth = 2;	    textCols = new TextField("", 3);	    grid.setConstraints(textCols, gridc);	    settingsDialog.add(textCols);	    lbl = new Label("Rows:");	    grid.setConstraints(lbl, gridc);	    settingsDialog.add(lbl);	    textRows = new TextField("", 3);	    grid.setConstraints(textRows, gridc);	    settingsDialog.add(textRows);	    gridc.gridy = 2;	    gridc.gridwidth = 2;	    lbl = new Label("Font:");	    grid.setConstraints(lbl, gridc);	    settingsDialog.add(lbl);	    gridc.gridwidth = 6;	    choiceFN = AWTConvenience.newChoice(fn);	    grid.setConstraints(choiceFN, gridc);	    settingsDialog.add(choiceFN);	    gridc.gridwidth = 2;	    textFS = new TextField("", 3);	    grid.setConstraints(textFS, gridc);	    settingsDialog.add(textFS);	    gridc.gridy = 3;	    gridc.gridwidth = 6;	    lbl = new Label("Scrollback buffer:");	    grid.setConstraints(lbl, gridc);	    settingsDialog.add(lbl);	    textSL = new TextField("", 4);	    grid.setConstraints(textSL, gridc);	    settingsDialog.add(textSL);	    gridc.gridy = 4;	    lbl = new Label("Scrollbar position:");	    grid.setConstraints(lbl, gridc);	    settingsDialog.add(lbl);	    choiceSB = AWTConvenience.newChoice(sb);	    grid.setConstraints(choiceSB, gridc);	    settingsDialog.add(choiceSB);	    lblAlert = new Label("", Label.CENTER);	    gridc.insets = new Insets(0, 0, 0, 0);	    gridc.gridy = 5;	    gridc.fill  = GridBagConstraints.HORIZONTAL;	    gridc.gridwidth = GridBagConstraints.REMAINDER;	    gridc.anchor = GridBagConstraints.CENTER;	    grid.setConstraints(lblAlert, gridc);	    settingsDialog.add(lblAlert);	    Panel bp = new Panel(new FlowLayout());	    Button b;	    bp.add(b = new Button("OK"));	    b.addActionListener(new Actions(ACT_SETTINGS));	    bp.add(b = new Button("Cancel"));	    b.addActionListener(new AWTConvenience.CloseAction(settingsDialog));	    gridc.gridy = 6;	    grid.setConstraints(bp, gridc);	    settingsDialog.add(bp);	    settingsDialog.addWindowListener(new AWTConvenience.CloseAdapter(b));	    AWTConvenience.setBackgroundOfChildren(settingsDialog);	    settingsDialog.setResizable(true);	    settingsDialog.pack();	}	choiceTE.select(term.getProperty("te"));	choiceFN.select(term.getProperty("fn"));	textFS.setText(term.getProperty("fs"));	textCols.setText(String.valueOf(term.cols()));	textRows.setText(String.valueOf(term.rows()));	choiceSB.select(term.getProperty("sb"));	textSL.setText(term.getProperty("sl"));	lblAlert.setText("");	AWTConvenience.placeDialog(settingsDialog);	choiceTE.requestFocus();	settingsDialog.setVisible(true);    }    TextField textFG, textBG, textCC;    Choice choiceFG, choiceBG, choiceCC;    Dialog colorsDialog;    Label lblAlertC;    public final void termColorsDialog() {	if(colorsDialog == null) {	    colorsDialog = new Dialog(term.ownerFrame, "Terminal Colors", true);	    ItemListener       ilC;	    Label              lbl;	    GridBagLayout      grid  = new GridBagLayout();

⌨️ 快捷键说明

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