Java Code Examples for javax.print.attribute.standard.OrientationRequested#equals()

The following examples show how to use javax.print.attribute.standard.OrientationRequested#equals() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PrinterJob.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Calculates a <code>PageFormat</code> with values consistent with those
 * supported by the current <code>PrintService</code> for this job
 * (ie the value returned by <code>getPrintService()</code>) and media,
 * printable area and orientation contained in <code>attributes</code>.
 * <p>
 * Calling this method does not update the job.
 * It is useful for clients that have a set of attributes obtained from
 * <code>printDialog(PrintRequestAttributeSet attributes)</code>
 * and need a PageFormat to print a Pageable object.
 * @param attributes a set of printing attributes, for example obtained
 * from calling printDialog. If <code>attributes</code> is null a default
 * PageFormat is returned.
 * @return a <code>PageFormat</code> whose settings conform with
 * those of the current service and the specified attributes.
 * @since 1.6
 */
public PageFormat getPageFormat(PrintRequestAttributeSet attributes) {

    PrintService service = getPrintService();
    PageFormat pf = defaultPage();

    if (service == null || attributes == null) {
        return pf;
    }

    Media media = (Media)attributes.get(Media.class);
    MediaPrintableArea mpa =
        (MediaPrintableArea)attributes.get(MediaPrintableArea.class);
    OrientationRequested orientReq =
       (OrientationRequested)attributes.get(OrientationRequested.class);

    if (media == null && mpa == null && orientReq == null) {
       return pf;
    }
    Paper paper = pf.getPaper();

    /* If there's a media but no media printable area, we can try
     * to retrieve the default value for mpa and use that.
     */
    if (mpa == null && media != null &&
        service.isAttributeCategorySupported(MediaPrintableArea.class)) {
        Object mpaVals =
            service.getSupportedAttributeValues(MediaPrintableArea.class,
                                                null, attributes);
        if (mpaVals instanceof MediaPrintableArea[] &&
            ((MediaPrintableArea[])mpaVals).length > 0) {
            mpa = ((MediaPrintableArea[])mpaVals)[0];
        }
    }

    if (media != null &&
        service.isAttributeValueSupported(media, null, attributes)) {
        if (media instanceof MediaSizeName) {
            MediaSizeName msn = (MediaSizeName)media;
            MediaSize msz = MediaSize.getMediaSizeForName(msn);
            if (msz != null) {
                double inch = 72.0;
                double paperWid = msz.getX(MediaSize.INCH) * inch;
                double paperHgt = msz.getY(MediaSize.INCH) * inch;
                paper.setSize(paperWid, paperHgt);
                if (mpa == null) {
                    paper.setImageableArea(inch, inch,
                                           paperWid-2*inch,
                                           paperHgt-2*inch);
                }
            }
        }
    }

    if (mpa != null &&
        service.isAttributeValueSupported(mpa, null, attributes)) {
        float [] printableArea =
            mpa.getPrintableArea(MediaPrintableArea.INCH);
        for (int i=0; i < printableArea.length; i++) {
            printableArea[i] = printableArea[i]*72.0f;
        }
        paper.setImageableArea(printableArea[0], printableArea[1],
                               printableArea[2], printableArea[3]);
    }

    if (orientReq != null &&
        service.isAttributeValueSupported(orientReq, null, attributes)) {
        int orient;
        if (orientReq.equals(OrientationRequested.REVERSE_LANDSCAPE)) {
            orient = PageFormat.REVERSE_LANDSCAPE;
        } else if (orientReq.equals(OrientationRequested.LANDSCAPE)) {
            orient = PageFormat.LANDSCAPE;
        } else {
            orient = PageFormat.PORTRAIT;
        }
        pf.setOrientation(orient);
    }

    pf.setPaper(paper);
    pf = validatePage(pf);
    return pf;
}
 
Example 2
Source File: PrinterJob.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Calculates a <code>PageFormat</code> with values consistent with those
 * supported by the current <code>PrintService</code> for this job
 * (ie the value returned by <code>getPrintService()</code>) and media,
 * printable area and orientation contained in <code>attributes</code>.
 * <p>
 * Calling this method does not update the job.
 * It is useful for clients that have a set of attributes obtained from
 * <code>printDialog(PrintRequestAttributeSet attributes)</code>
 * and need a PageFormat to print a Pageable object.
 * @param attributes a set of printing attributes, for example obtained
 * from calling printDialog. If <code>attributes</code> is null a default
 * PageFormat is returned.
 * @return a <code>PageFormat</code> whose settings conform with
 * those of the current service and the specified attributes.
 * @since 1.6
 */
public PageFormat getPageFormat(PrintRequestAttributeSet attributes) {

    PrintService service = getPrintService();
    PageFormat pf = defaultPage();

    if (service == null || attributes == null) {
        return pf;
    }

    Media media = (Media)attributes.get(Media.class);
    MediaPrintableArea mpa =
        (MediaPrintableArea)attributes.get(MediaPrintableArea.class);
    OrientationRequested orientReq =
       (OrientationRequested)attributes.get(OrientationRequested.class);

    if (media == null && mpa == null && orientReq == null) {
       return pf;
    }
    Paper paper = pf.getPaper();

    /* If there's a media but no media printable area, we can try
     * to retrieve the default value for mpa and use that.
     */
    if (mpa == null && media != null &&
        service.isAttributeCategorySupported(MediaPrintableArea.class)) {
        Object mpaVals =
            service.getSupportedAttributeValues(MediaPrintableArea.class,
                                                null, attributes);
        if (mpaVals instanceof MediaPrintableArea[] &&
            ((MediaPrintableArea[])mpaVals).length > 0) {
            mpa = ((MediaPrintableArea[])mpaVals)[0];
        }
    }

    if (media != null &&
        service.isAttributeValueSupported(media, null, attributes)) {
        if (media instanceof MediaSizeName) {
            MediaSizeName msn = (MediaSizeName)media;
            MediaSize msz = MediaSize.getMediaSizeForName(msn);
            if (msz != null) {
                double inch = 72.0;
                double paperWid = msz.getX(MediaSize.INCH) * inch;
                double paperHgt = msz.getY(MediaSize.INCH) * inch;
                paper.setSize(paperWid, paperHgt);
                if (mpa == null) {
                    paper.setImageableArea(inch, inch,
                                           paperWid-2*inch,
                                           paperHgt-2*inch);
                }
            }
        }
    }

    if (mpa != null &&
        service.isAttributeValueSupported(mpa, null, attributes)) {
        float [] printableArea =
            mpa.getPrintableArea(MediaPrintableArea.INCH);
        for (int i=0; i < printableArea.length; i++) {
            printableArea[i] = printableArea[i]*72.0f;
        }
        paper.setImageableArea(printableArea[0], printableArea[1],
                               printableArea[2], printableArea[3]);
    }

    if (orientReq != null &&
        service.isAttributeValueSupported(orientReq, null, attributes)) {
        int orient;
        if (orientReq.equals(OrientationRequested.REVERSE_LANDSCAPE)) {
            orient = PageFormat.REVERSE_LANDSCAPE;
        } else if (orientReq.equals(OrientationRequested.LANDSCAPE)) {
            orient = PageFormat.LANDSCAPE;
        } else {
            orient = PageFormat.PORTRAIT;
        }
        pf.setOrientation(orient);
    }

    pf.setPaper(paper);
    pf = validatePage(pf);
    return pf;
}
 
Example 3
Source File: PrinterJob.java    From jdk-1.7-annotated with Apache License 2.0 4 votes vote down vote up
/**
 * Calculates a <code>PageFormat</code> with values consistent with those
 * supported by the current <code>PrintService</code> for this job
 * (ie the value returned by <code>getPrintService()</code>) and media,
 * printable area and orientation contained in <code>attributes</code>.
 * <p>
 * Calling this method does not update the job.
 * It is useful for clients that have a set of attributes obtained from
 * <code>printDialog(PrintRequestAttributeSet attributes)</code>
 * and need a PageFormat to print a Pageable object.
 * @param attributes a set of printing attributes, for example obtained
 * from calling printDialog. If <code>attributes</code> is null a default
 * PageFormat is returned.
 * @return a <code>PageFormat</code> whose settings conform with
 * those of the current service and the specified attributes.
 * @since 1.6
 */
