?? vdu.java
字號:
/* * 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.terminal;import java.awt.Component;import java.awt.Graphics;import java.awt.Color;import java.awt.Dimension;import java.awt.Font;import java.awt.FontMetrics;import java.awt.Point;import java.awt.Insets;import java.awt.Event;import java.awt.Label;import java.awt.Frame;import java.awt.Rectangle;import java.awt.Scrollbar;import java.awt.Image;import java.awt.Toolkit;import java.awt.MediaTracker;import java.awt.Graphics2D;import java.awt.KeyboardFocusManager;import java.util.Collections;import java.awt.Graphics;import java.awt.print.Printable;import java.awt.print.PrinterJob;import java.awt.print.PrinterException;import java.awt.print.PageFormat;import java.awt.AWTEvent;import java.awt.AWTEventMulticaster;import java.awt.event.KeyListener;import java.awt.event.KeyEvent;import java.awt.event.AdjustmentListener;import java.awt.event.AdjustmentEvent;import java.awt.event.MouseListener;import java.awt.event.MouseMotionListener;import java.awt.event.MouseEvent;import java.awt.event.FocusListener;import java.awt.event.FocusEvent;import java.io.InputStream;import java.io.UnsupportedEncodingException;import java.util.Timer;import java.util.TimerTask;import component.GraphicFont;/** * Video Display Unit emulation. This class implements all necessary * features of a character display unit, but not the actual terminal emulation. * It can be used as the base for terminal emulations of any kind. * <P> * This is a lightweight component. It will render very badly if used * in standard AWT components without overloaded update() method. The * update() method must call paint() immediately without clearing the * components graphics context or parts of the screen will simply * disappear. * <P> * <B>Maintainer:</B> Matthias L. Jugel * * @version $Id: VDU.java,v 2.38 2001/03/23 20:50:51 leo Exp $ * @author Matthias L. Jugel, Marcus Mei遪er */public class VDU extends Component implements MouseListener, MouseMotionListener { /** The current version id tag */ public final static String ID = "$Id: VDU.java,v 2.38 2001/03/23 20:50:51 leo Exp $"; /** Enable debug messages. */ public final static int debug = 0; /** lightweight component definitions */ private final static long VDU_EVENTS = AWTEvent.KEY_EVENT_MASK | AWTEvent.FOCUS_EVENT_MASK | AWTEvent.ACTION_EVENT_MASK | AWTEvent.MOUSE_MOTION_EVENT_MASK | AWTEvent.MOUSE_EVENT_MASK; private Dimension scrSize; /* rows and columns */ private Insets insets; /* size of the border */ private boolean raised; /* indicator if the border is raised */ private char charArray[][]; /* contains the characters */ private int charAttributes[][]; /* contains character attrs */ // private int bufSize, maxBufSize; /* buffer sizes */ private int maxBufSize; /* buffer sizes */ private int windowBase; /* where the start displaying */ private int screenBase; /* the actual screen start */ private int topMargin; /* top scroll margin */ private int bottomMargin; /* bottom scroll margin */ private int xoffset = 0; /* x offset to the margin for char */ private int yoffset = 0; /* y offset to the margin for char */ private Font normalFont; /* normal font */ private FontMetrics fm; /* current font metrics */ private int charWidth; /* current width of a char */ private int charHeight; /* current height of a char */ private int charDescent; /* base line descent */ private int resizeStrategy; /* current resizing strategy */ private int cursorX, cursorY; /* current cursor position */ private boolean showcursor = true; /* show cursor */ private int scrCursorX, scrCursorY; /* screen cursor position */ private Point selectBegin, selectEnd; /* selection coordinates */ private String selection; /* contains the selected text */ private Scrollbar scrollBar; // private SoftFont sf = new SoftFont(); private GraphicFont gf; /* use GraphicFont replace SoftFont .CPC. */ private boolean update[]; /* contains the lines that need update */ private boolean colorPrinting = false; /* print display in color */ // private Image backingStore = null; private Image backingStore[]; /* images per line */ private boolean display[]; /* contains the lines that need display */ private boolean blink[]; /* contains the lines that have blink char */ private boolean blinking = true; /* blink char now is display */ private int mSecond; /* millisecond count for display */ private Object semaphore = new Object(); /** * Create a color representation that is brighter than the standard * color but not what we would like to use for bold characters. * @param clr the standard color * @return the new brighter color */ private Color brighten(Color clr) { return new Color(Math.max((int) (clr.getRed() * 0.4), 0), Math.max((int) (clr.getGreen() * 0.4), 0), Math.max((int) (clr.getBlue() * 0.4), 0)); } /** * adjust the color not as bright as pure color. * @param clr the standard color * @return the ne color */ private Color adjust(Color clr, double coefficient) { return new Color(Math.max((int) (clr.getRed() * coefficient), 0), Math.max((int) (clr.getGreen() * coefficient), 0), Math.max((int) (clr.getBlue() * coefficient), 0)); } private final double LOW_LIGHT = 0.5176; private final double HIGH_LIGHT = 1.0; /** A list of colors used for representation of the display */ private Color color[] = { adjust(Color.black, LOW_LIGHT), adjust(Color.red, LOW_LIGHT), adjust(Color.green, LOW_LIGHT), adjust(Color.yellow, LOW_LIGHT), adjust(Color.blue, LOW_LIGHT), adjust(Color.magenta, LOW_LIGHT), adjust(Color.cyan, LOW_LIGHT), adjust(Color.white, 0.77), adjust(Color.white, LOW_LIGHT), adjust(Color.red, HIGH_LIGHT), adjust(Color.green, HIGH_LIGHT), adjust(Color.yellow, HIGH_LIGHT), adjust(Color.blue, HIGH_LIGHT), adjust(Color.magenta, HIGH_LIGHT), adjust(Color.cyan, HIGH_LIGHT), adjust(Color.white, HIGH_LIGHT), }; public final static int COLOR_0 = 0; public final static int COLOR_1 = 1; public final static int COLOR_2 = 2; public final static int COLOR_3 = 3; public final static int COLOR_4 = 4; public final static int COLOR_5 = 5; public final static int COLOR_6 = 6; public final static int COLOR_7 = 7; /* definitions of standards for the display unit */ private static int COLOR_FG_STD = 7; private static int COLOR_BG_STD = 0; private static int COLOR_FG_BOLD = 16; private final static int COLOR = 0x7f8; private final static int COLOR_FG = 0x78; private final static int COLOR_BG = 0x780; /** User defineable cursor colors */ private Color cursorColorFG = null; private Color cursorColorBG = null; private Color scrCursorColorFG = null; private Color scrCursorColorBG = null; /** Scroll up when inserting a line. */ public final static boolean SCROLL_UP = false; /** Scroll down when inserting a line. */ public final static boolean SCROLL_DOWN = true; /** Do nothing when the component is resized. */ public final static int RESIZE_NONE = 0; /** Resize the width and height of the character screen. */ public final static int RESIZE_SCREEN = 1; /** Resize the font to the new screen size. */ public final static int RESIZE_FONT = 2; /** Make character normal. */ public final static int NORMAL = 0x00; /** Make character bold. */ public final static int BOLD = 0x01; /** Underline character. */ public final static int UNDERLINE = 0x02; /** Invert character. */ public final static int INVERT = 0x04; /** Blink character. */ public final static int BLINK = 0x800; private final int FG_MASK = COLOR_FG | BOLD | UNDERLINE | INVERT | BLINK; private final int BG_MASK = COLOR_BG | BOLD | INVERT; private TimerTask blinkingChar = new TimerTask() { public void run() { mSecond += 100; if (mSecond == 800) { blinking = !blinking; for (int i = 0; i < scrSize.height; i ++) update[i + 1] = blink[i]; mSecond = 0; } redraw(); paint(); } }; private Timer timer = new Timer(); private HostPrint hp = new HostPrint(); /** * Create a new video display unit with the passed width and height in * characters using a special font and font size. These features can * be set independently using the appropriate properties. * @param width the length of the character lines * @param height the amount of lines on the screen * @param font the font to be used (usually Monospaced) */ public VDU(int width, int height, Font font) { // lightweight component handling enableEvents(VDU_EVENTS); // set the normal font to use setFont(font); // set the standard resize strategy setResizeStrategy(RESIZE_FONT); // set the display screen size setScreenSize(width, height); // setForeground(Color.white); // setBackground(Color.black); setForeground(color[COLOR_FG_STD]); setBackground(color[COLOR_BG_STD]); cursorColorFG = color[COLOR_FG_STD]; cursorColorBG = color[COLOR_BG_STD]; clearSelection(); addMouseListener(this); addMouseMotionListener(this); setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, Collections.EMPTY_SET); setFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, Collections.EMPTY_SET); setFocusTraversalKeys(KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS, Collections.EMPTY_SET); selection = null; // load the GIF font .CPC. MediaTracker tracker = new MediaTracker(this); try { InputStream is = VDU.class.getResourceAsStream("/de/mud/font/Fixedsys.20.gif"); byte[] fb = new byte[is.available()]; int offset = 0; while (offset < fb.length) { int bytesread = is.read(fb, offset, fb.length - offset); if (bytesread == -1) break; offset += bytesread; } Image fontImage = Toolkit.getDefaultToolkit().createImage(fb); tracker.addImage(fontImage, 0); tracker.waitForID(0); gf = new GraphicFont(fontImage, color); } catch (Exception e) { System.err.println("jta: cannot load .gif" + e.getMessage()); } // timer.schedule(blinkingChar, 0, 800); timer.schedule(blinkingChar, 0, 100); hp.start(); } /** * Create a display unit with specific size, Font is "Monospaced", size 12. * @param width the length of the character lines * @param height the amount of lines on the screen */ public VDU(int width, int height) { this(width, height, new Font("Monospaced", Font.PLAIN, 20)); // this(width, height, new Font("穝燦
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -