当前位置: 首页>>代码示例>>Java>>正文


Java Printable类代码示例

本文整理汇总了Java中java.awt.print.Printable的典型用法代码示例。如果您正苦于以下问题:Java Printable类的具体用法?Java Printable怎么用?Java Printable使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Printable类属于java.awt.print包,在下文中一共展示了Printable类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: print

import java.awt.print.Printable; //导入依赖的package包/类
/**
 * Print the plot to a printer, represented by the specified graphics
 * object.
 *
 * @param graphics The context into which the page is drawn.
 * @param format The size and orientation of the page being drawn.
 * @param index The zero based index of the page to be drawn.
 * @return PAGE_EXISTS if the page is rendered successfully, or
 * NO_SUCH_PAGE if pageIndex specifies a non-existent page.
 * @exception PrinterException If the print job is terminated.
 */

public synchronized int print(Graphics graphics, PageFormat format,
        int index) throws PrinterException {
    if (graphics == null) return Printable.NO_SUCH_PAGE;
    // We only print on one page.
    if (index >= 1) {
        return Printable.NO_SUCH_PAGE;
    }
    Graphics2D graphics2D = (Graphics2D) graphics;
    // Scale the printout to fit the pages.
    // Contributed by Laurent ETUR, Schlumberger Riboud Product Center
    double scalex = format.getImageableWidth() / (double) getWidth();
    double scaley = format.getImageableHeight() / (double) getHeight();
    double scale = Math.min(scalex, scaley);
    graphics2D.translate((int)format.getImageableX(),
            (int)format.getImageableY());
    graphics2D.scale(scale, scale);
    _drawPlot(graphics, true);
    return Printable.PAGE_EXISTS;
}
 
开发者ID:OpenDA-Association,项目名称:OpenDA,代码行数:32,代码来源:PlotBox.java

示例2: print

import java.awt.print.Printable; //导入依赖的package包/类
public int print(Graphics g, PageFormat pf, int index) {

        if (index > 0 || image == null) {
            return Printable.NO_SUCH_PAGE;
        }

        ((Graphics2D)g).translate(pf.getImageableX(), pf.getImageableY());
        int w = image.getWidth(null);
        int h = image.getHeight(null);
        int iw = (int)pf.getImageableWidth();
        int ih = (int)pf.getImageableHeight();

        // ensure image will fit
        int dw = w;
        int dh = h;
        if (dw > iw) {
            dh = (int)(dh * ( (float) iw / (float) dw)) ;
            dw = iw;
        }
        if (dh > ih) {
            dw = (int)(dw * ( (float) ih / (float) dh)) ;
            dh = ih;
        }
        // centre on page
        int dx = (iw - dw) / 2;
        int dy = (ih - dh) / 2;

        g.drawImage(image, dx, dy, dx+dw, dy+dh, 0, 0, w, h, null);
        return Printable.PAGE_EXISTS;
    }
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:31,代码来源:ImagePrinter.java

示例3: EPSPrinter

import java.awt.print.Printable; //导入依赖的package包/类
public EPSPrinter(Printable printable, String title,
                  PrintStream stream,
                  int x, int y, int wid, int hgt) {

    this.printable = printable;
    this.epsTitle = title;
    this.stream = stream;
    llx = x;
    lly = y;
    urx = llx+wid;
    ury = lly+hgt;
    // construct a PageFormat with zero margins representing the
    // exact bounds of the applet. ie construct a theoretical
    // paper which happens to exactly match applet panel size.
    Paper p = new Paper();
    p.setSize((double)wid, (double)hgt);
    p.setImageableArea(0.0,0.0, (double)wid, (double)hgt);
    pf = new PageFormat();
    pf.setPaper(p);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:21,代码来源:PSPrinterJob.java

示例4: getPrintable

import java.awt.print.Printable; //导入依赖的package包/类
/**
 * Returns {@code TextComponentPrintable} to print {@code textComponent}.
 *
 * @param textComponent {@code JTextComponent} to print
 * @param headerFormat the page header, or {@code null} for none
 * @param footerFormat the page footer, or {@code null} for none
 * @return {@code TextComponentPrintable} to print {@code textComponent}
 */
public static Printable getPrintable(final JTextComponent textComponent,
        final MessageFormat headerFormat,
        final MessageFormat footerFormat) {

    if (textComponent instanceof JEditorPane
            && isFrameSetDocument(textComponent.getDocument())) {
        //for document with frames we create one printable per
        //frame and merge them with the CompoundPrintable.
        List<JEditorPane> frames = getFrames((JEditorPane) textComponent);
        List<CountingPrintable> printables =
            new ArrayList<CountingPrintable>();
        for (JEditorPane frame : frames) {
            printables.add((CountingPrintable)
                           getPrintable(frame, headerFormat, footerFormat));
        }
        return new CompoundPrintable(printables);
    } else {
        return new TextComponentPrintable(textComponent,
           headerFormat, footerFormat);
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:30,代码来源:TextComponentPrintable.java

示例5: printWithJavaPrintDialog

import java.awt.print.Printable; //导入依赖的package包/类
private static void printWithJavaPrintDialog() {
    final JTable table = createAuthorTable(50);
    Printable printable = table.getPrintable(
            JTable.PrintMode.NORMAL,
            new MessageFormat("Author Table"),
            new MessageFormat("Page - {0}"));

    PrinterJob job = PrinterJob.getPrinterJob();
    job.setPrintable(printable);

    boolean printAccepted = job.printDialog();
    if (printAccepted) {
        try {
            job.print();
            closeFrame();
        } catch (PrinterException e) {
            throw new RuntimeException(e);
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:21,代码来源:ImageableAreaTest.java

示例6: print

import java.awt.print.Printable; //导入依赖的package包/类
public static void print() {

        // Set working printable to print pages
        printJob.setPrintable(new Printable() {
            public int print(Graphics graphics, PageFormat pageFormat,
                    int pageIndex) throws PrinterException {
                return NO_SUCH_PAGE;
            }
        });

        // Display Print dialog
        if (!printJob.printDialog()) {
            System.out.println("\tPrinting canceled by user");
            return;
        }

        try {
            printJob.print();
        } catch (PrinterException e) {
        }
    }
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:22,代码来源:PrintDlgSelectionAttribTest.java

示例7: print

import java.awt.print.Printable; //导入依赖的package包/类
public int print(java.awt.Graphics graphics,
        java.awt.print.PageFormat pageFormat, int pageIndex)
        throws java.awt.print.PrinterException {
    if (pageIndex > 0) {
        return (Printable.NO_SUCH_PAGE);
    } else {
        java.awt.Graphics2D g2d = (java.awt.Graphics2D) graphics;
        vv.setDoubleBuffered(false);
        g2d.translate(pageFormat.getImageableX(), pageFormat
                .getImageableY());

        vv.paint(g2d);
        vv.setDoubleBuffered(true);

        return (Printable.PAGE_EXISTS);
    }
}
 
开发者ID:dev-cuttlefish,项目名称:cuttlefish,代码行数:18,代码来源:GraphEditorDemo.java

示例8: endPage

import java.awt.print.Printable; //导入依赖的package包/类
/**
 * End a page.
 */
@Override
protected void endPage(PageFormat format, Printable painter,
                       int index) {

    deviceEndPage(format, painter, index);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:10,代码来源:WPrinterJob.java

示例9: printWithJavaPrintDialog

import java.awt.print.Printable; //导入依赖的package包/类
private static void printWithJavaPrintDialog() {
    final JTable table = createAuthorTable(42);
    Printable printable = table.getPrintable(
            JTable.PrintMode.NORMAL,
            new MessageFormat("Author Table"),
            new MessageFormat("Page - {0}"));

    PrinterJob job = PrinterJob.getPrinterJob();
    job.setPrintable(printable);

    boolean printAccepted = job.printDialog();
    if (printAccepted) {
        try {
            job.print();
            closeFrame();
        } catch (PrinterException e) {
            throw new RuntimeException(e);
        }
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:21,代码来源:ImageableAreaTest.java

示例10: print

import java.awt.print.Printable; //导入依赖的package包/类
public int print(Graphics g, PageFormat pf, int pageIndex)
                     throws PrinterException {

    if (pageIndex > 0) {
        return Printable.NO_SUCH_PAGE;
    }
    g.translate((int) pf.getImageableX(), (int) pf.getImageableY());
    g.setFont(new Font("Dialog", Font.PLAIN, 36));
    g.drawString("\u4e00\u4e01\u4e02\u4e03\u4e04English", 20, 100);
    return Printable.PAGE_EXISTS;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:12,代码来源:PrintLatinCJKTest.java

示例11: PathGraphics

import java.awt.print.Printable; //导入依赖的package包/类
protected PathGraphics(Graphics2D graphics, PrinterJob printerJob,
                       Printable painter, PageFormat pageFormat,
                       int pageIndex, boolean canRedraw) {
    super(graphics, printerJob);

    mPainter = painter;
    mPageFormat = pageFormat;
    mPageIndex = pageIndex;
    mCanRedraw = canRedraw;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:11,代码来源:PathGraphics.java

示例12: printDifferentRowHeight

import java.awt.print.Printable; //导入依赖的package包/类
private static void printDifferentRowHeight() {
    final JTable table = createAuthorTable(50);
    table.setRowHeight(15, table.getRowHeight(15)+10);
    Printable printable = table.getPrintable(
            JTable.PrintMode.NORMAL,
            new MessageFormat("Author Table"),
            new MessageFormat("Page - {0}"));

    PrinterJob job = PrinterJob.getPrinterJob();
    job.setPrintable(printable);

    boolean printAccepted = job.printDialog();
    if (printAccepted) {
        try {
            job.print();
            closeFrame();
        } catch (PrinterException e) {
            throw new RuntimeException(e);
        }
    }

}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:23,代码来源:ImageableAreaTest.java

示例13: getPrintable

import java.awt.print.Printable; //导入依赖的package包/类
/**
 * Return this class, which is the Printable object.
 * @param pageIndex the page number of the page to be printed.
 * @return this class, which is the Printable object.
 * @throws java.lang.IndexOutOfBoundsException
 */
public Printable getPrintable(int pageIndex) throws IndexOutOfBoundsException {
    if (pageIndex >= mNumPages) {
        throw new IndexOutOfBoundsException();
    }

    return this;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:14,代码来源:PageableScene.java

示例14: print

import java.awt.print.Printable; //导入依赖的package包/类
/**
 * @return <code>true</code> on success. <code>false</code> if user aborts printing.
 */
public static boolean print(Printable printable) throws PrinterException {
	getPrinterJob().setPrintable(printable);
	if (getPrinterJob().printDialog()) {
		PrintingTools.getPrinterJob().print(printSettings);
		return true;
	} else {
		return false;
	}
}
 
开发者ID:transwarpio,项目名称:rapidminer,代码行数:13,代码来源:PrintingTools.java

示例15: print

import java.awt.print.Printable; //导入依赖的package包/类
public void print() {
  PrinterJob printJob = PrinterJob.getPrinterJob();
  printJob.setPrintable((g, format, page) -> {
    if (page > 0) {
      return Printable.NO_SUCH_PAGE;
    }
    // get the bounds of the component
    Rectangle drawingArea = getDrawingArea();
    double cHeight = drawingArea.getSize().getHeight();
    double cWidth = drawingArea.getSize().getWidth();
    // get the bounds of the printable area
    double pHeight = format.getImageableHeight();
    double pWidth = format.getImageableWidth();
    double pXStart = format.getImageableX();
    double pYStart = format.getImageableY();
    //find ratio
    double xRatio = pWidth / cWidth;
    double yRatio = pHeight / cHeight;
    Graphics2D g2d = (Graphics2D) g;
    //translate and scale accordingly
    g2d.translate(pXStart, pYStart);
    g2d.scale(xRatio, yRatio);
    paintDrawing(g2d, drawingArea.x, drawingArea.y);
    return Printable.PAGE_EXISTS;
  });
  if (printJob.printDialog()) {
    try {
      printJob.print();
    } catch (PrinterException e) {
      UIUtility.error(e.getMessage());
    }
  }
}
 
开发者ID:onprom,项目名称:onprom,代码行数:34,代码来源:UMLDiagramPanel.java


注:本文中的java.awt.print.Printable类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。