public PageFormat getPageFormat(PrintRequestAttributeSet attributes) {

    PrintService service = getPrintService();
    PageFormat pf = defaultPage();

    if (service == null || attributes == null) {
        return pf;
    }

    Media media = (Media)attributes.get(Media.class);
    MediaPrintableArea mpa =
        (MediaPrintableArea)attributes.get(MediaPrintableArea.class);
    OrientationRequested orientReq =
       (OrientationRequested)attributes.get(OrientationRequested.class);

    if (media == null && mpa == null && orientReq == null) {
       return pf;
    }
    Paper paper = pf.getPaper();

    /* If there's a media but no media printable area, we can try
     * to retrieve the default value for mpa and use that.
     */
    if (mpa == null && media != null &&
        service.isAttributeCategorySupported(MediaPrintableArea.class)) {
        Object mpaVals =
            service.getSupportedAttributeValues(MediaPrintableArea.class,
                                                null, attributes);
        if (mpaVals instanceof MediaPrintableArea[] &&
            ((MediaPrintableArea[])mpaVals).length > 0) {
            mpa = ((MediaPrintableArea[])mpaVals)[0];
        }
    }

    if (media != null &&
        service.isAttributeValueSupported(media, null, attributes)) {
        if (media instanceof MediaSizeName) {
            MediaSizeName msn = (MediaSizeName)media;
            MediaSize msz = MediaSize.getMediaSizeForName(msn);
            if (msz != null) {
                double inch = 72.0;
                double paperWid = msz.getX(MediaSize.INCH) * inch;
                double paperHgt = msz.getY(MediaSize.INCH) * inch;
                paper.setSize(paperWid, paperHgt);
                if (mpa == null) {
                    paper.setImageableArea(inch, inch,
                                           paperWid-2*inch,
                                           paperHgt-2*inch);
                }
            }
        }
    }

    if (mpa != null &&
        service.isAttributeValueSupported(mpa, null, attributes)) {
        float [] printableArea =
            mpa.getPrintableArea(MediaPrintableArea.INCH);
        for (int i=0; i < printableArea.length; i++) {
            printableArea[i] = printableArea[i]*72.0f;
        }
        paper.setImageableArea(printableArea[0], printableArea[1],
                               printableArea[2], printableArea[3]);
    }

    if (orientReq != null &&
        service.isAttributeValueSupported(orientReq, null, attributes)) {
        int orient;
        if (orientReq.equals(OrientationRequested.REVERSE_LANDSCAPE)) {
            orient = PageFormat.REVERSE_LANDSCAPE;
        } else if (orientReq.equals(OrientationRequested.LANDSCAPE)) {
            orient = PageFormat.LANDSCAPE;
        } else {
            orient = PageFormat.PORTRAIT;
        }
        pf.setOrientation(orient);
    }

    pf.setPaper(paper);
    pf = validatePage(pf);
    return pf;
}
 
Example 4
Source File: PrinterJob.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Calculates a <code>PageFormat</code> with values consistent with those
 * supported by the current <code>PrintService</code> for this job
 * (ie the value returned by <code>getPrintService()</code>) and media,
 * printable area and orientation contained in <code>attributes</code>.
 * <p>
 * Calling this method does not update the job.
 * It is useful for clients that have a set of attributes obtained from
 * <code>printDialog(PrintRequestAttributeSet attributes)</code>
 * and need a PageFormat to print a Pageable object.
 * @param attributes a set of printing attributes, for example obtained
 * from calling printDialog. If <code>attributes</code> is null a default
 * PageFormat is returned.
 * @return a <code>PageFormat</code> whose settings conform with
 * those of the current service and the specified attributes.
 * @since 1.6
 */
public PageFormat getPageFormat(PrintRequestAttributeSet attributes) {

    PrintService service = getPrintService();
    PageFormat pf = defaultPage();

    if (service == null || attributes == null) {
        return pf;
    }

    Media media = (Media)attributes.get(Media.class);
    MediaPrintableArea mpa =
        (MediaPrintableArea)attributes.get(MediaPrintableArea.class);
    OrientationRequested orientReq =
       (OrientationRequested)attributes.get(OrientationRequested.class);

    if (media == null && mpa == null && orientReq == null) {
       return pf;
    }
    Paper paper = pf.getPaper();

    /* If there's a media but no media printable area, we can try
     * to retrieve the default value for mpa and use that.
     */
    if (mpa == null && media != null &&
        service.isAttributeCategorySupported(MediaPrintableArea.class)) {
        Object mpaVals =
            service.getSupportedAttributeValues(MediaPrintableArea.class,
                                                null, attributes);
        if (mpaVals instanceof MediaPrintableArea[] &&
            ((MediaPrintableArea[])mpaVals).length > 0) {
            mpa = ((MediaPrintableArea[])mpaVals)[0];
        }
    }

    if (media != null &&
        service.isAttributeValueSupported(media, null, attributes)) {
        if (media instanceof MediaSizeName) {
            MediaSizeName msn = (MediaSizeName)media;
            MediaSize msz = MediaSize.getMediaSizeForName(msn);
            if (msz != null) {
                double inch = 72.0;
                double paperWid = msz.getX(MediaSize.INCH) * inch;
                double paperHgt = msz.getY(MediaSize.INCH) * inch;
                paper.setSize(paperWid, paperHgt);
                if (mpa == null) {
                    paper.setImageableArea(inch, inch,
                                           paperWid-2*inch,
                                           paperHgt-2*inch);
                }
            }
        }
    }

    if (mpa != null &&
        service.isAttributeValueSupported(mpa, null, attributes)) {
        float [] printableArea =
            mpa.getPrintableArea(MediaPrintableArea.INCH);
        for (int i=0; i < printableArea.length; i++) {
            printableArea[i] = printableArea[i]*72.0f;
        }
        paper.setImageableArea(printableArea[0], printableArea[1],
                               printableArea[2], printableArea[3]);
    }

    if (orientReq != null &&
        service.isAttributeValueSupported(orientReq, null, attributes)) {
        int orient;
        if (orientReq.equals(OrientationRequested.REVERSE_LANDSCAPE)) {
            orient = PageFormat.REVERSE_LANDSCAPE;
        } else if (orientReq.equals(OrientationRequested.LANDSCAPE)) {
            orient = PageFormat.LANDSCAPE;
        } else {
            orient = PageFormat.PORTRAIT;
        }
        pf.setOrientation(orient);
    }

    pf.setPaper(paper);
    pf = validatePage(pf);
    return pf;
}
 
Example 5
Source File: PrinterJob.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Calculates a <code>PageFormat</code> with values consistent with those
 * supported by the current <code>PrintService</code> for this job
 * (ie the value returned by <code>getPrintService()</code>) and media,
 * printable area and orientation contained in <code>attributes</code>.
 * <p>
 * Calling this method does not update the job.
 * It is useful for clients that have a set of attributes obtained from
 * <code>printDialog(PrintRequestAttributeSet attributes)</code>
 * and need a PageFormat to print a Pageable object.
 * @param attributes a set of printing attributes, for example obtained
 * from calling printDialog. If <code>attributes</code> is null a default
 * PageFormat is returned.
 * @return a <code>PageFormat</code> whose settings conform with
 * those of the current service and the specified attributes.
 * @since 1.6
 */
