use of java.awt.print.PrinterJob in project freeplane by freeplane.
the class PrintController method print.
public void print(Printable mapView, boolean showDlg) throws PrinterException {
if (!acquirePrinterJobAndPageFormat(showDlg)) {
return;
}
getPrinterJob().setPrintable(mapView, getPageFormat());
if (!showDlg || printDialog()) {
if (mapView instanceof MapView)
((MapView) mapView).preparePrinting();
try {
final PrinterJob printerJob = getPrinterJob();
if (mapView instanceof Component) {
final String name = ((Component) mapView).getName();
if (name != null)
printerJob.setJobName(name);
}
printerJob.print();
} catch (PrinterException ex) {
LogUtils.warn(ex);
} finally {
if (mapView instanceof MapView)
((MapView) mapView).endPrinting();
}
}
}
use of java.awt.print.PrinterJob in project com.revolsys.open by revolsys.
the class Print method actionPerformed.
@Override
public void actionPerformed(final ActionEvent event) {
final Project project = Project.get();
final Viewport2D viewport = project.getViewport();
final PrinterJob job = PrinterJob.getPrinterJob();
final PageFormat format = job.defaultPage();
format.setOrientation(PageFormat.PORTRAIT);
final Paper paper = format.getPaper();
paper.setImageableArea(29, 29, format.getWidth() - 58, format.getHeight() - 58);
format.setPaper(paper);
if (this.printService != null) {
try {
job.setPrintService(this.printService);
} catch (final PrinterException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
final BoundingBox boundingBox = viewport.getBoundingBox();
final MapPageable pageable = new MapPageable(project, boundingBox, format, 20000, 300, 200);
job.setPageable(pageable);
final boolean doPrint = job.printDialog();
if (doPrint) {
this.printService = job.getPrintService();
Invoke.background("Print", () -> {
try {
job.print();
} catch (final Exception e) {
Logs.error(this, "Unable to print", e);
}
});
}
}
use of java.awt.print.PrinterJob in project com.revolsys.open by revolsys.
the class SinglePage method print.
public static void print() {
final Project project = Project.get();
final Viewport2D viewport = project.getViewport();
final int viewWidth = viewport.getViewWidthPixels();
final int viewHeight = viewport.getViewHeightPixels();
final BoundingBox boundingBox = viewport.getBoundingBox();
final double scaleForVisible = viewport.getScaleForVisible();
final PrinterJob job = PrinterJob.getPrinterJob();
job.setJobName(project.getName());
final PageFormat format = job.defaultPage();
final PrintRequestAttributeSet printAttributes = new HashPrintRequestAttributeSet();
if (boundingBox.getAspectRatio() > 1) {
format.setOrientation(PageFormat.LANDSCAPE);
// printAttributes.add(OrientationRequested.LANDSCAPE);
} else {
format.setOrientation(PageFormat.PORTRAIT);
// printAttributes.add(OrientationRequested.PORTRAIT);
}
final SinglePage pageable = new SinglePage(project, boundingBox, viewWidth, viewHeight, scaleForVisible);
job.setPageable(pageable);
final boolean doPrint = job.printDialog();
if (doPrint) {
Invoke.background("Print", () -> {
try {
job.print();
} catch (final PrinterAbortException e) {
} catch (final Exception e) {
Logs.error(SinglePage.class, "Unable to print", e);
}
});
}
}
use of java.awt.print.PrinterJob in project OpenNotebook by jaltekruse.
the class NotebookPanel method print.
public void print() {
DocPrinter docPrinter = new DocPrinter();
docPrinter.setDoc(getCurrentDocViewer().getDoc());
PrinterJob job = PrinterJob.getPrinterJob();
Paper paper = new Paper();
Document doc = getCurrentDocViewer().getDoc();
paper.setImageableArea(doc.getxMargin(), doc.getyMargin(), doc.getWidth() - 2 * doc.getxMargin(), doc.getHeight() - 2 * doc.getyMargin());
paper.setSize(doc.getWidth(), doc.getHeight());
PageFormat pf = job.defaultPage();
pf.setPaper(paper);
job.setPrintable(docPrinter, pf);
job.setJobName(getCurrentDocViewer().getDoc().getName());
boolean ok = job.printDialog();
if (ok) {
try {
job.print();
} catch (PrinterException ex) {
/* The job did not successfully complete */
}
}
}
use of java.awt.print.PrinterJob in project binnavi by google.
the class CGraphPrinter method print.
/**
* Prints a graph. The user is given the opportunity to choose a number of options from a dialog
* before.
*
* @param parent Parent window of created dialogs.
* @param graph The graph to print.
*/
public static void print(final JFrame parent, final ZyGraph graph) {
final String[] area = { "Print the visible part of the graph only", "Print the whole graph" };
final OptionHandler printOptions = new OptionHandler("Print Options");
printOptions.addInt("Poster rows", 1);
printOptions.addInt("Poster columns", 1);
printOptions.addBool("Add poster coordinates", false);
printOptions.addEnum("Print Area", area, 1);
final Graph2DPrinter gprinter = new Graph2DPrinter(graph.getView());
// show custom print dialog and adopt values
if (!printOptions.showEditor()) {
return;
}
gprinter.setPosterRows(printOptions.getInt("Poster rows"));
gprinter.setPosterColumns(printOptions.getInt("Poster columns"));
gprinter.setPrintPosterCoords(printOptions.getBool("Add poster coordinates"));
if (printOptions.get("Print Area").equals("Print the whole graph")) {
gprinter.setClipType(Graph2DPrinter.CLIP_GRAPH);
} else {
gprinter.setClipType(Graph2DPrinter.CLIP_VIEW);
}
// show default print dialogs
final PrinterJob printJob = PrinterJob.getPrinterJob();
PageFormat pageFormat = printJob.defaultPage();
final PageFormat pageFormat2 = printJob.pageDialog(pageFormat);
if (pageFormat2 == pageFormat) {
return;
}
pageFormat = pageFormat2;
// setup printjob.
// Graph2DPrinter is of type Printable
printJob.setPrintable(gprinter, pageFormat);
if (printJob.printDialog()) {
try {
printJob.print();
} catch (final PrinterException exception) {
final String innerMessage = "E00119: " + "Graph could not be printed";
final String innerDescription = CUtilityFunctions.createDescription(String.format("The graph '%s' could not be printed because there was a problem with the printer.", graph.getRawView().getName()), new String[] { "There was a problem with the printer." }, new String[] { "The print operation could not be completed." });
NaviErrorDialog.show(parent, innerMessage, innerDescription, exception);
}
}
}
Aggregations