Search in sources :

Example 1 with PrinterException

use of java.awt.print.PrinterException 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 */
        }
    }
}
Also used : PageFormat(java.awt.print.PageFormat) Paper(java.awt.print.Paper) PrinterException(java.awt.print.PrinterException) PrinterJob(java.awt.print.PrinterJob)

Example 2 with PrinterException

use of java.awt.print.PrinterException in project gephi by gephi.

the class SimpleHTMLReport method printButtonActionPerformed.

// </editor-fold>//GEN-END:initComponents
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 {
        if (pjob.printDialog()) {
            pjob.print();
        }
    } catch (PrinterException e) {
        e.printStackTrace();
    }
}
Also used : PageFormat(java.awt.print.PageFormat) PrinterException(java.awt.print.PrinterException) PrinterJob(java.awt.print.PrinterJob)

Example 3 with PrinterException

use of java.awt.print.PrinterException 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);
        }
    }
}
Also used : PageFormat(java.awt.print.PageFormat) Graph2DPrinter(y.view.Graph2DPrinter) PrinterException(java.awt.print.PrinterException) OptionHandler(y.option.OptionHandler) PrinterJob(java.awt.print.PrinterJob)

Example 4 with PrinterException

use of java.awt.print.PrinterException in project jdk8u_jdk by JetBrains.

the class RadialGradientPrintingTest method createUI.

public static void createUI() {
    f = new JFrame("RadialGradient Printing Test");
    f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    final RadialGradientPrintingTest gpt = new RadialGradientPrintingTest();
    Container c = f.getContentPane();
    c.add(BorderLayout.CENTER, gpt);
    final JButton print = new JButton("Print");
    print.addActionListener(new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            PrinterJob job = PrinterJob.getPrinterJob();
            job.setPrintable(gpt);
            final boolean doPrint = job.printDialog();
            if (doPrint) {
                try {
                    job.print();
                } catch (PrinterException ex) {
                    throw new RuntimeException(ex);
                }
            }
        }
    });
    c.add(print, BorderLayout.SOUTH);
    f.pack();
    f.setVisible(true);
}
Also used : Container(java.awt.Container) JFrame(javax.swing.JFrame) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton) PrinterException(java.awt.print.PrinterException) AbstractAction(javax.swing.AbstractAction) PrinterJob(java.awt.print.PrinterJob)

Example 5 with PrinterException

use of java.awt.print.PrinterException in project jdk8u_jdk by JetBrains.

the class TexturePaintPrintingTest method printTexture.

private static void printTexture() {
    f = new JFrame("Texture Printing Test");
    f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    final TexturePaintPrintingTest gpt = new TexturePaintPrintingTest();
    Container c = f.getContentPane();
    c.add(BorderLayout.CENTER, gpt);
    final JButton print = new JButton("Print");
    print.addActionListener(new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            PrinterJob job = PrinterJob.getPrinterJob();
            job.setPrintable(gpt);
            final boolean doPrint = job.printDialog();
            if (doPrint) {
                try {
                    job.print();
                } catch (PrinterException ex) {
                    throw new RuntimeException(ex);
                }
            }
        }
    });
    c.add(print, BorderLayout.SOUTH);
    f.pack();
    f.setVisible(true);
}
Also used : Container(java.awt.Container) JFrame(javax.swing.JFrame) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton) PrinterException(java.awt.print.PrinterException) AbstractAction(javax.swing.AbstractAction) PrinterJob(java.awt.print.PrinterJob)

Aggregations

PrinterException (java.awt.print.PrinterException)27 PrinterJob (java.awt.print.PrinterJob)15 PageFormat (java.awt.print.PageFormat)11 PrintService (javax.print.PrintService)8 Printable (java.awt.print.Printable)5 StreamPrintService (javax.print.StreamPrintService)5 HashPrintRequestAttributeSet (javax.print.attribute.HashPrintRequestAttributeSet)5 HeadlessException (java.awt.HeadlessException)4 File (java.io.File)4 IOException (java.io.IOException)4 PrintRequestAttributeSet (javax.print.attribute.PrintRequestAttributeSet)4 Container (java.awt.Container)3 ActionEvent (java.awt.event.ActionEvent)3 Paper (java.awt.print.Paper)3 PrintException (javax.print.PrintException)3 AbstractAction (javax.swing.AbstractAction)3 JButton (javax.swing.JButton)3 JFrame (javax.swing.JFrame)3 Graphics2D (java.awt.Graphics2D)2 Rectangle (java.awt.Rectangle)2