public PageFormat getPageFormat(PrintRequestAttributeSet attributes) {

    PrintService service = getPrintService();
    PageFormat pf = defaultPage();

    if (service == null || attributes == null) {
        return pf;
    }

    Media media = (Media)attributes.get(Media.class);
    MediaPrintableArea mpa =
        (MediaPrintableArea)attributes.get(MediaPrintableArea.class);
    OrientationRequested orientReq =
       (OrientationRequested)attributes.get(OrientationRequested.class);

    if (media == null && mpa == null && orientReq == null) {
       return pf;
    }
    Paper paper = pf.getPaper();

    /* If there's a media but no media printable area, we can try
     * to retrieve the default value for mpa and use that.
     */
    if (mpa == null && media != null &&
        service.isAttributeCategorySupported(MediaPrintableArea.class)) {
        Object mpaVals =
            service.getSupportedAttributeValues(MediaPrintableArea.class,
                                                null, attributes);
        if (mpaVals instanceof MediaPrintableArea[] &&
            ((MediaPrintableArea[])mpaVals).length > 0) {
            mpa = ((MediaPrintableArea[])mpaVals)[0];
        }
    }

    if (media != null &&
        service.isAttributeValueSupported(media, null, attributes)) {
        if (media instanceof MediaSizeName) {
            MediaSizeName msn = (MediaSizeName)media;
            MediaSize msz = MediaSize.getMediaSizeForName(msn);
            if (msz != null) {
                double inch = 72.0;
                double paperWid = msz.getX(MediaSize.INCH) * inch;
                double paperHgt = msz.getY(MediaSize.INCH) * inch;
                paper.setSize(paperWid, paperHgt);
                if (mpa == null) {
                    paper.setImageableArea(inch, inch,
                                           paperWid-2*inch,
                                           paperHgt-2*inch);
                }
            }
        }
    }

    if (mpa != null &&
        service.isAttributeValueSupported(mpa, null, attributes)) {
        float [] printableArea =
            mpa.getPrintableArea(MediaPrintableArea.INCH);
        for (int i=0; i < printableArea.length; i++) {
            printableArea[i] = printableArea[i]*72.0f;
        }
        paper.setImageableArea(printableArea[0], printableArea[1],
                               printableArea[2], printableArea[3]);
    }

    if (orientReq != null &&
        service.isAttributeValueSupported(orientReq, null, attributes)) {
        int orient;
        if (orientReq.equals(OrientationRequested.REVERSE_LANDSCAPE)) {
            orient = PageFormat.REVERSE_LANDSCAPE;
        } else if (orientReq.equals(OrientationRequested.LANDSCAPE)) {
            orient = PageFormat.LANDSCAPE;
        } else {
            orient = PageFormat.PORTRAIT;
        }
        pf.setOrientation(orient);
    }

    pf.setPaper(paper);
    pf = validatePage(pf);
    return pf;
}
 
Example 6
Source File: PrinterJob.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Calculates a <code>PageFormat</code> with values consistent with those
 * supported by the current <code>PrintService</code> for this job
 * (ie the value returned by <code>getPrintService()</code>) and media,
 * printable area and orientation contained in <code>attributes</code>.
 * <p>
 * Calling this method does not update the job.
 * It is useful for clients that have a set of attributes obtained from
 * <code>printDialog(PrintRequestAttributeSet attributes)</code>
 * and need a PageFormat to print a Pageable object.
 * @param attributes a set of printing attributes, for example obtained
 * from calling printDialog. If <code>attributes</code> is null a default
 * PageFormat is returned.
 * @return a <code>PageFormat</code> whose settings conform with
 * those of the current service and the specified attributes.
 * @since 1.6
 */
public PageFormat getPageFormat(PrintRequestAttributeSet attributes) {

    PrintService service = getPrintService();
    PageFormat pf = defaultPage();

    if (service == null || attributes == null) {
        return pf;
    }

    Media media = (Media)attributes.get(Media.class);
    MediaPrintableArea mpa =
        (MediaPrintableArea)attributes.get(MediaPrintableArea.class);
    OrientationRequested orientReq =
       (OrientationRequested)attributes.get(OrientationRequested.class);

    if (media == null && mpa == null && orientReq == null) {
       return pf;
    }
    Paper paper = pf.getPaper();

    /* If there's a media but no media printable area, we can try
     * to retrieve the default value for mpa and use that.
     */
    if (mpa == null && media != null &&
        service.isAttributeCategorySupported(MediaPrintableArea.class)) {
        Object mpaVals =
            service.getSupportedAttributeValues(MediaPrintableArea.class,
                                                null, attributes);
        if (mpaVals instanceof MediaPrintableArea[] &&
            ((MediaPrintableArea[])mpaVals).length > 0) {
            mpa = ((MediaPrintableArea[])mpaVals)[0];
        }
    }

    if (media != null &&
        service.isAttributeValueSupported(media, null, attributes)) {
        if (media instanceof MediaSizeName) {
            MediaSizeName msn = (MediaSizeName)media;
            MediaSize msz = MediaSize.getMediaSizeForName(msn);
            if (msz != null) {
                double inch = 72.0;
                double paperWid = msz.getX(MediaSize.INCH) * inch;
                double paperHgt = msz.getY(MediaSize.INCH) * inch;
                paper.setSize(paperWid, paperHgt);
                if (mpa == null) {
                    paper.setImageableArea(inch, inch,
                                           paperWid-2*inch,
                                           paperHgt-2*inch);
                }
            }
        }
    }

    if (mpa != null &&
        service.isAttributeValueSupported(mpa, null, attributes)) {
        float [] printableArea =
            mpa.getPrintableArea(MediaPrintableArea.INCH);
        for (int i=0; i < printableArea.length; i++) {
            printableArea[i] = printableArea[i]*72.0f;
        }
        paper.setImageableArea(printableArea[0], printableArea[1],
                               printableArea[2], printableArea[3]);
    }

    if (orientReq != null &&
        service.isAttributeValueSupported(orientReq, null, attributes)) {
        int orient;
        if (orientReq.equals(OrientationRequested.REVERSE_LANDSCAPE)) {
            orient = PageFormat.REVERSE_LANDSCAPE;
        } else if (orientReq.equals(OrientationRequested.LANDSCAPE)) {
            orient = PageFormat.LANDSCAPE;
        } else {
            orient = PageFormat.PORTRAIT;
        }
        pf.setOrientation(orient);
    }

    pf.setPaper(paper);
    pf = validatePage(pf);
    return pf;
}
 
Example 7
Source File: PrinterJob.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Calculates a <code>PageFormat</code> with values consistent with those
 * supported by the current <code>PrintService</code> for this job
 * (ie the value returned by <code>getPrintService()</code>) and media,
 * printable area and orientation contained in <code>attributes</code>.
 * <p>
 * Calling this method does not update the job.
 * It is useful for clients that have a set of attributes obtained from
 * <code>printDialog(PrintRequestAttributeSet attributes)</code>
 * and need a PageFormat to print a Pageable object.
 * @param attributes a set of printing attributes, for example obtained
 * from calling printDialog. If <code>attributes</code> is null a default
 * PageFormat is returned.
 * @return a <code>PageFormat</code> whose settings conform with
 * those of the current service and the specified attributes.
 * @since 1.6
 */
public PageFormat getPageFormat(PrintRequestAttributeSet attributes) {

    PrintService service = getPrintService();
    PageFormat pf = defaultPage();

    if (service == null || attributes == null) {
        return pf;
    }

    Media media = (Media)attributes.get(Media.class);
    MediaPrintableArea mpa =
        (MediaPrintableArea)attributes.get(MediaPrintableArea.class);
    OrientationRequested orientReq =
       (OrientationRequested)attributes.get(OrientationRequested.class);

    if (media == null && mpa == null && orientReq == null) {
       return pf;
    }
    Paper paper = pf.getPaper();

    /* If there's a media but no media printable area, we can try
     * to retrieve the default value for mpa and use that.
     */
    if (mpa == null && media != null &&
        service.isAttributeCategorySupported(MediaPrintableArea.class)) {
        Object mpaVals =
            service.getSupportedAttributeValues(MediaPrintableArea.class,
                                                null, attributes);
        if (mpaVals instanceof MediaPrintableArea[] &&
            ((MediaPrintableArea[])mpaVals).length > 0) {
            mpa = ((MediaPrintableArea[])mpaVals)[0];
        }
    }

    if (media != null &&
        service.isAttributeValueSupported(media, null, attributes)) {
        if (media instanceof MediaSizeName) {
            MediaSizeName msn = (MediaSizeName)media;
            MediaSize msz = MediaSize.getMediaSizeForName(msn);
            if (msz != null) {
                double inch = 72.0;
                double paperWid = msz.getX(MediaSize.INCH) * inch;
                double paperHgt = msz.getY(MediaSize.INCH) * inch;
                paper.setSize(paperWid, paperHgt);
                if (mpa == null) {
                    paper.setImageableArea(inch, inch,
                                           paperWid-2*inch,
                                           paperHgt-2*inch);
                }
            }
        }
    }

    if (mpa != null &&
        service.isAttributeValueSupported(mpa, null, attributes)) {
        float [] printableArea =
            mpa.getPrintableArea(MediaPrintableArea.INCH);
        for (int i=0; i < printableArea.length; i++) {
            printableArea[i] = printableArea[i]*72.0f;
        }
        paper.setImageableArea(printableArea[0], printableArea[1],
                               printableArea[2], printableArea[3]);
    }

    if (orientReq != null &&
        service.isAttributeValueSupported(orientReq, null, attributes)) {
        int orient;
        if (orientReq.equals(OrientationRequested.REVERSE_LANDSCAPE)) {
            orient = PageFormat.REVERSE_LANDSCAPE;
        } else if (orientReq.equals(OrientationRequested.LANDSCAPE)) {
            orient = PageFormat.LANDSCAPE;
        } else {
            orient = PageFormat.PORTRAIT;
        }
        pf.setOrientation(orient);
    }

    pf.setPaper(paper);
    pf = validatePage(pf);
    return pf;
}
 
Example 8
Source File: PrinterJob.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Calculates a <code>PageFormat</code> with values consistent with those
 * supported by the current <code>PrintService</code> for this job
 * (ie the value returned by <code>getPrintService()</code>) and media,
 * printable area and orientation contained in <code>attributes</code>.
 * <p>
 * Calling this method does not update the job.
 * It is useful for clients that have a set of attributes obtained from
 * <code>printDialog(PrintRequestAttributeSet attributes)</code>
 * and need a PageFormat to print a Pageable object.
 * @param attributes a set of printing attributes, for example obtained
 * from calling printDialog. If <code>attributes</code> is null a default
 * PageFormat is returned.
 * @return a <code>PageFormat</code> whose settings conform with
 * those of the current service and the specified attributes.
 * @since 1.6
 */
public PageFormat getPageFormat(PrintRequestAttributeSet attributes) {

    PrintService service = getPrintService();
    PageFormat pf = defaultPage();

    if (service == null || attributes == null) {
        return pf;
    }

    Media media = (Media)attributes.get(Media.class);
    MediaPrintableArea mpa =
        (MediaPrintableArea)attributes.get(MediaPrintableArea.class);
    OrientationRequested orientReq =
       (OrientationRequested)attributes.get(OrientationRequested.class);

    if (media == null && mpa == null && orientReq == null) {
       return pf;
    }
    Paper paper = pf.getPaper();

    /* If there's a media but no media printable area, we can try
     * to retrieve the default value for mpa and use that.
     */
    if (mpa == null && media != null &&
        service.isAttributeCategorySupported(MediaPrintableArea.class)) {
        Object mpaVals =
            service.getSupportedAttributeValues(MediaPrintableArea.class,
                                                null, attributes);
        if (mpaVals instanceof MediaPrintableArea[] &&
            ((MediaPrintableArea[])mpaVals).length > 0) {
            mpa = ((MediaPrintableArea[])mpaVals)[0];
        }
    }

    if (media != null &&
        service.isAttributeValueSupported(media, null, attributes)) {
        if (media instanceof MediaSizeName) {
            MediaSizeName msn = (MediaSizeName)media;
            MediaSize msz = MediaSize.getMediaSizeForName(msn);
            if (msz != null) {
                double inch = 72.0;
                double paperWid = msz.getX(MediaSize.INCH) * inch;
                double paperHgt = msz.getY(MediaSize.INCH) * inch;
                paper.setSize(paperWid, paperHgt);
                if (mpa == null) {
                    paper.setImageableArea(inch, inch,
                                           paperWid-2*inch,
                                           paperHgt-2*inch);
                }
            }
        }
    }

    if (mpa != null &&
        service.isAttributeValueSupported(mpa, null, attributes)) {
        float [] printableArea =
            mpa.getPrintableArea(MediaPrintableArea.INCH);
        for (int i=0; i < printableArea.length; i++) {
            printableArea[i] = printableArea[i]*72.0f;
        }
        paper.setImageableArea(printableArea[0], printableArea[1],
                               printableArea[2], printableArea[3]);
    }

    if (orientReq != null &&
        service.isAttributeValueSupported(orientReq, null, attributes)) {
        int orient;
        if (orientReq.equals(OrientationRequested.REVERSE_LANDSCAPE)) {
            orient = PageFormat.REVERSE_LANDSCAPE;
        } else if (orientReq.equals(OrientationRequested.LANDSCAPE)) {
            orient = PageFormat.LANDSCAPE;
        } else {
            orient = PageFormat.PORTRAIT;
        }
        pf.setOrientation(orient);
    }

    pf.setPaper(paper);
    pf = validatePage(pf);
    return pf;
}
 
Example 9
Source File: PrinterJob.java    From Java8CN with Apache License 2.0 4 votes vote down vote up
/**
 * Calculates a <code>PageFormat</code> with values consistent with those
 * supported by the current <code>PrintService</code> for this job
 * (ie the value returned by <code>getPrintService()</code>) and media,
 * printable area and orientation contained in <code>attributes</code>.
 * <p>
 * Calling this method does not update the job.
 * It is useful for clients that have a set of attributes obtained from
 * <code>printDialog(PrintRequestAttributeSet attributes)</code>
 * and need a PageFormat to print a Pageable object.
 * @param attributes a set of printing attributes, for example obtained
 * from calling printDialog. If <code>attributes</code> is null a default
 * PageFormat is returned.
 * @return a <code>PageFormat</code> whose settings conform with
 * those of the current service and the specified attributes.
 * @since 1.6
 */
public PageFormat getPageFormat(PrintRequestAttributeSet attributes) {

    PrintService service = getPrintService();
    PageFormat pf = defaultPage();

    if (service == null || attributes == null) {
        return pf;
    }

    Media media = (Media)attributes.get(Media.class);
    MediaPrintableArea mpa =
        (MediaPrintableArea)attributes.get(MediaPrintableArea.class);
    OrientationRequested orientReq =
       (OrientationRequested)attributes.get(OrientationRequested.class);

    if (media == null && mpa == null && orientReq == null) {
       return pf;
    }
    Paper paper = pf.getPaper();

    /* If there's a media but no media printable area, we can try
     * to retrieve the default value for mpa and use that.
     */
    if (mpa == null && media != null &&
        service.isAttributeCategorySupported(MediaPrintableArea.class)) {
        Object mpaVals =
            service.getSupportedAttributeValues(MediaPrintableArea.class,
                                                null, attributes);
        if (mpaVals instanceof MediaPrintableArea[] &&
            ((MediaPrintableArea[])mpaVals).length > 0) {
            mpa = ((MediaPrintableArea[])mpaVals)[0];
        }
    }

    if (media != null &&
        service.isAttributeValueSupported(media, null, attributes)) {
        if (media instanceof MediaSizeName) {
            MediaSizeName msn = (MediaSizeName)media;
            MediaSize msz = MediaSize.getMediaSizeForName(msn);
            if (msz != null) {
                double inch = 72.0;
                double paperWid = msz.getX(MediaSize.INCH) * inch;
                double paperHgt = msz.getY(MediaSize.INCH) * inch;
                paper.setSize(paperWid, paperHgt);
                if (mpa == null) {
                    paper.setImageableArea(inch, inch,
                                           paperWid-2*inch,
                                           paperHgt-2*inch);
                }
            }
        }
    }

    if (mpa != null &&
        service.isAttributeValueSupported(mpa, null, attributes)) {
        float [] printableArea =
            mpa.getPrintableArea(MediaPrintableArea.INCH);
        for (int i=0; i < printableArea.length; i++) {
            printableArea[i] = printableArea[i]*72.0f;
        }
        paper.setImageableArea(printableArea[0], printableArea[1],
                               printableArea[2], printableArea[3]);
    }

    if (orientReq != null &&
        service.isAttributeValueSupported(orientReq, null, attributes)) {
        int orient;
        if (orientReq.equals(OrientationRequested.REVERSE_LANDSCAPE)) {
            orient = PageFormat.REVERSE_LANDSCAPE;
        } else if (orientReq.equals(OrientationRequested.LANDSCAPE)) {
            orient = PageFormat.LANDSCAPE;
        } else {
            orient = PageFormat.PORTRAIT;
        }
        pf.setOrientation(orient);
    }

    pf.setPaper(paper);
    pf = validatePage(pf);
    return pf;
}
 
