Java Code Examples for javax.print.attribute.Attribute

The following are top voted examples for showing how to use javax.print.attribute.Attribute. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: OpenJSharp   File: UnixPrintService.java   Source Code and License 6 votes vote down vote up
public boolean
    isAttributeCategorySupported(Class<? extends Attribute> category)
{
    if (category == null) {
        throw new NullPointerException("null category");
    }
    if (!(Attribute.class.isAssignableFrom(category))) {
        throw new IllegalArgumentException(category +
                                         " is not an Attribute");
    }

    for (int i=0;i<otherAttrCats.length;i++) {
        if (category == otherAttrCats[i]) {
            return true;
        }
    }
    return false;
}
 
Example 2
Project: jdk8u-jdk   File: Win32PrintService.java   Source Code and License 6 votes vote down vote up
public boolean
    isAttributeCategorySupported(Class<? extends Attribute> category)
{

    if (category == null) {
        throw new NullPointerException("null category");
    }

    if (!(Attribute.class.isAssignableFrom(category))) {
        throw new IllegalArgumentException(category +
                                           " is not an Attribute");
    }

    Class[] classList = getSupportedAttributeCategories();
    for (int i = 0; i < classList.length; i++) {
        if (category.equals(classList[i])) {
            return true;
        }
    }

    return false;
}
 
Example 3
Project: openjdk-jdk10   File: WPrinterJob.java   Source Code and License 6 votes vote down vote up
private void setMediaTrayAttrib(Attribute attr) {
    if (attr == MediaTray.BOTTOM) {
        mAttMediaTray = 2;    // DMBIN_LOWER
    } else if (attr == MediaTray.ENVELOPE) {
        mAttMediaTray = 5;    // DMBIN_ENVELOPE
    } else if (attr == MediaTray.LARGE_CAPACITY) {
        mAttMediaTray = 11;      // DMBIN_LARGECAPACITY
    } else if (attr == MediaTray.MAIN) {
        mAttMediaTray =1;               // DMBIN_UPPER
    } else if (attr == MediaTray.MANUAL) {
        mAttMediaTray = 4;              // DMBIN_MANUAL
    } else if (attr == MediaTray.MIDDLE) {
        mAttMediaTray = 3;              // DMBIN_MIDDLE
    } else if (attr == MediaTray.SIDE) {
        // no equivalent predefined value
        mAttMediaTray = 7;              // DMBIN_AUTO
    } else if (attr == MediaTray.TOP) {
        mAttMediaTray = 1;              // DMBIN_UPPER
    } else {
        if (attr instanceof Win32MediaTray) {
            mAttMediaTray = ((Win32MediaTray)attr).winID;
        } else {
            mAttMediaTray = 1;  // default
        }
    }
}
 
Example 4
Project: jdk8u-jdk   File: UnixPrintService.java   Source Code and License 6 votes vote down vote up
public PrintServiceAttributeSet getUpdatedAttributes() {
    PrintServiceAttributeSet currSet = getDynamicAttributes();
    if (lastSet == null) {
        lastSet = currSet;
        return AttributeSetUtilities.unmodifiableView(currSet);
    } else {
        PrintServiceAttributeSet updates =
            new HashPrintServiceAttributeSet();
        Attribute []attrs = currSet.toArray();
        Attribute attr;
        for (int i=0; i<attrs.length; i++) {
            attr = attrs[i];
            if (!lastSet.containsValue(attr)) {
                updates.add(attr);
            }
        }
        lastSet = currSet;
        return AttributeSetUtilities.unmodifiableView(updates);
    }
}
 
Example 5
Project: OpenJSharp   File: Win32PrintService.java   Source Code and License 6 votes vote down vote up
public PrintServiceAttributeSet getUpdatedAttributes() {
    PrintServiceAttributeSet currSet = getDynamicAttributes();
    if (lastSet == null) {
        lastSet = currSet;
        return AttributeSetUtilities.unmodifiableView(currSet);
    } else {
        PrintServiceAttributeSet updates =
            new HashPrintServiceAttributeSet();
        Attribute []attrs =  currSet.toArray();
        for (int i=0; i<attrs.length; i++) {
            Attribute attr = attrs[i];
            if (!lastSet.containsValue(attr)) {
                updates.add(attr);
            }
        }
        lastSet = currSet;
        return AttributeSetUtilities.unmodifiableView(updates);
    }
}
 
Example 6
Project: jdk8u-jdk   File: Win32PrintService.java   Source Code and License 6 votes vote down vote up
public PrintServiceAttributeSet getUpdatedAttributes() {
    PrintServiceAttributeSet currSet = getDynamicAttributes();
    if (lastSet == null) {
        lastSet = currSet;
        return AttributeSetUtilities.unmodifiableView(currSet);
    } else {
        PrintServiceAttributeSet updates =
            new HashPrintServiceAttributeSet();
        Attribute []attrs =  currSet.toArray();
        for (int i=0; i<attrs.length; i++) {
            Attribute attr = attrs[i];
            if (!lastSet.containsValue(attr)) {
                updates.add(attr);
            }
        }
        lastSet = currSet;
        return AttributeSetUtilities.unmodifiableView(updates);
    }
}
 
Example 7
Project: OpenJSharp   File: WPrinterJob.java   Source Code and License 6 votes vote down vote up
private void setMediaTrayAttrib(Attribute attr) {
    if (attr == MediaTray.BOTTOM) {
        mAttMediaTray = 2;    // DMBIN_LOWER
    } else if (attr == MediaTray.ENVELOPE) {
        mAttMediaTray = 5;    // DMBIN_ENVELOPE
    } else if (attr == MediaTray.LARGE_CAPACITY) {
        mAttMediaTray = 11;      // DMBIN_LARGECAPACITY
    } else if (attr == MediaTray.MAIN) {
        mAttMediaTray =1;               // DMBIN_UPPER
    } else if (attr == MediaTray.MANUAL) {
        mAttMediaTray = 4;              // DMBIN_MANUAL
    } else if (attr == MediaTray.MIDDLE) {
        mAttMediaTray = 3;              // DMBIN_MIDDLE
    } else if (attr == MediaTray.SIDE) {
        // no equivalent predefined value
        mAttMediaTray = 7;              // DMBIN_AUTO
    } else if (attr == MediaTray.TOP) {
        mAttMediaTray = 1;              // DMBIN_UPPER
    } else {
        if (attr instanceof Win32MediaTray) {
            mAttMediaTray = ((Win32MediaTray)attr).winID;
        } else {
            mAttMediaTray = 1;  // default
        }
    }
}
 
Example 8
Project: OpenJSharp   File: RasterPrinterJob.java   Source Code and License 5 votes vote down vote up
protected boolean isSupportedValue(Attribute attrval,
                                 PrintRequestAttributeSet attrset) {
    PrintService ps = getPrintService();
    return
        (attrval != null && ps != null &&
         ps.isAttributeValueSupported(attrval,
                                      DocFlavor.SERVICE_FORMATTED.PAGEABLE,
                                      attrset));
}
 
Example 9
Project: OpenJSharp   File: PrintJobAttributeException.java   Source Code and License 5 votes vote down vote up
public Attribute[] getUnsupportedValues() {
    if (attr == null) {
        return null;
    } else {
        Attribute [] attrs = { attr};
        return attrs;
    }
}
 
Example 10
Project: jdk8u-jdk   File: UnixPrintService.java   Source Code and License 5 votes vote down vote up
public AttributeSet getUnsupportedAttributes(DocFlavor flavor,
                                             AttributeSet attributes) {

    if (flavor != null && !isDocFlavorSupported(flavor)) {
        throw new IllegalArgumentException("flavor " + flavor +
                                           "is not supported");
    }

    if (attributes == null) {
        return null;
    }

    Attribute attr;
    AttributeSet unsupp = new HashAttributeSet();
    Attribute []attrs = attributes.toArray();
    for (int i=0; i<attrs.length; i++) {
        try {
            attr = attrs[i];
            if (!isAttributeCategorySupported(attr.getCategory())) {
                unsupp.add(attr);
            } else if (!isAttributeValueSupported(attr, flavor,
                                                  attributes)) {
                unsupp.add(attr);
            }
        } catch (ClassCastException e) {
        }
    }
    if (unsupp.isEmpty()) {
        return null;
    } else {
        return unsupp;
    }
}
 
