📄 sshmenuhandlerfull.java
字号:
final static int MENU_FILE = 0; final static int MENU_SETTINGS = 1; final static int MENU_TUNNELS = 2; final static int MENU_HELP = 3; final static int M_FILE_NEW = 1; final static int M_FILE_CLONE = 2; final static int M_FILE_CONN = 3; final static int M_FILE_DISC = 4; final static int M_FILE_LOAD = 6; final static int M_FILE_SAVE = 7; final static int M_FILE_SAVEAS = 8; final static int M_FILE_CREATID = 10; final static int M_FILE_EDITPKI = 11; final static int M_FILE_CAPTURE = 13; final static int M_FILE_SEND = 14; final static int M_FILE_CLOSE = 16; final static int M_FILE_EXIT = 17; final static int M_SET_SSH_NEW = 1; final static int M_SET_SSH_PREF = 2; final static int M_SET_TERM = 3; final static int M_SET_TERM_MSC = 4; final static int M_SET_TERM_COL = 5; final static int M_SET_PROXY = 6; final static int M_SET_RESET = 7; final static int M_SET_AUTOSAVE = 9; final static int M_SET_AUTOLOAD = 10; final static int M_SET_SAVEPWD = 11; final static int M_TUNL_SIMPLE = 1; final static int M_TUNL_ADVANCED = 2; final static int M_TUNL_CURRENT = 4; final static int M_HELP_TOPICS = 1; final static int M_HELP_ABOUT = 2; final static String[][] menuTexts = { { "File", "New Terminal", "Clone Terminal", "Connect...", "Disconnect", null, "Load Settings...", "Save Settings", "Save Settings As...", null, "Create Keypair...", "Edit/Convert Keypair...", null, "_Capture To File...", "Send ASCII File...", null, "Close", "Exit" }, { "Settings", "New Server...", "Preferences...", "Terminal...", "Terminal Misc...", "Terminal Colors...", "Proxy...", "Reset To Defaults", null, "_Auto Save Settings", "_Auto Load Settings", "_Save Passwords" }, { "Tunnels", "Basic...", "Advanced...", null, "Current Connections..." }, { "Help", "Help Topics...", "About MindTerm" }, }; final static int NO_SHORTCUT = -1; final static int[][] menuShortCuts = { { NO_SHORTCUT, KeyEvent.VK_N, KeyEvent.VK_O, KeyEvent.VK_C, NO_SHORTCUT, NO_SHORTCUT, NO_SHORTCUT, KeyEvent.VK_S, NO_SHORTCUT, NO_SHORTCUT, NO_SHORTCUT, NO_SHORTCUT, NO_SHORTCUT, NO_SHORTCUT, NO_SHORTCUT, NO_SHORTCUT, KeyEvent.VK_E, KeyEvent.VK_X }, { NO_SHORTCUT, KeyEvent.VK_H, NO_SHORTCUT, KeyEvent.VK_T, KeyEvent.VK_M, 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, 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 }, }; Object[][] menuItems; public void init(MindTerm mindterm, SSHInteractiveClient client, Frame parent, TerminalWin term) { this.mindterm = mindterm; this.client = client; this.parent = parent; this.term = term; this.modules = new MindTermModule[32]; this.modMenuItems = new MenuItem[32]; this.modCnt = 0; for(int i = 0; i < modules.length; i++) { String className = client.propsHandler.getProperty("module" + i); if(className == null) { break; } try { modules[i] = (MindTermModule)Class.forName(className).newInstance(); modules[i].init(client); modCnt++; } catch (Exception e) { alertDialog("Module class '" + className + "' not found"); } } } int popButtonNum = 3; public void setPopupButton(int popButtonNum) { term.setPopupButton(popButtonNum); this.popButtonNum = popButtonNum; } public int getPopupButton() { return popButtonNum; } 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; } Menu getPluginMenu() { Menu m = null; if(modCnt > 0) { m = new Menu("Plugins"); int i = 0; for(; i < modCnt; i++) { String label = getModuleLabel(i); if(label != null) { MenuItem mi = new MenuItem(label); modMenuItems[i] = mi; mi.addActionListener(new Actions(ACT_MOD_BASE + i)); m.add(mi); } } if(i == 0) { m = null; } } return m; } String getModuleLabel(int module) { return client.propsHandler.getProperty("module" + module + ".label"); } void modulesConnect() { for(int i = 0; i < modCnt; i++) { modules[i].connected(client); } } void modulesDisconnect() { for(int i = 0; i < modCnt; i++) { modules[i].disconnected(client); } } 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_NEW: mindterm.newWindow(); break; case M_FILE_CLONE: mindterm.cloneWindow(); break; case M_FILE_CONN: connectDialog(); break; case M_FILE_DISC: if(mindterm.confirmClose()) { client.forcedDisconnect(); client.quiet = client.initQuiet; } break; case M_FILE_LOAD: loadFileDialog(); break; case M_FILE_SAVE: try { if(client.propsHandler.savePasswords && client.propsHandler.emptyPropertyPassword()) { String pwd = setPasswordDialog("Please set password for alias " + client.propsHandler.currentAlias, "MindTerm - Set File Password"); if(pwd == null) return; client.propsHandler.setPropertyPassword(pwd); } client.propsHandler.saveCurrentFile(); } catch (Throwable t) { alertDialog("Error saving settings: " + t.getMessage()); } break; case M_FILE_SAVEAS: saveAsFileDialog(); break; case M_FILE_CREATID: SSHKeyGenerationDialog.show(parent, client); break; case M_FILE_EDITPKI: SSHKeyGenerationDialog.editKeyDialog(parent, client); break; case M_FILE_CAPTURE: if(((CheckboxMenuItem)menuItems[MENU_FILE][M_FILE_CAPTURE]).getState()) { if(!((TerminalMenuHandlerFull)term.getMenus()).captureToFileDialog()) { ((CheckboxMenuItem) menuItems[MENU_FILE][M_FILE_CAPTURE]).setState(false); } } else { ((TerminalMenuHandlerFull)term.getMenus()).endCapture(); } break; case M_FILE_SEND: ((TerminalMenuHandlerFull)term.getMenus()).sendFileDialog(); break; case M_FILE_CLOSE: mindterm.close(); break; case M_FILE_EXIT: mindterm.exit(); break; } break; case MENU_SETTINGS: switch(id[1]) { case M_SET_SSH_NEW: sshSettingsDialog(); break; case M_SET_SSH_PREF: sshSettingsDialog2(); break; case M_SET_TERM: ((TerminalMenuHandlerFull)term.getMenus()).termSettingsDialog(); break; case M_SET_TERM_COL: ((TerminalMenuHandlerFull)term.getMenus()).termColorsDialog(); break; case M_SET_TERM_MSC: ((TerminalMenuHandlerFull)term.getMenus()).termSettingsDialog2(); break; case M_SET_PROXY: SSHProxyDialog.show("MindTerm - Proxy Settings", parent, client.propsHandler); break; case M_SET_RESET: client.propsHandler.resetToDefaults(); break; case M_SET_AUTOSAVE: client.propsHandler.setAutoSaveProps( ((CheckboxMenuItem)menuItems[MENU_SETTINGS][M_SET_AUTOSAVE]).getState()); update(); break; case M_SET_AUTOLOAD: client.propsHandler.setAutoLoadProps( ((CheckboxMenuItem)menuItems[MENU_SETTINGS][M_SET_AUTOLOAD]).getState()); update(); break; case M_SET_SAVEPWD: client.propsHandler.setSavePasswords( ((CheckboxMenuItem)menuItems[MENU_SETTINGS][M_SET_SAVEPWD]).getState()); if(client.propsHandler.savePasswords && client.propsHandler.emptyPropertyPassword() && client.propsHandler.getAlias() != null) { String pwd = setPasswordDialog("Please set password for alias " + client.propsHandler.currentAlias, "MindTerm - Set File Password"); if(pwd == null) { client.propsHandler.setSavePasswords(false); update(); return; } client.propsHandler.setPropertyPassword(pwd); } break; } break; case MENU_TUNNELS: switch(id[1]) { case M_TUNL_SIMPLE: SSHTunnelDialog.show("MindTerm - Basic Tunnels Setup", client, client.propsHandler, parent); break; case M_TUNL_ADVANCED: advancedTunnelsDialog(); break; case M_TUNL_CURRENT: currentTunnelsDialog(); break; } break; case MENU_HELP: switch(id[1]) { case M_HELP_TOPICS: break; case M_HELP_ABOUT: about(parent, client); break; } break; } } public void update() { boolean isOpen = client.isOpened(); boolean isConnected = client.isConnected(); boolean hasHomeDir = (client.propsHandler.getSSHHomeDir() != null); ((MenuItem)menuItems[MENU_FILE][M_FILE_SEND]).setEnabled(isOpen); ((MenuItem)menuItems[MENU_FILE][M_FILE_SAVEAS]).setEnabled(isOpen && hasHomeDir); ((MenuItem)menuItems[MENU_FILE][M_FILE_CONN]).setEnabled(!isConnected); ((MenuItem)menuItems[MENU_FILE][M_FILE_DISC]).setEnabled(isConnected); ((MenuItem)menuItems[MENU_FILE][M_FILE_LOAD]).setEnabled(!isConnected); ((MenuItem)menuItems[MENU_FILE][M_FILE_SAVE]).setEnabled(client.propsHandler.wantSave() && client.propsHandler.currentAlias != null); ((MenuItem)menuItems[MENU_SETTINGS][M_SET_SSH_NEW]).setEnabled(!isOpen); ((MenuItem)menuItems[MENU_SETTINGS][M_SET_SSH_PREF]).setEnabled(isOpen); ((MenuItem)menuItems[MENU_SETTINGS][M_SET_PROXY]).setEnabled(!isOpen); ((MenuItem)menuItems[MENU_SETTINGS][M_SET_RESET]).setEnabled(!isOpen); ((CheckboxMenuItem)menuItems[MENU_SETTINGS][M_SET_AUTOSAVE]).setEnabled(hasHomeDir); ((CheckboxMenuItem)menuItems[MENU_SETTINGS][M_SET_AUTOLOAD]).setEnabled(hasHomeDir); ((CheckboxMenuItem)menuItems[MENU_SETTINGS][M_SET_SAVEPWD]).setEnabled(hasHomeDir); ((CheckboxMenuItem)menuItems[MENU_SETTINGS][M_SET_AUTOSAVE]).setState(client.propsHandler.autoSaveProps); ((CheckboxMenuItem)menuItems[MENU_SETTINGS][M_SET_AUTOLOAD]).setState(client.propsHandler.autoLoadProps); ((CheckboxMenuItem)menuItems[MENU_SETTINGS][M_SET_SAVEPWD]).setState(client.propsHandler.savePasswords); ((MenuItem)menuItems[MENU_TUNNELS][M_TUNL_CURRENT]).setEnabled(isOpen); ((MenuItem)menuItems[MENU_TUNNELS][M_TUNL_SIMPLE]).setEnabled(isOpen); ((MenuItem)menuItems[MENU_TUNNELS][M_TUNL_ADVANCED]).setEnabled(isOpen); // !!! REMOVE !!! // ((MenuItem)menuItems[MENU_HELP][M_HELP_TOPICS]).setEnabled(false); updatePluginMenu(); } void updatePluginMenu() { for(int i = 0; i < modCnt; i++) { if(getModuleLabel(i) != null) { modMenuItems[i].setEnabled(modules[i].isAvailable(client)); } } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -