?? hostprint.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.Graphics;import java.awt.Graphics2D;import java.awt.Color;import java.awt.geom.Point2D;import java.awt.Font;import java.io.UnsupportedEncodingException;import java.awt.print.Printable;import java.awt.print.PrinterJob;import java.awt.print.PrinterException;import java.awt.print.PageFormat;import java.awt.print.Book;import java.awt.print.PrinterException;import java.util.LinkedList;import java.util.NoSuchElementException;/** * Process the print job form host. * <P> * <B>Maintainer:</B> Jutso Hung * * @version $Id: HostPrint.java,v 1.3 2001/06/07 11:40:15 jutso Exp $ * @author Jutso Hung */public class HostPrint extends Thread implements Printable {// public class HostPrint implements Printable { protected PrinterJob pjob; protected PageFormat pformat; private LinkedList q = new LinkedList(); private boolean threadSuspended; private StringBuffer hpStr = new StringBuffer(); private int px, py; private boolean wrape = true; private char charBuf; private int wLength = 0; private int pagePtr = -1; /* to point out what page index can draw */ private int qPtr = 0; /* point out what queue have been print out */ public void setPageFormat(PageFormat pf) { pformat = pf; px = (int) pformat.getImageableX() + 10; py = (int) pformat.getImageableY() + 12; pjob.setPrintable(this, pformat); } public void setPrinterJob(PrinterJob pj) { pjob = pj; } public void printChar(char c) { if (wLength == 0) { if (c >= 128 && c <= 255) { charBuf = c; wLength++; } else makePage(c, 1); } else { if (c >= '@' && c <= 255) { wLength++; makePage((char)((charBuf << 8) | c), wLength); } else { makePage(charBuf, 1); makePage(c, 1); } wLength = 0; } } public synchronized void makePage(char c, int w) { hpStr.append(c); // if (c == '\f' || hpStr.length() > 1023) { if (c == '\f') { synchronized(q) { q.add(hpStr.toString()); } hpStr = new StringBuffer(); notify(); } } public void run() { while (true) { synchronized (this) { try { wait(); } catch (InterruptedException e) { System.err.println("Printing error: " + e.getMessage()); } } try { pagePtr = -1; qPtr = 0; pjob.print(); } catch (PrinterException exception) { System.err.println("Printing error: " + exception); } catch (ArrayIndexOutOfBoundsException exception) { System.err.println("Printing error: " + exception.getMessage()); } } } public int print(Graphics g, PageFormat format, int pageIndex) { Graphics2D g2d = (Graphics2D) g; g2d.translate(format.getImageableX() + 10, format.getImageableY() + 12); g2d.setPaint(Color.black); Point2D.Float pen = new Point2D.Float(); // Font fnt = new Font("穝燦
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -