📄 terminal.java
字号:
/* * This file is part of "The Java Telnet Application". * * (c) Matthias L. Jugel, Marcus Mei遪er 1996-2002. All Rights Reserved. * * Please visit http://javatelnet.org/ for updates and contact. * * --LICENSE NOTICE-- * This program 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 * of the License, or (at your option) any later version. * * This program 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 program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * --LICENSE NOTICE-- * */package de.mud.jta.plugin;import de.mud.jta.FilterPlugin;import de.mud.jta.Plugin;import de.mud.jta.PluginBus;import de.mud.jta.PluginConfig;import de.mud.jta.VisualTransferPlugin;import de.mud.jta.event.ConfigurationListener;import de.mud.jta.event.FocusStatus;import de.mud.jta.event.LocalEchoListener;import de.mud.jta.event.OnlineStatusListener;import de.mud.jta.event.ReturnFocusListener;import de.mud.jta.event.SoundRequest;import de.mud.jta.event.TelnetCommandRequest;import de.mud.jta.event.TerminalTypeListener;import de.mud.jta.event.WindowSizeListener;import de.mud.terminal.vt320;import de.mud.terminal.SwingTerminal;import javax.swing.JComponent;import javax.swing.JMenu;import javax.swing.JMenuItem;import javax.swing.JPanel;import javax.swing.JScrollBar;import javax.swing.JFrame;import java.awt.BorderLayout;import java.awt.Color;import java.awt.Container;import java.awt.Cursor;import java.awt.Dimension;import java.awt.Font;import java.awt.datatransfer.Clipboard;import java.awt.datatransfer.ClipboardOwner;import java.awt.datatransfer.DataFlavor;import java.awt.datatransfer.StringSelection;import java.awt.datatransfer.Transferable;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.FocusEvent;import java.awt.event.FocusListener;import java.io.IOException;import java.net.MalformedURLException;import java.net.URL;import java.util.Enumeration;import java.util.Hashtable;import java.util.Properties;/** * 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.41 2002/05/08 16:32:36 leo 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 SwingTerminal terminal; protected vt320 emulation; /** * 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 JPanel tPanel; /** holds the terminal menu */ protected JMenu menu; private Thread reader = null; private Hashtable colors = new Hashtable(); private boolean localecho_overridden = false; private Color codeToColor(String code) { if (colors.get(code) != null) return (Color) colors.get(code); else try { if (Color.getColor(code) != null) return Color.getColor(code); else return Color.decode(code); } catch (Exception e) { error("ignoring unknown color code: " + code); } return null; } /** * Create a new terminal plugin and initialize the terminal emulation. */ public Terminal(final PluginBus bus, final String id) { super(bus, id); // create the terminal emulation emulation = 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)); } }; // create terminal terminal = new SwingTerminal(emulation); // 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.gray); colors.put("darkgray", Color.darkGray); if (!personalJava) { menu = new JMenu("Terminal"); JMenuItem item; JMenu fgm = new JMenu("Foreground"); JMenu bgm = new JMenu("Background"); 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 JMenuItem(color)); item.addActionListener(fgl); bgm.add(item = new JMenuItem(color)); item.addActionListener(bgl); } menu.add(fgm); menu.add(bgm); menu.add(item = new JMenuItem("Smaller Font")); 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) { Container parent = tPanel; do { parent = parent.getParent(); } while(parent != null && !(parent instanceof JFrame)); if (parent instanceof JFrame) ((java.awt.Frame) parent).pack(); tPanel.getParent().doLayout(); tPanel.getParent().validate(); } } }); menu.add(item = new JMenuItem("Larger Font")); 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) { Container parent = tPanel; do { parent = parent.getParent(); } while(parent != null && !(parent instanceof JFrame)); if (parent instanceof JFrame) ((java.awt.Frame) parent).pack(); tPanel.getParent().doLayout(); tPanel.getParent().validate(); } } }); menu.add(item = new JMenuItem("Buffer +50")); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { emulation.setBufferSize(emulation.getBufferSize() + 50); } }); menu.add(item = new JMenuItem("Buffer -50")); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { emulation.setBufferSize(emulation.getBufferSize() - 50); } }); menu.addSeparator(); menu.add(item = new JMenuItem("Reset Terminal")); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { emulation.reset(); } }); } // !personalJava // the container for our terminal must use double-buffering // or at least reduce flicker by overloading update() tPanel = new JPanel(new BorderLayout()) { // reduce flickering public void update(java.awt.Graphics g) { paint(g); } // we don't want to print the container, just the terminal contents public void print(java.awt.Graphics g) { terminal.print(g); } }; 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); if (reader == null) { reader = new Thread(Terminal.this); reader.start(); } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -