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; }
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; }
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 } } }
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); } }
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); } }
protected boolean isSupportedValue(Attribute attrval, PrintRequestAttributeSet attrset) { PrintService ps = getPrintService(); return (attrval != null && ps != null && ps.isAttributeValueSupported(attrval, DocFlavor.SERVICE_FORMATTED.PAGEABLE, attrset)); }
public Attribute[] getUnsupportedValues() { if (attr == null) { return null; } else { Attribute [] attrs = { attr}; return attrs; } }
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; } }
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]); } }
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; }
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; } }
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 } }
private void setColorAttrib(Attribute attr) { if (attr == Chromaticity.COLOR) { mAttChromaticity = 2; // DMCOLOR_COLOR } else { mAttChromaticity = 1; // DMCOLOR_MONOCHROME } }
private void setCollateAttrib(Attribute attr) { if (attr == SheetCollate.COLLATED) { mAttCollate = 1; // DMCOLLATE_TRUE } else { mAttCollate = 0; // DMCOLLATE_FALSE } }
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; } }
PrintJobAttributeException(String s, Class cat, Attribute attrval) { super(s); attr = attrval; category = cat; }
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; }
@Override public boolean isAttributeCategorySupported(Class<? extends Attribute> category) { return false; }
@Override public Object getSupportedAttributeValues( Class<? extends Attribute> category, DocFlavor flavor, AttributeSet attributes) { return _attributes.get(category); }
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; }
private void setQualityAttrib(Attribute attr, PrintRequestAttributeSet set) { setQualityAttrib(attr); set.add(attr); }
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; } } }
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; }
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; }
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; } } }
@Override public boolean isAttributeValueSupported(Attribute attrval, DocFlavor flavor, AttributeSet attributes) { return false; }
@Override public Object getDefaultAttributeValue(Class<? extends Attribute> category) { return null; }
@Override public Object getSupportedAttributeValues(Class<? extends Attribute> category, DocFlavor flavor, AttributeSet attributes) { return null; }
private void setCollateAttrib(Attribute attr, PrintRequestAttributeSet set) { setCollateAttrib(attr); set.add(attr); }
/** * 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; }
/** * 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; }
/** * 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; }
/** * 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; }
/** * 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; }
/** * 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; }
/** * 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; }