protected static PrintService lookupDefaultPrintService() { PrintService service = PrintServiceLookup.lookupDefaultPrintService(); /* Pageable implies Printable so checking both isn't strictly needed */ if (service != null && service.isDocFlavorSupported( DocFlavor.SERVICE_FORMATTED.PAGEABLE) && service.isDocFlavorSupported( DocFlavor.SERVICE_FORMATTED.PRINTABLE)) { return service; } else { PrintService []services = PrintServiceLookup.lookupPrintServices( DocFlavor.SERVICE_FORMATTED.PAGEABLE, null); if (services.length > 0) { return services[0]; } } return null; }
private static ArrayList getFactories(DocFlavor flavor, String outType) { if (flavor == null && outType == null) { return getAllFactories(); } ArrayList list = new ArrayList(); Iterator iterator = getAllFactories().iterator(); while (iterator.hasNext()) { StreamPrintServiceFactory factory = (StreamPrintServiceFactory)iterator.next(); if ((outType == null || outType.equalsIgnoreCase(factory.getOutputFormat())) && (flavor == null || isMember(flavor, factory.getSupportedDocFlavors()))) { list.add(factory); } } return list; }
public DocFlavor[] getSupportedDocFlavors() { int len = supportedFlavors.length; DocFlavor[] supportedDocFlavors; int caps = getPrinterCapabilities(); // doc flavors supported // if PostScript is supported if ((caps & DEVCAP_POSTSCRIPT) != 0) { supportedDocFlavors = new DocFlavor[len+3]; System.arraycopy(supportedFlavors, 0, supportedDocFlavors, 0, len); supportedDocFlavors[len] = DocFlavor.BYTE_ARRAY.POSTSCRIPT; supportedDocFlavors[len+1] = DocFlavor.INPUT_STREAM.POSTSCRIPT; supportedDocFlavors[len+2] = DocFlavor.URL.POSTSCRIPT; } else { supportedDocFlavors = new DocFlavor[len]; System.arraycopy(supportedFlavors, 0, supportedDocFlavors, 0, len); } return supportedDocFlavors; }
private void initSupportedDocFlavors() { String hostEnc = DocFlavor.hostEncoding.toLowerCase(Locale.ENGLISH); if (!hostEnc.equals("utf-8") && !hostEnc.equals("utf-16") && !hostEnc.equals("utf-16be") && !hostEnc.equals("utf-16le") && !hostEnc.equals("us-ascii")) { int len = supportedDocFlavorsInit.length; DocFlavor[] flavors = new DocFlavor[len + supportedHostDocFlavors.length]; // copy host encoding flavors System.arraycopy(supportedHostDocFlavors, 0, flavors, len, supportedHostDocFlavors.length); System.arraycopy(supportedDocFlavorsInit, 0, flavors, 0, len); supportedDocFlavors = flavors; } else { supportedDocFlavors = supportedDocFlavorsInit; } }
public boolean isDocFlavorSupported(DocFlavor flavor) { /* To avoid a native query which may be time-consuming * do not invoke native unless postscript support is being queried. * Instead just check the ones we 'always' support */ DocFlavor[] supportedDocFlavors; if (isPostScriptFlavor(flavor)) { supportedDocFlavors = getSupportedDocFlavors(); } else { supportedDocFlavors = supportedFlavors; } for (int f=0; f<supportedDocFlavors.length; f++) { if (flavor.equals(supportedDocFlavors[f])) { return true; } } return false; }
@Override public void actionPerformed(ActionEvent e) { try { if (selectedDriver == null) return; PrintService ps = (PrintService)printers.getSelectedItem(); PrintRequestAttributeSet attr = new HashPrintRequestAttributeSet(); attr.add(new Copies(1)); attr.add((Media)ps.getDefaultAttributeValue(Media.class)); // set to default paper from printer attr.add(OrientationRequested.LANDSCAPE); SimpleDoc doc = new SimpleDoc(activeLabel, DocFlavor.SERVICE_FORMATTED.PRINTABLE, null); ps.createPrintJob().print(doc, attr); } catch (PrintException ex) { log.log(Level.SEVERE, "\bBarcode print failed: " + ex.getMessage(), ex); } }
static MediaTray getMediaTray( PrintService ps, String name) { Media[] media = (Media[])ps.getSupportedAttributeValues( Media.class, DocFlavor.SERVICE_FORMATTED.PAGEABLE, null); for (Media m : media) { if ( m instanceof MediaTray) { System.out.println("MediaTray=" + m.toString() ); if ( m.toString().trim().indexOf( name ) > -1 ) { return (MediaTray)m; } } } 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); } } }
protected boolean isSupportedValue(Attribute attrval, PrintRequestAttributeSet attrset) { PrintService ps = getPrintService(); return (attrval != null && ps != null && ps.isAttributeValueSupported(attrval, DocFlavor.SERVICE_FORMATTED.PAGEABLE, attrset)); }
public boolean isDocFlavorSupported(DocFlavor flavor) { if (supportedDocFlavors == null) { getSupportedDocFlavors(); } if (supportedDocFlavors != null) { for (int f=0; f<supportedDocFlavors.length; f++) { if (flavor.equals(supportedDocFlavors[f])) { return true; } } } return false; }
public boolean isDocFlavorSupported(DocFlavor flavor) { DocFlavor [] flavors = getSupportedDocFlavors(); for (int f=0; f<flavors.length; f++) { if (flavor.equals(flavors[f])) { return true; } } return 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; } }
private static boolean isMember(DocFlavor flavor, DocFlavor[] flavors) { for (int f=0; f<flavors.length; f++ ) { if (flavor.equals(flavors[f])) { return true; } } return false; }
public MultiDocPrintService[] getMultiDocPrintServices(DocFlavor[] flavors, AttributeSet attributes) { SecurityManager security = System.getSecurityManager(); if (security != null) { security.checkPrintJobAccess(); } return new MultiDocPrintService[0]; }
private boolean isPostScriptFlavor(DocFlavor flavor) { if (flavor.equals(DocFlavor.BYTE_ARRAY.POSTSCRIPT) || flavor.equals(DocFlavor.INPUT_STREAM.POSTSCRIPT) || flavor.equals(DocFlavor.URL.POSTSCRIPT)) { return true; } else { return false; } }
private boolean isAutoSense(DocFlavor flavor) { if (flavor.equals(DocFlavor.BYTE_ARRAY.AUTOSENSE) || flavor.equals(DocFlavor.INPUT_STREAM.AUTOSENSE) || flavor.equals(DocFlavor.URL.AUTOSENSE)) { return true; } else { return 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; } }
public DocFlavor[] getSupportedDocFlavors() { if (supportedDocFlavors == null) { initSupportedDocFlavors(); } int len = supportedDocFlavors.length; DocFlavor[] flavors = new DocFlavor[len]; System.arraycopy(supportedDocFlavors, 0, flavors, 0, len); return flavors; }
public boolean isDocFlavorSupported(DocFlavor flavor) { if (supportedDocFlavors == null) { initSupportedDocFlavors(); } for (int f=0; f<supportedDocFlavors.length; f++) { if (flavor.equals(supportedDocFlavors[f])) { return true; } } return false; }
@Override public DocFlavor[] getSupportedDocFlavors(){ int len = supportedFlavors.length; DocFlavor[] result = new DocFlavor[len]; System.arraycopy(supportedFlavors, 0, result, 0, len); return result; }
@Override public boolean isDocFlavorSupported(DocFlavor flavor){ for (int f=0; f<supportedFlavors.length; f++) { if (flavor.equals(supportedFlavors[f])) { return true; } } return false; }