Search in sources :

Example 11 with PageFormat

use of java.awt.print.PageFormat in project jdk8u_jdk by JetBrains.

the class RasterPrinterJob method validatePage.

/**
     * The passed in PageFormat is cloned and altered to be usable on
     * the PrinterJob's current printer.
     */
public PageFormat validatePage(PageFormat page) {
    PageFormat newPage = (PageFormat) page.clone();
    Paper newPaper = new Paper();
    validatePaper(newPage.getPaper(), newPaper);
    newPage.setPaper(newPaper);
    return newPage;
}
Also used : PageFormat(java.awt.print.PageFormat) Paper(java.awt.print.Paper)

Example 12 with PageFormat

use of java.awt.print.PageFormat in project jdk8u_jdk by JetBrains.

the class RasterPrinterJob method defaultPage.

/**
     * The passed in PageFormat will be copied and altered to describe
     * the default page size and orientation of the PrinterJob's
     * current printer.
     * Platform subclasses which can access the actual default paper size
     * for a printer may override this method.
     */
public PageFormat defaultPage(PageFormat page) {
    PageFormat newPage = (PageFormat) page.clone();
    newPage.setOrientation(PageFormat.PORTRAIT);
    Paper newPaper = new Paper();
    double ptsPerInch = 72.0;
    double w, h;
    Media media = null;
    PrintService service = getPrintService();
    if (service != null) {
        MediaSize size;
        media = (Media) service.getDefaultAttributeValue(Media.class);
        if (media instanceof MediaSizeName && ((size = MediaSize.getMediaSizeForName((MediaSizeName) media)) != null)) {
            w = size.getX(MediaSize.INCH) * ptsPerInch;
            h = size.getY(MediaSize.INCH) * ptsPerInch;
            newPaper.setSize(w, h);
            newPaper.setImageableArea(ptsPerInch, ptsPerInch, w - 2.0 * ptsPerInch, h - 2.0 * ptsPerInch);
            newPage.setPaper(newPaper);
            return newPage;
        }
    }
    /* Default to A4 paper outside North America.
         */
    String defaultCountry = Locale.getDefault().getCountry();
    if (// ie "C"
    !Locale.getDefault().equals(Locale.ENGLISH) && defaultCountry != null && !defaultCountry.equals(Locale.US.getCountry()) && !defaultCountry.equals(Locale.CANADA.getCountry())) {
        double mmPerInch = 25.4;
        w = Math.rint((210.0 * ptsPerInch) / mmPerInch);
        h = Math.rint((297.0 * ptsPerInch) / mmPerInch);
        newPaper.setSize(w, h);
        newPaper.setImageableArea(ptsPerInch, ptsPerInch, w - 2.0 * ptsPerInch, h - 2.0 * ptsPerInch);
    }
    newPage.setPaper(newPaper);
    return newPage;
}
Also used : PageFormat(java.awt.print.PageFormat) MediaSize(javax.print.attribute.standard.MediaSize) MediaSizeName(javax.print.attribute.standard.MediaSizeName) Media(javax.print.attribute.standard.Media) Paper(java.awt.print.Paper) PrintService(javax.print.PrintService) StreamPrintService(javax.print.StreamPrintService)

Example 13 with PageFormat

use of java.awt.print.PageFormat in project jdk8u_jdk by JetBrains.

the class WPrinterJob method pageDialog.

/* Instance Methods */
/**
     * Display a dialog to the user allowing the modification of a
     * PageFormat instance.
     * The <code>page</code> argument is used to initialize controls
     * in the page setup dialog.
     * If the user cancels the dialog, then the method returns the
     * original <code>page</code> object unmodified.
     * If the user okays the dialog then the method returns a new
     * PageFormat object with the indicated changes.
     * In either case the original <code>page</code> object will
     * not be modified.
     * @param     page    the default PageFormat presented to the user
     *                    for modification
     * @return    the original <code>page</code> object if the dialog
     *            is cancelled, or a new PageFormat object containing
     *            the format indicated by the user if the dialog is
     *            acknowledged
     * @exception HeadlessException if GraphicsEnvironment.isHeadless()
     * returns true.
     * @see java.awt.GraphicsEnvironment#isHeadless
     * @since     JDK1.2
     */
@Override
public PageFormat pageDialog(PageFormat page) throws HeadlessException {
    if (GraphicsEnvironment.isHeadless()) {
        throw new HeadlessException();
    }
    if (!(getPrintService() instanceof Win32PrintService)) {
        return super.pageDialog(page);
    }
    PageFormat pageClone = (PageFormat) page.clone();
    boolean result = false;
    /*
         * Fix for 4507585: show the native modal dialog the same way printDialog() does so
         * that it won't block event dispatching when called on EventDispatchThread.
         */
    WPageDialog dialog = new WPageDialog((Frame) null, this, pageClone, null);
    dialog.setRetVal(false);
    dialog.setVisible(true);
    result = dialog.getRetVal();
    dialog.dispose();
    // myService => current PrintService
    if (result && (myService != null)) {
        // It's possible that current printer is changed through
        // the "Printer..." button so we query again from native.
        String printerName = getNativePrintService();
        if (!myService.getName().equals(printerName)) {
            // we update the current PrintService
            try {
                setPrintService(Win32PrintServiceLookup.getWin32PrintLUS().getPrintServiceByName(printerName));
            } catch (PrinterException e) {
            }
        }
        // Update attributes, this will preserve the page settings.
        //  - same code as in RasterPrinterJob.java
        updatePageAttributes(myService, pageClone);
        return pageClone;
    } else {
        return page;
    }
}
Also used : Win32PrintService(sun.print.Win32PrintService) PageFormat(java.awt.print.PageFormat) HeadlessException(java.awt.HeadlessException) PrinterException(java.awt.print.PrinterException)

Example 14 with PageFormat

use of java.awt.print.PageFormat in project jdk8u_jdk by JetBrains.

the class WPrinterJob method defaultPage.

/**
     * The passed in PageFormat will be copied and altered to describe
     * the default page size and orientation of the PrinterJob's
     * current printer.
     * Note: PageFormat.getPaper() returns a clone and getDefaultPage()
     * gets that clone so it won't overwrite the original paper.
     */
@Override
public PageFormat defaultPage(PageFormat page) {
    PageFormat newPage = (PageFormat) page.clone();
    getDefaultPage(newPage);
    return newPage;
}
Also used : PageFormat(java.awt.print.PageFormat)

Example 15 with PageFormat

use of java.awt.print.PageFormat in project jgnash by ccavanaugh.

the class DynamicJasperReportPanel method pageSetupAction.

private void pageSetupAction() {
    PageFormat oldFormat = report.getPageFormat();
    PrinterJob job = PrinterJob.getPrinterJob();
    PageFormat format = job.pageDialog(oldFormat);
    if (format != oldFormat) {
        report.setPageFormat(format);
        refreshReport();
    }
}
Also used : PageFormat(java.awt.print.PageFormat) PrinterJob(java.awt.print.PrinterJob)

Aggregations

PageFormat (java.awt.print.PageFormat)32 Paper (java.awt.print.Paper)12 PrinterException (java.awt.print.PrinterException)11 PrinterJob (java.awt.print.PrinterJob)10 PrintService (javax.print.PrintService)9 Printable (java.awt.print.Printable)6 PrintRequestAttributeSet (javax.print.attribute.PrintRequestAttributeSet)6 MediaSize (javax.print.attribute.standard.MediaSize)6 HeadlessException (java.awt.HeadlessException)5 StreamPrintService (javax.print.StreamPrintService)5 HashPrintRequestAttributeSet (javax.print.attribute.HashPrintRequestAttributeSet)5 Media (javax.print.attribute.standard.Media)5 Graphics2D (java.awt.Graphics2D)4 BufferedImage (java.awt.image.BufferedImage)4 File (java.io.File)4 MediaSizeName (javax.print.attribute.standard.MediaSizeName)4 OrientationRequested (javax.print.attribute.standard.OrientationRequested)4 AffineTransform (java.awt.geom.AffineTransform)3 Rectangle2D (java.awt.geom.Rectangle2D)3 IOException (java.io.IOException)3