Search in sources :

Example 1 with MediaPrintableArea

use of javax.print.attribute.standard.MediaPrintableArea in project jdk8u_jdk by JetBrains.

the class ImageableAreaTest method printWithCustomImageareaSize.

private static void printWithCustomImageareaSize() {
    final JTable table = createAuthorTable(18);
    PrintRequestAttributeSet printAttributes = new HashPrintRequestAttributeSet();
    printAttributes.add(DialogTypeSelection.NATIVE);
    printAttributes.add(new Copies(1));
    printAttributes.add(new MediaPrintableArea(0.25f, 0.25f, 8.0f, 5.0f, MediaPrintableArea.INCH));
    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(printAttributes);
    if (printAccepted) {
        try {
            job.print(printAttributes);
            closeFrame();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    } else {
        throw new RuntimeException("User cancels the printer job!");
    }
}
Also used : MediaPrintableArea(javax.print.attribute.standard.MediaPrintableArea) MessageFormat(java.text.MessageFormat) Copies(javax.print.attribute.standard.Copies) JTable(javax.swing.JTable) Printable(java.awt.print.Printable) HashPrintRequestAttributeSet(javax.print.attribute.HashPrintRequestAttributeSet) PrinterException(java.awt.print.PrinterException) PrintRequestAttributeSet(javax.print.attribute.PrintRequestAttributeSet) HashPrintRequestAttributeSet(javax.print.attribute.HashPrintRequestAttributeSet) PrinterJob(java.awt.print.PrinterJob)

Example 2 with MediaPrintableArea

use of javax.print.attribute.standard.MediaPrintableArea in project adempiere by adempiere.

the class CPaper method setPrintRequestAttributeSet.

//  getPrintRequestAttributes
/**
	 *  Set Print Request Attributes
	 *  @param prats PrintRequestAttributeSet
	 */
public void setPrintRequestAttributeSet(PrintRequestAttributeSet prats) {
    boolean landscape = m_landscape;
    MediaSize ms = m_mediaSize;
    MediaPrintableArea area = getMediaPrintableArea();
    Attribute[] atts = prats.toArray();
    for (int i = 0; i < atts.length; i++) {
        if (atts[i] instanceof OrientationRequested) {
            OrientationRequested or = (OrientationRequested) atts[i];
            if (or.equals(OrientationRequested.PORTRAIT))
                landscape = false;
            else
                landscape = true;
        } else if (atts[i] instanceof MediaSizeName) {
            MediaSizeName msn = (MediaSizeName) atts[i];
            ms = MediaSize.getMediaSizeForName(msn);
        } else if (atts[i] instanceof MediaPrintableArea) {
            area = (MediaPrintableArea) atts[i];
        } else
            //	unhandeled
            System.out.println(atts[i].getName() + " = " + atts[i] + " - " + atts[i].getCategory());
    }
    //
    setMediaSize(ms, landscape);
    setMediaPrintableArea(area);
}
Also used : MediaPrintableArea(javax.print.attribute.standard.MediaPrintableArea) MediaSize(javax.print.attribute.standard.MediaSize) Attribute(javax.print.attribute.Attribute) MediaSizeName(javax.print.attribute.standard.MediaSizeName) OrientationRequested(javax.print.attribute.standard.OrientationRequested)

Example 3 with MediaPrintableArea

use of javax.print.attribute.standard.MediaPrintableArea in project jgnash by ccavanaugh.

the class PrintableCheckLayout method getPageFormat.

public PageFormat getPageFormat() {
    PrintRequestAttributeSet printAttributes = checkLayout.getPrintAttributes();
    if (pageFormat == null) {
        // create a default pageFormat
        PageFormat format = getPrinterJob().defaultPage();
        Paper paper = format.getPaper();
        MediaSizeName media = (MediaSizeName) printAttributes.get(Media.class);
        MediaSize ms = MediaSize.getMediaSizeForName(media);
        MediaPrintableArea ma = (MediaPrintableArea) printAttributes.get(MediaPrintableArea.class);
        if (ma != null) {
            int INCH = MediaPrintableArea.INCH;
            paper.setImageableArea((ma.getX(INCH) * 72), (ma.getY(INCH) * 72), (ma.getWidth(INCH) * 72), (ma.getHeight(INCH) * 72));
        }
        if (ms != null) {
            paper.setSize((ms.getX(Size2DSyntax.INCH) * 72), (ms.getY(Size2DSyntax.INCH) * 72));
        }
        format.setPaper(paper);
        OrientationRequested or = (OrientationRequested) printAttributes.get(OrientationRequested.class);
        if (or != null) {
            if (or == OrientationRequested.LANDSCAPE) {
                format.setOrientation(PageFormat.LANDSCAPE);
            } else if (or == OrientationRequested.REVERSE_LANDSCAPE) {
                format.setOrientation(PageFormat.REVERSE_LANDSCAPE);
            } else if (or == OrientationRequested.PORTRAIT) {
                format.setOrientation(PageFormat.PORTRAIT);
            } else if (or == OrientationRequested.REVERSE_PORTRAIT) {
                format.setOrientation(PageFormat.PORTRAIT);
            }
        }
        pageFormat = format;
    }
    return pageFormat;
}
Also used : PageFormat(java.awt.print.PageFormat) MediaPrintableArea(javax.print.attribute.standard.MediaPrintableArea) MediaSize(javax.print.attribute.standard.MediaSize) MediaSizeName(javax.print.attribute.standard.MediaSizeName) Media(javax.print.attribute.standard.Media) Paper(java.awt.print.Paper) OrientationRequested(javax.print.attribute.standard.OrientationRequested) PrintRequestAttributeSet(javax.print.attribute.PrintRequestAttributeSet)

Example 4 with MediaPrintableArea

use of javax.print.attribute.standard.MediaPrintableArea in project jdk8u_jdk by JetBrains.

the class CUPSPrinter method initMedia.

/**
     * Initialize media by translating PPD info to PrintService attributes.
     */
private synchronized void initMedia() {
    if (initialized) {
        return;
    } else {
        initialized = true;
    }
    if (pageSizes == null) {
        return;
    }
    cupsMediaPrintables = new MediaPrintableArea[nPageSizes];
    cupsMediaSNames = new MediaSizeName[nPageSizes];
    cupsCustomMediaSNames = new CustomMediaSizeName[nPageSizes];
    CustomMediaSizeName msn;
    MediaPrintableArea mpa;
    float length, width, x, y, w, h;
    // initialize names and printables
    for (int i = 0; i < nPageSizes; i++) {
        // media width and length
        width = (float) (pageSizes[i * 6] / PRINTER_DPI);
        length = (float) (pageSizes[i * 6 + 1] / PRINTER_DPI);
        // media printable area
        x = (float) (pageSizes[i * 6 + 2] / PRINTER_DPI);
        h = (float) (pageSizes[i * 6 + 3] / PRINTER_DPI);
        w = (float) (pageSizes[i * 6 + 4] / PRINTER_DPI);
        y = (float) (pageSizes[i * 6 + 5] / PRINTER_DPI);
        msn = new CustomMediaSizeName(media[i * 2], media[i * 2 + 1], width, length);
        // add to list of standard MediaSizeNames
        if ((cupsMediaSNames[i] = msn.getStandardMedia()) == null) {
            // add custom if no matching standard media
            cupsMediaSNames[i] = msn;
            // add this new custom msn to MediaSize array
            if ((width > 0.0) && (length > 0.0)) {
                try {
                    new MediaSize(width, length, Size2DSyntax.INCH, msn);
                } catch (IllegalArgumentException e) {
                    /* PDF printer in Linux for Ledger paper causes
                        "IllegalArgumentException: X dimension > Y dimension".
                        We rotate based on IPP spec. */
                    new MediaSize(length, width, Size2DSyntax.INCH, msn);
                }
            }
        }
        // add to list of custom MediaSizeName
        // for internal use of IPPPrintService
        cupsCustomMediaSNames[i] = msn;
        mpa = null;
        try {
            mpa = new MediaPrintableArea(x, y, w, h, MediaPrintableArea.INCH);
        } catch (IllegalArgumentException e) {
            if (width > 0 && length > 0) {
                mpa = new MediaPrintableArea(0, 0, width, length, MediaPrintableArea.INCH);
            }
        }
        cupsMediaPrintables[i] = mpa;
    }
    // initialize trays
    cupsMediaTrays = new MediaTray[nTrays];
    MediaTray mt;
    for (int i = 0; i < nTrays; i++) {
        mt = new CustomMediaTray(media[(nPageSizes + i) * 2], media[(nPageSizes + i) * 2 + 1]);
        cupsMediaTrays[i] = mt;
    }
}
Also used : MediaPrintableArea(javax.print.attribute.standard.MediaPrintableArea) MediaSize(javax.print.attribute.standard.MediaSize) CustomMediaTray(sun.print.CustomMediaTray) MediaTray(javax.print.attribute.standard.MediaTray) CustomMediaTray(sun.print.CustomMediaTray) CustomMediaSizeName(sun.print.CustomMediaSizeName)

Example 5 with MediaPrintableArea

use of javax.print.attribute.standard.MediaPrintableArea in project jdk8u_jdk by JetBrains.

the class UnixPrintService method getAllPrintableAreas.

private MediaPrintableArea[] getAllPrintableAreas() {
    if (mpas == null) {
        Media[] media = (Media[]) getSupportedAttributeValues(Media.class, null, null);
        mpas = new MediaPrintableArea[media.length];
        for (int i = 0; i < mpas.length; i++) {
            if (media[i] instanceof MediaSizeName) {
                MediaSizeName msn = (MediaSizeName) media[i];
                MediaSize mediaSize = MediaSize.getMediaSizeForName(msn);
                if (mediaSize == null) {
                    mpas[i] = (MediaPrintableArea) getDefaultAttributeValue(MediaPrintableArea.class);
                } else {
                    mpas[i] = new MediaPrintableArea(0.25f, 0.25f, mediaSize.getX(MediaSize.INCH) - 0.5f, mediaSize.getY(MediaSize.INCH) - 0.5f, MediaSize.INCH);
                }
            }
        }
    }
    MediaPrintableArea[] mpasCopy = new MediaPrintableArea[mpas.length];
    System.arraycopy(mpas, 0, mpasCopy, 0, mpas.length);
    return mpasCopy;
}
Also used : MediaPrintableArea(javax.print.attribute.standard.MediaPrintableArea) MediaSize(javax.print.attribute.standard.MediaSize) MediaSizeName(javax.print.attribute.standard.MediaSizeName) Media(javax.print.attribute.standard.Media)

Aggregations

MediaPrintableArea (javax.print.attribute.standard.MediaPrintableArea)16 MediaSizeName (javax.print.attribute.standard.MediaSizeName)12 Media (javax.print.attribute.standard.Media)11 OrientationRequested (javax.print.attribute.standard.OrientationRequested)11 MediaSize (javax.print.attribute.standard.MediaSize)10 File (java.io.File)5 Attribute (javax.print.attribute.Attribute)5 Destination (javax.print.attribute.standard.Destination)5 Fidelity (javax.print.attribute.standard.Fidelity)5 JobName (javax.print.attribute.standard.JobName)5 RequestingUserName (javax.print.attribute.standard.RequestingUserName)5 SheetCollate (javax.print.attribute.standard.SheetCollate)5 PageFormat (java.awt.print.PageFormat)4 Paper (java.awt.print.Paper)4 URI (java.net.URI)4 PrintServiceAttribute (javax.print.attribute.PrintServiceAttribute)4 Chromaticity (javax.print.attribute.standard.Chromaticity)4 PageRanges (javax.print.attribute.standard.PageRanges)4 URISyntaxException (java.net.URISyntaxException)3 HashPrintRequestAttributeSet (javax.print.attribute.HashPrintRequestAttributeSet)3