public PrintServiceAttributeSet getAttributes() { PrintServiceAttributeSet attrs = new HashPrintServiceAttributeSet(); attrs.add(getPrinterName()); attrs.add(getPrinterIsAcceptingJobs()); PrinterState prnState = getPrinterState(); if (prnState != null) { attrs.add(prnState); } PrinterStateReasons prnStateReasons = getPrinterStateReasons(); if (prnStateReasons != null) { attrs.add(prnStateReasons); } attrs.add(getQueuedJobCount()); int caps = getPrinterCapabilities(); if ((caps & DEVCAP_COLOR) != 0) { attrs.add(ColorSupported.SUPPORTED); } else { attrs.add(ColorSupported.NOT_SUPPORTED); } return AttributeSetUtilities.unmodifiableView(attrs); }
public <T extends PrintServiceAttribute> T getAttribute(Class<T> category) { if (category == null) { throw new NullPointerException("category"); } if (!(PrintServiceAttribute.class.isAssignableFrom(category))) { throw new IllegalArgumentException("Not a PrintServiceAttribute"); } if (category == PrinterName.class) { return (T)getPrinterName(); } else if (category == PrinterState.class) { return (T)getPrinterState(); } else if (category == PrinterStateReasons.class) { return (T)getPrinterStateReasons(); } else if (category == QueuedJobCount.class) { return (T)getQueuedJobCount(); } else if (category == PrinterIsAcceptingJobs.class) { return (T)getPrinterIsAcceptingJobs(); } else { return null; } }
@SuppressWarnings("unchecked") public <T extends PrintServiceAttribute> T getAttribute(Class<T> category) { if (category == null) { throw new NullPointerException("category"); } if (!(PrintServiceAttribute.class.isAssignableFrom(category))) { throw new IllegalArgumentException("Not a PrintServiceAttribute"); } if (category == PrinterName.class) { return (T)getPrinterName(); } else if (category == PrinterState.class) { return (T)getPrinterState(); } else if (category == PrinterStateReasons.class) { return (T)getPrinterStateReasons(); } else if (category == QueuedJobCount.class) { return (T)getQueuedJobCount(); } else if (category == PrinterIsAcceptingJobs.class) { return (T)getPrinterIsAcceptingJobs(); } else { return null; } }
/** * Associate this PrinterJob with a new PrintService. * * Throws <code>PrinterException</code> if the specified service * cannot support the <code>Pageable</code> and * <code>Printable</code> interfaces necessary to support 2D printing. * @param a print service which supports 2D printing. * * @throws PrinterException if the specified service does not support * 2D printing or no longer available. */ public void setPrintService(PrintService service) throws PrinterException { if (service == null) { throw new PrinterException("Service cannot be null"); } else if (!(service instanceof StreamPrintService) && service.getName() == null) { throw new PrinterException("Null PrintService name."); } else { // Check the list of services. This service may have been // deleted already PrinterState prnState = (PrinterState)service.getAttribute( PrinterState.class); if (prnState == PrinterState.STOPPED) { PrinterStateReasons prnStateReasons = (PrinterStateReasons)service.getAttribute( PrinterStateReasons.class); if ((prnStateReasons != null) && (prnStateReasons.containsKey(PrinterStateReason.SHUTDOWN))) { throw new PrinterException("PrintService is no longer available."); } } if (service.isDocFlavorSupported( DocFlavor.SERVICE_FORMATTED.PAGEABLE) && service.isDocFlavorSupported( DocFlavor.SERVICE_FORMATTED.PRINTABLE)) { myService = service; } else { throw new PrinterException("Not a 2D print service: " + service); } } }
private PrinterStateReasons getPrinterStateReasons() { if (isInvalid) { PrinterStateReasons psr = new PrinterStateReasons(); psr.put(PrinterStateReason.SHUTDOWN, Severity.ERROR); return psr; } else { return null; } }
public <T extends PrintServiceAttribute> T getAttribute(Class<T> category) { if (category == null) { throw new NullPointerException("category"); } if (!(PrintServiceAttribute.class.isAssignableFrom(category))) { throw new IllegalArgumentException("Not a PrintServiceAttribute"); } if (category == ColorSupported.class) { int caps = getPrinterCapabilities(); if ((caps & DEVCAP_COLOR) != 0) { return (T)ColorSupported.SUPPORTED; } else { return (T)ColorSupported.NOT_SUPPORTED; } } else if (category == PrinterName.class) { return (T)getPrinterName(); } else if (category == PrinterState.class) { return (T)getPrinterState(); } else if (category == PrinterStateReasons.class) { return (T)getPrinterStateReasons(); } else if (category == QueuedJobCount.class) { return (T)getQueuedJobCount(); } else if (category == PrinterIsAcceptingJobs.class) { return (T)getPrinterIsAcceptingJobs(); } else { return null; } }
public PrintServiceAttributeSet getAttributes() { PrintServiceAttributeSet attrs = new HashPrintServiceAttributeSet(); attrs.add(getPrinterName()); attrs.add(getPrinterIsAcceptingJobs()); PrinterState prnState = getPrinterState(); if (prnState != null) { attrs.add(prnState); } PrinterStateReasons prnStateReasons = getPrinterStateReasons(); if (prnStateReasons != null) { attrs.add(prnStateReasons); } attrs.add(getQueuedJobCount()); return AttributeSetUtilities.unmodifiableView(attrs); }
@Override public PrintServiceAttributeSet getAttributes(){ PrintServiceAttributeSet attrs = new HashPrintServiceAttributeSet(); attrs.add(getPrinterName()); PrinterIsAcceptingJobs acptJobs = getAttribute(PrinterIsAcceptingJobs.class); if(acptJobs != null){ attrs.add(acptJobs); } PrinterState prnState = getAttribute(PrinterState.class); if(prnState != null){ attrs.add(prnState); } PrinterStateReasons prnStateReasons = getAttribute(PrinterStateReasons.class); if(prnStateReasons != null){ attrs.add(prnStateReasons); } QueuedJobCount jobCount = getAttribute(QueuedJobCount.class); if(jobCount != null){ attrs.add(jobCount); } // TODO: Seems to be more accurate than settings.get_SupportsColor(), which doesn't work for CutePDF if(settings.get_DefaultPageSettings().get_Color()){ attrs.add(ColorSupported.SUPPORTED); }else{ attrs.add(ColorSupported.NOT_SUPPORTED); } return AttributeSetUtilities.unmodifiableView(attrs); }
/** * Associate this PrinterJob with a new PrintService. * * Throws {@code PrinterException} if the specified service * cannot support the {@code Pageable} and * {@code Printable} interfaces necessary to support 2D printing. * @param service print service which supports 2D printing. * * @throws PrinterException if the specified service does not support * 2D printing or no longer available. */ public void setPrintService(PrintService service) throws PrinterException { if (service == null) { throw new PrinterException("Service cannot be null"); } else if (!(service instanceof StreamPrintService) && service.getName() == null) { throw new PrinterException("Null PrintService name."); } else { // Check the list of services. This service may have been // deleted already PrinterState prnState = service.getAttribute(PrinterState.class); if (prnState == PrinterState.STOPPED) { PrinterStateReasons prnStateReasons = service.getAttribute(PrinterStateReasons.class); if ((prnStateReasons != null) && (prnStateReasons.containsKey(PrinterStateReason.SHUTDOWN))) { throw new PrinterException("PrintService is no longer available."); } } if (service.isDocFlavorSupported( DocFlavor.SERVICE_FORMATTED.PAGEABLE) && service.isDocFlavorSupported( DocFlavor.SERVICE_FORMATTED.PRINTABLE)) { myService = service; } else { throw new PrinterException("Not a 2D print service: " + service); } } }