Search in sources :

Example 1 with MediaSizeName

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

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

use of javax.print.attribute.standard.MediaSizeName in project camel by apache.

the class PrinterConfiguration method assignMediaSize.

private MediaSizeName assignMediaSize(String size) {
    MediaSizeAssigner mediaSizeAssigner = new MediaSizeAssigner();
    MediaSizeName answer;
    if (size == null) {
        // default to NA letter if no size configured
        answer = MediaSizeName.NA_LETTER;
    } else if (size.toLowerCase().startsWith("iso")) {
        answer = mediaSizeAssigner.selectMediaSizeNameISO(size);
    } else if (size.startsWith("jis")) {
        answer = mediaSizeAssigner.selectMediaSizeNameJIS(size);
    } else if (size.startsWith("na")) {
        answer = mediaSizeAssigner.selectMediaSizeNameNA(size);
    } else {
        answer = mediaSizeAssigner.selectMediaSizeNameOther(size);
    }
    return answer;
}
Also used : MediaSizeName(javax.print.attribute.standard.MediaSizeName)

Example 4 with MediaSizeName

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

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

MediaSizeName (javax.print.attribute.standard.MediaSizeName)31 Media (javax.print.attribute.standard.Media)16 MediaSize (javax.print.attribute.standard.MediaSize)16 OrientationRequested (javax.print.attribute.standard.OrientationRequested)14 MediaPrintableArea (javax.print.attribute.standard.MediaPrintableArea)11 Attribute (javax.print.attribute.Attribute)9 Destination (javax.print.attribute.standard.Destination)9 Chromaticity (javax.print.attribute.standard.Chromaticity)8 Copies (javax.print.attribute.standard.Copies)8 Fidelity (javax.print.attribute.standard.Fidelity)8 JobName (javax.print.attribute.standard.JobName)8 File (java.io.File)7 URI (java.net.URI)7 PrintService (javax.print.PrintService)7 PageRanges (javax.print.attribute.standard.PageRanges)7 SheetCollate (javax.print.attribute.standard.SheetCollate)7 Sides (javax.print.attribute.standard.Sides)7 RequestingUserName (javax.print.attribute.standard.RequestingUserName)5 PageFormat (java.awt.print.PageFormat)4 Paper (java.awt.print.Paper)4