javax.print.attribute.standard.Chromaticity Java Examples

The following examples show how to use javax.print.attribute.standard.Chromaticity. 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: WrongPaperForBookPrintingTest.java    From openjdk-jdk8u with GNU General Public License v2.0 7 votes vote down vote up
private static void doTest() {
    PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
    aset.add(Chromaticity.MONOCHROME);

    MediaSize isoA5Size = MediaSize.getMediaSizeForName(MediaSizeName.ISO_A5);
    float[] size = isoA5Size.getSize(Size2DSyntax.INCH);
    Paper paper = new Paper();
    paper.setSize(size[0] * 72.0, size[1] * 72.0);
    paper.setImageableArea(0.0, 0.0, size[0] * 72.0, size[1] * 72.0);
    PageFormat pf = new PageFormat();
    pf.setPaper(paper);

    Book pageable = new Book();
    pageable.append(new WrongPaperForBookPrintingTest(), pf);

    PrinterJob job = PrinterJob.getPrinterJob();
    job.setPageable(pageable);
    if (job.printDialog()) {
        try {
            job.print(aset);
        } catch (PrinterException pe) {
            throw new RuntimeException(pe);
        }
    }
}
 
Example #2
Source File: WrongPaperPrintingTest.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
private static void doTest() {
    PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
    aset.add(Chromaticity.MONOCHROME);

    MediaSize isoA5Size = MediaSize.getMediaSizeForName(MediaSizeName.ISO_A5);
    float[] size = isoA5Size.getSize(Size2DSyntax.INCH);
    Paper paper = new Paper();
    paper.setSize(size[0] * 72.0, size[1] * 72.0);
    paper.setImageableArea(0.0, 0.0, size[0] * 72.0, size[1] * 72.0);
    PageFormat pf = new PageFormat();
    pf.setPaper(paper);

    PrinterJob job = PrinterJob.getPrinterJob();
    job.setPrintable(new WrongPaperPrintingTest(), job.validatePage(pf));
    if (job.printDialog()) {
        try {
            job.print(aset);
        } catch (PrinterException pe) {
            throw new RuntimeException(pe);
        }
    }
}
 
Example #3
Source File: WrongPaperPrintingTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
private static void doTest() {
    PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
    aset.add(Chromaticity.MONOCHROME);

    MediaSize isoA5Size = MediaSize.getMediaSizeForName(MediaSizeName.ISO_A5);
    float[] size = isoA5Size.getSize(Size2DSyntax.INCH);
    Paper paper = new Paper();
    paper.setSize(size[0] * 72.0, size[1] * 72.0);
    paper.setImageableArea(0.0, 0.0, size[0] * 72.0, size[1] * 72.0);
    PageFormat pf = new PageFormat();
    pf.setPaper(paper);

    PrinterJob job = PrinterJob.getPrinterJob();
    job.setPrintable(new WrongPaperPrintingTest(), job.validatePage(pf));
    if (job.printDialog()) {
        try {
            job.print(aset);
        } catch (PrinterException pe) {
            throw new RuntimeException(pe);
        }
    }
}
 
Example #4
Source File: WrongPaperPrintingTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private static void doTest() {
    PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
    aset.add(Chromaticity.MONOCHROME);

    MediaSize isoA5Size = MediaSize.getMediaSizeForName(MediaSizeName.ISO_A5);
    float[] size = isoA5Size.getSize(Size2DSyntax.INCH);
    Paper paper = new Paper();
    paper.setSize(size[0] * 72.0, size[1] * 72.0);
    paper.setImageableArea(0.0, 0.0, size[0] * 72.0, size[1] * 72.0);
    PageFormat pf = new PageFormat();
    pf.setPaper(paper);

    PrinterJob job = PrinterJob.getPrinterJob();
    job.setPrintable(new WrongPaperPrintingTest(), job.validatePage(pf));
    if (job.printDialog()) {
        try {
            job.print(aset);
        } catch (PrinterException pe) {
            throw new RuntimeException(pe);
        }
    }
}
 
Example #5
Source File: WrongPaperPrintingTest.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private static void doTest() {
    PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
    aset.add(Chromaticity.MONOCHROME);

    MediaSize isoA5Size = MediaSize.getMediaSizeForName(MediaSizeName.ISO_A5);
    float[] size = isoA5Size.getSize(Size2DSyntax.INCH);
    Paper paper = new Paper();
    paper.setSize(size[0] * 72.0, size[1] * 72.0);
    paper.setImageableArea(0.0, 0.0, size[0] * 72.0, size[1] * 72.0);
    PageFormat pf = new PageFormat();
    pf.setPaper(paper);

    PrinterJob job = PrinterJob.getPrinterJob();
    job.setPrintable(new WrongPaperPrintingTest(), job.validatePage(pf));
    if (job.printDialog()) {
        try {
            job.print(aset);
        } catch (PrinterException pe) {
            throw new RuntimeException(pe);
        }
    }
}
 
Example #6
Source File: WrongPaperPrintingTest.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
private static void doTest() {
    PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
    aset.add(Chromaticity.MONOCHROME);

    MediaSize isoA5Size = MediaSize.getMediaSizeForName(MediaSizeName.ISO_A5);
    float[] size = isoA5Size.getSize(Size2DSyntax.INCH);
    Paper paper = new Paper();
    paper.setSize(size[0] * 72.0, size[1] * 72.0);
    paper.setImageableArea(0.0, 0.0, size[0] * 72.0, size[1] * 72.0);
    PageFormat pf = new PageFormat();
    pf.setPaper(paper);

    PrinterJob job = PrinterJob.getPrinterJob();
    job.setPrintable(new WrongPaperPrintingTest(), job.validatePage(pf));
    if (job.printDialog()) {
        try {
            job.print(aset);
        } catch (PrinterException pe) {
            throw new RuntimeException(pe);
        }
    }
}
 
Example #7
Source File: WrongPaperPrintingTest.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private static void doTest() {
    PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
    aset.add(Chromaticity.MONOCHROME);

    MediaSize isoA5Size = MediaSize.getMediaSizeForName(MediaSizeName.ISO_A5);
    float[] size = isoA5Size.getSize(Size2DSyntax.INCH);
    Paper paper = new Paper();
    paper.setSize(size[0] * 72.0, size[1] * 72.0);
    paper.setImageableArea(0.0, 0.0, size[0] * 72.0, size[1] * 72.0);
    PageFormat pf = new PageFormat();
    pf.setPaper(paper);

    PrinterJob job = PrinterJob.getPrinterJob();
    job.setPrintable(new WrongPaperPrintingTest(), job.validatePage(pf));
    if (job.printDialog()) {
        try {
            job.print(aset);
        } catch (PrinterException pe) {
            throw new RuntimeException(pe);
        }
    }
}
 
Example #8
Source File: PageSetupPanel.java    From gcs with Mozilla Public License 2.0 6 votes vote down vote up
private void createChromaticityCombo(PrintRequestAttributeSet set) {
    Chromaticity[] chromacities = (Chromaticity[]) mService.getSupportedAttributeValues(Chromaticity.class, DocFlavor.SERVICE_FORMATTED.PRINTABLE, null);
    if (chromacities != null && chromacities.length > 0) {
        Set<Chromaticity>          possible = new HashSet<>(Arrays.asList(chromacities));
        ArrayList<InkChromaticity> choices  = new ArrayList<>();
        for (InkChromaticity chromaticity : InkChromaticity.values()) {
            if (possible.contains(chromaticity.getChromaticity())) {
                choices.add(chromaticity);
            }
        }
        mChromaticity = new JComboBox<>(choices.toArray(new InkChromaticity[0]));
        mChromaticity.setSelectedItem(PrintUtilities.getChromaticity(mService, set, true));
        UIUtilities.setToPreferredSizeOnly(mChromaticity);
        LinkedLabel label = new LinkedLabel(I18n.Text("Color"), mChromaticity);
        add(label, new PrecisionLayoutData().setEndHorizontalAlignment());
        add(mChromaticity);
    } else {
        mChromaticity = null;
    }
}
 
Example #9
Source File: WrongPaperForBookPrintingTest.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private static void doTest() {
    PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
    aset.add(Chromaticity.MONOCHROME);

    MediaSize isoA5Size = MediaSize.getMediaSizeForName(MediaSizeName.ISO_A5);
    float[] size = isoA5Size.getSize(Size2DSyntax.INCH);
    Paper paper = new Paper();
    paper.setSize(size[0] * 72.0, size[1] * 72.0);
    paper.setImageableArea(0.0, 0.0, size[0] * 72.0, size[1] * 72.0);
    PageFormat pf = new PageFormat();
    pf.setPaper(paper);

    Book pageable = new Book();
    pageable.append(new WrongPaperForBookPrintingTest(), pf);

    PrinterJob job = PrinterJob.getPrinterJob();
    job.setPageable(pageable);
    if (job.printDialog()) {
        try {
            job.print(aset);
        } catch (PrinterException pe) {
            throw new RuntimeException(pe);
        }
    }
}
 
Example #10
Source File: WPrinterJob.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
private void setColorAttrib(Attribute attr) {
    if (attr == Chromaticity.COLOR) {
        mAttChromaticity = 2; // DMCOLOR_COLOR
    } else {
        mAttChromaticity = 1; // DMCOLOR_MONOCHROME
    }
}
 
Example #11
Source File: WPrinterJob.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
private void setColorAttrib(Attribute attr) {
    if (attr == Chromaticity.COLOR) {
        mAttChromaticity = 2; // DMCOLOR_COLOR
    } else {
        mAttChromaticity = 1; // DMCOLOR_MONOCHROME
    }
}
 
Example #12
Source File: WPrinterJob.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
private void setColorAttrib(Attribute attr) {
    if (attr == Chromaticity.COLOR) {
        mAttChromaticity = 2; // DMCOLOR_COLOR
    } else {
        mAttChromaticity = 1; // DMCOLOR_MONOCHROME
    }
}
 
Example #13
Source File: WPrinterJob.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private void setColorAttrib(Attribute attr) {
    if (attr == Chromaticity.COLOR) {
        mAttChromaticity = 2; // DMCOLOR_COLOR
    } else {
        mAttChromaticity = 1; // DMCOLOR_MONOCHROME
    }
}
 
Example #14
Source File: WPrinterJob.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private void setColorAttrib(Attribute attr) {
    if (attr == Chromaticity.COLOR) {
        mAttChromaticity = 2; // DMCOLOR_COLOR
    } else {
        mAttChromaticity = 1; // DMCOLOR_MONOCHROME
    }
}
 
Example #15
Source File: WPrinterJob.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private void setColorAttrib(Attribute attr) {
    if (attr == Chromaticity.COLOR) {
        mAttChromaticity = 2; // DMCOLOR_COLOR
    } else {
        mAttChromaticity = 1; // DMCOLOR_MONOCHROME
    }
}
 
