當前位置: 首頁>>代碼示例>>Java>>正文


Java PrintService.getName方法代碼示例

本文整理匯總了Java中javax.print.PrintService.getName方法的典型用法代碼示例。如果您正苦於以下問題:Java PrintService.getName方法的具體用法?Java PrintService.getName怎麽用?Java PrintService.getName使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.print.PrintService的用法示例。


在下文中一共展示了PrintService.getName方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: main

import javax.print.PrintService; //導入方法依賴的package包/類
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");
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:18,代碼來源:GetPrintServices.java

示例2: setPrintService

import javax.print.PrintService; //導入方法依賴的package包/類
/**
 * 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);
        }
    }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:46,代碼來源:RasterPrinterJob.java

示例3: ServiceNotifier

import javax.print.PrintService; //導入方法依賴的package包/類
ServiceNotifier(PrintService service) {
    super(service.getName() + " notifier");
    this.service = service;
    listeners = new Vector();
    try {
          setPriority(Thread.NORM_PRIORITY-1);
          setDaemon(true);
          start();
    } catch (SecurityException e) {
    }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:12,代碼來源:ServiceNotifier.java

示例4: endDoc

import javax.print.PrintService; //導入方法依賴的package包/類
/**
 * Invoked by the RasterPrintJob super class
 * this method is called after that last page
 * has been imaged.
 */
protected void endDoc() throws PrinterException {
    if (mPSStream != null) {
        mPSStream.println(EOF_COMMENT);
        mPSStream.flush();
        if (mDestType != RasterPrinterJob.STREAM) {
            mPSStream.close();
        }
    }
    if (mDestType == RasterPrinterJob.PRINTER) {
        PrintService pServ = getPrintService();
        if (pServ != null) {
            mDestination = pServ.getName();
           if (isMac) {
                PrintServiceAttributeSet psaSet = pServ.getAttributes();
                if (psaSet != null) {
                    mDestination = psaSet.get(PrinterName.class).toString() ;
                }
            }
        }
        PrinterSpooler spooler = new PrinterSpooler();
        java.security.AccessController.doPrivileged(spooler);
        if (spooler.pex != null) {
            throw spooler.pex;
        }
    }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:32,代碼來源:PSPrinterJob.java

示例5: UnixPrintJob

import javax.print.PrintService; //導入方法依賴的package包/類
UnixPrintJob(PrintService service) {
    this.service = service;
    mDestination = service.getName();
    if (UnixPrintServiceLookup.isMac()) {
        mDestination = ((IPPPrintService)service).getDest();
    }
    mDestType = UnixPrintJob.DESTPRINTER;
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:9,代碼來源:UnixPrintJob.java

示例6: main

import javax.print.PrintService; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
  for (PrintService service : PrintServiceLookup.lookupPrintServices(null, null)) {
    String serviceName = service.getName();
    PrintService serviceByName = lookupByName(serviceName);
    if (!service.equals(serviceByName)) {
      throw new RuntimeException("NOK " + serviceName
                                 + " expected: " + service.getClass().getName()
                                 + " got: " + serviceByName.getClass().getName());
    }
  }
  System.out.println("Test PASSED");
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:13,代碼來源:GetPrintServices.java

示例7: setPrintService

import javax.print.PrintService; //導入方法依賴的package包/類
/**
 * 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);
        }
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:44,代碼來源:RasterPrinterJob.java

示例8: ServiceNotifier

import javax.print.PrintService; //導入方法依賴的package包/類
ServiceNotifier(PrintService service) {
    super(null, null, service.getName() + " notifier", 0, false);
    this.service = service;
    listeners = new Vector<>();
    try {
          setPriority(Thread.NORM_PRIORITY-1);
          setDaemon(true);
          start();
    } catch (SecurityException e) {
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:12,代碼來源:ServiceNotifier.java

示例9: endDoc

import javax.print.PrintService; //導入方法依賴的package包/類
/**
 * Invoked by the RasterPrintJob super class
 * this method is called after that last page
 * has been imaged.
 */
protected void endDoc() throws PrinterException {
    if (mPSStream != null) {
        mPSStream.println(EOF_COMMENT);
        mPSStream.flush();
        if (mPSStream.checkError()) {
            abortDoc();
            throw new PrinterException("Error while writing to file");
        }
        if (mDestType != RasterPrinterJob.STREAM) {
            mPSStream.close();
        }
    }
    if (mDestType == RasterPrinterJob.PRINTER) {
        PrintService pServ = getPrintService();
        if (pServ != null) {
            mDestination = pServ.getName();
           if (isMac) {
                PrintServiceAttributeSet psaSet = pServ.getAttributes();
                if (psaSet != null) {
                    mDestination = psaSet.get(PrinterName.class).toString() ;
                }
            }
        }
        PrinterSpooler spooler = new PrinterSpooler();
        java.security.AccessController.doPrivileged(spooler);
        if (spooler.pex != null) {
            throw spooler.pex;
        }
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:36,代碼來源:PSPrinterJob.java

示例10: UnixPrintJob

import javax.print.PrintService; //導入方法依賴的package包/類
UnixPrintJob(PrintService service) {
    this.service = service;
    mDestination = service.getName();
    if (PrintServiceLookupProvider.isMac()) {
        mDestination = ((IPPPrintService)service).getDest();
    }
    mDestType = UnixPrintJob.DESTPRINTER;
    JobSheets js = (JobSheets)(service.
                                  getDefaultAttributeValue(JobSheets.class));
    if (js != null && js.equals(JobSheets.NONE)) {
        mNoJobSheet = true;
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:14,代碼來源:UnixPrintJob.java

示例11: getPrinterAttrib

import javax.print.PrintService; //導入方法依賴的package包/類
private final String getPrinterAttrib() {
    // getPrintService will get current print service or default if none
    PrintService service = this.getPrintService();
    String name = (service != null) ? service.getName() : null;
    return name;
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:7,代碼來源:WPrinterJob.java

示例12: getPrinterDestName

import javax.print.PrintService; //導入方法依賴的package包/類
private String getPrinterDestName(PrintService ps) {
    if (isMac()) {
        return ((IPPPrintService)ps).getDest();
    }
    return ps.getName();
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:7,代碼來源:UnixPrintServiceLookup.java

示例13: getPrinterAttrib

import javax.print.PrintService; //導入方法依賴的package包/類
private String getPrinterAttrib() {
    // getPrintService will get current print service or default if none
    PrintService service = this.getPrintService();
    String name = (service != null) ? service.getName() : null;
    return name;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:7,代碼來源:WPrinterJob.java


注:本文中的javax.print.PrintService.getName方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。