List of usage examples for java.awt.print PrinterJob printDialog
public abstract boolean printDialog() throws HeadlessException;
From source file:io.github.mzmine.util.jfreechart.JFreeChartUtils.java
public static void printChart(ChartViewer chartNode) { // As of java 1.8.0_74, the JavaFX printing support seems to do poor // job. It creates pixelated, low-resolution print outs. For that // reason, we use the AWT PrinterJob class, until the JavaFX printing // support is improved. SwingUtilities.invokeLater(() -> { PrinterJob job = PrinterJob.getPrinterJob(); PageFormat pf = job.defaultPage(); PageFormat pf2 = job.pageDialog(pf); if (pf2 == pf) return; ChartPanel p = new ChartPanel(chartNode.getChart()); job.setPrintable(p, pf2);//from w w w.j a va 2s .com if (!job.printDialog()) return; try { job.print(); } catch (PrinterException e) { e.printStackTrace(); MZmineGUI.displayMessage("Error printing: " + e.getMessage()); } }); }
From source file:com.imag.nespros.gui.plugin.GraphEditor.java
private static void initMenu() { JMenu menu = new JMenu("File"); menu.add(new AbstractAction("Make Image") { public void actionPerformed(ActionEvent e) { JFileChooser chooser = new JFileChooser(); int option = chooser.showSaveDialog(demo); if (option == JFileChooser.APPROVE_OPTION) { File file = chooser.getSelectedFile(); demo.writeJPEGImage(file); }/*from w w w . j a v a2 s . c om*/ } }); menu.add(new AbstractAction("Print") { public void actionPerformed(ActionEvent e) { PrinterJob printJob = PrinterJob.getPrinterJob(); printJob.setPrintable(demo); if (printJob.printDialog()) { try { printJob.print(); } catch (Exception ex) { ex.printStackTrace(); } } } }); menu.add(new AbstractAction("Save topology") { public void actionPerformed(ActionEvent e) { JFileChooser chooser = new JFileChooser(); int option = chooser.showSaveDialog(demo); if (option == JFileChooser.APPROVE_OPTION) { File file = chooser.getSelectedFile(); try { demo.save(file); frame.setTitle(file.getName()); } catch (IOException ex) { Logger.getLogger(GraphEditor.class.getName()).log(Level.SEVERE, null, ex); } } } }); menu.add(new AbstractAction("Load topology") { public void actionPerformed(ActionEvent e) { JFileChooser chooser = new JFileChooser(); int option = chooser.showOpenDialog(demo); if (option == JFileChooser.APPROVE_OPTION) { File file = chooser.getSelectedFile(); try { //EPGraph.getInstance().resetMapping(); simu.resetMapping(); demo.load(file); frame.setTitle("Simulator - " + file.getName()); } catch (FileNotFoundException ex) { Logger.getLogger(GraphEditor.class.getName()).log(Level.SEVERE, null, ex); } } } }); JMenu menu2 = new JMenu("View"); menu2.add(new AbstractAction("Layout") { @Override public void actionPerformed(ActionEvent e) { Layout l = new CircleLayout<Device, ComLink>(Topology.getInstance().getGraph()); l.setInitializer(vv.getGraphLayout()); l.setSize(vv.getSize()); LayoutTransition<Device, ComLink> lt = new LayoutTransition<>(vv, vv.getGraphLayout(), l); Animator animator = new Animator(lt); animator.start(); vv.getRenderContext().getMultiLayerTransformer().setToIdentity(); vv.repaint(); } }); menu2.add(new AbstractAction("Event Composition Networks") { @Override public void actionPerformed(ActionEvent e) { showEPGraph(EPGraph.getInstance().getGraph()); } }); JPopupMenu.setDefaultLightWeightPopupEnabled(false); JMenuBar menuBar = new JMenuBar(); menuBar.add(menu); menuBar.add(menu2); frame.setJMenuBar(menuBar); frame.getContentPane().add(demo); frame.pack(); frame.setVisible(true); buildEPGraphs(); showEPGraph(EPGraph.getInstance().getGraph()); }
From source file:PrintUIWindow.java
public void actionPerformed(ActionEvent e) { PrinterJob job = PrinterJob.getPrinterJob(); job.setPrintable(this); boolean ok = job.printDialog(); if (ok) {//w w w . j a v a 2s. c o m try { job.print(); } catch (PrinterException ex) { /* The job did not successfully complete */ } } }
From source file:com.alvermont.terraj.util.io.PrintUtilities.java
/** * Carry out the print operation for the component * * @throws java.awt.print.PrinterException If there is an error in printing *//*from w w w . j a v a 2 s.co m*/ public void print() throws PrinterException { PrinterJob printJob = PrinterJob.getPrinterJob(); printJob.setPrintable(this); if (printJob.printDialog()) { try { log.debug("Calling PrintJob.print()"); printJob.print(); log.debug("End PrintJob.print()"); } catch (PrinterException pe) { log.error("Error printing: " + pe); throw pe; } } }
From source file:playground.artemc.calibration.charts.CustomChartPanel.java
public void createPrintJob() { 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();/*from ww w . ja va2 s . co m*/ } catch (PrinterException e) { JOptionPane.showMessageDialog(this, e); } } } }
From source file:PrintableComponent.java
/** * This method is not part of the Printable interface. It is a method * that sets up the PrinterJob and initiates the printing. *//* w w w .jav a2 s . c om*/ public void print() throws PrinterException { // Get the PrinterJob object PrinterJob job = PrinterJob.getPrinterJob(); // Get the default page format, then allow the user to modify it PageFormat format = job.pageDialog(job.defaultPage()); // Tell the PrinterJob what to print job.setPrintable(this, format); // Ask the user to confirm, and then begin the printing process if (job.printDialog()) job.print(); }
From source file:JavaWorldPrintExample1.java
/** * Constructor: Example1/*from w w w . j a v a 2 s . com*/ * <p> * */ public JavaWorldPrintExample1() { //--- Create a printerJob object PrinterJob printJob = PrinterJob.getPrinterJob(); //--- Set the printable class to this one since we //--- are implementing the Printable interface printJob.setPrintable(this); //--- Show a print dialog to the user. If the user //--- click the print button, then print otherwise //--- cancel the print job if (printJob.printDialog()) { try { printJob.print(); } catch (Exception PrintException) { PrintException.printStackTrace(); } } }
From source file:com.alvermont.terraj.planet.ui.TerrainFrame.java
private void printItemActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_printItemActionPerformed {//GEN-HEADEREND:event_printItemActionPerformed final PrinterJob printJob = PrinterJob.getPrinterJob(); final PageFormat pf = printJob.pageDialog(printJob.defaultPage()); printJob.setPrintable(new ImagePrinter(image, pf), pf); if (printJob.printDialog()) { try {// w ww . j ava 2 s . c o m printJob.print(); } catch (Exception e) { log.error("Error printing", e); JOptionPane.showMessageDialog(this, "Error: " + e.getMessage() + "\nCheck log file for full details", "Error Printing", JOptionPane.ERROR_MESSAGE); } } }
From source file:org.fhaes.fhfilechecker.FrameViewHelp.java
public void btnPrint_actionPerformed(ActionEvent e) { // Get a PrinterJob PrinterJob job = PrinterJob.getPrinterJob(); // Ask user for page format (e.g., portrait/landscape) PageFormat pf = job.pageDialog(job.defaultPage()); // Specify the Printable is an instance of // PrintListingPainter; also provide given PageFormat job.setPrintable(new PrintListingPainter(out_file_name), pf); // Print 1 copy job.setCopies(1);/*from w ww . j a v a 2s.c om*/ // Put up the dialog box if (job.printDialog()) { // Print the job if the user didn't cancel printing try { job.print(); } catch (Exception ex) { /* handle exception */} } }
From source file:org.fhaes.fhfilechecker.FrameViewOutput.java
public void btnPrint_actionPerformed(ActionEvent e) { // Get a PrinterJob PrinterJob job = PrinterJob.getPrinterJob(); // Ask user for page format (e.g., portrait/landscape) PageFormat pf = job.pageDialog(job.defaultPage()); // Specify the Printable is an instance of // PrintListingPainter; also provide given PageFormat job.setPrintable(new PrintListingPainter(out_file_name), pf); // Print 1 copy job.setCopies(1);/*from w w w.j a v a2 s.com*/ // Put up the dialog box if (job.printDialog()) { // Print the job if the user didn't cancel printing try { job.print(); } catch (Exception ex) { /* handle exception */} } }