Example 10
Source File: PrinterJob.java    From jdk1.8-source-analysis with Apache License 2.0 4 votes vote down vote up
/**
 * Calculates a <code>PageFormat</code> with values consistent with those
 * supported by the current <code>PrintService</code> for this job
 * (ie the value returned by <code>getPrintService()</code>) and media,
 * printable area and orientation contained in <code>attributes</code>.
 * <p>
 * Calling this method does not update the job.
 * It is useful for clients that have a set of attributes obtained from
 * <code>printDialog(PrintRequestAttributeSet attributes)</code>
 * and need a PageFormat to print a Pageable object.
 * @param attributes a set of printing attributes, for example obtained
 * from calling printDialog. If <code>attributes</code> is null a default
 * PageFormat is returned.
 * @return a <code>PageFormat</code> whose settings conform with
 * those of the current service and the specified attributes.
 * @since 1.6
 */
public PageFormat getPageFormat(PrintRequestAttributeSet attributes) {

    PrintService service = getPrintService();
    PageFormat pf = defaultPage();

    if (service == null || attributes == null) {
        return pf;
    }

    Media media = (Media)attributes.get(Media.class);
    MediaPrintableArea mpa =
        (MediaPrintableArea)attributes.get(MediaPrintableArea.class);
    OrientationRequested orientReq =
       (OrientationRequested)attributes.get(OrientationRequested.class);

    if (media == null && mpa == null && orientReq == null) {
       return pf;
    }
    Paper paper = pf.getPaper();

    /* If there's a media but no media printable area, we can try
     * to retrieve the default value for mpa and use that.
     */
    if (mpa == null && media != null &&
        service.isAttributeCategorySupported(MediaPrintableArea.class)) {
        Object mpaVals =
            service.getSupportedAttributeValues(MediaPrintableArea.class,
                                                null, attributes);
        if (mpaVals instanceof MediaPrintableArea[] &&
            ((MediaPrintableArea[])mpaVals).length > 0) {
            mpa = ((MediaPrintableArea[])mpaVals)[0];
        }
    }

    if (media != null &&
        service.isAttributeValueSupported(media, null, attributes)) {
        if (media instanceof MediaSizeName) {
            MediaSizeName msn = (MediaSizeName)media;
            MediaSize msz = MediaSize.getMediaSizeForName(msn);
            if (msz != null) {
                double inch = 72.0;
                double paperWid = msz.getX(MediaSize.INCH) * inch;
                double paperHgt = msz.getY(MediaSize.INCH) * inch;
                paper.setSize(paperWid, paperHgt);
                if (mpa == null) {
                    paper.setImageableArea(inch, inch,
                                           paperWid-2*inch,
                                           paperHgt-2*inch);
                }
            }
        }
    }

    if (mpa != null &&
        service.isAttributeValueSupported(mpa, null, attributes)) {
        float [] printableArea =
            mpa.getPrintableArea(MediaPrintableArea.INCH);
        for (int i=0; i < printableArea.length; i++) {
            printableArea[i] = printableArea[i]*72.0f;
        }
        paper.setImageableArea(printableArea[0], printableArea[1],
                               printableArea[2], printableArea[3]);
    }

    if (orientReq != null &&
        service.isAttributeValueSupported(orientReq, null, attributes)) {
        int orient;
        if (orientReq.equals(OrientationRequested.REVERSE_LANDSCAPE)) {
            orient = PageFormat.REVERSE_LANDSCAPE;
        } else if (orientReq.equals(OrientationRequested.LANDSCAPE)) {
            orient = PageFormat.LANDSCAPE;
        } else {
            orient = PageFormat.PORTRAIT;
        }
        pf.setOrientation(orient);
    }

    pf.setPaper(paper);
    pf = validatePage(pf);
    return pf;
}
 
Example 11
Source File: PrinterJob.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Calculates a {@code PageFormat} with values consistent with those
 * supported by the current {@code PrintService} for this job
 * (ie the value returned by {@code getPrintService()}) and media,
 * printable area and orientation contained in {@code attributes}.
 * <p>
 * Calling this method does not update the job.
 * It is useful for clients that have a set of attributes obtained from
 * {@code printDialog(PrintRequestAttributeSet attributes)}
 * and need a PageFormat to print a Pageable object.
 * @param attributes a set of printing attributes, for example obtained
 * from calling printDialog. If {@code attributes} is null a default
 * PageFormat is returned.
 * @return a {@code PageFormat} whose settings conform with
 * those of the current service and the specified attributes.
 * @since 1.6
 */
public PageFormat getPageFormat(PrintRequestAttributeSet attributes) {

    PrintService service = getPrintService();
    PageFormat pf = defaultPage();

    if (service == null || attributes == null) {
        return pf;
    }

    Media media = (Media)attributes.get(Media.class);
    MediaPrintableArea mpa =
        (MediaPrintableArea)attributes.get(MediaPrintableArea.class);
    OrientationRequested orientReq =
       (OrientationRequested)attributes.get(OrientationRequested.class);

    if (media == null && mpa == null && orientReq == null) {
       return pf;
    }
    Paper paper = pf.getPaper();

    /* If there's a media but no media printable area, we can try
     * to retrieve the default value for mpa and use that.
     */
    if (mpa == null && media != null &&
        service.isAttributeCategorySupported(MediaPrintableArea.class)) {
        Object mpaVals =
            service.getSupportedAttributeValues(MediaPrintableArea.class,
                                                null, attributes);
        if (mpaVals instanceof MediaPrintableArea[] &&
            ((MediaPrintableArea[])mpaVals).length > 0) {
            mpa = ((MediaPrintableArea[])mpaVals)[0];
        }
    }

    if (media != null &&
        service.isAttributeValueSupported(media, null, attributes)) {
        if (media instanceof MediaSizeName) {
            MediaSizeName msn = (MediaSizeName)media;
            MediaSize msz = MediaSize.getMediaSizeForName(msn);
            if (msz != null) {
                double inch = 72.0;
                double paperWid = msz.getX(MediaSize.INCH) * inch;
                double paperHgt = msz.getY(MediaSize.INCH) * inch;
                paper.setSize(paperWid, paperHgt);
                if (mpa == null) {
                    paper.setImageableArea(inch, inch,
                                           paperWid-2*inch,
                                           paperHgt-2*inch);
                }
            }
        }
    }

    if (mpa != null &&
        service.isAttributeValueSupported(mpa, null, attributes)) {
        float [] printableArea =
            mpa.getPrintableArea(MediaPrintableArea.INCH);
        for (int i=0; i < printableArea.length; i++) {
            printableArea[i] = printableArea[i]*72.0f;
        }
        paper.setImageableArea(printableArea[0], printableArea[1],
                               printableArea[2], printableArea[3]);
    }

    if (orientReq != null &&
        service.isAttributeValueSupported(orientReq, null, attributes)) {
        int orient;
        if (orientReq.equals(OrientationRequested.REVERSE_LANDSCAPE)) {
            orient = PageFormat.REVERSE_LANDSCAPE;
        } else if (orientReq.equals(OrientationRequested.LANDSCAPE)) {
            orient = PageFormat.LANDSCAPE;
        } else {
            orient = PageFormat.PORTRAIT;
        }
        pf.setOrientation(orient);
    }

    pf.setPaper(paper);
    pf = validatePage(pf);
    return pf;
}
 
Example 12
Source File: PrinterJob.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
/**
 * Calculates a {@code PageFormat} with values consistent with those
 * supported by the current {@code PrintService} for this job
 * (ie the value returned by {@code getPrintService()}) and media,
 * printable area and orientation contained in {@code attributes}.
 * <p>
 * Calling this method does not update the job.
 * It is useful for clients that have a set of attributes obtained from
 * {@code printDialog(PrintRequestAttributeSet attributes)}
 * and need a PageFormat to print a Pageable object.
 * @param attributes a set of printing attributes, for example obtained
 * from calling printDialog. If {@code attributes} is null a default
 * PageFormat is returned.
 * @return a {@code PageFormat} whose settings conform with
 * those of the current service and the specified attributes.
 * @since 1.6
 */
