Java 类javax.print.PrintServiceLookup 实例源码

项目:OpenJSharp    文件:RasterPrinterJob.java   
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;
}
项目:openjdk-jdk10    文件:RasterPrinterJob.java   
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;
}
项目:openjdk-jdk10    文件:TestMediaTraySelection.java   
public static void main(String[] args)  throws Exception {
    prservices = PrintServiceLookup.lookupDefaultPrintService();
    if (prservices == null) {
        System.out.println("No print service found");
        return;
    }
    System.out.println(" Print service " + prservices);
    SwingUtilities.invokeAndWait(() -> {
        doTest(TestMediaTraySelection::printTest);
    });
    mainThread = Thread.currentThread();
    try {
        Thread.sleep(90000);
    } catch (InterruptedException e) {
        if (!testPassed && testGeneratedInterrupt) {
            throw new RuntimeException("Banner page did not print");
        }
    }
    if (!testGeneratedInterrupt) {
        throw new RuntimeException("user has not executed the test");
    }
}
项目:openjdk-jdk10    文件:ServiceDlgPageRangeTest.java   
/**
 * Starts the application.
 */
public static void printTest() {

    System.out.println("\nDefault print service: " +
                          PrintServiceLookup.lookupDefaultPrintService());
    System.out.println("is flavor: "+flavor+" supported? "+
                                 services[0].isDocFlavorSupported(flavor));
    System.out.println("is Page Ranges category supported? "+
               services[0].isAttributeCategorySupported(PageRanges.class));
    System.out.println("is PageRanges[2] value supported ? "+
               services[0].isAttributeValueSupported(
                                         new PageRanges(2), flavor, null));

    HashPrintRequestAttributeSet prSet = new HashPrintRequestAttributeSet();
    //prSet.add(new PageRanges(2));
    PrintService selService = ServiceUI.printDialog(null, 200, 200,
                                      services, services[0], flavor, prSet);

    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]);
    }
}
项目:openjdk-jdk10    文件:ServiceDlgPageRangeTest.java   
/**
 * Starts the application.
 */
public static void main(java.lang.String[] args) throws Exception {
    services = PrintServiceLookup.lookupPrintServices(flavor,  null);

    if (services.length == 0) {
        System.out.println("No print service found!!");
        return;
    }
    SwingUtilities.invokeAndWait(() -> {
        doTest(ServiceDlgPageRangeTest::printTest);
    });
    mainThread = Thread.currentThread();
    try {
        Thread.sleep(600000);
    } catch (InterruptedException e) {
        if (!testPassed && testGeneratedInterrupt) {
            throw new RuntimeException("PageRanges option is not disabled "
                    + "for for Non serv-formatted flvrs");
        }
    }
    if (!testGeneratedInterrupt) {
        throw new RuntimeException("user has not executed the test");
    }
}
项目:openjdk-jdk10    文件:GetPrintServices.java   
public static void main(String[] args) throws Exception {
    for (PrintService service : PrintServiceLookup.lookupPrintServices(null, null)) {
        String serviceName = service.getName();
        PrinterName name = service.getAttribute(PrinterName.class);
        String printerName = name.getValue();

        PrintService serviceByName = lookupByName(printerName);
        System.out.println("service " + service);
        System.out.println("serviceByName " + serviceByName);
        if (!service.equals(serviceByName)) {
            throw new RuntimeException("NOK " + serviceName
                               + " expected: " + service.getClass().getName()
                               + " got: " + serviceByName.getClass().getName());
        }
    }
    System.out.println("Test PASSED");
}
项目:openjdk9    文件:RasterPrinterJob.java   
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;
}
项目:openbravo-pos    文件:ReportUtils.java   
public static PrintService getPrintService(String printername) {

    // Initalize print service

    if (printername == null) {
        return PrintServiceLookup.lookupDefaultPrintService();       
    } else {

        if ("(Show dialog)".equals(printername)) {
            return null; // null means "you have to show the print dialog"
        } else if ("(Default)".equals(printername)) {
            return PrintServiceLookup.lookupDefaultPrintService(); 
        } else {
            PrintService[] pservices = 
                    PrintServiceLookup.lookupPrintServices(DocFlavor.SERVICE_FORMATTED.PRINTABLE , null);
            for (PrintService s : pservices) {    
                if (printername.equals(s.getName())) {
                    return s;
                }
            }
            return PrintServiceLookup.lookupDefaultPrintService();       
        }                
    }                 
}
项目:jdk8u_jdk    文件:RasterPrinterJob.java   
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;
}
项目:lookaside_java-1.8.0-openjdk    文件:RasterPrinterJob.java   
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;
}
项目:Camel    文件:PrinterPrintTest.java   
protected void setupJavaPrint() {
    // "install" another default printer
    PrintService psDefault = mock(PrintService.class);
    when(psDefault.getName()).thenReturn("DefaultPrinter");
    when(psDefault.isDocFlavorSupported(any(DocFlavor.class))).thenReturn(Boolean.TRUE);
    PrintServiceLookup psLookup = mock(PrintServiceLookup.class);
    when(psLookup.getPrintServices()).thenReturn(new PrintService[]{psDefault});
    when(psLookup.getDefaultPrintService()).thenReturn(psDefault);
    DocPrintJob docPrintJob = mock(DocPrintJob.class);
    when(psDefault.createPrintJob()).thenReturn(docPrintJob);
    MediaTray[] trays = new MediaTray[]{
        MediaTray.TOP,
        MediaTray.MIDDLE,
        MediaTray.BOTTOM
    };
    when(psDefault.getSupportedAttributeValues(Media.class, null, null)).thenReturn(trays);
    PrintServiceLookup.registerServiceProvider(psLookup);
}
项目:wifepos    文件:ReportUtils.java   
/**
 *
 * @param printername
 * @return
 */