Example #16
Source File: WPrinterJob.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
private void setColorAttrib(Attribute attr) {
    if (attr == Chromaticity.COLOR) {
        mAttChromaticity = 2; // DMCOLOR_COLOR
    } else {
        mAttChromaticity = 1; // DMCOLOR_MONOCHROME
    }
}
 
Example #17
Source File: WPrinterJob.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private void setColorAttrib(Attribute attr) {
    if (attr == Chromaticity.COLOR) {
        mAttChromaticity = 2; // DMCOLOR_COLOR
    } else {
        mAttChromaticity = 1; // DMCOLOR_MONOCHROME
    }
}
 
Example #18
Source File: WPrinterJob.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
private void setColorAttrib(Attribute attr) {
    if (attr == Chromaticity.COLOR) {
        mAttChromaticity = 2; // DMCOLOR_COLOR
    } else {
        mAttChromaticity = 1; // DMCOLOR_MONOCHROME
    }
}
 
Example #19
Source File: WPrinterJob.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private void setColorAttrib(Attribute attr) {
    if (attr == Chromaticity.COLOR) {
        mAttChromaticity = 2; // DMCOLOR_COLOR
    } else {
        mAttChromaticity = 1; // DMCOLOR_MONOCHROME
    }
}
 
Example #20
Source File: UnixPrintService.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
public boolean isAttributeValueSupported(Attribute attr,
                                         DocFlavor flavor,
                                         AttributeSet attributes) {
    if (attr == null) {
        throw new NullPointerException("null attribute");
    }
    if (flavor != null) {
        if (!isDocFlavorSupported(flavor)) {
            throw new IllegalArgumentException(flavor +
                                           " is an unsupported flavor");
        } else if (isAutoSense(flavor)) {
            return false;
        }
    }
    Class category = attr.getCategory();
    if (!isAttributeCategorySupported(category)) {
        return false;
    }
    else if (attr.getCategory() == Chromaticity.class) {
        if (flavor == null || isServiceFormattedFlavor(flavor)) {
            return attr == Chromaticity.COLOR;
        } else {
            return false;
        }
    }
    else if (attr.getCategory() == Copies.class) {
        return (flavor == null ||
               !(flavor.equals(DocFlavor.INPUT_STREAM.POSTSCRIPT) ||
                 flavor.equals(DocFlavor.URL.POSTSCRIPT) ||
                 flavor.equals(DocFlavor.BYTE_ARRAY.POSTSCRIPT))) &&
            isSupportedCopies((Copies)attr);
    } else if (attr.getCategory() == Destination.class) {
        URI uri = ((Destination)attr).getURI();
            if ("file".equals(uri.getScheme()) &&
                !(uri.getSchemeSpecificPart().equals(""))) {
            return true;
        } else {
        return false;
        }
    } else if (attr.getCategory() == Media.class) {
        if (attr instanceof MediaSizeName) {
            return isSupportedMedia((MediaSizeName)attr);
        } else {
            return false;
        }
    } else if (attr.getCategory() == OrientationRequested.class) {
        if (attr == OrientationRequested.REVERSE_PORTRAIT ||
            (flavor != null) &&
            !isServiceFormattedFlavor(flavor)) {
            return false;
        }
    } else if (attr.getCategory() == PageRanges.class) {
        if (flavor != null &&
            !(flavor.equals(DocFlavor.SERVICE_FORMATTED.PAGEABLE) ||
            flavor.equals(DocFlavor.SERVICE_FORMATTED.PRINTABLE))) {
            return false;
        }
    } else if (attr.getCategory() == SheetCollate.class) {
        if (flavor != null &&
            !(flavor.equals(DocFlavor.SERVICE_FORMATTED.PAGEABLE) ||
            flavor.equals(DocFlavor.SERVICE_FORMATTED.PRINTABLE))) {
            return false;
        }
    } else if (attr.getCategory() == Sides.class) {
        if (flavor != null &&
            !(flavor.equals(DocFlavor.SERVICE_FORMATTED.PAGEABLE) ||
            flavor.equals(DocFlavor.SERVICE_FORMATTED.PRINTABLE))) {
            return false;
        }
    }
    return true;
}
 
