List of usage examples for java.awt.print PrinterJob printDialog
public abstract boolean printDialog() throws HeadlessException;
From source file:com.isti.traceview.common.TraceViewChartPanel.java
/** * Creates a print job for the chart./*from w ww .jav a 2 s . c o m*/ */ public void createChartPrintJob() { PrinterJob job = PrinterJob.getPrinterJob(); PageFormat pf = job.defaultPage(); pf.setOrientation(PageFormat.LANDSCAPE); PageFormat pf2 = job.pageDialog(pf); if (pf2 != pf) { job.setPrintable(this, pf2); if (job.printDialog()) { try { job.print(); } catch (PrinterException e) { JOptionPane.showMessageDialog(this, e); } } } }
From source file:jhplot.gui.GHPanel.java
/** * Print the canvas//w ww . java 2 s . c o m * */ public void printGraph() { if (isBorderShown()) showBorders(false); CanvasPanel.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); Thread t = new Thread() { public void run() { try { PrinterJob prnJob = PrinterJob.getPrinterJob(); // set the Printable to the PrinterJob prnJob.setPrintable(new Printable() { public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) { if (pageIndex == 0) { Graphics2D g2d = (Graphics2D) graphics; double ratioX = pageFormat.getImageableWidth() / CanvasPanel.getSize().width; double ratioY = pageFormat.getImageableHeight() / CanvasPanel.getSize().height; double factor = Math.min(ratioX, ratioY); g2d.scale(factor, factor); g2d.translate(pageFormat.getImageableX(), pageFormat.getImageableY()); disableDoubleBuffering(CanvasPanel); CanvasPanel.print(g2d); enableDoubleBuffering(CanvasPanel); return Printable.PAGE_EXISTS; } return Printable.NO_SUCH_PAGE; } }); if (prnJob.printDialog()) { JHPlot.showStatusBarText("Printing.."); prnJob.print(); } } catch (PrinterException e) { e.printStackTrace(); } } }; t.start(); CanvasPanel.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); }
From source file:com.rapidminer.gui.plotter.charts.AbstractChartPanel.java
/** * Creates a print job for the chart.//from w w w. ja v a 2s. c o m */ @Override public void createChartPrintJob() { PrinterJob job = PrinterJob.getPrinterJob(); PageFormat pf = job.defaultPage(); PageFormat pf2 = job.pageDialog(pf); if (pf2 != pf) { job.setPrintable(this, pf2); if (job.printDialog()) { try { job.print(); } catch (PrinterException e) { JOptionPane.showMessageDialog(this, e); } } } }
From source file:gda.plots.SimplePlot.java
/** * This overrides the method in ChartPanel which seems to behave slightly differently. The replacement may be * unecessary -investigate./* w ww . j a v a 2 s.c o m*/ */ @Override public void createChartPrintJob() { PrinterJob printerJob = PrinterJob.getPrinterJob(); PageFormat pageFormat = printerJob.defaultPage(); pageFormat.setOrientation(PageFormat.LANDSCAPE); printerJob.setPrintable(this, pageFormat); try { if (printerJob.printDialog()) { printerJob.print(); } } catch (PrinterException pe) { logger.error("Caught PrinterException: " + pe.getMessage()); } }
From source file:lu.fisch.unimozer.Diagram.java
public void printDiagram() { // print preview takes a lot of memory (don't know why) // so it is a good idea to sugest to the JVM to clean up the heap System.gc();// w w w.j av a2s .c o m printOptions = PrintOptions.showModal(frame, "Print options"); if (printOptions.OK == true) { this.deselectAll(); this.cleanAll(); this.repaint(); if (printOptions.getJob() == PrintOptions.JOB_PREVIEW) { PrintPreview pp = new PrintPreview(frame, this); pp.setLocation(Math.round((frame.getWidth() - pp.getWidth()) / 2 + frame.getLocation().x), (frame.getHeight() - pp.getHeight()) / 2 + frame.getLocation().y); pp.setVisible(true); } else { try { // Use default printer, no dialog PrinterJob prnJob = PrinterJob.getPrinterJob(); // get the default page format PageFormat pf0 = prnJob.defaultPage(); // clone it PageFormat pf1 = (PageFormat) pf0.clone(); Paper p = pf0.getPaper(); // set to zero margin p.setImageableArea(0, 0, pf0.getWidth(), pf0.getHeight()); pf1.setPaper(p); // let the printer validate it PageFormat pf2 = prnJob.validatePage(pf1); //prnJob.pageDialog(prnJob.defaultPage()); prnJob.setPrintable(this, pf2); if (prnJob.printDialog()) { setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); prnJob.print(); setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); } } catch (PrinterException ex) { ex.printStackTrace(); System.err.println("Printing error: " + ex.toString()); } } } System.gc(); }
From source file:org.apache.pdfbox.debugger.PDFDebugger.java
private void printMenuItemActionPerformed(ActionEvent evt) { if (document != null) { try {//from w ww . j a v a2 s . c o m PrinterJob job = PrinterJob.getPrinterJob(); job.setPageable(new PDFPageable(document)); if (job.printDialog()) { job.print(); } } catch (PrinterException e) { throw new RuntimeException(e); } } }
From source file:org.gephi.ui.components.ReportSelection.java
private void printButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_printButtonActionPerformed PrinterJob pjob = PrinterJob.getPrinterJob(); PageFormat pf = pjob.defaultPage(); pjob.setPrintable(this, pf); try {/* w ww .jav a2 s .c o m*/ if (pjob.printDialog()) { pjob.print(); } } catch (PrinterException e) { e.printStackTrace(); } }
From source file:org.jab.docsearch.DocSearch.java
private void doPrint() { PrinterJob pj = PrinterJob.getPrinterJob(); pj.setJobName("docSearcher"); pj.setPageable(vista);//from w ww. j a va 2 s .c om try { if (pj.printDialog()) { pj.print(); } } catch (PrinterException pe) { logger.fatal("doPrint() failed with PrinterException", pe); showMessage(dsErrPrint, pe.toString()); } }
From source file:org.openscience.jmol.app.Jmol.java
/** * added print command, so that it can be used by RasmolScriptHandler **//* ww w. j a v a 2s.c o m*/ public void print() { PrinterJob job = PrinterJob.getPrinterJob(); job.setPrintable(display); if (job.printDialog()) { try { job.print(); } catch (PrinterException e) { Logger.error("Error while printing", e); } } }
From source file:org.pentaho.reporting.engine.classic.core.modules.gui.print.PrintUtil.java
public static boolean print(final MasterReport report, final ReportProgressListener progressListener) throws PrinterException, ReportProcessingException { final ModifiableConfiguration reportConfiguration = report.getReportConfiguration(); final String jobName = reportConfiguration.getConfigProperty(PRINTER_JOB_NAME_KEY, report.getTitle()); final PrinterJob printerJob = PrinterJob.getPrinterJob(); if (jobName != null) { printerJob.setJobName(jobName);/* w w w .jav a2 s .c o m*/ } final PrintReportProcessor reportPane = new PrintReportProcessor(report); if (progressListener != null) { reportPane.addReportProgressListener(progressListener); } try { reportPane.fireProcessingStarted(); printerJob.setPageable(reportPane); printerJob.setCopies(getNumberOfCopies(reportConfiguration)); if (printerJob.printDialog()) { printerJob.print(); return true; } return false; } finally { reportPane.fireProcessingFinished(); reportPane.close(); if (progressListener != null) { reportPane.removeReportProgressListener(progressListener); } } }