Search in sources :

Example 1 with MediaTray

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

the class PrinterPrintTest method setupJavaPrint.

protected void setupJavaPrint() {
    // "install" another default printer
    PrintService psDefault = mock(PrintService.class);
    when(psDefault.getName()).thenReturn("DefaultPrinter");
    when(psDefault.isDocFlavorSupported(any(DocFlavor.class))).thenReturn(Boolean.TRUE);
    PrintServiceLookup psLookup = mock(PrintServiceLookup.class);
    when(psLookup.getPrintServices()).thenReturn(new PrintService[] { psDefault });
    when(psLookup.getDefaultPrintService()).thenReturn(psDefault);
    DocPrintJob docPrintJob = mock(DocPrintJob.class);
    when(psDefault.createPrintJob()).thenReturn(docPrintJob);
    MediaTray[] trays = new MediaTray[] { MediaTray.TOP, MediaTray.MIDDLE, MediaTray.BOTTOM };
    when(psDefault.getSupportedAttributeValues(Media.class, null, null)).thenReturn(trays);
    PrintServiceLookup.registerServiceProvider(psLookup);
}
Also used : PrintServiceLookup(javax.print.PrintServiceLookup) DocPrintJob(javax.print.DocPrintJob) MediaTray(javax.print.attribute.standard.MediaTray) DocFlavor(javax.print.DocFlavor) PrintService(javax.print.PrintService)

Example 2 with MediaTray

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

the class PrinterProducer method resolveMediaTray.

private MediaTray resolveMediaTray(String tray) {
    Media[] medias = (Media[]) getPrintService().getSupportedAttributeValues(Media.class, null, null);
    if (medias == null) {
        return null;
    } else {
        for (Media media : medias) {
            if (media instanceof MediaTray) {
                MediaTray mediaTray = (MediaTray) media;
                String trayName = mediaTray.toString().trim();
                if (trayName.contains(" ")) {
                    trayName = trayName.replace(' ', '_');
                }
                if (trayName.equals(tray)) {
                    return mediaTray;
                }
            }
        }
        return null;
    }
}
Also used : Media(javax.print.attribute.standard.Media) MediaTray(javax.print.attribute.standard.MediaTray)

Example 3 with MediaTray

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

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

the class Win32MediaSize method isAttributeValueSupported.

public boolean isAttributeValueSupported(Attribute attr, DocFlavor flavor, AttributeSet attributes) {
    if (attr == null) {
        throw new NullPointerException("null attribute");
    }
    Class category = attr.getCategory();
    if (flavor != null) {
        if (!isDocFlavorSupported(flavor)) {
            throw new IllegalArgumentException(flavor + " is an unsupported flavor");
        // if postscript & category is already specified within the PostScript data
        // we return false
        } else if (isAutoSense(flavor) || (isPostScriptFlavor(flavor) && (isPSDocAttr(category)))) {
            return false;
        }
    }
    if (!isAttributeCategorySupported(category)) {
        return false;
    } else if (category == Chromaticity.class) {
        if ((flavor == null) || flavor.equals(DocFlavor.SERVICE_FORMATTED.PAGEABLE) || flavor.equals(DocFlavor.SERVICE_FORMATTED.PRINTABLE) || flavor.equals(DocFlavor.BYTE_ARRAY.GIF) || flavor.equals(DocFlavor.INPUT_STREAM.GIF) || flavor.equals(DocFlavor.URL.GIF) || flavor.equals(DocFlavor.BYTE_ARRAY.JPEG) || flavor.equals(DocFlavor.INPUT_STREAM.JPEG) || flavor.equals(DocFlavor.URL.JPEG) || flavor.equals(DocFlavor.BYTE_ARRAY.PNG) || flavor.equals(DocFlavor.INPUT_STREAM.PNG) || flavor.equals(DocFlavor.URL.PNG)) {
            int caps = getPrinterCapabilities();
            if ((caps & DEVCAP_COLOR) != 0) {
                return true;
            } else {
                return attr == Chromaticity.MONOCHROME;
            }
        } else {
            return false;
        }
    } else if (category == Copies.class) {
        return isSupportedCopies((Copies) attr);
    } else if (category == Destination.class) {
        URI uri = ((Destination) attr).getURI();
        if ("file".equals(uri.getScheme()) && !(uri.getSchemeSpecificPart().equals(""))) {
            return true;
        } else {
            return false;
        }
    } else if (category == Media.class) {
        if (attr instanceof MediaSizeName) {
            return isSupportedMedia((MediaSizeName) attr);
        }
        if (attr instanceof MediaTray) {
            return isSupportedMediaTray((MediaTray) attr);
        }
    } else if (category == MediaPrintableArea.class) {
        return isSupportedMediaPrintableArea((MediaPrintableArea) attr);
    } else if (category == SunAlternateMedia.class) {
        Media media = ((SunAlternateMedia) attr).getMedia();
        return isAttributeValueSupported(media, flavor, attributes);
    } else if (category == PageRanges.class || category == SheetCollate.class || category == Sides.class) {
        if (flavor != null && !(flavor.equals(DocFlavor.SERVICE_FORMATTED.PAGEABLE) || flavor.equals(DocFlavor.SERVICE_FORMATTED.PRINTABLE))) {
            return false;
        }
    } else if (category == PrinterResolution.class) {
        if (attr instanceof PrinterResolution) {
            return isSupportedResolution((PrinterResolution) attr);
        }
    } else if (category == OrientationRequested.class) {
        if (attr == OrientationRequested.REVERSE_PORTRAIT || (flavor != null) && !(flavor.equals(DocFlavor.SERVICE_FORMATTED.PAGEABLE) || flavor.equals(DocFlavor.SERVICE_FORMATTED.PRINTABLE) || flavor.equals(DocFlavor.INPUT_STREAM.GIF) || flavor.equals(DocFlavor.INPUT_STREAM.JPEG) || flavor.equals(DocFlavor.INPUT_STREAM.PNG) || flavor.equals(DocFlavor.BYTE_ARRAY.GIF) || flavor.equals(DocFlavor.BYTE_ARRAY.JPEG) || flavor.equals(DocFlavor.BYTE_ARRAY.PNG) || flavor.equals(DocFlavor.URL.GIF) || flavor.equals(DocFlavor.URL.JPEG) || flavor.equals(DocFlavor.URL.PNG))) {
            return false;
        }
    } else if (category == ColorSupported.class) {
        int caps = getPrinterCapabilities();
        boolean isColorSup = ((caps & DEVCAP_COLOR) != 0);
        if ((!isColorSup && (attr == ColorSupported.SUPPORTED)) || (isColorSup && (attr == ColorSupported.NOT_SUPPORTED))) {
            return false;
        }
    }
    return true;
}
Also used : Destination(javax.print.attribute.standard.Destination) PageRanges(javax.print.attribute.standard.PageRanges) MediaSizeName(javax.print.attribute.standard.MediaSizeName) Media(javax.print.attribute.standard.Media) URI(java.net.URI) OrientationRequested(javax.print.attribute.standard.OrientationRequested) MediaPrintableArea(javax.print.attribute.standard.MediaPrintableArea) PrinterResolution(javax.print.attribute.standard.PrinterResolution) SheetCollate(javax.print.attribute.standard.SheetCollate) Chromaticity(javax.print.attribute.standard.Chromaticity) MediaTray(javax.print.attribute.standard.MediaTray)