public static PrintService getPrintService(String printername) {

    // Initalize print service

    if (printername == null) {
        return PrintServiceLookup.lookupDefaultPrintService();       
    } else {

        if ("(Show dialog)".equals(printername)) {
            return null; // null means "you have to show the print dialog"
        } else if ("(Default)".equals(printername)) {
            return PrintServiceLookup.lookupDefaultPrintService(); 
        } else {
            PrintService[] pservices = 
                    PrintServiceLookup.lookupPrintServices(DocFlavor.SERVICE_FORMATTED.PRINTABLE , null);
            for (PrintService s : pservices) {    
                if (printername.equals(s.getName())) {
                    return s;
                }
            }
            return PrintServiceLookup.lookupDefaultPrintService();       
        }                
    }                 
}
项目:micro-Blagajna    文件:ReportUtils.java   
/**
 *
 * @param printername
 * @return
 */
public static PrintService getPrintService(String printername) {

    // Initalize print service

    if (printername == null) {
        return PrintServiceLookup.lookupDefaultPrintService();       
    } else {

        if ("(Show dialog)".equals(printername)) {
            return null; // null means "you have to show the print dialog"
        } else if ("(Default)".equals(printername)) {
            return PrintServiceLookup.lookupDefaultPrintService(); 
        } else {
            PrintService[] pservices = 
                    PrintServiceLookup.lookupPrintServices(DocFlavor.SERVICE_FORMATTED.PRINTABLE , null);
            for (PrintService s : pservices) {    
                if (printername.equals(s.getName())) {
                    return s;
                }
            }
            return PrintServiceLookup.lookupDefaultPrintService();       
        }                
    }                 
}
项目:metasfresh    文件:PrinterRoutingBL.java   
@Cached
/* package */PrintService getSystemPrintService(final String printerName)
{
    final PrintService[] services = PrintServiceLookup.lookupPrintServices(null, null);
    if (services == null || services.length == 0)
    {
        return null;
    }
    for (final PrintService service : services)
    {
        if (service.getName().equals(printerName))
        {
            return service;
        }
    }
    return null;
}
项目:lixia-javardp    文件:Printer.java   
@Override
public void create(String filename) {
    // find the printing service
    //http://www.coderanch.com/t/385989/java/java/send-raw-data-printer
    AttributeSet attributeSet = new HashAttributeSet();  
    attributeSet.add(new PrinterName(filename, null));
    PrintService[] services = PrintServiceLookup.lookupPrintServices(null, attributeSet);
    if(services.length > 0){
        if(printFile != null){
            printFile.deleteOnExit();
            printFile = null;
        }
        try {
            printFile = File.createTempFile("printer_"+name,".redirect");
        } catch (IOException e) {
            e.printStackTrace();
        }
        printService = services[0];
    }

}
项目:infobip-open-jdk-8    文件:RasterPrinterJob.java   
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;
}
项目:jdk8u-dev-jdk    文件:RasterPrinterJob.java   
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;
}
项目:unicenta    文件:ReportUtils.java   
/**
 *
 * @param printername
 * @return
 */
