本文整理匯總了Java中javax.print.PrintService類的典型用法代碼示例。如果您正苦於以下問題:Java PrintService類的具體用法?Java PrintService怎麽用?Java PrintService使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
PrintService類屬於javax.print包,在下文中一共展示了PrintService類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: thirdPartyPrintLogic
import javax.print.PrintService; //導入依賴的package包/類
static void thirdPartyPrintLogic(String printerName) throws Exception {
PrinterJob printerjob = PrinterJob.getPrinterJob();
printerjob.setCopies(2);
printerjob.setJobName("myJobName");
printerjob.setPrintable(new DummyPrintable());
for (PrintService printService : PrinterJob.lookupPrintServices()) {
System.out.println("check printer name of service " + printService);
if (printerName.equals(printService.getName())) {
System.out.println("correct printer service do print...");
printerjob.setPrintService(printService);
printerjob.print();
break;
}
}
}
示例2: main
import javax.print.PrintService; //導入依賴的package包/類
public static void main(String[] args) throws Exception {
job = PrinterJob.getPrinterJob();
PrintService prtSrv = job.getPrintService();
if (job.getPrintService() == null) {
System.out.println("No printers. Test cannot continue");
return;
}
if (!prtSrv.isAttributeCategorySupported(JobSheets.class)) {
return;
}
SwingUtilities.invokeAndWait(() -> {
doTest(BannerTest::printTest);
});
mainThread = Thread.currentThread();
try {
Thread.sleep(180000);
} 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");
}
}
示例3: addPrintServiceToList
import javax.print.PrintService; //導入依賴的package包/類
private int addPrintServiceToList(ArrayList<PrintService> printerList, PrintService ps) {
int index = printerList.indexOf(ps);
// Check if PrintService with same name is already in the list.
if (CUPSPrinter.isCupsRunning() && index != -1) {
// Bug in Linux: Duplicate entry of a remote printer
// and treats it as local printer but it is returning wrong
// information when queried using IPP. Workaround is to remove it.
// Even CUPS ignores these entries as shown in lpstat or using
// their web configuration.
PrinterURI uri = ps.getAttribute(PrinterURI.class);
if (uri.getURI().getHost().equals("localhost")) {
IPPPrintService.debug_println(debugPrefix+"duplicate PrintService, ignoring the new local printer: "+ps);
return index; // Do not add this.
}
PrintService oldPS = printerList.get(index);
uri = oldPS.getAttribute(PrinterURI.class);
if (uri.getURI().getHost().equals("localhost")) {
IPPPrintService.debug_println(debugPrefix+"duplicate PrintService, removing existing local printer: "+oldPS);
printerList.remove(oldPS);
} else {
return index;
}
}
printerList.add(ps);
return (printerList.size() - 1);
}
示例4: printTest
import javax.print.PrintService; //導入依賴的package包/類
/**
* 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]);
}
}
示例5: lookupDefaultPrintService
import javax.print.PrintService; //導入依賴的package包/類
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;
}
示例6: setPrinterNameAttrib
import javax.print.PrintService; //導入依賴的package包/類
private void setPrinterNameAttrib(String printerName) {
PrintService service = this.getPrintService();
if (printerName == null) {
return;
}
if (service != null && printerName.equals(service.getName())) {
return;
} else {
PrintService []services = PrinterJob.lookupPrintServices();
for (int i=0; i<services.length; i++) {
if (printerName.equals(services[i].getName())) {
try {
this.setPrintService(services[i]);
} catch (PrinterException e) {
}
return;
}
}
}
//** END Functions called by native code for querying/updating attributes
}
示例7: matchingService
import javax.print.PrintService; //導入依賴的package包/類
@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;
}
示例8: updatePageAttributes
import javax.print.PrintService; //導入依賴的package包/類
protected void updatePageAttributes(PrintService service,
PageFormat page) {
if (this.attributes == null) {
this.attributes = new HashPrintRequestAttributeSet();
}
updateAttributesWithPageFormat(service, page, this.attributes);
}
示例9: 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");
}
示例10: main
import javax.print.PrintService; //導入依賴的package包/類
public static void main(String[] args) {
PrintService[] services = PrintServiceLookup.lookupPrintServices(null, null);
for(final PrintService service: services) {
Thread thread = new Thread() {
public void run() {
service.getSupportedAttributeValues(Media.class, null, null);
}
};
thread.start();
}
}
示例11: main
import javax.print.PrintService; //導入依賴的package包/類
public static void main (String[] args) throws Exception {
job = PrinterJob.getPrinterJob();
PrintService prtSrv = job.getPrintService();
if (prtSrv == null) {
System.out.println("No printers. Test cannot continue");
return;
}
// do not run the test if JobSheet category is not supported
if (!prtSrv.isAttributeCategorySupported(JobSheets.class)) {
return;
}
// check system default banner option and let user know what to expect
JobSheets js = (JobSheets)job.getPrintService().
getDefaultAttributeValue(JobSheets.class);
if (js != null && js.equals(JobSheets.NONE)) {
noJobSheet = true;
}
SwingUtilities.invokeAndWait(() -> {
doTest(TestCheckSystemDefaultBannerOption::printTest);
});
mainThread = Thread.currentThread();
try {
Thread.sleep(60000);
} catch (InterruptedException e) {
if (!testPassed && testGeneratedInterrupt) {
String banner = noJobSheet ? "Banner page" : " No Banner page";
throw new RuntimeException(banner + " is printed");
}
}
if (!testGeneratedInterrupt) {
throw new RuntimeException("user has not executed the test");
}
}
示例12: doPrinterJob
import javax.print.PrintService; //導入依賴的package包/類
public static void doPrinterJob(String fileStr, OrientationRequested o) {
PrinterJob pj = PrinterJob.getPrinterJob();
PrintService ps = pj.getPrintService();
if (ps == null) {
System.out.println("No print service found.");
return;
}
pj.setPrintable(new PrintToDir());
PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
aset.add(o);
File f = new File(fileStr);
// f.deleteOnExit();
URI dest = f.toURI();
Destination d = new Destination(dest);
if (ps.isAttributeValueSupported(d, null, null)) {
aset.add(d);
try {
pj.print(aset);
} catch (PrinterException e) {
System.out.println("PrinterJob passed.");
return;
}
throw new RuntimeException("PrinterJob:PrinterException expected but not thrown. \nTEST FAILED");
} else {
System.out.println("Destination attribute is not a supported value. PrinterJob passed.");
}
}
示例13: 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);
}
}
}
示例14: isSupportedValue
import javax.print.PrintService; //導入依賴的package包/類
protected boolean isSupportedValue(Attribute attrval,
PrintRequestAttributeSet attrset) {
PrintService ps = getPrintService();
return
(attrval != null && ps != null &&
ps.isAttributeValueSupported(attrval,
DocFlavor.SERVICE_FORMATTED.PAGEABLE,
attrset));
}
示例15: getPrinterGraphicsConfig
import javax.print.PrintService; //導入依賴的package包/類
synchronized PrinterGraphicsConfig getPrinterGraphicsConfig() {
if (pgConfig != null) {
return pgConfig;
}
String deviceID = "Printer Device";
PrintService service = getPrintService();
if (service != null) {
deviceID = service.toString();
}
pgConfig = new PrinterGraphicsConfig(deviceID,
defaultDeviceTransform,
deviceWidth, deviceHeight);
return pgConfig;
}