Example 11
Project: openjdk-jdk10   File: ServiceDlgSheetCollateTest.java   Source Code and License 5 votes vote down vote up
private static void printTest() {
    ServiceDlgSheetCollateTest pd = new ServiceDlgSheetCollateTest();
    DocFlavor flavor = DocFlavor.INPUT_STREAM.JPEG;
    //DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE;
    PrintService defService = null, service[] = null;
    defService = PrintServiceLookup.lookupDefaultPrintService();
    service = PrintServiceLookup.lookupPrintServices(flavor, null);

    if ((service == null) || (service.length == 0)) {
        throw new RuntimeException("No Printer services found");
    }
    if (defService != null) {
        System.out.println("\nDefault print service: " + service );
        System.out.println("is flavor: "+flavor+" supported? "+
                        defService.isDocFlavorSupported(flavor));
        System.out.println("is SheetCollate category supported? "+
              defService.isAttributeCategorySupported(SheetCollate.class));
        System.out.println("is SheetCollate.COLLATED value supported ? "+
              defService.isAttributeValueSupported(SheetCollate.COLLATED,
                                                        flavor, null));
    }
    HashPrintRequestAttributeSet prSet = new HashPrintRequestAttributeSet();
    try {
        PrintService selService = ServiceUI.printDialog(null, 200, 200, service, defService, flavor, prSet);
    } catch (IllegalArgumentException ia) {
        System.out.println("Exception thrown : " + ia);
    }

    System.out.println("\nSelected Values\n");
    Attribute attr[] = prSet.toArray();
    for (int x = 0; x < attr.length; x ++) {
        System.out.println("Attribute: " + attr[x].getName() + " Value: " + attr[x]);
    }

}
 
Example 12
Project: jdk8u-jdk   File: UnixPrintServiceLookup.java   Source Code and License 5 votes vote down vote up
private boolean matchesAttributes(PrintService service,
                                  PrintServiceAttributeSet attributes) {

    Attribute [] attrs =  attributes.toArray();
    Attribute serviceAttr;
    for (int i=0; i<attrs.length; i++) {
        serviceAttr
            = service.getAttribute((Class<PrintServiceAttribute>)attrs[i].getCategory());
        if (serviceAttr == null || !serviceAttr.equals(attrs[i])) {
            return false;
        }
    }
    return true;
}
 
Example 13
Project: jdk8u-jdk   File: WPrinterJob.java   Source Code and License 5 votes vote down vote up
private void setSidesAttrib(Attribute attr) {
    if (attr == Sides.TWO_SIDED_LONG_EDGE) {
        mAttSides = 2; // DMDUP_VERTICAL
    } else if (attr == Sides.TWO_SIDED_SHORT_EDGE) {
        mAttSides = 3; // DMDUP_HORIZONTAL
    } else { // Sides.ONE_SIDED
        mAttSides = 1;
    }
}
 
Example 14
Project: jdk8u-jdk   File: RasterPrinterJob.java   Source Code and License 5 votes vote down vote up
protected boolean isSupportedValue(Attribute attrval,
                                 PrintRequestAttributeSet attrset) {
    PrintService ps = getPrintService();
    return
        (attrval != null && ps != null &&
         ps.isAttributeValueSupported(attrval,
                                      DocFlavor.SERVICE_FORMATTED.PAGEABLE,
                                      attrset));
}
 
Example 15
Project: openjdk-jdk10   File: WPrinterJob.java   Source Code and License 5 votes vote down vote up
private void setQualityAttrib(Attribute attr) {
    if (attr == PrintQuality.HIGH) {
        mAttQuality = -4; // DMRES_HIGH
    } else if (attr == PrintQuality.NORMAL) {
        mAttQuality = -3; // DMRES_MEDIUM
    } else {
        mAttQuality = -2; // DMRES_LOW
    }
}
 
Example 16
Project: openjdk-jdk10   File: WPrinterJob.java   Source Code and License 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
Project: jdk8u-jdk   File: WPrinterJob.java   Source Code and License 5 votes vote down vote up
private void setCollateAttrib(Attribute attr) {
    if (attr == SheetCollate.COLLATED) {
        mAttCollate = 1; // DMCOLLATE_TRUE
    } else {
        mAttCollate = 0; // DMCOLLATE_FALSE
    }
}
 
Example 18
Project: jdk8u-jdk   File: PSStreamPrintService.java   Source Code and License 5 votes vote down vote up
public AttributeSet getUnsupportedAttributes(DocFlavor flavor,
                                             AttributeSet attributes) {

    if (flavor != null && !isDocFlavorSupported(flavor)) {
        throw new IllegalArgumentException("flavor " + flavor +
                                           "is not supported");
    }

    if (attributes == null) {
        return null;
    }

    Attribute attr;
    AttributeSet unsupp = new HashAttributeSet();
    Attribute[] attrs = attributes.toArray();
    for (int i=0; i<attrs.length; i++) {
        try {
            attr = attrs[i];
            if (!isAttributeCategorySupported(attr.getCategory())) {
                unsupp.add(attr);
            } else if (!isAttributeValueSupported(attr, flavor,
                                                  attributes)) {
                unsupp.add(attr);
            }
        } catch (ClassCastException e) {
        }
    }
    if (unsupp.isEmpty()) {
        return null;
    } else {
        return unsupp;
    }
}
 
