📄 terminal.java
字号:
if(reader == null) { reader = new Thread(Terminal.this); reader.start(); } } public void offline() { if(debug > 0) System.err.println("Terminal: offline"); if(reader != null) reader = null; } }); bus.registerPluginListener(new TerminalTypeListener() { public String getTerminalType() { return terminal.getTerminalID(); } }); bus.registerPluginListener(new WindowSizeListener() { public Dimension getWindowSize() { return terminal.getScreenSize(); } }); bus.registerPluginListener(new LocalEchoListener() { public void setLocalEcho(boolean echo) { if (!localecho_overridden) terminal.setLocalEcho(echo); } }); bus.registerPluginListener(new ConfigurationListener() { public void setConfiguration(PluginConfig config) { configure(config); } }); bus.registerPluginListener(new ReturnFocusListener() { public void returnFocus() { terminal.requestFocus(); } }); bus.registerPluginListener(new PrinterJobListener() { public void receivePrinterJob(PrinterJob pj) { terminal.setPrinterJob(pj); } }); bus.registerPluginListener(new PageFormatListener() { public void receivePageFormat(PageFormat pf) { terminal.setPageFormat(pf); } }); /* // register a focus status listener, let the plugin know the frame get focus bus.registerPluginListener(new FocusStatusListener() { public void pluginGainedFocus(Plugin plugin) { terminal.setFocus(); } public void pluginLostFocus(Plugin plugin) { // do nothing } }); */ } 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); } if((tmp = cfg.getProperty("Terminal", id, "colorSet")) != null) { 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 set[] = new Color[8]; for(int i = 0; i < 8; i++) if((tmp = colorSet.getProperty("color"+i)) != null) if(colors.get(tmp) != null) set[i] = (Color)colors.get(tmp); else try { if(Color.getColor(tmp) != null) set[i] = Color.getColor(tmp); else set[i] = Color.decode(tmp); } catch(Exception e) { error("ignoring unknown color code: "+tmp); } 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) { terminal.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"; Scrollbar scrollBar = new Scrollbar(); tPanel.add(direction, scrollBar); terminal.setScrollbar(scrollBar); } } if((tmp = cfg.getProperty("Terminal", id, "id")) != null) terminal.setTerminalID(tmp); if((tmp = cfg.getProperty("Terminal", id, "answerback")) != null) terminal.setAnswerBack(tmp); if((tmp = cfg.getProperty("Terminal", id, "buffer")) != null) terminal.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()); terminal.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(terminal.RESIZE_FONT); else if(tmp.equals("screen")) terminal.setResizeStrategy(terminal.RESIZE_SCREEN); else terminal.setResizeStrategy(terminal.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) terminal.setKeyCodes(keyCodes); } if((tmp = cfg.getProperty("Terminal", id, "VMS")) != null) terminal.setVMS((Boolean.valueOf(tmp)).booleanValue()); if((tmp = cfg.getProperty("Terminal", id, "IBM")) != null) terminal.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[] t, b = new byte[256]; int n = 0; while(n >= 0) try { n = read(b); if(debug > 0 && n > 0) System.err.println("Terminal: \""+(new String(b, 0, n, encoding))+"\""); if(n > 0) terminal.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 int read(byte[] b) throws IOException { return source.read(b); } public void write(byte[] b) throws IOException { source.write(b); } public Component getPluginVisual() { return tPanel; } public Menu 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 + -