List of usage examples for java.awt.print PrinterJob setPrintable
public abstract void setPrintable(Printable painter, PageFormat format);
From source file:com.rcp.wbw.demo.ChartComposite.java
/** * Creates a print job for the chart.// ww w .j ava2 s .co 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 ww w.j a va2s . c om*/ */ 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:org.gumtree.vis.awt.JChartPanel.java
@Override public void createChartPrintJob() { setCursor(WAIT_CURSOR);/*from w ww .j a va 2 s .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 w w. ja v a 2s . co 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:com.rapidminer.gui.plotter.charts.AbstractChartPanel.java
/** * Creates a print job for the chart./*from www . j a v a2 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./* w ww .j ava 2 s. co 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 .ja v 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.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 {//from w w w . j a v a2 s . com if (pjob.printDialog()) { pjob.print(); } } catch (PrinterException e) { e.printStackTrace(); } }
From source file:processing.app.Editor.java
/** * Handler for File → Print.//www .j a v a2 s.c om */ public void handlePrint() { statusNotice(_("Printing...")); //printerJob = null; PrinterJob printerJob = PrinterJob.getPrinterJob(); if (pageFormat != null) { //System.out.println("setting page format " + pageFormat); printerJob.setPrintable(textarea, pageFormat); } else { printerJob.setPrintable(textarea); } // set the name of the job to the code name printerJob.setJobName(sketch.getCurrentCode().getPrettyName()); if (printerJob.printDialog()) { try { printerJob.print(); statusNotice(_("Done printing.")); } catch (PrinterException pe) { statusError(_("Error while printing.")); pe.printStackTrace(); } } else { statusNotice(_("Printing canceled.")); } //printerJob = null; // clear this out? }