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

📄 printmanager.java

📁 WAP ide 代码
💻 JAVA
字号:
package wapide;import javax.swing.*;import java.awt.print.*;import java.awt.*;import javax.swing.*;import java.util.*;/** * The Print Manager for the IDE and other programs.  Currently * only the IDEFrame classes has support for printing.  The only printing this * class is capable of is the printing of graphics controls, such as JTextPane's. * In the future text support will be built in to the class so that * proper formatted text can be printed by the IDE and the other * classes. * Copyright:    Copyright (c) 2003 * @author Mark Busman * @version 1.0 * * For License and contact information see WAPIDE.java */public class PrintManager implements Printable {  private PageFormat documentPageFormat = new PageFormat();  private PrinterJob printJob = PrinterJob.getPrinterJob();  private Component componentToBePrinted;  /**   * Constructs a new PrintManager.   */  public PrintManager() {  }  /**   * Sets the graphics component.   */  public void setComponent(Component c) {    this.componentToBePrinted = c;  }  /**   * Shows the printer setup dialog.   */  public void showPageSetup() {    documentPageFormat = printJob.pageDialog (documentPageFormat);  }  /**   * Not yet implemented...   */  public void print() {    //super.print();  }  /**   * Not yet implemented...   */  public void printText(JTextPane thePane, Vector attribVector) {    // format text using attributed string  }  /**   * Not yet implemented...   */  public void printText(String theText, boolean printPortait) {    // plain black and white text  }  /**   * Print a graphical component, such as a JTextPane's contents.  Prints as   * a graphical image, not text.   */  public void printGraphics() {    PrinterJob printJob = PrinterJob.getPrinterJob();    printJob.setPrintable(this);    if (printJob.printDialog())      try {        printJob.print();      } catch(PrinterException pe) {        JOptionPane.showConfirmDialog(null, "Error Printing: " + pe, "Printer Error", JOptionPane.OK_OPTION, JOptionPane.ERROR_MESSAGE);      }  }  /**   * Print a graphical component, such as a JTextPane's contents.  Prints as   * a graphical image, not text.  Allows for some user options.   * @param Graphics g - the graphical context.   * @param PageFormat format - the page orientation, ,argins, etc.   * @param int pageIndex - the page number(s) to print.   */  public int print(Graphics g, PageFormat pageFormat, int pageIndex) {    if (pageIndex > 0) {      return(NO_SUCH_PAGE);    } else {      Graphics2D g2d = (Graphics2D)g;      g2d.translate(pageFormat.getImageableX(), pageFormat.getImageableY());      disableDoubleBuffering(componentToBePrinted);      componentToBePrinted.paint(g2d);      enableDoubleBuffering(componentToBePrinted);      return(PAGE_EXISTS);    }  }  /**   * Overridden to provide better functionality.   */  public static void disableDoubleBuffering(Component c) {    RepaintManager currentManager = RepaintManager.currentManager(c);    currentManager.setDoubleBufferingEnabled(false);  }  /**   * Overridden to provide better functionality.   */  public static void enableDoubleBuffering(Component c) {    RepaintManager currentManager = RepaintManager.currentManager(c);    currentManager.setDoubleBufferingEnabled(true);  }}

⌨️ 快捷键说明

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