Search in sources :

Example 1 with ServiceUIFactory

use of javax.print.ServiceUIFactory in project adempiere by adempiere.

the class PrintUtil method dump.

//	dump
/**
	 * 	Dump Stream Print Services
	 * 	@param docFlavor flavor
	 */
public static void dump(DocFlavor docFlavor) {
    System.out.println();
    System.out.println("DocFlavor=" + docFlavor);
    PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
    PrintService[] pss = PrintServiceLookup.lookupPrintServices(docFlavor, pras);
    for (int i = 0; i < pss.length; i++) {
        PrintService ps = pss[i];
        System.out.println("- " + ps);
        System.out.println("  Factory=" + ps.getServiceUIFactory());
        ServiceUIFactory uiF = pss[i].getServiceUIFactory();
        if (uiF != null) {
            System.out.println("about");
            JDialog about = (JDialog) uiF.getUI(ServiceUIFactory.ABOUT_UIROLE, ServiceUIFactory.JDIALOG_UI);
            about.setVisible(true);
            System.out.println("admin");
            JDialog admin = (JDialog) uiF.getUI(ServiceUIFactory.ADMIN_UIROLE, ServiceUIFactory.JDIALOG_UI);
            admin.setVisible(true);
            System.out.println("main");
            JDialog main = (JDialog) uiF.getUI(ServiceUIFactory.MAIN_UIROLE, ServiceUIFactory.JDIALOG_UI);
            main.setVisible(true);
            System.out.println("reserved");
            JDialog res = (JDialog) uiF.getUI(ServiceUIFactory.RESERVED_UIROLE, ServiceUIFactory.JDIALOG_UI);
            res.setVisible(true);
        }
        //
        DocFlavor[] dfs = pss[i].getSupportedDocFlavors();
        System.out.println("  - Supported Doc Flavors");
        for (int j = 0; j < dfs.length; j++) System.out.println("    -> " + dfs[j]);
        //	Attribute
        Class[] attCat = pss[i].getSupportedAttributeCategories();
        System.out.println("  - Supported Attribute Categories");
        for (int j = 0; j < attCat.length; j++) System.out.println("    -> " + attCat[j].getName() + " = " + pss[i].getDefaultAttributeValue((Class<? extends Attribute>) attCat[j]));
    //
    }
}
Also used : Attribute(javax.print.attribute.Attribute) DocFlavor(javax.print.DocFlavor) HashPrintRequestAttributeSet(javax.print.attribute.HashPrintRequestAttributeSet) JDialog(javax.swing.JDialog) HashPrintRequestAttributeSet(javax.print.attribute.HashPrintRequestAttributeSet) PrintRequestAttributeSet(javax.print.attribute.PrintRequestAttributeSet) PrintService(javax.print.PrintService) ServiceUIFactory(javax.print.ServiceUIFactory)

Example 2 with ServiceUIFactory

use of javax.print.ServiceUIFactory 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

PrintService (javax.print.PrintService)2 ServiceUIFactory (javax.print.ServiceUIFactory)2 Attribute (javax.print.attribute.Attribute)2 HashPrintRequestAttributeSet (javax.print.attribute.HashPrintRequestAttributeSet)2 PrintRequestAttributeSet (javax.print.attribute.PrintRequestAttributeSet)2 PageFormat (java.awt.print.PageFormat)1 PrinterException (java.awt.print.PrinterException)1 PrinterJob (java.awt.print.PrinterJob)1 DocFlavor (javax.print.DocFlavor)1 JDialog (javax.swing.JDialog)1 JPanel (javax.swing.JPanel)1