public PageFormat getPageFormat(PrintRequestAttributeSet attributes) {

    PrintService service = getPrintService();
    PageFormat pf = defaultPage();

    if (service == null || attributes == null) {
        return pf;
    }

    Media media = (Media)attributes.get(Media.class);
    MediaPrintableArea mpa =
        (MediaPrintableArea)attributes.get(MediaPrintableArea.class);
    OrientationRequested orientReq =
       (OrientationRequested)attributes.get(OrientationRequested.class);

    if (media == null && mpa == null && orientReq == null) {
       return pf;
    }
    Paper paper = pf.getPaper();

    /* If there's a media but no media printable area, we can try
     * to retrieve the default value for mpa and use that.
     */
    if (mpa == null && media != null &&
        service.isAttributeCategorySupported(MediaPrintableArea.class)) {
        Object mpaVals =
            service.getSupportedAttributeValues(MediaPrintableArea.class,
                                                null, attributes);
        if (mpaVals instanceof MediaPrintableArea[] &&
            ((MediaPrintableArea[])mpaVals).length > 0) {
            mpa = ((MediaPrintableArea[])mpaVals)[0];
        }
    }

    if (media != null &&
        service.isAttributeValueSupported(media, null, attributes)) {
        if (media instanceof MediaSizeName) {
            MediaSizeName msn = (MediaSizeName)media;
            MediaSize msz = MediaSize.getMediaSizeForName(msn);
            if (msz != null) {
                double inch = 72.0;
                double paperWid = msz.getX(MediaSize.INCH) * inch;
                double paperHgt = msz.getY(MediaSize.INCH) * inch;
                paper.setSize(paperWid, paperHgt);
                if (mpa == null) {
                    paper.setImageableArea(inch, inch,
                                           paperWid-2*inch,
                                           paperHgt-2*inch);
                }
            }
        }
    }

    if (mpa != null &&
        service.isAttributeValueSupported(mpa, null, attributes)) {
        float [] printableArea =
            mpa.getPrintableArea(MediaPrintableArea.INCH);
        for (int i=0; i < printableArea.length; i++) {
            printableArea[i] = printableArea[i]*72.0f;
        }
        paper.setImageableArea(printableArea[0], printableArea[1],
                               printableArea[2], printableArea[3]);
    }

    if (orientReq != null &&
        service.isAttributeValueSupported(orientReq, null, attributes)) {
        int orient;
        if (orientReq.equals(OrientationRequested.REVERSE_LANDSCAPE)) {
            orient = PageFormat.REVERSE_LANDSCAPE;
        } else if (orientReq.equals(OrientationRequested.LANDSCAPE)) {
            orient = PageFormat.LANDSCAPE;
        } else {
            orient = PageFormat.PORTRAIT;
        }
        pf.setOrientation(orient);
    }

    pf.setPaper(paper);
    pf = validatePage(pf);
    return pf;
}
 
Example 13
Source File: PrinterJob.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Calculates a <code>PageFormat</code> with values consistent with those
 * supported by the current <code>PrintService</code> for this job
 * (ie the value returned by <code>getPrintService()</code>) and media,
 * printable area and orientation contained in <code>attributes</code>.
 * <p>
 * Calling this method does not update the job.
 * It is useful for clients that have a set of attributes obtained from
 * <code>printDialog(PrintRequestAttributeSet attributes)</code>
 * and need a PageFormat to print a Pageable object.
 * @param attributes a set of printing attributes, for example obtained
 * from calling printDialog. If <code>attributes</code> is null a default
 * PageFormat is returned.
 * @return a <code>PageFormat</code> whose settings conform with
 * those of the current service and the specified attributes.
 * @since 1.6
 */
public PageFormat getPageFormat(PrintRequestAttributeSet attributes) {

    PrintService service = getPrintService();
    PageFormat pf = defaultPage();

    if (service == null || attributes == null) {
        return pf;
    }

    Media media = (Media)attributes.get(Media.class);
    MediaPrintableArea mpa =
        (MediaPrintableArea)attributes.get(MediaPrintableArea.class);
    OrientationRequested orientReq =
       (OrientationRequested)attributes.get(OrientationRequested.class);

    if (media == null && mpa == null && orientReq == null) {
       return pf;
    }
    Paper paper = pf.getPaper();

    /* If there's a media but no media printable area, we can try
     * to retrieve the default value for mpa and use that.
     */
    if (mpa == null && media != null &&
        service.isAttributeCategorySupported(MediaPrintableArea.class)) {
        Object mpaVals =
            service.getSupportedAttributeValues(MediaPrintableArea.class,
                                                null, attributes);
        if (mpaVals instanceof MediaPrintableArea[] &&
            ((MediaPrintableArea[])mpaVals).length > 0) {
            mpa = ((MediaPrintableArea[])mpaVals)[0];
        }
    }

    if (media != null &&
        service.isAttributeValueSupported(media, null, attributes)) {
        if (media instanceof MediaSizeName) {
            MediaSizeName msn = (MediaSizeName)media;
            MediaSize msz = MediaSize.getMediaSizeForName(msn);
            if (msz != null) {
                double inch = 72.0;
                double paperWid = msz.getX(MediaSize.INCH) * inch;
                double paperHgt = msz.getY(MediaSize.INCH) * inch;
                paper.setSize(paperWid, paperHgt);
                if (mpa == null) {
                    paper.setImageableArea(inch, inch,
                                           paperWid-2*inch,
                                           paperHgt-2*inch);
                }
            }
        }
    }

    if (mpa != null &&
        service.isAttributeValueSupported(mpa, null, attributes)) {
        float [] printableArea =
            mpa.getPrintableArea(MediaPrintableArea.INCH);
        for (int i=0; i < printableArea.length; i++) {
            printableArea[i] = printableArea[i]*72.0f;
        }
        paper.setImageableArea(printableArea[0], printableArea[1],
                               printableArea[2], printableArea[3]);
    }

    if (orientReq != null &&
        service.isAttributeValueSupported(orientReq, null, attributes)) {
        int orient;
        if (orientReq.equals(OrientationRequested.REVERSE_LANDSCAPE)) {
            orient = PageFormat.REVERSE_LANDSCAPE;
        } else if (orientReq.equals(OrientationRequested.LANDSCAPE)) {
            orient = PageFormat.LANDSCAPE;
        } else {
            orient = PageFormat.PORTRAIT;
        }
        pf.setOrientation(orient);
    }

    pf.setPaper(paper);
    pf = validatePage(pf);
    return pf;
}
 
Example 14
Source File: PrinterJob.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Calculates a <code>PageFormat</code> with values consistent with those
 * supported by the current <code>PrintService</code> for this job
 * (ie the value returned by <code>getPrintService()</code>) and media,
 * printable area and orientation contained in <code>attributes</code>.
 * <p>
 * Calling this method does not update the job.
 * It is useful for clients that have a set of attributes obtained from
 * <code>printDialog(PrintRequestAttributeSet attributes)</code>
 * and need a PageFormat to print a Pageable object.
 * @param attributes a set of printing attributes, for example obtained
 * from calling printDialog. If <code>attributes</code> is null a default
 * PageFormat is returned.
 * @return a <code>PageFormat</code> whose settings conform with
 * those of the current service and the specified attributes.
 * @since 1.6
 */
