From 620db985e7584929ce8e1b7317979d8a5e3f2f8b Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Wed, 23 Apr 2014 10:34:02 -0400 Subject: [PATCH] hatch : create job settings from config hash cont. Signed-off-by: Bill Erickson --- src/org/evergreen_ils/hatch/PrintManager.java | 87 ++++++++++----------------- 1 file changed, 31 insertions(+), 56 deletions(-) diff --git a/src/org/evergreen_ils/hatch/PrintManager.java b/src/org/evergreen_ils/hatch/PrintManager.java index dc6420f..6df0ff7 100644 --- a/src/org/evergreen_ils/hatch/PrintManager.java +++ b/src/org/evergreen_ils/hatch/PrintManager.java @@ -65,6 +65,37 @@ public class PrintManager { return extractSettingsFromJob(job); } + public void print(WebEngine engine, Mapparams) { + + Long msgid = (Long) params.get("msgid"); + Boolean showDialog = (Boolean) params.get("showDialog"); + + Map settings = + (Map) params.get("config"); + + HatchWebSocketHandler socket = + (HatchWebSocketHandler) params.get("socket"); + + PrinterJob job = null; + try { + job = buildPrinterJob(settings); + } catch(IllegalArgumentException e) { + socket.reply(e.toString(), msgid, false); + } + + if (showDialog != null && showDialog.booleanValue()) { + if (!job.showPrintDialog(null)) { + // job canceled by user + socket.reply("Print job canceled", msgid); + } + } + + engine.print(job); + job.endJob(); + + socket.reply("Print job succeeded", msgid); + } + public PrinterJob buildPrinterJob( Map settings) throws IllegalArgumentException { @@ -197,62 +228,6 @@ public class PrintManager { } } - - public void print(WebEngine engine, Mapparams) { - - //debugPrintService(null); // testing - - /* - Map attrs = - (Map) params.get("attributes"); - - String printerName = (String) attrs.get("printer-name"); - PrintService service = getPrintServiceByName(printerName); - - if (service == null) { - logger.warn("printer '" + printerName + "' not found!"); - debugPrintService(); - return; - } - - PrinterJob job = PrinterJob.createPrinterJob(); - Attribute mediaAttr = getAttribute( - service, Media.class, (String) attrs.get("media")); - - Attribute orientationAttr = getAttribute( - service, RequestedOrientation.class, - (String) attrs.get("orientation")); - - PrintRequestAttributeSet attrSet = new PrintRequestAttributeSet(); - if (mediaAttr != null) attrSet.add(mediaAttr); - if (orientationAttr != null) attrSet.add(orientationAttr); - */ - - - //getPrinterByName(); ... - Printer printer = Printer.getDefaultPrinter(); // TODO - PageLayout firstLayout = printer.createPageLayout( - Paper.NA_LETTER, - PageOrientation.LANDSCAPE, - 0.1 * 72, 0.2 * 72, 0.3 * 72, 0.4 * 72 - ); - - logger.info("orig job page layout " + firstLayout.toString()); - PrinterJob job = PrinterJob.createPrinterJob(printer); - - job.getJobSettings().setPageLayout(firstLayout); - if (!job.showPrintDialog(null)) return; // print canceled by user - - Map settings = extractSettingsFromJob(job); - engine.print(job); - job.endJob(); - - HatchWebSocketHandler socket = - (HatchWebSocketHandler) params.get("socket"); - - socket.reply(settings, (Long) params.get("msgid")); - } - protected Map extractSettingsFromJob(PrinterJob job) { Map settings = new HashMap(); JobSettings jobSettings = job.getJobSettings(); -- 2.11.0