Example 19
Project: OpenJSharp   File: PrintJobAttributeException.java   Source Code and License 4 votes vote down vote up
PrintJobAttributeException(String s, Class cat, Attribute attrval) {
    super(s);
    attr = attrval;
    category = cat;
}
 
Example 20
Project: OpenJSharp   File: PSStreamPrintService.java   Source Code and License 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 21
Project: openjdk-jdk10   File: DummyPrintTest.java   Source Code and License 4 votes vote down vote up
@Override
public boolean isAttributeCategorySupported(Class<? extends Attribute> category) {
    return false;
}
 
Example 22
Project: jdk8u-jdk   File: PrintServiceStub.java   Source Code and License 4 votes vote down vote up
@Override
public Object getSupportedAttributeValues(
        Class<? extends Attribute> category, DocFlavor flavor,
        AttributeSet attributes) {
    return _attributes.get(category);
}
 
Example 23
Project: OpenJSharp   File: UnixPrintService.java   Source Code and License 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
Project: openjdk-jdk10   File: WPrinterJob.java   Source Code and License 4 votes vote down vote up
private void setQualityAttrib(Attribute attr,
                              PrintRequestAttributeSet set) {
    setQualityAttrib(attr);
    set.add(attr);
}
 
Example 25
Project: jdk8u-jdk   File: PSStreamPrintJob.java   Source Code and License 4 votes vote down vote up
private void getAttributeValues(DocFlavor flavor) throws PrintException {

        Attribute attr;
        Class category;

        if (reqAttrSet.get(Fidelity.class) == Fidelity.FIDELITY_TRUE) {
            fidelity = true;
        } else {
            fidelity = false;
        }

        Attribute []attrs = reqAttrSet.toArray();
        for (int i=0; i<attrs.length; i++) {
            attr = attrs[i];
            category = attr.getCategory();
            if (fidelity == true) {
                if (!service.isAttributeCategorySupported(category)) {
                    notifyEvent(PrintJobEvent.JOB_FAILED);
                    throw new PrintJobAttributeException(
                        "unsupported category: " + category, category, null);
                } else if
                    (!service.isAttributeValueSupported(attr, flavor, null)) {
                    notifyEvent(PrintJobEvent.JOB_FAILED);
                    throw new PrintJobAttributeException(
                        "unsupported attribute: " + attr, null, attr);
                }
            }
            if (category == JobName.class) {
                jobName = ((JobName)attr).getValue();
            } else if (category == Copies.class) {
                copies = ((Copies)attr).getValue();
            } else if (category == Media.class) {
                if (attr instanceof MediaSizeName &&
                    service.isAttributeValueSupported(attr, null, null)) {
                    mediaSize =
                        MediaSize.getMediaSizeForName((MediaSizeName)attr);
                }
            } else if (category == OrientationRequested.class) {
                orient = (OrientationRequested)attr;
            }
        }
    }
 
Example 26
Project: OpenJSharp   File: Win32PrintJob.java   Source Code and License 4 votes vote down vote up
private PrintDocument createPrintDocument() throws PrintException{
    PrintDocument printDocument = new PrintDocument();
    PrinterSettings settings = printDocument.get_PrinterSettings();
    settings.set_PrinterName( service.getName() );
    if( !settings.get_IsValid() ){
    	throw new PrintException("Printer name ''" + service.getName() + "' is invalid.");
    }
    
    if( jobName != null ){
    	printDocument.set_DocumentName( jobName );
    }
    printDocument.get_DefaultPageSettings().set_Color(printColor);
    
    Attribute destination = reqAttrSet.get(Destination.class);
    if(destination instanceof Destination){
    	File destFile = new File(((Destination)destination).getURI());
        settings.set_PrintFileName(destFile.getAbsolutePath());
        settings.set_PrintToFile(true);
    }
    
    settings.set_Copies((short)copies);
    boolean collated = false;
    if(copies > 1){
        Object collate = reqAttrSet.get(SheetCollate.class);
        if( collate == null ){
        	collate = service.getDefaultAttributeValue(SheetCollate.class);
        }
        collated = collate == SheetCollate.COLLATED;
        settings.set_Collate( collated );
    }
    Attribute pageRangeObj = reqAttrSet.get(PageRanges.class);
    if( pageRangeObj != null ){
    	int[][] ranges = ((PageRanges)pageRangeObj).getMembers();
    	if( ranges.length > 1 ){
			settings.set_PrintRange( PrintRange.wrap( PrintRange.Selection ) );
    	} else {
    		if( ranges.length > 0 ){
    			settings.set_FromPage(ranges[0][0]);
    			settings.set_ToPage(ranges[0][1]);
    			settings.set_PrintRange( PrintRange.wrap( PrintRange.SomePages ) );
    		} // else allPages???
    	}
    } else {
    	settings.set_PrintRange( PrintRange.wrap( PrintRange.AllPages ) );
    }
    pageRanges = new PageNumberConverter( (PageRanges)pageRangeObj, copies, collated );
    return printDocument;
}
 