Example #21
Source File: PrintJob2D.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
private void updateAttributes() {
    Copies c = (Copies)attributes.get(Copies.class);
    jobAttributes.setCopies(c.getValue());

    SunPageSelection sel =
        (SunPageSelection)attributes.get(SunPageSelection.class);
    if (sel == SunPageSelection.RANGE) {
        jobAttributes.setDefaultSelection(DefaultSelectionType.RANGE);
    } else if (sel == SunPageSelection.SELECTION) {
        jobAttributes.setDefaultSelection(DefaultSelectionType.SELECTION);
    } else {
        jobAttributes.setDefaultSelection(DefaultSelectionType.ALL);
    }

    Destination dest = (Destination)attributes.get(Destination.class);
    if (dest != null) {
        jobAttributes.setDestination(DestinationType.FILE);
        jobAttributes.setFileName(dest.getURI().getPath());
    } else {
        jobAttributes.setDestination(DestinationType.PRINTER);
    }

    PrintService serv = printerJob.getPrintService();
    if (serv != null) {
        jobAttributes.setPrinter(serv.getName());
    }

    PageRanges range = (PageRanges)attributes.get(PageRanges.class);
    int[][] members = range.getMembers();
    jobAttributes.setPageRanges(members);

    SheetCollate collation =
        (SheetCollate)attributes.get(SheetCollate.class);
    if (collation == SheetCollate.COLLATED) {
        jobAttributes.setMultipleDocumentHandling(
        MultipleDocumentHandlingType.SEPARATE_DOCUMENTS_COLLATED_COPIES);
    } else {
        jobAttributes.setMultipleDocumentHandling(
        MultipleDocumentHandlingType.SEPARATE_DOCUMENTS_UNCOLLATED_COPIES);
    }

    Sides sides = (Sides)attributes.get(Sides.class);
    if (sides == Sides.TWO_SIDED_LONG_EDGE) {
        jobAttributes.setSides(SidesType.TWO_SIDED_LONG_EDGE);
    } else if (sides == Sides.TWO_SIDED_SHORT_EDGE) {
        jobAttributes.setSides(SidesType.TWO_SIDED_SHORT_EDGE);
    } else {
        jobAttributes.setSides(SidesType.ONE_SIDED);
    }

    // PageAttributes

    Chromaticity color =
        (Chromaticity)attributes.get(Chromaticity.class);
    if (color == Chromaticity.COLOR) {
        pageAttributes.setColor(ColorType.COLOR);
    } else {
        pageAttributes.setColor(ColorType.MONOCHROME);
    }

    OrientationRequested orient =
        (OrientationRequested)attributes.get(OrientationRequested.class);
    if (orient == OrientationRequested.LANDSCAPE) {
        pageAttributes.setOrientationRequested(
                                   OrientationRequestedType.LANDSCAPE);
    } else {
        pageAttributes.setOrientationRequested(
                                   OrientationRequestedType.PORTRAIT);
    }

    PrintQuality qual = (PrintQuality)attributes.get(PrintQuality.class);
    if (qual == PrintQuality.DRAFT) {
        pageAttributes.setPrintQuality(PrintQualityType.DRAFT);
    } else if (qual == PrintQuality.HIGH) {
        pageAttributes.setPrintQuality(PrintQualityType.HIGH);
    } else { // NORMAL
        pageAttributes.setPrintQuality(PrintQualityType.NORMAL);
    }

    Media msn = (Media)attributes.get(Media.class);
    if (msn != null && msn instanceof MediaSizeName) {
        MediaType mType = unMapMedia((MediaSizeName)msn);

        if (mType != null) {
            pageAttributes.setMedia(mType);
        }
    }
    debugPrintAttributes(false, false);
}
 
Example #22
Source File: WPrinterJob.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * copy the attributes to the native print job
 * Note that this method, and hence the re-initialisation
 * of the GDI values is done on each entry to the print dialog since
 * an app could redisplay the print dialog for the same job and
 * 1) the application may have changed attribute settings
 * 2) the application may have changed the printer.
 * In the event that the user changes the printer using the
  dialog, then it is up to GDI to report back all changed values.
 */
@Override
protected void setAttributes(PrintRequestAttributeSet attributes)
    throws PrinterException {

    // initialize attribute values
    initAttributeMembers();
    super.setAttributes(attributes);

    mAttCopies = getCopiesInt();
    mDestination = destinationAttr;

    if (attributes == null) {
        return; // now always use attributes, so this shouldn't happen.
    }
    Attribute[] attrs = attributes.toArray();
    for (int i=0; i< attrs.length; i++) {
        Attribute attr = attrs[i];
        try {
             if (attr.getCategory() == Sides.class) {
                setSidesAttrib(attr);
            }
            else if (attr.getCategory() == Chromaticity.class) {
                setColorAttrib(attr);
            }
            else if (attr.getCategory() == PrinterResolution.class) {
                setResolutionAttrib(attr);
            }
            else if (attr.getCategory() == PrintQuality.class) {
                setQualityAttrib(attr);
            }
            else if (attr.getCategory() == SheetCollate.class) {
                setCollateAttrib(attr);
            }  else if (attr.getCategory() == Media.class ||
                        attr.getCategory() == SunAlternateMedia.class) {
                /* SunAlternateMedia is used if its a tray, and
                 * any Media that is specified is not a tray.
                 */
                if (attr.getCategory() == SunAlternateMedia.class) {
                    Media media = (Media)attributes.get(Media.class);
                    if (media == null ||
                        !(media instanceof MediaTray)) {
                        attr = ((SunAlternateMedia)attr).getMedia();
                    }
                }
                if (attr instanceof MediaSizeName) {
                    setWin32MediaAttrib(attr);
                }
                if (attr instanceof MediaTray) {
                    setMediaTrayAttrib(attr);
                }
            }

        } catch (ClassCastException e) {
        }
    }
}
 
