Search in sources :

Example 1 with MediaSize

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

the class MediaMappingsTest method main.

public static void main(String[] args) {
    MediaSize sizeA = MediaSize.getMediaSizeForName(MediaSizeName.A);
    new MediaSize(1.0f, 2.0f, MediaSize.MM, MediaSizeName.A);
    if (!sizeA.equals(MediaSize.getMediaSizeForName(MediaSizeName.A))) {
        throw new RuntimeException("mapping changed");
    }
    MediaSize sizeB = MediaSize.getMediaSizeForName(MediaSizeName.B);
    new MediaSize(1, 2, MediaSize.MM, MediaSizeName.B);
    if (!sizeB.equals(MediaSize.getMediaSizeForName(MediaSizeName.B))) {
        throw new RuntimeException("mapping changed");
    }
}
Also used : MediaSize(javax.print.attribute.standard.MediaSize)

Example 2 with MediaSize

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

the class MPrintPaper method getMediaSize.

/**************************************************************************
	 * 	Get Media Size.
	 *  The search is hard coded as the javax.print.MediaSize* info is private
	 * 	@return MediaSize from Code
	 */
public MediaSize getMediaSize() {
    if (m_mediaSize != null)
        return m_mediaSize;
    //
    String nameCode = getCode();
    if (nameCode != null) {
        //	Get Name
        MediaSizeName nameMedia = null;
        CMediaSizeName msn = new CMediaSizeName(4);
        String[] names = msn.getStringTable();
        for (int i = 0; i < names.length; i++) {
            String name = names[i];
            if (name.equalsIgnoreCase(nameCode)) {
                nameMedia = (MediaSizeName) msn.getEnumValueTable()[i];
                log.finer("Name=" + nameMedia);
                break;
            }
        }
        if (nameMedia != null) {
            m_mediaSize = MediaSize.getMediaSizeForName(nameMedia);
            log.fine("Name->Size=" + m_mediaSize);
        }
    }
    //	Create New Media Size
    if (m_mediaSize == null) {
        float x = getSizeX().floatValue();
        float y = getSizeY().floatValue();
        if (x > 0 && y > 0) {
            m_mediaSize = new MediaSize(x, y, getUnitsInt(), MediaSizeName.A);
            log.fine("Size=" + m_mediaSize);
        }
    }
    //	Fallback
    if (m_mediaSize == null)
        m_mediaSize = getMediaSizeDefault();
    return m_mediaSize;
}
Also used : MediaSize(javax.print.attribute.standard.MediaSize) MediaSizeName(javax.print.attribute.standard.MediaSizeName)

Example 3 with MediaSize

use of javax.print.attribute.standard.MediaSize 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 4 with MediaSize

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

the class ReportPrintFactory method getDefaultPage.

/**
     * Returns the default paper size for a report
     * 
     * @return page format
     */
private static PageFormat getDefaultPage() {
    /* A4 is the assumed default */
    MediaSize defaultMediaSize = MediaSize.ISO.A4;
    /* US and Canada use letter size as the default */
    Locale[] letterLocales = new Locale[] { Locale.US, Locale.CANADA, Locale.CANADA_FRENCH };
    if (Arrays.asList(letterLocales).contains(Locale.getDefault())) {
        defaultMediaSize = MediaSize.NA.LETTER;
    }
    /* Create the default paper size with a default margin */
    Paper paper = new Paper();
    int width = (int) (defaultMediaSize.getX(MediaSize.INCH) / (1f / 72f));
    int height = (int) (defaultMediaSize.getY(MediaSize.INCH) / (1f / 72f));
    paper.setSize(width, height);
    paper.setImageableArea(DEFAULT_MARGIN, DEFAULT_MARGIN, width - (2 * DEFAULT_MARGIN), height - (2 * DEFAULT_MARGIN));
    PageFormat format = new PageFormat();
    format.setPaper(paper);
    /* if a default printer is found, validate the page */
    PrintService[] services = PrinterJob.lookupPrintServices();
    if (services.length != 0) {
        // no printers found on the system.                     
        format = PrinterJob.getPrinterJob().validatePage(format);
    }
    return format;
}
Also used : Locale(java.util.Locale) PageFormat(java.awt.print.PageFormat) MediaSize(javax.print.attribute.standard.MediaSize) Paper(java.awt.print.Paper) PrintService(javax.print.PrintService)

Example 5 with MediaSize

use of javax.print.attribute.standard.MediaSize 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)

Aggregations

MediaSize (javax.print.attribute.standard.MediaSize)21 MediaSizeName (javax.print.attribute.standard.MediaSizeName)16 Media (javax.print.attribute.standard.Media)10 MediaPrintableArea (javax.print.attribute.standard.MediaPrintableArea)10 OrientationRequested (javax.print.attribute.standard.OrientationRequested)8 PageFormat (java.awt.print.PageFormat)6 Paper (java.awt.print.Paper)6 PrintService (javax.print.PrintService)5 JobName (javax.print.attribute.standard.JobName)4 Attribute (javax.print.attribute.Attribute)3 Fidelity (javax.print.attribute.standard.Fidelity)3 RequestingUserName (javax.print.attribute.standard.RequestingUserName)3 SheetCollate (javax.print.attribute.standard.SheetCollate)3 File (java.io.File)2 ArrayList (java.util.ArrayList)2 StreamPrintService (javax.print.StreamPrintService)2 PrintRequestAttributeSet (javax.print.attribute.PrintRequestAttributeSet)2 PrintServiceAttribute (javax.print.attribute.PrintServiceAttribute)2 Chromaticity (javax.print.attribute.standard.Chromaticity)2 CopiesSupported (javax.print.attribute.standard.CopiesSupported)2