public PageFormat getPageFormat(PrintRequestAttributeSet attributes) {

    PrintService service = getPrintService();
    PageFormat pf = defaultPage();

    if (service == null || attributes == null) {
        return pf;
    }

    Media media = (Media)attributes.get(Media.class);
    MediaPrintableArea mpa =
        (MediaPrintableArea)attributes.get(MediaPrintableArea.class);
    OrientationRequested orientReq =
       (OrientationRequested)attributes.get(OrientationRequested.class);

    if (media == null && mpa == null && orientReq == null) {
       return pf;
    }
    Paper paper = pf.getPaper();

    /* If there's a media but no media printable area, we can try
     * to retrieve the default value for mpa and use that.
     */
    if (mpa == null && media != null &&
        service.isAttributeCategorySupported(MediaPrintableArea.class)) {
        Object mpaVals =
            service.getSupportedAttributeValues(MediaPrintableArea.class,
                                                null, attributes);
        if (mpaVals instanceof MediaPrintableArea[] &&
            ((MediaPrintableArea[])mpaVals).length > 0) {
            mpa = ((MediaPrintableArea[])mpaVals)[0];
        }
    }

    if (media != null &&
        service.isAttributeValueSupported(media, null, attributes)) {
        if (media instanceof MediaSizeName) {
            MediaSizeName msn = (MediaSizeName)media;
            MediaSize msz = MediaSize.getMediaSizeForName(msn);
            if (msz != null) {
                double inch = 72.0;
                double paperWid = msz.getX(MediaSize.INCH) * inch;
                double paperHgt = msz.getY(MediaSize.INCH) * inch;
                paper.setSize(paperWid, paperHgt);
                if (mpa == null) {
                    paper.setImageableArea(inch, inch,
                                           paperWid-2*inch,
                                           paperHgt-2*inch);
                }
            }
        }
    }

    if (mpa != null &&
        service.isAttributeValueSupported(mpa, null, attributes)) {
        float [] printableArea =
            mpa.getPrintableArea(MediaPrintableArea.INCH);
        for (int i=0; i < printableArea.length; i++) {
            printableArea[i] = printableArea[i]*72.0f;
        }
        paper.setImageableArea(printableArea[0], printableArea[1],
                               printableArea[2], printableArea[3]);
    }

    if (orientReq != null &&
        service.isAttributeValueSupported(orientReq, null, attributes)) {
        int orient;
        if (orientReq.equals(OrientationRequested.REVERSE_LANDSCAPE)) {
            orient = PageFormat.REVERSE_LANDSCAPE;
        } else if (orientReq.equals(OrientationRequested.LANDSCAPE)) {
            orient = PageFormat.LANDSCAPE;
        } else {
            orient = PageFormat.PORTRAIT;
        }
        pf.setOrientation(orient);
    }

    pf.setPaper(paper);
    pf = validatePage(pf);
    return pf;
}
 
Example 15
Source File: PrinterJob.java    From JDKSourceCode1.8 with MIT License 4 votes vote down vote up
/**
 * Calculates a <code>PageFormat</code> with values consistent with those
 * supported by the current <code>PrintService</code> for this job
 * (ie the value returned by <code>getPrintService()</code>) and media,
 * printable area and orientation contained in <code>attributes</code>.
 * <p>
 * Calling this method does not update the job.
 * It is useful for clients that have a set of attributes obtained from
 * <code>printDialog(PrintRequestAttributeSet attributes)</code>
 * and need a PageFormat to print a Pageable object.
 * @param attributes a set of printing attributes, for example obtained
 * from calling printDialog. If <code>attributes</code> is null a default
 * PageFormat is returned.
 * @return a <code>PageFormat</code> whose settings conform with
 * those of the current service and the specified attributes.
 * @since 1.6
 */
public PageFormat getPageFormat(PrintRequestAttributeSet attributes) {

    PrintService service = getPrintService();
    PageFormat pf = defaultPage();

    if (service == null || attributes == null) {
        return pf;
    }

    Media media = (Media)attributes.get(Media.class);
    MediaPrintableArea mpa =
        (MediaPrintableArea)attributes.get(MediaPrintableArea.class);
    OrientationRequested orientReq =
       (OrientationRequested)attributes.get(OrientationRequested.class);

    if (media == null && mpa == null && orientReq == null) {
       return pf;
    }
    Paper paper = pf.getPaper();

    /* If there's a media but no media printable area, we can try
     * to retrieve the default value for mpa and use that.
     */
    if (mpa == null && media != null &&
        service.isAttributeCategorySupported(MediaPrintableArea.class)) {
        Object mpaVals =
            service.getSupportedAttributeValues(MediaPrintableArea.class,
                                                null, attributes);
        if (mpaVals instanceof MediaPrintableArea[] &&
            ((MediaPrintableArea[])mpaVals).length > 0) {
            mpa = ((MediaPrintableArea[])mpaVals)[0];
        }
    }

    if (media != null &&
        service.isAttributeValueSupported(media, null, attributes)) {
        if (media instanceof MediaSizeName) {
            MediaSizeName msn = (MediaSizeName)media;
            MediaSize msz = MediaSize.getMediaSizeForName(msn);
            if (msz != null) {
                double inch = 72.0;
                double paperWid = msz.getX(MediaSize.INCH) * inch;
                double paperHgt = msz.getY(MediaSize.INCH) * inch;
                paper.setSize(paperWid, paperHgt);
                if (mpa == null) {
                    paper.setImageableArea(inch, inch,
                                           paperWid-2*inch,
                                           paperHgt-2*inch);
                }
            }
        }
    }

    if (mpa != null &&
        service.isAttributeValueSupported(mpa, null, attributes)) {
        float [] printableArea =
            mpa.getPrintableArea(MediaPrintableArea.INCH);
        for (int i=0; i < printableArea.length; i++) {
            printableArea[i] = printableArea[i]*72.0f;
        }
        paper.setImageableArea(printableArea[0], printableArea[1],
                               printableArea[2], printableArea[3]);
    }

    if (orientReq != null &&
        service.isAttributeValueSupported(orientReq, null, attributes)) {
        int orient;
        if (orientReq.equals(OrientationRequested.REVERSE_LANDSCAPE)) {
            orient = PageFormat.REVERSE_LANDSCAPE;
        } else if (orientReq.equals(OrientationRequested.LANDSCAPE)) {
            orient = PageFormat.LANDSCAPE;
        } else {
            orient = PageFormat.PORTRAIT;
        }
        pf.setOrientation(orient);
    }

    pf.setPaper(paper);
    pf = validatePage(pf);
    return pf;
}
 
Example 16
Source File: PrinterJob.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Calculates a <code>PageFormat</code> with values consistent with those
 * supported by the current <code>PrintService</code> for this job
 * (ie the value returned by <code>getPrintService()</code>) and media,
 * printable area and orientation contained in <code>attributes</code>.
 * <p>
 * Calling this method does not update the job.
 * It is useful for clients that have a set of attributes obtained from
 * <code>printDialog(PrintRequestAttributeSet attributes)</code>
 * and need a PageFormat to print a Pageable object.
 * @param attributes a set of printing attributes, for example obtained
 * from calling printDialog. If <code>attributes</code> is null a default
 * PageFormat is returned.
 * @return a <code>PageFormat</code> whose settings conform with
 * those of the current service and the specified attributes.
 * @since 1.6
 */
public PageFormat getPageFormat(PrintRequestAttributeSet attributes) {

    PrintService service = getPrintService();
    PageFormat pf = defaultPage();

    if (service == null || attributes == null) {
        return pf;
    }

    Media media = (Media)attributes.get(Media.class);
    MediaPrintableArea mpa =
        (MediaPrintableArea)attributes.get(MediaPrintableArea.class);
    OrientationRequested orientReq =
       (OrientationRequested)attributes.get(OrientationRequested.class);

    if (media == null && mpa == null && orientReq == null) {
       return pf;
    }
    Paper paper = pf.getPaper();

    /* If there's a media but no media printable area, we can try
     * to retrieve the default value for mpa and use that.
     */
    if (mpa == null && media != null &&
        service.isAttributeCategorySupported(MediaPrintableArea.class)) {
        Object mpaVals =
            service.getSupportedAttributeValues(MediaPrintableArea.class,
                                                null, attributes);
        if (mpaVals instanceof MediaPrintableArea[] &&
            ((MediaPrintableArea[])mpaVals).length > 0) {
            mpa = ((MediaPrintableArea[])mpaVals)[0];
        }
    }

    if (media != null &&
        service.isAttributeValueSupported(media, null, attributes)) {
        if (media instanceof MediaSizeName) {
            MediaSizeName msn = (MediaSizeName)media;
            MediaSize msz = MediaSize.getMediaSizeForName(msn);
            if (msz != null) {
                double inch = 72.0;
                double paperWid = msz.getX(MediaSize.INCH) * inch;
                double paperHgt = msz.getY(MediaSize.INCH) * inch;
                paper.setSize(paperWid, paperHgt);
                if (mpa == null) {
                    paper.setImageableArea(inch, inch,
                                           paperWid-2*inch,
                                           paperHgt-2*inch);
                }
            }
        }
    }

    if (mpa != null &&
        service.isAttributeValueSupported(mpa, null, attributes)) {
        float [] printableArea =
            mpa.getPrintableArea(MediaPrintableArea.INCH);
        for (int i=0; i < printableArea.length; i++) {
            printableArea[i] = printableArea[i]*72.0f;
        }
        paper.setImageableArea(printableArea[0], printableArea[1],
                               printableArea[2], printableArea[3]);
    }

    if (orientReq != null &&
        service.isAttributeValueSupported(orientReq, null, attributes)) {
        int orient;
        if (orientReq.equals(OrientationRequested.REVERSE_LANDSCAPE)) {
            orient = PageFormat.REVERSE_LANDSCAPE;
        } else if (orientReq.equals(OrientationRequested.LANDSCAPE)) {
            orient = PageFormat.LANDSCAPE;
        } else {
            orient = PageFormat.PORTRAIT;
        }
        pf.setOrientation(orient);
    }

    pf.setPaper(paper);
    pf = validatePage(pf);
    return pf;
}
 