Example 27
Project: openjdk-jdk10   File: PSStreamPrintService.java   Source Code and License 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<? extends Attribute> 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 28
Project: openjdk-jdk10   File: Win32PrintJob.java   Source Code and License 4 votes vote down vote up
private void getAttributeValues(DocFlavor flavor) throws PrintException {

        if (reqAttrSet.get(Fidelity.class) == Fidelity.FIDELITY_TRUE) {
            fidelity = true;
        } else {
            fidelity = false;
        }

        Class<? extends Attribute> category;
        Attribute [] attrs = reqAttrSet.toArray();
        for (int i=0; i<attrs.length; i++) {
            Attribute attr = attrs[i];
            category = attr.getCategory();
            if (fidelity == true) {
                if (!service.isAttributeCategorySupported(category)) {
                    notifyEvent(PrintJobEvent.JOB_FAILED);
                    throw new PrintJobAttributeException(
                        "unsupported category: " + category, category, null);
                } else if
                    (!service.isAttributeValueSupported(attr, flavor, null)) {
                    notifyEvent(PrintJobEvent.JOB_FAILED);
                    throw new PrintJobAttributeException(
                        "unsupported attribute: " + attr, null, attr);
                }
            }
            if (category == Destination.class) {
              URI uri = ((Destination)attr).getURI();
              if (!"file".equals(uri.getScheme())) {
                notifyEvent(PrintJobEvent.JOB_FAILED);
                throw new PrintException("Not a file: URI");
              } else {
                try {
                  mDestination = (new File(uri)).getPath();
                } catch (Exception e) {
                  throw new PrintException(e);
                }
                // check write access
                SecurityManager security = System.getSecurityManager();
                if (security != null) {
                  try {
                    security.checkWrite(mDestination);
                  } catch (SecurityException se) {
                    notifyEvent(PrintJobEvent.JOB_FAILED);
                    throw new PrintException(se);
                  }
                }
              }
            } else if (category == JobName.class) {
                jobName = ((JobName)attr).getValue();
            } else if (category == Copies.class) {
                copies = ((Copies)attr).getValue();
            } else if (category == Media.class) {
              if (attr instanceof MediaSizeName) {
                    mediaName = (MediaSizeName)attr;
                    // If requested MediaSizeName is not supported,
                    // get the corresponding media size - this will
                    // be used to create a new PageFormat.
                    if (!service.isAttributeValueSupported(attr, null, null)) {
                        mediaSize = MediaSize.getMediaSizeForName(mediaName);
                    }
                }
            } else if (category == OrientationRequested.class) {
                orient = (OrientationRequested)attr;
            }
        }
    }
 
Example 29
Project: jdk8u-jdk   File: UnixPrintService.java   Source Code and License 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 30
Project: openjdk-jdk10   File: DummyPrintTest.java   Source Code and License 4 votes vote down vote up
@Override
public boolean isAttributeValueSupported(Attribute attrval,
                                         DocFlavor flavor,
                                         AttributeSet attributes) {
    return false;
}
 
Example 31
Project: openjdk-jdk10   File: DummyPrintTest.java   Source Code and License 4 votes vote down vote up
@Override
public Object getDefaultAttributeValue(Class<? extends Attribute> category) {
    return null;
}
 
Example 32
Project: openjdk-jdk10   File: DummyPrintTest.java   Source Code and License 4 votes vote down vote up
@Override
public Object getSupportedAttributeValues(Class<? extends Attribute> category,
                                DocFlavor flavor, AttributeSet attributes) {
    return null;
}
 
Example 33
Project: jdk8u-jdk   File: WPrinterJob.java   Source Code and License 4 votes vote down vote up
private void setCollateAttrib(Attribute attr,
                              PrintRequestAttributeSet set) {
    setCollateAttrib(attr);
    set.add(attr);
}
 
Example 34
Project: jdk8u-jdk   File: PageRanges.java   Source Code and License 2 votes vote down vote up
/**
 * Get the printing attribute class which is to be used as the "category"
 * for this printing attribute value.
 * <P>
 * For class PageRanges, the category is class PageRanges itself.
 *
 * @return  Printing attribute class (category), an instance of class
 *          {@link java.lang.Class java.lang.Class}.
 */
public final Class<? extends Attribute> getCategory() {
    return PageRanges.class;
}
 
