本文整理匯總了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");
}
示例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);
}
}
}
示例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) {
}
}
示例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;
}
}
}
示例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;
}
示例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");
}
示例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);
}
}
}
示例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) {
}
}
示例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;
}
}
}
示例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;
}
}
示例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;
}
示例12: getPrinterDestName
import javax.print.PrintService; //導入方法依賴的package包/類
private String getPrinterDestName(PrintService ps) {
if (isMac()) {
return ((IPPPrintService)ps).getDest();
}
return ps.getName();
}
示例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;
}