Example #23
Source File: UnixPrintService.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
public boolean isAttributeValueSupported(Attribute attr,
                                         DocFlavor flavor,
                                         AttributeSet attributes) {
    if (attr == null) {
        throw new NullPointerException("null attribute");
    }
    if (flavor != null) {
        if (!isDocFlavorSupported(flavor)) {
            throw new IllegalArgumentException(flavor +
                                           " is an unsupported flavor");
        } else if (isAutoSense(flavor)) {
            return false;
        }
    }
    Class category = attr.getCategory();
    if (!isAttributeCategorySupported(category)) {
        return false;
    }
    else if (attr.getCategory() == Chromaticity.class) {
        if (flavor == null || isServiceFormattedFlavor(flavor)) {
            return attr == Chromaticity.COLOR;
        } else {
            return false;
        }
    }
    else if (attr.getCategory() == Copies.class) {
        return (flavor == null ||
               !(flavor.equals(DocFlavor.INPUT_STREAM.POSTSCRIPT) ||
                 flavor.equals(DocFlavor.URL.POSTSCRIPT) ||
                 flavor.equals(DocFlavor.BYTE_ARRAY.POSTSCRIPT))) &&
            isSupportedCopies((Copies)attr);
    } else if (attr.getCategory() == Destination.class) {
        URI uri = ((Destination)attr).getURI();
            if ("file".equals(uri.getScheme()) &&
                !(uri.getSchemeSpecificPart().equals(""))) {
            return true;
        } else {
        return false;
        }
    } else if (attr.getCategory() == Media.class) {
        if (attr instanceof MediaSizeName) {
            return isSupportedMedia((MediaSizeName)attr);
        } else {
            return false;
        }
    } else if (attr.getCategory() == OrientationRequested.class) {
        if (attr == OrientationRequested.REVERSE_PORTRAIT ||
            (flavor != null) &&
            !isServiceFormattedFlavor(flavor)) {
            return false;
        }
    } else if (attr.getCategory() == PageRanges.class) {
        if (flavor != null &&
            !(flavor.equals(DocFlavor.SERVICE_FORMATTED.PAGEABLE) ||
            flavor.equals(DocFlavor.SERVICE_FORMATTED.PRINTABLE))) {
            return false;
        }
    } else if (attr.getCategory() == SheetCollate.class) {
        if (flavor != null &&
            !(flavor.equals(DocFlavor.SERVICE_FORMATTED.PAGEABLE) ||
            flavor.equals(DocFlavor.SERVICE_FORMATTED.PRINTABLE))) {
            return false;
        }
    } else if (attr.getCategory() == Sides.class) {
        if (flavor != null &&
            !(flavor.equals(DocFlavor.SERVICE_FORMATTED.PAGEABLE) ||
            flavor.equals(DocFlavor.SERVICE_FORMATTED.PRINTABLE))) {
            return false;
        }
    }
    return true;
}
 
Example #24
Source File: PSStreamPrintService.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
public boolean isAttributeValueSupported(Attribute attr,
                                         DocFlavor flavor,
                                         AttributeSet attributes) {
    if (attr == null) {
        throw new NullPointerException("null attribute");
    }
    if (flavor != null && !isDocFlavorSupported(flavor)) {
        throw new IllegalArgumentException(flavor +
                                           " is an unsupported flavor");
    }
    Class category = attr.getCategory();
    if (!isAttributeCategorySupported(category)) {
        return false;
    }
    else if (attr.getCategory() == Chromaticity.class) {
        return attr == Chromaticity.COLOR;
    }
    else if (attr.getCategory() == Copies.class) {
        return isSupportedCopies((Copies)attr);
    } else if (attr.getCategory() == Media.class &&
               attr instanceof MediaSizeName) {
        return isSupportedMedia((MediaSizeName)attr);
    } else if (attr.getCategory() == OrientationRequested.class) {
        if (attr == OrientationRequested.REVERSE_PORTRAIT ||
            (flavor != null) &&
            !(flavor.equals(DocFlavor.SERVICE_FORMATTED.PAGEABLE) ||
            flavor.equals(DocFlavor.SERVICE_FORMATTED.PRINTABLE))) {
            return false;
        }
    } else if (attr.getCategory() == PageRanges.class) {
        if (flavor != null &&
            !(flavor.equals(DocFlavor.SERVICE_FORMATTED.PAGEABLE) ||
            flavor.equals(DocFlavor.SERVICE_FORMATTED.PRINTABLE))) {
            return false;
        }
    } else if (attr.getCategory() == SheetCollate.class) {
        if (flavor != null &&
            !(flavor.equals(DocFlavor.SERVICE_FORMATTED.PAGEABLE) ||
            flavor.equals(DocFlavor.SERVICE_FORMATTED.PRINTABLE))) {
            return false;
        }
    } else if (attr.getCategory() == Sides.class) {
        if (flavor != null &&
            !(flavor.equals(DocFlavor.SERVICE_FORMATTED.PAGEABLE) ||
            flavor.equals(DocFlavor.SERVICE_FORMATTED.PRINTABLE))) {
            return false;
        }
    }
    return true;
}
 