Example 35
Project: openjdk-jdk10   File: JobMediaSheetsSupported.java   Source Code and License 2 votes vote down vote up
/**
 * Get the printing attribute class which is to be used as the "category"
 * for this printing attribute value.
 * <p>
 * For class {@code JobMediaSheetsSupported}, the category is class
 * {@code JobMediaSheetsSupported} itself.
 *
 * @return printing attribute class (category), an instance of class
 *         {@link Class java.lang.Class}
 */
public final Class<? extends Attribute> getCategory() {
    return JobMediaSheetsSupported.class;
}
 
Example 36
Project: jdk8u-jdk   File: PrinterMoreInfoManufacturer.java   Source Code and License 2 votes vote down vote up
/**
 * Get the printing attribute class which is to be used as the "category"
 * for this printing attribute value.
 * <P>
 * For class PrinterMoreInfoManufacturer, the category is
 * class PrinterMoreInfoManufacturer itself.
 *
 * @return  Printing attribute class (category), an instance of class
 *          {@link java.lang.Class java.lang.Class}.
 */
public final Class<? extends Attribute> getCategory() {
    return PrinterMoreInfoManufacturer.class;
}
 
Example 37
Project: openjdk-jdk10   File: Fidelity.java   Source Code and License 2 votes vote down vote up
/**
 * Get the printing attribute class which is to be used as the "category"
 * for this printing attribute value.
 * <p>
 * For class {@code Fidelity} the category is class
 * {@code Fidelity} itself.
 *
 * @return printing attribute class (category), an instance of class
 *         {@link Class java.lang.Class}
 */
public final Class<? extends Attribute> getCategory() {
    return Fidelity.class;
}
 
Example 38
Project: openjdk-jdk10   File: JobImpressionsCompleted.java   Source Code and License 2 votes vote down vote up
/**
 * Get the printing attribute class which is to be used as the "category"
 * for this printing attribute value.
 * <p>
 * For class {@code JobImpressionsCompleted}, the category is class
 * {@code JobImpressionsCompleted} itself.
 *
 * @return printing attribute class (category), an instance of class
 *         {@link Class java.lang.Class}
 */
public final Class<? extends Attribute> getCategory() {
    return JobImpressionsCompleted.class;
}
 
Example 39
Project: jdk8u-jdk   File: JobKOctets.java   Source Code and License 2 votes vote down vote up
/**
 * Get the printing attribute class which is to be used as the "category"
 * for this printing attribute value.
 * <P>
 * For class JobKOctets, the category is class JobKOctets itself.
 *
 * @return  Printing attribute class (category), an instance of class
 *          {@link java.lang.Class java.lang.Class}.
 */
public final Class<? extends Attribute> getCategory() {
    return JobKOctets.class;
}
 
Example 40
Project: OpenJSharp   File: PrinterName.java   Source Code and License 2 votes vote down vote up
/**
 * Get the printing attribute class which is to be used as the "category"
 * for this printing attribute value.
 * <P>
 * For class PrinterName, the category is
 * class PrinterName itself.
 *
 * @return  Printing attribute class (category), an instance of class
 *          {@link java.lang.Class java.lang.Class}.
 */
public final Class<? extends Attribute> getCategory() {
    return PrinterName.class;
}
 
Example 41
Project: OpenJSharp   File: SheetCollate.java   Source Code and License 2 votes vote down vote up
/**
 * Get the printing attribute class which is to be used as the "category"
 * for this printing attribute value.
 * <P>
 * For class SheetCollate, the category is class SheetCollate itself.
 *
 * @return  Printing attribute class (category), an instance of class
 *          {@link java.lang.Class java.lang.Class}.
 */
public final Class<? extends Attribute> getCategory() {
    return SheetCollate.class;
}
 
Example 42
Project: OpenJSharp   File: NumberOfInterveningJobs.java   Source Code and License 2 votes vote down vote up
/**
 * Get the printing attribute class which is to be used as the "category"
 * for this printing attribute value.
 * <P>
 * For class NumberOfInterveningJobs, the
 * category is class NumberOfInterveningJobs itself.
 *
 * @return  Printing attribute class (category), an instance of class
 *          {@link java.lang.Class java.lang.Class}.
 */
public final Class<? extends Attribute> getCategory() {
    return NumberOfInterveningJobs.class;
}
 
Example 43
Project: OpenJSharp   File: PrinterLocation.java   Source Code and License 2 votes vote down vote up
/**
 * Get the printing attribute class which is to be used as the "category"
 * for this printing attribute value.
 * <P>
 * For class PrinterLocation, the
 * category is class PrinterLocation itself.
 *
 * @return  Printing attribute class (category), an instance of class
 *          {@link java.lang.Class java.lang.Class}.
 */
