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; } }
@Override public <T extends PrintServiceAttribute>T getAttribute(Class<T> category){ if(category == null){ throw new NullPointerException("category"); } if(!(PrintServiceAttribute.class.isAssignableFrom(category))){ throw new IllegalArgumentException("The categhory '" + category + "' is not a valid PrintServiceAttribute"); } if(category == ColorSupported.class){ // works better than settings.get_SupportsColor(); if(settings.get_DefaultPageSettings().get_Color()){ return (T)ColorSupported.SUPPORTED; }else{ return (T)ColorSupported.NOT_SUPPORTED; } }else if(category == PrinterName.class){ return (T)getPrinterName(); } else { // QueuedJobCount and PrinterIsAcceptingJobs return (T)peer.getPrinterStatus(printer, category); } }
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) { @SuppressWarnings("unchecked") T tmp = (T)ColorSupported.SUPPORTED; return tmp; } 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; } }
@SuppressWarnings("unchecked") // Cast to Class<PrintServiceAttribute> boolean matchingService(PrintService service, PrintServiceAttributeSet serviceSet) { if (serviceSet != null) { Attribute [] attrs = serviceSet.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; }
/** * @see javax.print.PrintService#getAttribute(java.lang.Class) */ public <T extends PrintServiceAttribute> T getAttribute(Class<T> category) { if (category == null) throw new NullPointerException("category may not be null"); if (! PrintServiceAttribute.class.isAssignableFrom(category)) throw new IllegalArgumentException( "category must be of type PrintServiceAttribute"); Set<T> set = getPrinterAttributeSet(category); if (set != null && set.size() > 0) return set.iterator().next(); return null; }
/** * @see javax.print.PrintService#getAttributes() */ public PrintServiceAttributeSet getAttributes() { PrintServiceAttributeSet set = new HashPrintServiceAttributeSet(); for (Set<Attribute> attrSet : printerAttr.values()) { for (Attribute attr : attrSet) { if (attr instanceof PrintServiceAttribute) set.add(attr); } } return AttributeSetUtilities.unmodifiableView(set); }
/** * @see javax.print.PrintService#getAttribute(java.lang.Class) */ public PrintServiceAttribute getAttribute(Class category) { if (category == null) throw new NullPointerException("category may not be null"); if (! PrintServiceAttribute.class.isAssignableFrom(category)) throw new IllegalArgumentException( "category must be of type PrintServiceAttribute"); Set set = getPrinterAttributeSet(category); if (set != null && set.size() > 0) return (PrintServiceAttribute) set.toArray()[0]; return null; }
/** * @see javax.print.PrintService#getAttributes() */ public PrintServiceAttributeSet getAttributes() { PrintServiceAttributeSet set = new HashPrintServiceAttributeSet(); Iterator it = printerAttr.values().iterator(); while (it.hasNext()) { Iterator it2 = ((Set) it.next()).iterator(); while (it2.hasNext()) { Attribute attr = (Attribute) it2.next(); if (attr instanceof PrintServiceAttribute) set.add(attr); } } return AttributeSetUtilities.unmodifiableView(set); }
/** * Function to print code Zpl to local zebra(usb) * * @param zpl * code Zpl to print * @param ip * ip adress * @param port * port * @throws ZebraPrintException * if zpl could not be printed */ public static void printZpl(String zpl, String printerName) throws ZebraPrintException { try { PrintService psZebra = null; String sPrinterName = null; PrintService[] services = PrintServiceLookup.lookupPrintServices(null, null); for (int i = 0; i < services.length; i++) { PrintServiceAttribute attr = services[i].getAttribute(PrinterName.class); sPrinterName = ((PrinterName) attr).getValue(); if (sPrinterName.toLowerCase().indexOf(printerName) >= 0) { psZebra = services[i]; break; } } if (psZebra == null) { throw new ZebraPrintNotFoundException("Zebra printer not found : " + printerName); } DocPrintJob job = psZebra.createPrintJob(); byte[] by = zpl.getBytes(); DocFlavor flavor = DocFlavor.BYTE_ARRAY.AUTOSENSE; Doc doc = new SimpleDoc(by, flavor, null); job.print(doc, null); } catch (PrintException e) { throw new ZebraPrintException("Cannot print label on this printer : " + printerName, e); } }
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) { return (T)ColorSupported.SUPPORTED; } else { return null; } }
boolean matchingService(PrintService service, PrintServiceAttributeSet serviceSet) { if (serviceSet != null) { Attribute [] attrs = serviceSet.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; }
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; } }
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 boolean matchesAttributes(PrintService service, PrintServiceAttributeSet attributes) { Attribute [] attrs = attributes.toArray(); for (int i=0; i<attrs.length; i++) { @SuppressWarnings("unchecked") Attribute serviceAttr = service.getAttribute((Class<PrintServiceAttribute>)attrs[i].getCategory()); if (serviceAttr == null || !serviceAttr.equals(attrs[i])) { return false; } } return true; }
@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 == 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; } }