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

📄 terminal.java

📁 java 平台 telnet 繁体中文版
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * This file is part of "The Java Telnet Application". * * This is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * "The Java Telnet Application" is distributed in the hope that it will be * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this software; see the file COPYING.  If not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */package de.mud.jta.plugin;import de.mud.jta.Plugin;import de.mud.jta.PluginConfig;import de.mud.jta.FilterPlugin;import de.mud.jta.VisualTransferPlugin;import de.mud.jta.PluginBus;import de.mud.jta.PrintScreen;import de.mud.terminal.vt320;import de.mud.jta.event.ConfigurationListener;import de.mud.jta.event.OnlineStatusListener;import de.mud.jta.event.TerminalTypeListener;import de.mud.jta.event.WindowSizeListener;import de.mud.jta.event.LocalEchoListener;import de.mud.jta.event.FocusStatus;import de.mud.jta.event.FocusStatusListener;import de.mud.jta.event.ReturnFocusListener;import de.mud.jta.event.AppletListener;import de.mud.jta.event.PrinterJobListener;import de.mud.jta.event.PageFormatListener;import de.mud.jta.event.SoundRequest;import de.mud.jta.event.TelnetCommandRequest;import java.awt.Component;import java.awt.Panel;import java.awt.BorderLayout;import java.awt.Menu;import java.awt.MenuItem;import java.awt.Dimension;import java.awt.Font;import java.awt.Color;import java.awt.Scrollbar;import java.awt.Cursor;import java.awt.Toolkit;import java.awt.LayoutManager;import java.awt.print.PrinterJob;import java.awt.print.PageFormat;import java.awt.event.ActionListener;import java.awt.event.ActionEvent;import java.awt.event.FocusListener;import java.awt.event.FocusEvent;import java.awt.datatransfer.Clipboard;import java.awt.datatransfer.StringSelection;import java.awt.datatransfer.ClipboardOwner;import java.awt.datatransfer.Transferable;import java.awt.datatransfer.DataFlavor;import java.io.IOException;import java.io.InputStream;import java.net.URL;import java.net.MalformedURLException;import java.util.Properties;import java.util.Hashtable;import java.util.Enumeration;/** * The terminal plugin represents the actual terminal where the * data will be displayed and the gets the keyboard input to sent * back to the remote host. * <P> * <B>Maintainer:</B> Matthias L. Jugel * * @version $Id: Terminal.java,v 2.31 2000/12/03 17:56:29 marcus Exp $ * @author Matthias L. Jugel, Marcus Mei遪er */public class Terminal extends Plugin  implements FilterPlugin, VisualTransferPlugin, ClipboardOwner, Runnable {  private final static boolean personalJava = false;  private final static int debug = 0;  /** holds the actual terminal emulation */  protected vt320 terminal;  /**   * The default encoding is ISO 8859-1 (western).   * However, as you see the value is set to latin1 which is a value that   * is not even documented and thus incorrect, but it forces the default   * behaviour for western encodings. The correct value does not work in   * most available browsers.   */  protected String encoding = "latin1"; // "ISO8859_1";  /** if we have a url to an audioclip use it as ping */  protected SoundRequest audioBeep = null;  /** the terminal panel that is displayed on-screen */  protected Panel tPanel;  /** holds the terminal menu */  protected Menu menu;  private Thread reader = null;  private Hashtable colors = new Hashtable();  private boolean localecho_overridden = false;  /**   * Create a new terminal plugin and initialize the terminal emulation.   */  public Terminal(final PluginBus bus, final String id) {    super(bus, id);    // initialize colors    colors.put("black", Color.black);    colors.put("red", Color.red);    colors.put("green", Color.green);    colors.put("yellow", Color.yellow);    colors.put("blue", Color.blue);    colors.put("magenta", Color.magenta);    colors.put("orange", Color.orange);    colors.put("pink", Color.pink);    colors.put("cyan", Color.cyan);    colors.put("white", Color.white);    colors.put("gray", Color.white);    if(!personalJava) {    Font menufont = (Font)Toolkit.getDefaultToolkit().getDesktopProperty("win.menu.font");    menu = new Menu("沧狠诀");    menu.setFont(menufont);    MenuItem item;    Menu fgm = new Menu("玡春肅︹");    fgm.setFont(menufont);    Menu bgm = new Menu("璉春肅︹");    bgm.setFont(menufont);    Enumeration cols = colors.keys();    ActionListener fgl = new ActionListener() {      public void actionPerformed(ActionEvent e) {        terminal.setForeground((Color)colors.get(e.getActionCommand()));        tPanel.repaint();      }    };    ActionListener bgl = new ActionListener() {      public void actionPerformed(ActionEvent e) {        terminal.setBackground((Color)colors.get(e.getActionCommand()));        tPanel.repaint();      }    };    while(cols.hasMoreElements()) {      String color = (String)cols.nextElement();      fgm.add(item = new MenuItem(color));      item.setFont(menufont);      item.addActionListener(fgl);      bgm.add(item = new MenuItem(color));      item.setFont(menufont);      item.addActionListener(bgl);    }    menu.add(fgm);    menu.add(bgm);    menu.add(item = new MenuItem("Smaller Font"));    item.setFont(menufont);    item.addActionListener(new ActionListener() {      public void actionPerformed(ActionEvent e) {        Font font = terminal.getFont();        terminal.setFont(new Font(font.getName(),                             font.getStyle(), font.getSize()-1));        if(tPanel.getParent() != null) {          Component parent = tPanel.getParent();          if(parent instanceof java.awt.Frame)            ((java.awt.Frame)parent).pack();          tPanel.getParent().doLayout();          tPanel.getParent().validate();        }      }    });    menu.add(item = new MenuItem("Larger Font"));    item.setFont(menufont);    item.addActionListener(new ActionListener() {      public void actionPerformed(ActionEvent e) {        Font font = terminal.getFont();        terminal.setFont(new Font(font.getName(),                             font.getStyle(), font.getSize()+1));        if(tPanel.getParent() != null) {          Component parent = tPanel.getParent();          if(parent instanceof java.awt.Frame)            ((java.awt.Frame)parent).pack();          tPanel.getParent().doLayout();          tPanel.getParent().validate();        }      }    });    menu.add(item = new MenuItem("Buffer +50"));    item.setFont(menufont);    item.addActionListener(new ActionListener() {      public void actionPerformed(ActionEvent e) {        terminal.setBufferSize(terminal.getBufferSize() + 50);      }    });    menu.add(item = new MenuItem("Buffer -50"));    item.setFont(menufont);    item.addActionListener(new ActionListener() {      public void actionPerformed(ActionEvent e) {        terminal.setBufferSize(terminal.getBufferSize() - 50);      }    });    menu.addSeparator();    menu.add(item = new MenuItem("Reset Terminal"));    item.setFont(menufont);    item.addActionListener(new ActionListener() {      public void actionPerformed(ActionEvent e) {        terminal.reset();      }    });    } // !personalJava    // create the terminal emulation    terminal = new vt320() {      public void write(byte[] b) {        try {          Terminal.this.write(b);        } catch(IOException e) {          reader = null;        }      }      // provide audio feedback if that is configured      public void beep() {        if(audioBeep != null) bus.broadcast(audioBeep);      }      public void sendTelnetCommand(byte cmd) {        bus.broadcast(new TelnetCommandRequest(cmd));      }      public void handle_osc(String osc) {        int scp = osc.indexOf(";");        try {          switch (Integer.parseInt(osc.substring(0, scp))) {            case 0:            case 2:              if(tPanel.getParent() != null) {                Component parent = tPanel.getParent();                if(parent instanceof java.awt.Frame)                  ((java.awt.Frame)parent).setTitle(osc.substring(scp + 1));              }              break;            default:              System.out.println("osc not supported : " + osc);          }        }        catch (NumberFormatException e) {}        catch (StringIndexOutOfBoundsException e) {          System.out.println("***" + osc + "***");        }      }    };    class PrintPanel extends Panel implements PrintScreen {      public PrintPanel(LayoutManager layout) {        super(layout);      }      // we don't want to print the container, just the terminal contents      public void printScreen(PrinterJob printerJob) {        terminal.printScreen(printerJob);      }    }    // the container for our terminal must use double-buffering    // or at least reduce flicker by overloading update()    tPanel = new PrintPanel(new BorderLayout()) {      // reduce flickering      public void update(java.awt.Graphics g) {        paint(g);      }      // increase display speed and ensure display at program starting      public void repaint() {        terminal.redraw();        terminal.paint();      }    };    tPanel.add("Center", terminal);    terminal.addFocusListener(new FocusListener() {      public void focusGained(FocusEvent evt) {        if(debug > 0)          System.err.println("Terminal: focus gained");        terminal.setCursor(Cursor.getPredefinedCursor(Cursor.TEXT_CURSOR));        bus.broadcast(new FocusStatus(Terminal.this, evt));      }      public void focusLost(FocusEvent evt) {        if(debug > 0)          System.err.println("Terminal: focus lost");        terminal.setCursor(Cursor.getDefaultCursor());        bus.broadcast(new FocusStatus(Terminal.this, evt));      }    });    // register an online status listener    bus.registerPluginListener(new OnlineStatusListener() {      public void online() {        if(debug > 0) System.err.println("Terminal: online "+reader);

⌨️ 快捷键说明

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