public final Class<? extends Attribute> getCategory() {
    return PrinterLocation.class;
}
 
Example 44
Project: OpenJSharp   File: NumberUp.java   Source Code and License 2 votes vote down vote up
/**
 * Get the printing attribute class which is to be used as the "category"
 * for this printing attribute value.
 * <P>
 * For class NumberUp, the category is class NumberUp itself.
 *
 * @return  Printing attribute class (category), an instance of class
 *          {@link java.lang.Class java.lang.Class}.
 */
public final Class<? extends Attribute> getCategory() {
    return NumberUp.class;
}
 
Example 45
Project: OpenJSharp   File: JobPrioritySupported.java   Source Code and License 2 votes vote down vote up
/**
 * Get the printing attribute class which is to be used as the "category"
 * for this printing attribute value.
 * <P>
 * For class JobPrioritySupported, the
 * category is class JobPrioritySupported itself.
 *
 * @return  Printing attribute class (category), an instance of class
 *          {@link java.lang.Class java.lang.Class}.
 */
public final Class<? extends Attribute> getCategory() {
    return JobPrioritySupported.class;
}
 
Example 46
Project: OpenJSharp   File: PDLOverrideSupported.java   Source Code and License 2 votes vote down vote up
/**
 * Get the printing attribute class which is to be used as the "category"
 * for this printing attribute value.
 * <P>
 * For class PDLOverrideSupported and any vendor-defined subclasses, the
 * category is class PDLOverrideSupported itself.
 *
 * @return  Printing attribute class (category), an instance of class
 *          {@link java.lang.Class java.lang.Class}.
 */
public final Class<? extends Attribute> getCategory() {
    return PDLOverrideSupported.class;
}
 
Example 47
Project: OpenJSharp   File: PrinterState.java   Source Code and License 2 votes vote down vote up
/**
 * Get the printing attribute class which is to be used as the "category"
 * for this printing attribute value.
 * <P>
 * For class PrinterState, the category is class PrinterState itself.
 *
 * @return  Printing attribute class (category), an instance of class
 *          {@link java.lang.Class java.lang.Class}.
 */
public final Class<? extends Attribute> getCategory() {
    return PrinterState.class;
}
 
Example 48
Project: openjdk-jdk10   File: JobStateReasons.java   Source Code and License 2 votes vote down vote up
/**
 * Get the printing attribute class which is to be used as the "category"
 * for this printing attribute value.
 * <p>
 * For class {@code JobStateReasons}, the category is class
 * JobStateReasons itself.
 *
 * @return printing attribute class (category), an instance of class
 *         {@link Class java.lang.Class}
 */
public final Class<? extends Attribute> getCategory() {
    return JobStateReasons.class;
}
 
Example 49
Project: OpenJSharp   File: JobImpressions.java   Source Code and License 2 votes vote down vote up
/**
 * Get the printing attribute class which is to be used as the "category"
 * for this printing attribute value.
 * <P>
 * For class JobImpressions, the category is class JobImpressions itself.
 *
 * @return  Printing attribute class (category), an instance of class
 *          {@link java.lang.Class java.lang.Class}.
 */
public final Class<? extends Attribute> getCategory() {
    return JobImpressions.class;
}
 
Example 50
Project: jdk8u-jdk   File: ColorSupported.java   Source Code and License 2 votes vote down vote up
/**
 * Get the printing attribute class which is to be used as the "category"
 * for this printing attribute value.
 * <P>
 * For class ColorSupported, the category is class ColorSupported itself.
 *
 * @return  Printing attribute class (category), an instance of class
 *          {@link java.lang.Class java.lang.Class}.
 */
public final Class<? extends Attribute> getCategory() {
    return ColorSupported.class;
}
 
Example 51
Project: jdk8u-jdk   File: MultipleDocumentHandling.java   Source Code and License 2 votes vote down vote up
/**
 * Get the printing attribute class which is to be used as the "category"
 * for this printing attribute value.
 * <P>
 * For class MultipleDocumentHandling and any vendor-defined subclasses,
 * the category is class MultipleDocumentHandling itself.
 *
 * @return  Printing attribute class (category), an instance of class
 *          {@link java.lang.Class java.lang.Class}.
 */
public final Class<? extends Attribute> getCategory() {
    return MultipleDocumentHandling.class;
}
 
Example 52
Project: OpenJSharp   File: MediaPrintableArea.java   Source Code and License 2 votes vote down vote up
/**
 * Get the printing attribute class which is to be used as the "category"
 * for this printing attribute value.
 * <P>
 * For class MediaPrintableArea, the category is
 * class MediaPrintableArea itself.
 *
 * @return  Printing attribute class (category), an instance of class
 *          {@link java.lang.Class java.lang.Class}.
 */