Example 17
Source File: PrinterJob.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Calculates a <code>PageFormat</code> with values consistent with those
 * supported by the current <code>PrintService</code> for this job
 * (ie the value returned by <code>getPrintService()</code>) and media,
 * printable area and orientation contained in <code>attributes</code>.
 * <p>
 * Calling this method does not update the job.
 * It is useful for clients that have a set of attributes obtained from
 * <code>printDialog(PrintRequestAttributeSet attributes)</code>
 * and need a PageFormat to print a Pageable object.
 * @param attributes a set of printing attributes, for example obtained
 * from calling printDialog. If <code>attributes</code> is null a default
 * PageFormat is returned.
 * @return a <code>PageFormat</code> whose settings conform with
 * those of the current service and the specified attributes.
 * @since 1.6
 */
public PageFormat getPageFormat(PrintRequestAttributeSet attributes) {

    PrintService service = getPrintService();
    PageFormat pf = defaultPage();

    if (service == null || attributes == null) {
        return pf;
    }

    Media media = (Media)attributes.get(Media.class);
    MediaPrintableArea mpa =
        (MediaPrintableArea)attributes.get(MediaPrintableArea.class);
    OrientationRequested orientReq =
       (OrientationRequested)attributes.get(OrientationRequested.class);

    if (media == null && mpa == null && orientReq == null) {
       return pf;
    }
    Paper paper = pf.getPaper();

    /* If there's a media but no media printable area, we can try
     * to retrieve the default value for mpa and use that.
     */
    if (mpa == null && media != null &&
        service.isAttributeCategorySupported(MediaPrintableArea.class)) {
        Object mpaVals =
            service.getSupportedAttributeValues(MediaPrintableArea.class,
                                                null, attributes);
        if (mpaVals instanceof MediaPrintableArea[] &&
            ((MediaPrintableArea[])mpaVals).length > 0) {
            mpa = ((MediaPrintableArea[])mpaVals)[0];
        }
    }

    if (media != null &&
        service.isAttributeValueSupported(media, null, attributes)) {
        if (media instanceof MediaSizeName) {
            MediaSizeName msn = (MediaSizeName)media;
            MediaSize msz = MediaSize.getMediaSizeForName(msn);
            if (msz != null) {
                double inch = 72.0;
                double paperWid = msz.getX(MediaSize.INCH) * inch;
                double paperHgt = msz.getY(MediaSize.INCH) * inch;
                paper.setSize(paperWid, paperHgt);
                if (mpa == null) {
                    paper.setImageableArea(inch, inch,
                                           paperWid-2*inch,
                                           paperHgt-2*inch);
                }
            }
        }
    }

    if (mpa != null &&
        service.isAttributeValueSupported(mpa, null, attributes)) {
        float [] printableArea =
            mpa.getPrintableArea(MediaPrintableArea.INCH);
        for (int i=0; i < printableArea.length; i++) {
            printableArea[i] = printableArea[i]*72.0f;
        }
        paper.setImageableArea(printableArea[0], printableArea[1],
                               printableArea[2], printableArea[3]);
    }

    if (orientReq != null &&
        service.isAttributeValueSupported(orientReq, null, attributes)) {
        int orient;
        if (orientReq.equals(OrientationRequested.REVERSE_LANDSCAPE)) {
            orient = PageFormat.REVERSE_LANDSCAPE;
        } else if (orientReq.equals(OrientationRequested.LANDSCAPE)) {
            orient = PageFormat.LANDSCAPE;
        } else {
            orient = PageFormat.PORTRAIT;
        }
        pf.setOrientation(orient);
    }

    pf.setPaper(paper);
    pf = validatePage(pf);
    return pf;
}
 
Example 18
Source File: PrinterJob.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Calculates a <code>PageFormat</code> with values consistent with those
 * supported by the current <code>PrintService</code> for this job
 * (ie the value returned by <code>getPrintService()</code>) and media,
 * printable area and orientation contained in <code>attributes</code>.
 * <p>
 * Calling this method does not update the job.
 * It is useful for clients that have a set of attributes obtained from
 * <code>printDialog(PrintRequestAttributeSet attributes)</code>
 * and need a PageFormat to print a Pageable object.
 * @param attributes a set of printing attributes, for example obtained
 * from calling printDialog. If <code>attributes</code> is null a default
 * PageFormat is returned.
 * @return a <code>PageFormat</code> whose settings conform with
 * those of the current service and the specified attributes.
 * @since 1.6
 */
public PageFormat getPageFormat(PrintRequestAttributeSet attributes) {

    PrintService service = getPrintService();
    PageFormat pf = defaultPage();

    if (service == null || attributes == null) {
        return pf;
    }

    Media media = (Media)attributes.get(Media.class);
    MediaPrintableArea mpa =
        (MediaPrintableArea)attributes.get(MediaPrintableArea.class);
    OrientationRequested orientReq =
       (OrientationRequested)attributes.get(OrientationRequested.class);

    if (media == null && mpa == null && orientReq == null) {
       return pf;
    }
    Paper paper = pf.getPaper();

    /* If there's a media but no media printable area, we can try
     * to retrieve the default value for mpa and use that.
     */
    if (mpa == null && media != null &&
        service.isAttributeCategorySupported(MediaPrintableArea.class)) {
        Object mpaVals =
            service.getSupportedAttributeValues(MediaPrintableArea.class,
                                                null, attributes);
        if (mpaVals instanceof MediaPrintableArea[] &&
            ((MediaPrintableArea[])mpaVals).length > 0) {
            mpa = ((MediaPrintableArea[])mpaVals)[0];
        }
    }

    if (media != null &&
        service.isAttributeValueSupported(media, null, attributes)) {
        if (media instanceof MediaSizeName) {
            MediaSizeName msn = (MediaSizeName)media;
            MediaSize msz = MediaSize.getMediaSizeForName(msn);
            if (msz != null) {
                double inch = 72.0;
                double paperWid = msz.getX(MediaSize.INCH) * inch;
                double paperHgt = msz.getY(MediaSize.INCH) * inch;
                paper.setSize(paperWid, paperHgt);
                if (mpa == null) {
                    paper.setImageableArea(inch, inch,
                                           paperWid-2*inch,
                                           paperHgt-2*inch);
                }
            }
        }
    }

    if (mpa != null &&
        service.isAttributeValueSupported(mpa, null, attributes)) {
        float [] printableArea =
            mpa.getPrintableArea(MediaPrintableArea.INCH);
        for (int i=0; i < printableArea.length; i++) {
            printableArea[i] = printableArea[i]*72.0f;
        }
        paper.setImageableArea(printableArea[0], printableArea[1],
                               printableArea[2], printableArea[3]);
    }

    if (orientReq != null &&
        service.isAttributeValueSupported(orientReq, null, attributes)) {
        int orient;
        if (orientReq.equals(OrientationRequested.REVERSE_LANDSCAPE)) {
            orient = PageFormat.REVERSE_LANDSCAPE;
        } else if (orientReq.equals(OrientationRequested.LANDSCAPE)) {
            orient = PageFormat.LANDSCAPE;
        } else {
            orient = PageFormat.PORTRAIT;
        }
        pf.setOrientation(orient);
    }

    pf.setPaper(paper);
    pf = validatePage(pf);
    return pf;
}