📄 terminal.java
字号:
public void offline() { if (debug > 0) System.err.println("Terminal: offline"); if (reader != null) reader = null; } }); bus.registerPluginListener(new TerminalTypeListener() { public String getTerminalType() { return emulation.getTerminalID(); } }); bus.registerPluginListener(new WindowSizeListener() { public Dimension getWindowSize() { return new Dimension(emulation.getColumns(), emulation.getRows()); } }); bus.registerPluginListener(new LocalEchoListener() { public void setLocalEcho(boolean echo) { if (!localecho_overridden) emulation.setLocalEcho(echo); } }); bus.registerPluginListener(new ConfigurationListener() { public void setConfiguration(PluginConfig config) { configure(config); } }); bus.registerPluginListener(new ReturnFocusListener() { public void returnFocus() { terminal.requestFocus(); } }); } private void configure(PluginConfig cfg) { String tmp; if ((tmp = cfg.getProperty("Terminal", id, "foreground")) != null) terminal.setForeground(Color.decode(tmp)); if ((tmp = cfg.getProperty("Terminal", id, "background")) != null) terminal.setBackground(Color.decode(tmp)); if ((tmp = cfg.getProperty("Terminal", id, "print.color")) != null) try { terminal.setColorPrinting(Boolean.valueOf(tmp).booleanValue()); } catch (Exception e) { error("Terminal.color.print: must be either true or false, not " + tmp); } System.err.print("colorSet: "); if ((tmp = cfg.getProperty("Terminal", id, "colorSet")) != null) { System.err.println(tmp); Properties colorSet = new Properties(); try { colorSet.load(getClass().getResourceAsStream(tmp)); } catch (Exception e) { try { colorSet.load(new URL(tmp).openStream()); } catch (Exception ue) { error("cannot find colorSet: " + tmp); error("resource access failed: " + e); error("URL access failed: " + ue); colorSet = null; } } if (colorSet != null) { Color set[] = terminal.getColorSet(); Color color = null; for (int i = 0; i < 8; i++) { if ((tmp = colorSet.getProperty("color" + i)) != null && (color = codeToColor(tmp)) != null) { set[i] = color; } } // special color for bold if ((tmp = colorSet.getProperty("bold")) != null && (color = codeToColor(tmp)) != null) { set[SwingTerminal.COLOR_BOLD] = color; } // special color for invert if ((tmp = colorSet.getProperty("invert")) != null && (color = codeToColor(tmp)) != null) { set[SwingTerminal.COLOR_INVERT] = color; } terminal.setColorSet(set); } } String cFG = cfg.getProperty("Terminal", id, "cursor.foreground"); String cBG = cfg.getProperty("Terminal", id, "cursor.background"); if (cFG != null || cBG != null) try { Color fg = (cFG == null ? terminal.getBackground() : (Color.getColor(cFG) != null ? Color.getColor(cFG):Color.decode(cFG))); Color bg = (cBG == null ? terminal.getForeground() : (Color.getColor(cBG) != null ? Color.getColor(cBG):Color.decode(cBG))); terminal.setCursorColors(fg, bg); } catch (Exception e) { error("ignoring unknown cursor color code: " + tmp); } if ((tmp = cfg.getProperty("Terminal", id, "border")) != null) { String size = tmp; boolean raised = false; if ((tmp = cfg.getProperty("Terminal", id, "borderRaised")) != null) raised = Boolean.valueOf(tmp).booleanValue(); terminal.setBorder(Integer.parseInt(size), raised); } if ((tmp = cfg.getProperty("Terminal", id, "localecho")) != null) { emulation.setLocalEcho(Boolean.valueOf(tmp).booleanValue()); localecho_overridden = true; } if ((tmp = cfg.getProperty("Terminal", id, "scrollBar")) != null && !personalJava) { String direction = tmp; if (!direction.equals("none")) { if (!direction.equals("East") && !direction.equals("West")) direction = "East"; JScrollBar scrollBar = new JScrollBar(); tPanel.add(direction, scrollBar); terminal.setScrollbar(scrollBar); } } if ((tmp = cfg.getProperty("Terminal", id, "id")) != null) emulation.setTerminalID(tmp); if ((tmp = cfg.getProperty("Terminal", id, "answerback")) != null) emulation.setAnswerBack(tmp); if ((tmp = cfg.getProperty("Terminal", id, "buffer")) != null) emulation.setBufferSize(Integer.parseInt(tmp)); if ((tmp = cfg.getProperty("Terminal", id, "size")) != null) try { int idx = tmp.indexOf(','); int width = Integer.parseInt(tmp.substring(1, idx).trim()); int height = Integer.parseInt(tmp.substring(idx + 1, tmp.length() - 1).trim()); emulation.setScreenSize(width, height); } catch (Exception e) { error("screen size is wrong: " + tmp); error("error: " + e); } if ((tmp = cfg.getProperty("Terminal", id, "resize")) != null) if (tmp.equals("font")) terminal.setResizeStrategy(SwingTerminal.RESIZE_FONT); else if (tmp.equals("screen")) terminal.setResizeStrategy(SwingTerminal.RESIZE_SCREEN); else terminal.setResizeStrategy(SwingTerminal.RESIZE_NONE); if ((tmp = cfg.getProperty("Terminal", id, "font")) != null) { String font = tmp; int style = Font.PLAIN, fsize = 12; if ((tmp = cfg.getProperty("Terminal", id, "fontSize")) != null) fsize = Integer.parseInt(tmp); String fontStyle = cfg.getProperty("Terminal", id, "fontStyle"); if (fontStyle == null || fontStyle.equals("plain")) style = Font.PLAIN; else if (fontStyle.equals("bold")) style = Font.BOLD; else if (fontStyle.equals("italic")) style = Font.ITALIC; else if (fontStyle.equals("bold+italic")) style = Font.BOLD | Font.ITALIC; terminal.setFont(new Font(font, style, fsize)); } if ((tmp = cfg.getProperty("Terminal", id, "keyCodes")) != null) { Properties keyCodes = new Properties(); try { keyCodes.load(getClass().getResourceAsStream(tmp)); } catch (Exception e) { try { keyCodes.load(new URL(tmp).openStream()); } catch (Exception ue) { error("cannot find keyCodes: " + tmp); error("resource access failed: " + e); error("URL access failed: " + ue); keyCodes = null; } } // set the key codes if we got the properties if (keyCodes != null) emulation.setKeyCodes(keyCodes); } if ((tmp = cfg.getProperty("Terminal", id, "VMS")) != null) emulation.setVMS((Boolean.valueOf(tmp)).booleanValue()); if ((tmp = cfg.getProperty("Terminal", id, "IBM")) != null) emulation.setIBMCharset((Boolean.valueOf(tmp)).booleanValue()); if ((tmp = cfg.getProperty("Terminal", id, "encoding")) != null) encoding = tmp; if ((tmp = cfg.getProperty("Terminal", id, "beep")) != null) try { audioBeep = new SoundRequest(new URL(tmp)); } catch (MalformedURLException e) { error("incorrect URL for audio ping: " + e); } tPanel.setBackground(terminal.getBackground()); } /** * Continuously read from our back end and display the data on screen. */ public void run() { byte[] b = new byte[256]; int n = 0; while (n >= 0) try { n = read(b); if (debug > 1 && n > 0) System.err.println("Terminal: \"" + (new String(b, 0, n, encoding)) + "\""); if (n > 0) emulation.putString(new String(b, 0, n, encoding)); tPanel.repaint(); } catch (IOException e) { reader = null; break; } } protected FilterPlugin source; public void setFilterSource(FilterPlugin source) { if (debug > 0) System.err.println("Terminal: connected to: " + source); this.source = source; } public FilterPlugin getFilterSource() { return source; } public int read(byte[] b) throws IOException { return source.read(b); } public void write(byte[] b) throws IOException { source.write(b); } public JComponent getPluginVisual() { return tPanel; } public JMenu getPluginMenu() { return menu; } public void copy(Clipboard clipboard) { String data = terminal.getSelection(); // check due to a bug in the hotspot vm if (data == null) return; StringSelection selection = new StringSelection(data); clipboard.setContents(selection, this); } public void paste(Clipboard clipboard) { if (clipboard == null) return; Transferable t = clipboard.getContents(this); try { /* InputStream is = (InputStream)t.getTransferData(DataFlavor.plainTextFlavor); if(debug > 0) System.out.println("Clipboard: available: "+is.available()); byte buffer[] = new byte[is.available()]; is.read(buffer); is.close(); */ byte buffer[] = ((String) t.getTransferData(DataFlavor.stringFlavor)).getBytes(); try { write(buffer); } catch (IOException e) { reader = null; } } catch (Exception e) { // ignore any clipboard errors if (debug > 0) e.printStackTrace(); } } public void lostOwnership(Clipboard clipboard, Transferable contents) { terminal.clearSelection(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -