當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。