public static PrintService getPrintService(String printername) {

    // Initalize print service

    if (printername == null) {
        return PrintServiceLookup.lookupDefaultPrintService();       
    } else {

        if ("(Show dialog)".equals(printername)) {
            return null; // null means "you have to show the print dialog"
        } else if ("(Default)".equals(printername)) {
            return PrintServiceLookup.lookupDefaultPrintService(); 
        } else {
            PrintService[] pservices = 
                    PrintServiceLookup.lookupPrintServices(DocFlavor.SERVICE_FORMATTED.PRINTABLE , null);
            for (PrintService s : pservices) {    
                if (printername.equals(s.getName())) {
                    return s;
                }
            }
            return PrintServiceLookup.lookupDefaultPrintService();       
        }                
    }                 
}
项目:jdk7-jdk    文件:RasterPrinterJob.java   
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;
}
项目:jdk7-jdk    文件:WPrinterJob.java   
public PrintService getPrintService() {
    if (myService == null) {
        String printerName = getNativePrintService();

        if (printerName != null) {
            myService = Win32PrintServiceLookup.getWin32PrintLUS().
                getPrintServiceByName(printerName);
            // no need to call setNativePrintService as this name is
            // currently set in native
            if (myService != null) {
                return myService;
            }
        }

        myService = PrintServiceLookup.lookupDefaultPrintService();
        if (myService != null) {
            try {
                setNativePrintService(myService.getName());
            } catch (Exception e) {
                myService = null;
            }
        }

      }
      return myService;
}
项目:openjdk-source-code-learn    文件:RasterPrinterJob.java   
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;
}
项目:openjdk-source-code-learn    文件:WPrinterJob.java   
public PrintService getPrintService() {
    if (myService == null) {
        String printerName = getNativePrintService();

        if (printerName != null) {
            myService = Win32PrintServiceLookup.getWin32PrintLUS().
                getPrintServiceByName(printerName);
            // no need to call setNativePrintService as this name is
            // currently set in native
            if (myService != null) {
                return myService;
            }
        }

        myService = PrintServiceLookup.lookupDefaultPrintService();
        if (myService != null) {
            try {
                setNativePrintService(myService.getName());
            } catch (Exception e) {
                myService = null;
            }
        }

      }
      return myService;
}
项目:WollMux    文件:DruckerController.java   
public DruckerController(DruckerModel model, JFrame parent, 
    MailMergeParams mmp) {

  this.mmp = mmp;
  this.model = model; 
  this.parent = parent;
  model.setDrucker(
    PrintParametersDialog.getCurrentPrinterName(
      mmp.getMMC().getTextDocument()));   

  PrintService[] printservices = PrintServiceLookup.lookupPrintServices(null,  null); 
  for ( PrintService service : printservices) {
    alleDrucker.add(service.getName());      
  }
  model.setAlleDrucker(alleDrucker);
}
项目:RipplePower    文件:PrintImageOutput.java   
public static boolean out(BufferedImage image) {
    try {
        DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE;
        PrintRequestAttributeSet requestAttributeSet = new HashPrintRequestAttributeSet();
        requestAttributeSet.add(MediaSizeName.ISO_A4);
        requestAttributeSet.add(new JobName(LSystem.applicationName + LSystem.getTime(), Locale.ENGLISH));
        PrintService[] services = PrintServiceLookup.lookupPrintServices(flavor, requestAttributeSet);
        PrintService defaultService = PrintServiceLookup.lookupDefaultPrintService();
        PrintService service = ServiceUI.printDialog(null, 100, 100, services, defaultService, flavor,
                requestAttributeSet);
        if (service != null) {
            DocPrintJob job = service.createPrintJob();
            SimpleDoc doc = new SimpleDoc(new BufferedImagePrintable(image), flavor, null);
            job.print(doc, requestAttributeSet);
        }
    } catch (Exception e) {
        return false;
    }
    return true;
}
项目:ph-commons    文件:JavaPrinterTrayFinderFuncTest.java   
@Test
public void testListPrinterTrays ()
{
  final PrintService [] aAllServices = PrintServiceLookup.lookupPrintServices (null, null);
  for (final PrintService aService : aAllServices)
  {
    s_aLogger.info (aService.toString ());
    final Object aAttrs = aService.getSupportedAttributeValues (Media.class,
                                                                DocFlavor.SERVICE_FORMATTED.PAGEABLE,
                                                                null);
    if (ArrayHelper.isArray (aAttrs))
    {
      for (final Media aElement : (Media []) aAttrs)
        if (aElement instanceof MediaTray)
          s_aLogger.info ("  " + aElement);
    }
  }
}
项目:OLD-OpenJDK8    文件:RasterPrinterJob.java   
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;
}
项目:OLD-OpenJDK8    文件:WPrinterJob.java   
public PrintService getPrintService() {
    if (myService == null) {
        String printerName = getNativePrintService();

        if (printerName != null) {
            myService = Win32PrintServiceLookup.getWin32PrintLUS().
                getPrintServiceByName(printerName);
            // no need to call setNativePrintService as this name is
            // currently set in native
            if (myService != null) {
                return myService;
            }
        }

        myService = PrintServiceLookup.lookupDefaultPrintService();
        if (myService instanceof Win32PrintService) {
            try {
                setNativePrintServiceIfNeeded(myService.getName());
            } catch (Exception e) {
                myService = null;
            }
        }

      }
      return myService;
}
项目:cn1    文件:ServiceUIDialog.java   
private int pageSetup(PrintService aService, 
                      PrintRequestAttributeSet requestAttrs) 
{
    myService = (aService == null)  
            ? PrintServiceLookup.lookupDefaultPrintService() 
            : aService;

    if ((requestAttrs == null) || (aService == null)) {
        return SETUP_ERROR;
    }

    attrs = requestAttrs;
    newAttrs = new HashPrintRequestAttributeSet(attrs);
    myService = aService;

    prepareDialog();        // prepare dialog
    fillPageSetupFields();  // Initialize dialog fields
    firstUse = false;
    return SETUP_OK;
}
项目:nordpos    文件:ReportUtils.java   
public static PrintService getPrintService(String printername) {

    // Initalize print service

    if (printername == null) {
        return PrintServiceLookup.lookupDefaultPrintService();       
    } else {

        if ("(Show dialog)".equals(printername)) {
            return null; // null means "you have to show the print dialog"
        } else if ("(Default)".equals(printername)) {
            return PrintServiceLookup.lookupDefaultPrintService(); 
        } else {
            PrintService[] pservices = 
                    PrintServiceLookup.lookupPrintServices(DocFlavor.SERVICE_FORMATTED.PRINTABLE , null);
            for (PrintService s : pservices) {    
                if (printername.equals(s.getName())) {
                    return s;
                }
            }
            return PrintServiceLookup.lookupDefaultPrintService();       
        }                
    }                 
}
项目:zebra-zpl    文件:ZebraUtils.java   
/**
 * 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);
    }
}
项目:openjdk-jdk7u-jdk    文件:RasterPrinterJob.java   
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;
}
项目:openjdk-jdk7u-jdk    文件:WPrinterJob.java   
public PrintService getPrintService() {
    if (myService == null) {
        String printerName = getNativePrintService();

        if (printerName != null) {
            myService = Win32PrintServiceLookup.getWin32PrintLUS().
                getPrintServiceByName(printerName);
            // no need to call setNativePrintService as this name is
            // currently set in native
            if (myService != null) {
                return myService;
            }
        }

        myService = PrintServiceLookup.lookupDefaultPrintService();
        if (myService != null) {
            try {
                setNativePrintServiceIfNeeded(myService.getName());
            } catch (Exception e) {
                myService = null;
            }
        }

      }
      return myService;
}
项目:birt    文件:PrintUtility.java   
/**
 * Find all the printer resources on the server
 * 
 * @return
 */