Example #25
Source File: PrintJob2D.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
private void updateAttributes() {
    Copies c = (Copies)attributes.get(Copies.class);
    jobAttributes.setCopies(c.getValue());

    SunPageSelection sel =
        (SunPageSelection)attributes.get(SunPageSelection.class);
    if (sel == SunPageSelection.RANGE) {
        jobAttributes.setDefaultSelection(DefaultSelectionType.RANGE);
    } else if (sel == SunPageSelection.SELECTION) {
        jobAttributes.setDefaultSelection(DefaultSelectionType.SELECTION);
    } else {
        jobAttributes.setDefaultSelection(DefaultSelectionType.ALL);
    }

    Destination dest = (Destination)attributes.get(Destination.class);
    if (dest != null) {
        jobAttributes.setDestination(DestinationType.FILE);
        jobAttributes.setFileName(dest.getURI().getPath());
    } else {
        jobAttributes.setDestination(DestinationType.PRINTER);
    }

    PrintService serv = printerJob.getPrintService();
    if (serv != null) {
        jobAttributes.setPrinter(serv.getName());
    }

    PageRanges range = (PageRanges)attributes.get(PageRanges.class);
    int[][] members = range.getMembers();
    jobAttributes.setPageRanges(members);

    SheetCollate collation =
        (SheetCollate)attributes.get(SheetCollate.class);
    if (collation == SheetCollate.COLLATED) {
        jobAttributes.setMultipleDocumentHandling(
        MultipleDocumentHandlingType.SEPARATE_DOCUMENTS_COLLATED_COPIES);
    } else {
        jobAttributes.setMultipleDocumentHandling(
        MultipleDocumentHandlingType.SEPARATE_DOCUMENTS_UNCOLLATED_COPIES);
    }

    Sides sides = (Sides)attributes.get(Sides.class);
    if (sides == Sides.TWO_SIDED_LONG_EDGE) {
        jobAttributes.setSides(SidesType.TWO_SIDED_LONG_EDGE);
    } else if (sides == Sides.TWO_SIDED_SHORT_EDGE) {
        jobAttributes.setSides(SidesType.TWO_SIDED_SHORT_EDGE);
    } else {
        jobAttributes.setSides(SidesType.ONE_SIDED);
    }

    // PageAttributes

    Chromaticity color =
        (Chromaticity)attributes.get(Chromaticity.class);
    if (color == Chromaticity.COLOR) {
        pageAttributes.setColor(ColorType.COLOR);
    } else {
        pageAttributes.setColor(ColorType.MONOCHROME);
    }

    OrientationRequested orient =
        (OrientationRequested)attributes.get(OrientationRequested.class);
    if (orient == OrientationRequested.LANDSCAPE) {
        pageAttributes.setOrientationRequested(
                                   OrientationRequestedType.LANDSCAPE);
    } else {
        pageAttributes.setOrientationRequested(
                                   OrientationRequestedType.PORTRAIT);
    }

    PrintQuality qual = (PrintQuality)attributes.get(PrintQuality.class);
    if (qual == PrintQuality.DRAFT) {
        pageAttributes.setPrintQuality(PrintQualityType.DRAFT);
    } else if (qual == PrintQuality.HIGH) {
        pageAttributes.setPrintQuality(PrintQualityType.HIGH);
    } else { // NORMAL
        pageAttributes.setPrintQuality(PrintQualityType.NORMAL);
    }

    Media msn = (Media)attributes.get(Media.class);
    if (msn != null && msn instanceof MediaSizeName) {
        MediaType mType = unMapMedia((MediaSizeName)msn);

        if (mType != null) {
            pageAttributes.setMedia(mType);
        }
    }
    debugPrintAttributes(false, false);
}
 
Example #26
Source File: PrintJob2D.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
private void updateAttributes() {
    Copies c = (Copies)attributes.get(Copies.class);
    jobAttributes.setCopies(c.getValue());

    SunPageSelection sel =
        (SunPageSelection)attributes.get(SunPageSelection.class);
    if (sel == SunPageSelection.RANGE) {
        jobAttributes.setDefaultSelection(DefaultSelectionType.RANGE);
    } else if (sel == SunPageSelection.SELECTION) {
        jobAttributes.setDefaultSelection(DefaultSelectionType.SELECTION);
    } else {
        jobAttributes.setDefaultSelection(DefaultSelectionType.ALL);
    }

    Destination dest = (Destination)attributes.get(Destination.class);
    if (dest != null) {
        jobAttributes.setDestination(DestinationType.FILE);
        jobAttributes.setFileName(dest.getURI().getPath());
    } else {
        jobAttributes.setDestination(DestinationType.PRINTER);
    }

    PrintService serv = printerJob.getPrintService();
    if (serv != null) {
        jobAttributes.setPrinter(serv.getName());
    }

    PageRanges range = (PageRanges)attributes.get(PageRanges.class);
    int[][] members = range.getMembers();
    jobAttributes.setPageRanges(members);

    SheetCollate collation =
        (SheetCollate)attributes.get(SheetCollate.class);
    if (collation == SheetCollate.COLLATED) {
        jobAttributes.setMultipleDocumentHandling(
        MultipleDocumentHandlingType.SEPARATE_DOCUMENTS_COLLATED_COPIES);
    } else {
        jobAttributes.setMultipleDocumentHandling(
        MultipleDocumentHandlingType.SEPARATE_DOCUMENTS_UNCOLLATED_COPIES);
    }

    Sides sides = (Sides)attributes.get(Sides.class);
    if (sides == Sides.TWO_SIDED_LONG_EDGE) {
        jobAttributes.setSides(SidesType.TWO_SIDED_LONG_EDGE);
    } else if (sides == Sides.TWO_SIDED_SHORT_EDGE) {
        jobAttributes.setSides(SidesType.TWO_SIDED_SHORT_EDGE);
    } else {
        jobAttributes.setSides(SidesType.ONE_SIDED);
    }

    // PageAttributes

    Chromaticity color =
        (Chromaticity)attributes.get(Chromaticity.class);
    if (color == Chromaticity.COLOR) {
        pageAttributes.setColor(ColorType.COLOR);
    } else {
        pageAttributes.setColor(ColorType.MONOCHROME);
    }

    OrientationRequested orient =
        (OrientationRequested)attributes.get(OrientationRequested.class);
    if (orient == OrientationRequested.LANDSCAPE) {
        pageAttributes.setOrientationRequested(
                                   OrientationRequestedType.LANDSCAPE);
    } else {
        pageAttributes.setOrientationRequested(
                                   OrientationRequestedType.PORTRAIT);
    }

    PrintQuality qual = (PrintQuality)attributes.get(PrintQuality.class);
    if (qual == PrintQuality.DRAFT) {
        pageAttributes.setPrintQuality(PrintQualityType.DRAFT);
    } else if (qual == PrintQuality.HIGH) {
        pageAttributes.setPrintQuality(PrintQualityType.HIGH);
    } else { // NORMAL
        pageAttributes.setPrintQuality(PrintQualityType.NORMAL);
    }

    Media msn = (Media)attributes.get(Media.class);
    if (msn != null && msn instanceof MediaSizeName) {
        MediaType mType = unMapMedia((MediaSizeName)msn);

        if (mType != null) {
            pageAttributes.setMedia(mType);
        }
    }
    debugPrintAttributes(false, false);
}
 
