do not return a printer if printer name does not match
This commit is contained in:
parent
616e607b55
commit
12fc41639a
1 changed files with 6 additions and 12 deletions
|
@ -27,9 +27,6 @@ import java.io.InputStream;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class PrintUtility {
|
public class PrintUtility {
|
||||||
|
|
||||||
public static void print(InputStream inputStream, DocFlavor docFlavor)
|
public static void print(InputStream inputStream, DocFlavor docFlavor)
|
||||||
|
@ -96,22 +93,20 @@ public class PrintUtility {
|
||||||
job.print();
|
job.print();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Printer getDefaultPrinter() {
|
||||||
|
return createPrinter(PrintServiceLookup.lookupDefaultPrintService());
|
||||||
|
}
|
||||||
|
|
||||||
public static Printer getPrinter(String printerName, DocFlavor docFlavor) {
|
public static Printer getPrinter(String printerName, DocFlavor docFlavor) {
|
||||||
Printer printer = null;
|
|
||||||
if (printerName != null) {
|
if (printerName != null) {
|
||||||
List<Printer> printers = findPrinters(docFlavor);
|
List<Printer> printers = findPrinters(docFlavor);
|
||||||
for (Printer p : printers) {
|
for (Printer p : printers) {
|
||||||
if (printerName.equalsIgnoreCase(p.getName())) {
|
if (printerName.equalsIgnoreCase(p.getName())) {
|
||||||
printer = p;
|
return p;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (printer == null) {
|
return null;
|
||||||
PrintService service = PrintServiceLookup.lookupDefaultPrintService();
|
|
||||||
printer = createPrinter(service);
|
|
||||||
}
|
|
||||||
return printer;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Printer findDefaultPrinter(DocFlavor docFlavor) {
|
public static Printer findDefaultPrinter(DocFlavor docFlavor) {
|
||||||
|
@ -141,7 +136,6 @@ public class PrintUtility {
|
||||||
if (attr != null) {
|
if (attr != null) {
|
||||||
printer.setModel(attr.toString());
|
printer.setModel(attr.toString());
|
||||||
}
|
}
|
||||||
//attr = service.getAttribute( PrinterIsAcceptingJobs.class );
|
|
||||||
printer.setStatus(Printer.STATUS_ACCEPTING_JOBS);
|
printer.setStatus(Printer.STATUS_ACCEPTING_JOBS);
|
||||||
attr = service.getAttribute(PrinterInfo.class);
|
attr = service.getAttribute(PrinterInfo.class);
|
||||||
if (attr != null) {
|
if (attr != null) {
|
||||||
|
|
Loading…
Reference in a new issue