public static List findPrinters( )
{
    List printers = new ArrayList( );

    PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet( );
    DocFlavor flavor = DocFlavor.INPUT_STREAM.POSTSCRIPT;
    PrintService[] printServices = PrintServiceLookup.lookupPrintServices(
            flavor, pras );
    if ( printServices != null )
    {
        for ( int i = 0; i < printServices.length; i++ )
        {
            PrintService service = printServices[i];
            printers.add( createPrinter( service ) );
        }
    }

    return printers;
}
项目:freeVM    文件:ServiceUIDialog.java   
private int pageSetup(PrintService aService, 
                      PrintRequestAttributeSet requestAttrs) 
{
    myService = (aService == null)  
            ? PrintServiceLookup.lookupDefaultPrintService() 
            : aService;

    if ((requestAttrs == null) || (aService == null)) {
        return SETUP_ERROR;
    }

    attrs = requestAttrs;
    newAttrs = new HashPrintRequestAttributeSet(attrs);
    myService = aService;

    prepareDialog();        // prepare dialog
    fillPageSetupFields();  // Initialize dialog fields
    firstUse = false;
    return SETUP_OK;
}
项目:freeVM    文件:ServiceUIDialog.java   
private int pageSetup(PrintService aService, 
                      PrintRequestAttributeSet requestAttrs) 
{
    myService = (aService == null)  
            ? PrintServiceLookup.lookupDefaultPrintService() 
            : aService;

    if ((requestAttrs == null) || (aService == null)) {
        return SETUP_ERROR;
    }

    attrs = requestAttrs;
    newAttrs = new HashPrintRequestAttributeSet(attrs);
    myService = aService;

    prepareDialog();        // prepare dialog
    fillPageSetupFields();  // Initialize dialog fields
    firstUse = false;
    return SETUP_OK;
}
项目:OpenbravoPOS    文件:ReportUtils.java   
public static PrintService getPrintService(String printername) {

    // Initalize print service

    if (printername == null) {
        return PrintServiceLookup.lookupDefaultPrintService();       
    } else {

        if ("(Show dialog)".equals(printername)) {
            return null; // null means "you have to show the print dialog"
        } else if ("(Default)".equals(printername)) {
            return PrintServiceLookup.lookupDefaultPrintService(); 
        } else {
            PrintService[] pservices = 
                    PrintServiceLookup.lookupPrintServices(DocFlavor.SERVICE_FORMATTED.PRINTABLE , null);
            for (PrintService s : pservices) {    
                if (printername.equals(s.getName())) {
                    return s;
                }
            }
            return PrintServiceLookup.lookupDefaultPrintService();       
        }                
    }                 
}
项目:openjdk-icedtea7    文件:RasterPrinterJob.java   
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;
}
项目:openjdk-icedtea7    文件:WPrinterJob.java   
public PrintService getPrintService() {
    if (myService == null) {
        String printerName = getNativePrintService();

        if (printerName != null) {
            myService = Win32PrintServiceLookup.getWin32PrintLUS().
                getPrintServiceByName(printerName);
            // no need to call setNativePrintService as this name is
            // currently set in native
            if (myService != null) {
                return myService;
            }
        }

        myService = PrintServiceLookup.lookupDefaultPrintService();
        if (myService != null) {
            try {
                setNativePrintService(myService.getName());
            } catch (Exception e) {
                myService = null;
            }
        }

      }
      return myService;
}
项目:wildfly-camel    文件:PrinterIntegrationTest.java   
@Before
public void setup() {
    PrintService psDefault = Mockito.mock(PrintService.class);
    Mockito.when(psDefault.getName()).thenReturn("DefaultPrinter");
    Mockito.when(psDefault.isDocFlavorSupported(Mockito.any(DocFlavor.class))).thenReturn(Boolean.TRUE);
    PrintServiceLookup psLookup = Mockito.mock(PrintServiceLookup.class);
    Mockito.when(psLookup.getPrintServices()).thenReturn(new PrintService[]{psDefault});
    Mockito.when(psLookup.getDefaultPrintService()).thenReturn(psDefault);
    DocPrintJob docPrintJob = Mockito.mock(DocPrintJob.class);
    Mockito.when(psDefault.createPrintJob()).thenReturn(docPrintJob);
    MediaTray[] trays = new MediaTray[]{
        MediaTray.TOP,
        MediaTray.MIDDLE,
        MediaTray.BOTTOM
    };
    Mockito.when(psDefault.getSupportedAttributeValues(Media.class, null, null)).thenReturn(trays);
    PrintServiceLookup.registerServiceProvider(psLookup);
}