Example #27
Source File: UnixPrintService.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public boolean isAttributeValueSupported(Attribute attr,
                                         DocFlavor flavor,
                                         AttributeSet attributes) {
    if (attr == null) {
        throw new NullPointerException("null attribute");
    }
    if (flavor != null) {
        if (!isDocFlavorSupported(flavor)) {
            throw new IllegalArgumentException(flavor +
                                           " is an unsupported flavor");
        } else if (isAutoSense(flavor)) {
            return false;
        }
    }
    Class<? extends Attribute> category = attr.getCategory();
    if (!isAttributeCategorySupported(category)) {
        return false;
    }
    else if (attr.getCategory() == Chromaticity.class) {
        if (flavor == null || isServiceFormattedFlavor(flavor)) {
            return attr == Chromaticity.COLOR;
        } else {
            return false;
        }
    }
    else if (attr.getCategory() == Copies.class) {
        return (flavor == null ||
               !(flavor.equals(DocFlavor.INPUT_STREAM.POSTSCRIPT) ||
                 flavor.equals(DocFlavor.URL.POSTSCRIPT) ||
                 flavor.equals(DocFlavor.BYTE_ARRAY.POSTSCRIPT))) &&
            isSupportedCopies((Copies)attr);
    } else if (attr.getCategory() == Destination.class) {
        URI uri = ((Destination)attr).getURI();
            if ("file".equals(uri.getScheme()) &&
                !(uri.getSchemeSpecificPart().equals(""))) {
            return true;
        } else {
        return false;
        }
    } else if (attr.getCategory() == Media.class) {
        if (attr instanceof MediaSizeName) {
            return isSupportedMedia((MediaSizeName)attr);
        } else {
            return false;
        }
    } else if (attr.getCategory() == OrientationRequested.class) {
        if (attr == OrientationRequested.REVERSE_PORTRAIT ||
            (flavor != null) &&
            !isServiceFormattedFlavor(flavor)) {
            return false;
        }
    } else if (attr.getCategory() == PageRanges.class) {
        if (flavor != null &&
            !(flavor.equals(DocFlavor.SERVICE_FORMATTED.PAGEABLE) ||
            flavor.equals(DocFlavor.SERVICE_FORMATTED.PRINTABLE))) {
            return false;
        }
    } else if (attr.getCategory() == SheetCollate.class) {
        if (flavor != null &&
            !(flavor.equals(DocFlavor.SERVICE_FORMATTED.PAGEABLE) ||
            flavor.equals(DocFlavor.SERVICE_FORMATTED.PRINTABLE))) {
            return false;
        }
    } else if (attr.getCategory() == Sides.class) {
        if (flavor != null &&
            !(flavor.equals(DocFlavor.SERVICE_FORMATTED.PAGEABLE) ||
            flavor.equals(DocFlavor.SERVICE_FORMATTED.PRINTABLE))) {
            return false;
        }
    }
    return true;
}
 
Example #28
Source File: WPrinterJob.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * copy the attributes to the native print job
 * Note that this method, and hence the re-initialisation
 * of the GDI values is done on each entry to the print dialog since
 * an app could redisplay the print dialog for the same job and
 * 1) the application may have changed attribute settings
 * 2) the application may have changed the printer.
 * In the event that the user changes the printer using the
  dialog, then it is up to GDI to report back all changed values.
 */
@Override
protected void setAttributes(PrintRequestAttributeSet attributes)
    throws PrinterException {

    // initialize attribute values
    initAttributeMembers();
    super.setAttributes(attributes);

    mAttCopies = getCopiesInt();
    mDestination = destinationAttr;

    if (attributes == null) {
        return; // now always use attributes, so this shouldn't happen.
    }
    Attribute[] attrs = attributes.toArray();
    for (int i=0; i< attrs.length; i++) {
        Attribute attr = attrs[i];
        try {
             if (attr.getCategory() == Sides.class) {
                setSidesAttrib(attr);
            }
            else if (attr.getCategory() == Chromaticity.class) {
                setColorAttrib(attr);
            }
            else if (attr.getCategory() == PrinterResolution.class) {
                if (myService.isAttributeValueSupported(attr, null, null)) {
                    setResolutionAttrib(attr);
                }
            }
            else if (attr.getCategory() == PrintQuality.class) {
                setQualityAttrib(attr);
            }
            else if (attr.getCategory() == SheetCollate.class) {
                setCollateAttrib(attr);
            }  else if (attr.getCategory() == Media.class ||
                        attr.getCategory() == SunAlternateMedia.class) {
                /* SunAlternateMedia is used if its a tray, and
                 * any Media that is specified is not a tray.
                 */
                if (attr.getCategory() == SunAlternateMedia.class) {
                    Media media = (Media)attributes.get(Media.class);
                    if (media == null ||
                        !(media instanceof MediaTray)) {
                        attr = ((SunAlternateMedia)attr).getMedia();
                    }
                }
                if (attr instanceof MediaSizeName) {
                    setWin32MediaAttrib(attr);
                }
                if (attr instanceof MediaTray) {
                    setMediaTrayAttrib(attr);
                }
            }

        } catch (ClassCastException e) {
        }
    }
}
 
