private void runDialogsAndPrint() throws java.awt.print.PrinterException { out("job starting for " + this.map); PrinterJob job = getPrinterJob(); out("got OS job: " + tufts.Util.tags(job)); if (job.printDialog()) { out("printDialog ran, waiting for format..."); // PageFormat format = getPageFormat(job, bounds); PageFormat format = getPageFormatInteractive(job, bounds); out("format: " + outpf(format)); if (format != null) { job.setJobName(jobName); job.setPrintable(this, format); // try setting pageable to see if it then // skips system dialog (we'd like a no-dialog option) // job.setPrintService(job.getPrintService()); // this only *sometimes* works as a workaround // for the vue ap mysteriously being raised above // the system print dialog... // VUE.frame.toBack(); out("printing..."); job.print(); } } out("job complete."); }
private PageFormat getPageFormat(PrinterJob job, Rectangle2D bounds) { if (pageFormat == null) { pageFormat = job.defaultPage(); // todo: keep a list of print formats for each map? if (bounds.getWidth() > bounds.getHeight()) pageFormat.setOrientation(PageFormat.LANDSCAPE); else pageFormat.setOrientation(PageFormat.PORTRAIT); } return pageFormat; }
/** * Run the system page format dialog using the last used PageFormat as the default setup. If user * hits cancel on the dialog, null is returned. */ private PageFormat getPageFormatInteractive(PrinterJob job, Rectangle2D bounds) { PageFormat initial = getPageFormat(job, bounds); PageFormat result = job.pageDialog(initial); if (result != initial) return pageFormat = result; else return null; // dialog was canceled }
private PrinterJob getPrinterJob() { // if (printerJob == null) printerJob = PrinterJob.getPrinterJob(); return printerJob; }