public final Class<? extends Attribute> getCategory() {
    return MediaPrintableArea.class;
}
 
Example 53
Project: jdk8u-jdk   File: JobHoldUntil.java   Source Code and License 2 votes vote down vote up
/**
 * Get the printing attribute class which is to be used as the "category"
 * for this printing attribute value.
 * <P>
 * For class JobHoldUntil, the category is class JobHoldUntil itself.
 *
 * @return  Printing attribute class (category), an instance of class
 *          {@link java.lang.Class java.lang.Class}.
 */
public final Class<? extends Attribute> getCategory() {
    return JobHoldUntil.class;
}
 
Example 54
Project: jdk8u-jdk   File: DocumentName.java   Source Code and License 2 votes vote down vote up
/**
 * Get the printing attribute class which is to be used as the "category"
 * for this printing attribute value.
 * <P>
 * For class DocumentName, the category is class DocumentName itself.
 *
 * @return  Printing attribute class (category), an instance of class
 *          {@link java.lang.Class java.lang.Class}.
 */
public final Class<? extends Attribute> getCategory() {
    return DocumentName.class;
}
 
Example 55
Project: jdk8u-jdk   File: JobStateReason.java   Source Code and License 2 votes vote down vote up
/**
 * Get the printing attribute class which is to be used as the "category"
 * for this printing attribute value.
 * <P>
 * For class JobStateReason and any vendor-defined subclasses, the
 * category  is class JobStateReason itself.
 *
 * @return  Printing attribute class (category), an instance of class
 *          {@link java.lang.Class java.lang.Class}.
 */
public final Class<? extends Attribute> getCategory() {
    return JobStateReason.class;
}
 
Example 56
Project: OpenJSharp   File: ReferenceUriSchemesSupported.java   Source Code and License 2 votes vote down vote up
/**
 * Get the printing attribute class which is to be used as the "category"
 * for this printing attribute value.
 * <P>
 * For class ReferenceUriSchemesSupported and any vendor-defined
 * subclasses, the category is class ReferenceUriSchemesSupported itself.
 *
 * @return  Printing attribute class (category), an instance of class
 *          {@link java.lang.Class java.lang.Class}.
 */
public final Class<? extends Attribute> getCategory() {
    return ReferenceUriSchemesSupported.class;
}
 
Example 57
Project: jdk8u-jdk   File: PresentationDirection.java   Source Code and License 2 votes vote down vote up
/**
 * Get the printing attribute class which is to be used as the "category"
 * for this printing attribute value.
 * <P>
 * For class PresentationDirection
 * the category is class PresentationDirection itself.
 *
 * @return  Printing attribute class (category), an instance of class
 *          {@link java.lang.Class java.lang.Class}.
 */
public final Class<? extends Attribute> getCategory() {
    return PresentationDirection.class;
}
 
Example 58
Project: jdk8u-jdk   File: OutputDeviceAssigned.java   Source Code and License 2 votes vote down vote up
/**
 * Get the printing attribute class which is to be used as the "category"
 * for this printing attribute value.
 * <P>
 * For class OutputDeviceAssigned, the
 * category is class OutputDeviceAssigned itself.
 *
 * @return  Printing attribute class (category), an instance of class
 *          {@link java.lang.Class java.lang.Class}.
 */
public final Class<? extends Attribute> getCategory() {
    return OutputDeviceAssigned.class;
}
 
Example 59
Project: openjdk-jdk10   File: PrinterMessageFromOperator.java   Source Code and License 2 votes vote down vote up
/**
 * Get the printing attribute class which is to be used as the "category"
 * for this printing attribute value.
 * <p>
 * For class {@code PrinterMessageFromOperator}, the category is class
 * {@code PrinterMessageFromOperator} itself.
 *
 * @return printing attribute class (category), an instance of class
 *         {@link Class java.lang.Class}
 */
public final Class<? extends Attribute> getCategory() {
    return PrinterMessageFromOperator.class;
}
 
Example 60
Project: jdk8u-jdk   File: PagesPerMinuteColor.java   Source Code and License 2 votes vote down vote up
/**
 * Get the printing attribute class which is to be used as the "category"
 * for this printing attribute value.
 * <P>
 * For class PagesPerMinuteColor, the
 * category is class PagesPerMinuteColor itself.
 *
 * @return  Printing attribute class (category), an instance of class
 *          {@link java.lang.Class java.lang.Class}.
 */
public final Class<? extends Attribute> getCategory() {
    return PagesPerMinuteColor.class;
}