Example 5 with MediaTray

use of javax.print.attribute.standard.MediaTray in project wildfly-camel by wildfly-extras.

the class PrinterIntegrationTest method setup.

@Before
public void setup() {
    PrintService psDefault = Mockito.mock(PrintService.class);
    Mockito.when(psDefault.getName()).thenReturn("DefaultPrinter");
    Mockito.when(psDefault.isDocFlavorSupported(Mockito.any(DocFlavor.class))).thenReturn(Boolean.TRUE);
    PrintServiceLookup psLookup = Mockito.mock(PrintServiceLookup.class);
    Mockito.when(psLookup.getPrintServices()).thenReturn(new PrintService[] { psDefault });
    Mockito.when(psLookup.getDefaultPrintService()).thenReturn(psDefault);
    DocPrintJob docPrintJob = Mockito.mock(DocPrintJob.class);
    Mockito.when(psDefault.createPrintJob()).thenReturn(docPrintJob);
    MediaTray[] trays = new MediaTray[] { MediaTray.TOP, MediaTray.MIDDLE, MediaTray.BOTTOM };
    Mockito.when(psDefault.getSupportedAttributeValues(Media.class, null, null)).thenReturn(trays);
    PrintServiceLookup.registerServiceProvider(psLookup);
}
Also used : PrintServiceLookup(javax.print.PrintServiceLookup) DocPrintJob(javax.print.DocPrintJob) MediaTray(javax.print.attribute.standard.MediaTray) DocFlavor(javax.print.DocFlavor) PrintService(javax.print.PrintService) Before(org.junit.Before)

Aggregations

MediaTray (javax.print.attribute.standard.MediaTray)12 Media (javax.print.attribute.standard.Media)4 Win32MediaTray (sun.print.Win32MediaTray)4 Chromaticity (javax.print.attribute.standard.Chromaticity)3 Copies (javax.print.attribute.standard.Copies)3 MediaSizeName (javax.print.attribute.standard.MediaSizeName)3 PrintQuality (javax.print.attribute.standard.PrintQuality)3 PrinterResolution (javax.print.attribute.standard.PrinterResolution)3 SunAlternateMedia (sun.print.SunAlternateMedia)3 Win32PrintService (sun.print.Win32PrintService)3 DocFlavor (javax.print.DocFlavor)2 DocPrintJob (javax.print.DocPrintJob)2 PrintService (javax.print.PrintService)2 PrintServiceLookup (javax.print.PrintServiceLookup)2 Attribute (javax.print.attribute.Attribute)2 PrintRequestAttributeSet (javax.print.attribute.PrintRequestAttributeSet)2 MediaPrintableArea (javax.print.attribute.standard.MediaPrintableArea)2 OrientationRequested (javax.print.attribute.standard.OrientationRequested)2 SheetCollate (javax.print.attribute.standard.SheetCollate)2 Sides (javax.print.attribute.standard.Sides)2