本文整理汇总了Java中javax.print.PrintServiceLookup类的典型用法代码示例。如果您正苦于以下问题:Java PrintServiceLookup类的具体用法?Java PrintServiceLookup怎么用?Java PrintServiceLookup使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PrintServiceLookup类属于javax.print包,在下文中一共展示了PrintServiceLookup类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: lookupDefaultPrintService
import javax.print.PrintServiceLookup; //导入依赖的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;
}
示例2: getPrintService
import javax.print.PrintServiceLookup; //导入依赖的package包/类
/**
*
* @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();
}
}
}
示例3: main
import javax.print.PrintServiceLookup; //导入依赖的package包/类
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");
}
}
示例4: printTest
import javax.print.PrintServiceLookup; //导入依赖的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: main
import javax.print.PrintServiceLookup; //导入依赖的package包/类
/**
* 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");
}
}
示例6: main
import javax.print.PrintServiceLookup; //导入依赖的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");
}
示例7: getPrintService
import javax.print.PrintServiceLookup; //导入依赖的package包/类
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();
}
}
}
示例8: setupJavaPrint
import javax.print.PrintServiceLookup; //导入依赖的package包/类
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);
}
示例9:
import javax.print.PrintServiceLookup; //导入依赖的package包/类
@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;
}
示例10: getDefaultPrinterNameFromIni
import javax.print.PrintServiceLookup; //导入依赖的package包/类
private String getDefaultPrinterNameFromIni(final String propName)
{
log.debug("Looking for " + propName + " in ini file");
String printerName = Ini.getProperty(propName);
if (!Check.isEmpty(printerName))
{
log.debug("Found printerName: " + printerName);
return printerName;
}
log.debug("Looking for machine's printers");
final PrintService[] services = PrintServiceLookup.lookupPrintServices(null, null);
if (services == null || services.length == 0)
{
// [email protected]: so what? we don't need a printer to generate PDFs
// log.warn("No default printer found on this machine");
return "";
}
printerName = services[0].getName();
Ini.setProperty(propName, printerName);
log.debug("Found printerName: " + printerName);
return printerName;
}
示例11: create
import javax.print.PrintServiceLookup; //导入依赖的package包/类
@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];
}
}
示例12: getPrintService
import javax.print.PrintServiceLookup; //导入依赖的package包/类
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;
}
示例13: DruckerController
import javax.print.PrintServiceLookup; //导入依赖的package包/类
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);
}
示例14: out
import javax.print.PrintServiceLookup; //导入依赖的package包/类
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;
}
示例15: testListPrinterTrays
import javax.print.PrintServiceLookup; //导入依赖的package包/类
@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);
}
}
}