Search in sources :

Example 26 with PrinterException

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

the class GraphPane method printProfile.

public void printProfile(String s) {
    annotate = s;
    PrinterJob job = PrinterJob.getPrinterJob();
    job.setPrintable(this);
    boolean ok = job.printDialog();
    if (ok) {
        try {
            job.print();
        } catch (PrinterException ex) {
            log.error("Exception whilst printing profile " + ex);
        }
    }
}
Also used : PrinterException(java.awt.print.PrinterException) PrinterJob(java.awt.print.PrinterJob)

Example 27 with PrinterException

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

the class PrintUtil method testPS.

//	dump
/*************************************************************************/
/**
	 * 	Test Print Services
	 */
private static void testPS() {
    PrintService ps = getDefaultPrintService();
    ServiceUIFactory factory = ps.getServiceUIFactory();
    System.out.println(factory);
    if (factory != null) {
        System.out.println("Factory");
        JPanel p0 = (JPanel) factory.getUI(ServiceUIFactory.ABOUT_UIROLE, ServiceUIFactory.JDIALOG_UI);
        p0.setVisible(true);
        JPanel p1 = (JPanel) factory.getUI(ServiceUIFactory.ADMIN_UIROLE, ServiceUIFactory.JDIALOG_UI);
        p1.setVisible(true);
        JPanel p2 = (JPanel) factory.getUI(ServiceUIFactory.MAIN_UIROLE, ServiceUIFactory.JDIALOG_UI);
        p2.setVisible(true);
    }
    System.out.println("1----------");
    PrinterJob pj = PrinterJob.getPrinterJob();
    PrintRequestAttributeSet pratts = getDefaultPrintRequestAttributes();
    //	Page Dialog
    PageFormat pf = pj.pageDialog(pratts);
    System.out.println("Pratts Size = " + pratts.size());
    Attribute[] atts = pratts.toArray();
    for (int i = 0; i < atts.length; i++) System.out.println(atts[i].getName() + " = " + atts[i] + " - " + atts[i].getCategory());
    System.out.println("PageFormat h=" + pf.getHeight() + ",w=" + pf.getWidth() + " - x=" + pf.getImageableX() + ",y=" + pf.getImageableY() + " - ih=" + pf.getImageableHeight() + ",iw=" + pf.getImageableWidth() + " - Orient=" + pf.getOrientation());
    ps = pj.getPrintService();
    System.out.println("PrintService = " + ps.getName());
    //	Print Dialog
    System.out.println("2----------");
    pj.printDialog(pratts);
    System.out.println("Pratts Size = " + pratts.size());
    atts = pratts.toArray();
    for (int i = 0; i < atts.length; i++) System.out.println(atts[i].getName() + " = " + atts[i] + " - " + atts[i].getCategory());
    pf = pj.defaultPage();
    System.out.println("PageFormat h=" + pf.getHeight() + ",w=" + pf.getWidth() + " - x=" + pf.getImageableX() + ",y=" + pf.getImageableY() + " - ih=" + pf.getImageableHeight() + ",iw=" + pf.getImageableWidth() + " - Orient=" + pf.getOrientation());
    ps = pj.getPrintService();
    System.out.println("PrintService= " + ps.getName());
    System.out.println("3----------");
    try {
        pj.setPrintService(ps);
    } catch (PrinterException pe) {
        System.out.println(pe);
    }
    pf = pj.validatePage(pf);
    System.out.println("PageFormat h=" + pf.getHeight() + ",w=" + pf.getWidth() + " - x=" + pf.getImageableX() + ",y=" + pf.getImageableY() + " - ih=" + pf.getImageableHeight() + ",iw=" + pf.getImageableWidth() + " - Orient=" + pf.getOrientation());
    ps = pj.getPrintService();
    System.out.println("PrintService= " + ps.getName());
    System.out.println("4----------");
    pj.printDialog();
}
Also used : JPanel(javax.swing.JPanel) PageFormat(java.awt.print.PageFormat) Attribute(javax.print.attribute.Attribute) PrinterException(java.awt.print.PrinterException) PrintService(javax.print.PrintService) ServiceUIFactory(javax.print.ServiceUIFactory) PrinterJob(java.awt.print.PrinterJob) HashPrintRequestAttributeSet(javax.print.attribute.HashPrintRequestAttributeSet) PrintRequestAttributeSet(javax.print.attribute.PrintRequestAttributeSet)

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