List of usage examples for java.awt.print PrinterJob print
public abstract void print() throws PrinterException;
From source file:com.sshtools.sshterm.SshTerminalPanel.java
public void printScreen() { try {//from w w w. j a va 2 s . co m PrinterJob job = PrinterJob.getPrinterJob(); job.setPrintable(terminal, pageFormat); if (job.printDialog()) { setCursor(Cursor.getPredefinedCursor(3)); job.print(); setCursor(Cursor.getPredefinedCursor(0)); } } catch (PrinterException pe) { JOptionPane.showMessageDialog(this, pe.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); } }
From source file:rulebender.editors.dat.view.CustomizedChartComposite.java
/** * Creates a print job for the chart.//w ww .j a va2 s.c om */ public void createChartPrintJob() { //FIXME try to replace swing print stuff by swt 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) { MessageBox messageBox = new MessageBox(this.canvas.getShell(), SWT.OK | SWT.ICON_ERROR); messageBox.setMessage(e.getMessage()); messageBox.open(); } } } }
From source file:com.rcp.wbw.demo.ChartComposite.java
/** * Creates a print job for the chart.//from ww w . j av a 2s .c o m */ public void createChartPrintJob() { // FIXME try to replace swing print stuff by swt 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) { MessageBox messageBox = new MessageBox(this.canvas.getShell(), SWT.OK | SWT.ICON_ERROR); messageBox.setMessage(e.getMessage()); messageBox.open(); } } } }
From source file:org.mwc.cmap.grideditor.chart.FixedChartComposite.java
/** * Creates a print job for the chart.//from w ww . j a v a 2 s. co m */ public void createChartPrintJob() { // FIXME try to replace swing print stuff by swt final PrinterJob job = PrinterJob.getPrinterJob(); final PageFormat pf = job.defaultPage(); final PageFormat pf2 = job.pageDialog(pf); if (pf2 != pf) { job.setPrintable(this, pf2); if (job.printDialog()) { try { job.print(); } catch (final PrinterException e) { final MessageBox messageBox = new MessageBox(this.canvas.getShell(), SWT.OK | SWT.ICON_ERROR); messageBox.setMessage(e.getMessage()); messageBox.open(); } } } }
From source file:net.sf.jasperreports.engine.print.JRPrinterAWT.java
/** * *//*w w w . j av a 2s .c o m*/ public boolean printPages(int firstPageIndex, int lastPageIndex, boolean withPrintDialog) throws JRException { boolean isOK = true; if (firstPageIndex < 0 || firstPageIndex > lastPageIndex || lastPageIndex >= jasperPrint.getPages().size()) { throw new JRException("Invalid page index range : " + firstPageIndex + " - " + lastPageIndex + " of " + jasperPrint.getPages().size()); } pageOffset = firstPageIndex; PrinterJob printJob = PrinterJob.getPrinterJob(); // fix for bug ID 6255588 from Sun bug database initPrinterJobFields(printJob); if (jasperPrint.getProperty("printService") != null) { String printServiceName = jasperPrint.getProperty("printService"); try { PrintService[] services = PrintServiceLookup.lookupPrintServices(null, null); for (PrintService se : services) { if (se.getName().contains(printServiceName)) { printJob.setPrintService(se); break; } } } catch (PrinterException ex) { Logger.getLogger(JRPrinterAWT.class.getName()).log(Level.SEVERE, null, ex); } } PageFormat pageFormat = printJob.defaultPage(); Paper paper = pageFormat.getPaper(); printJob.setJobName("JasperReports - " + jasperPrint.getName()); switch (jasperPrint.getOrientationValue()) { case LANDSCAPE: { pageFormat.setOrientation(PageFormat.LANDSCAPE); paper.setSize(jasperPrint.getPageHeight(), jasperPrint.getPageWidth()); paper.setImageableArea(0, 0, jasperPrint.getPageHeight(), jasperPrint.getPageWidth()); break; } case PORTRAIT: default: { pageFormat.setOrientation(PageFormat.PORTRAIT); paper.setSize(jasperPrint.getPageWidth(), jasperPrint.getPageHeight()); paper.setImageableArea(0, 0, jasperPrint.getPageWidth(), jasperPrint.getPageHeight()); } } pageFormat.setPaper(paper); Book book = new Book(); book.append(this, pageFormat, lastPageIndex - firstPageIndex + 1); printJob.setPageable(book); try { if (withPrintDialog) { if (printJob.printDialog()) { printJob.print(); } else { isOK = false; } } else { printJob.print(); } } catch (Exception ex) { throw new JRException("Error printing report.", ex); } return isOK; }
From source file:org.gumtree.vis.awt.JChartPanel.java
@Override public void createChartPrintJob() { setCursor(WAIT_CURSOR);/*from w w w . j a va2s . c om*/ PrinterJob job = PrinterJob.getPrinterJob(); PageFormat pf = job.defaultPage(); PageFormat pf2 = job.pageDialog(pf); if (pf2 != pf) { job.setPrintable(this, pf2); try { job.print(); } catch (PrinterException e) { JOptionPane.showMessageDialog(this, e); } finally { setCursor(defaultCursor); } } setCursor(defaultCursor); }
From source file:com.isti.traceview.common.TraceViewChartPanel.java
/** * Creates a print job for the chart./*from w ww .ja v 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/*from w ww . j av a2 s . c om*/ * */ 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 ww . jav a 2 s . 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./*from w w w. j ava 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()); } }