Example #29
Source File: PSStreamPrintService.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
public boolean isAttributeValueSupported(Attribute attr,
                                         DocFlavor flavor,
                                         AttributeSet attributes) {
    if (attr == null) {
        throw new NullPointerException("null attribute");
    }
    if (flavor != null && !isDocFlavorSupported(flavor)) {
        throw new IllegalArgumentException(flavor +
                                           " is an unsupported flavor");
    }
    Class category = attr.getCategory();
    if (!isAttributeCategorySupported(category)) {
        return false;
    }
    else if (attr.getCategory() == Chromaticity.class) {
        return attr == Chromaticity.COLOR;
    }
    else if (attr.getCategory() == Copies.class) {
        return isSupportedCopies((Copies)attr);
    } else if (attr.getCategory() == Media.class &&
               attr instanceof MediaSizeName) {
        return isSupportedMedia((MediaSizeName)attr);
    } else if (attr.getCategory() == OrientationRequested.class) {
        if (attr == OrientationRequested.REVERSE_PORTRAIT ||
            (flavor != null) &&
            !(flavor.equals(DocFlavor.SERVICE_FORMATTED.PAGEABLE) ||
            flavor.equals(DocFlavor.SERVICE_FORMATTED.PRINTABLE))) {
            return false;
        }
    } else if (attr.getCategory() == PageRanges.class) {
        if (flavor != null &&
            !(flavor.equals(DocFlavor.SERVICE_FORMATTED.PAGEABLE) ||
            flavor.equals(DocFlavor.SERVICE_FORMATTED.PRINTABLE))) {
            return false;
        }
    } else if (attr.getCategory() == SheetCollate.class) {
        if (flavor != null &&
            !(flavor.equals(DocFlavor.SERVICE_FORMATTED.PAGEABLE) ||
            flavor.equals(DocFlavor.SERVICE_FORMATTED.PRINTABLE))) {
            return false;
        }
    } else if (attr.getCategory() == Sides.class) {
        if (flavor != null &&
            !(flavor.equals(DocFlavor.SERVICE_FORMATTED.PAGEABLE) ||
            flavor.equals(DocFlavor.SERVICE_FORMATTED.PRINTABLE))) {
            return false;
        }
    }
    return true;
}
 
Example #30
Source File: WPrinterJob.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
private void setJobAttributes(PrintRequestAttributeSet attributes,
                                    int fields, int values,
                                    short copies,
                                    short dmPaperSize,
                                    short dmPaperWidth,
                                    short dmPaperLength,
                                    short dmDefaultSource,
                                    short xRes,
                                    short yRes) {

    if (attributes == null) {
        return;
    }

    if ((fields & DM_COPIES) != 0) {
        attributes.add(new Copies(copies));
    }

    if ((fields & DM_COLLATE) != 0) {
        if ((values & SET_COLLATED) != 0) {
            attributes.add(SheetCollate.COLLATED);
        } else {
            attributes.add(SheetCollate.UNCOLLATED);
        }
    }

    if ((fields & DM_ORIENTATION) != 0) {
        if ((values & SET_ORIENTATION) != 0) {
            attributes.add(OrientationRequested.LANDSCAPE);
        } else {
            attributes.add(OrientationRequested.PORTRAIT);
        }
    }

    if ((fields & DM_COLOR) != 0) {
        if ((values & SET_COLOR) != 0) {
            attributes.add(Chromaticity.COLOR);
        } else {
            attributes.add(Chromaticity.MONOCHROME);
        }
    }

    if ((fields & DM_PRINTQUALITY) != 0) {
        /* value < 0 indicates quality setting.
         * value > 0 indicates X resolution. In that case
         * hopefully we will also find y-resolution specified.
         * If its not, assume its the same as x-res.
         * Maybe Java code should try to reconcile this against
         * the printers claimed set of supported resolutions.
         */
        if (xRes < 0) {
            PrintQuality quality;
            if ((values & SET_RES_LOW) != 0) {
                quality = PrintQuality.DRAFT;
            } else if ((fields & SET_RES_HIGH) != 0) {
                quality = PrintQuality.HIGH;
            } else {
                quality = PrintQuality.NORMAL;
            }
            attributes.add(quality);
        } else if (xRes > 0 && yRes > 0) {
            attributes.add(
                new PrinterResolution(xRes, yRes, PrinterResolution.DPI));
        }
    }

    if ((fields & DM_DUPLEX) != 0) {
        Sides sides;
        if ((values & SET_DUP_VERTICAL) != 0) {
            sides = Sides.TWO_SIDED_LONG_EDGE;
        } else if ((values & SET_DUP_HORIZONTAL) != 0) {
            sides = Sides.TWO_SIDED_SHORT_EDGE;
        } else {
            sides = Sides.ONE_SIDED;
        }
        attributes.add(sides);
    }

    if ((fields & DM_PAPERSIZE) != 0) {
        addPaperSize(attributes, dmPaperSize, dmPaperWidth, dmPaperLength);
    }

    if ((fields & DM_DEFAULTSOURCE) != 0) {
        MediaTray tray =
            ((Win32PrintService)myService).findMediaTray(dmDefaultSource);
        attributes.add(new SunAlternateMedia(tray));
    }
}