/** BrowserView requires a stage for rendering */
private Stage primaryStage;
- /** Our logger instance */
- static Logger logger;
-
/** Queue of incoming print requests */
private static LinkedBlockingQueue<JSONObject>
printRequestQueue = new LinkedBlockingQueue<JSONObject>();
+
+ static final Logger logger = Logger.getLogger("org.evergreen_ils.hatch");
/**
* Printable region containing a browser.
}
}
- /* TODO: make me configurable via config file
- */
- public static Logger getLogger() {
- if (logger != null) return logger;
-
- logger = Logger.getLogger("org.evergreen_ils.hatch");
- logger.setLevel(Level.ALL);
-
- ConsoleHandler handler = new ConsoleHandler();
- handler.setLevel(Level.ALL);
- handler.setFormatter(new SimpleFormatter());
- logger.addHandler(handler);
-
- logger.setUseParentHandlers(false);
-
- return logger;
- }
-
/**
* Hatch main.
public class PrintManager {
/** Our logger instance */
- static final Logger logger = Hatch.getLogger();
+ static final Logger logger = Logger.getLogger("org.evergreen_ils.hatch");
/**
* Returns all known Printer's.
response.put("message", "OK");
try {
-
response.put("clientid", request.getLong("clientid"));
response.put("msgid", request.getLong("msgid"));
protected PageLayout buildPageLayout(
JSONObject settings, Printer printer) {
- JSONObject layoutMap = settings.optJSONObject("pageLayout");
+ PrinterAttributes printerAttrs = printer.getPrinterAttributes();
- if (layoutMap == null) {
- // Start with a sane default. The Java default is wonky.
- return printer.createPageLayout(
- Paper.NA_LETTER,
- PageOrientation.PORTRAIT,
- Printer.MarginType.DEFAULT
- );
- }
+ // Start with default page layout options, replace where possible.
+ Paper paper = printerAttrs.getDefaultPaper();
+ PageOrientation orientation = printerAttrs.getDefaultPageOrientation();
- PrinterAttributes printerAttrs = printer.getPrinterAttributes();
+ String paperName = settings.optString("paper", null);
+ String orientationName = settings.optString("pageOrientation", null);
+ String marginName = settings.optString("marginType", null);
- // find the paper by name
- Paper paper = null;
- String paperName = (String) layoutMap.get("paper");
- Set<Paper> papers = printerAttrs.getSupportedPapers();
- for (Paper source : papers) {
- if (source.getName().equals(paperName)) {
- //logger.info("Found matching paper for " + paperName);
- paper = source;
- break;
+ if (paperName != null) {
+ for (Paper source : printerAttrs.getSupportedPapers()) {
+ if (source.getName().equals(paperName)) {
+ logger.finer("Found matching paper: " + paperName);
+ paper = source;
+ break;
+ }
}
}
- if (paper == null)
- paper = printerAttrs.getDefaultPaper();
+ if (orientationName != null) {
+ orientation = PageOrientation.valueOf(orientationName);
+ }
+ if (settings.optBoolean("autoMargins", true)) {
+ // Using a pre-defined, automatic margin option
+
+ Printer.MarginType margin = Printer.MarginType.DEFAULT;
+ if (marginName != null) {
+ // An auto-margin type has been specified
+ for (Printer.MarginType marg : Printer.MarginType.values()) {
+ if (marg.toString().equals(marginName)) {
+ logger.finer("Found matching margin: " + marginName);
+ margin = marg;
+ break;
+ }
+ }
+ }
+
+ return printer.createPageLayout(paper, orientation, margin);
+ }
+
+ // Using manual margins
+ // Any un-specified margins default to 54 == 0.75 inches.
return printer.createPageLayout(
- paper,
- PageOrientation.valueOf((String) layoutMap.get("pageOrientation")),
- ((Number) layoutMap.get("leftMargin")).doubleValue(),
- ((Number) layoutMap.get("rightMargin")).doubleValue(),
- ((Number) layoutMap.get("topMargin")).doubleValue(),
- ((Number) layoutMap.get("bottomMargin")).doubleValue()
+ paper, orientation,
+ settings.optDouble("leftMargin", 54),
+ settings.optDouble("rightMargin", 54),
+ settings.optDouble("topMargin", 54),
+ settings.optDouble("bottomMargin", 54)
);
}
}
String paperSource = settings.optString("paperSource");
+ logger.finer("paper source = " + paperSource);
if (paperSource != null) {
- // find the paperSource by name
-
- Set<PaperSource> paperSources =
- printerAttrs.getSupportedPaperSources();
-
- for (PaperSource source : paperSources) {
+ for (PaperSource source : printerAttrs.getSupportedPaperSources()) {
+ logger.info("looking at paper source: " + source.getName());
if (source.getName().equals(paperSource)) {
- logger.fine("Found paper source: " + paperSource);
+ logger.finer("Found paper source: " + paperSource);
jobSettings.setPaperSource(source);
break;
}
printerAttrs.getSupportedPaperSources()) {
paperSourcesArray.put(source.getName());
}
- options.put("paperSource", papersArray);
+ options.put("paperSource", paperSourcesArray);
options.put("defaultPaperSource",
printerAttrs.getDefaultPaperSource().getName());