Search in sources :

Example 46 with PrintService

use of javax.print.PrintService in project jdk8u_jdk by JetBrains.

the class TestRaceCond method trial.

static void trial() {
    PrintService pserv1 = PrintServiceLookup.lookupDefaultPrintService();
    PrintService[] pservs = PrintServiceLookup.lookupPrintServices(null, null);
    PrintService pserv2 = PrintServiceLookup.lookupDefaultPrintService();
    if ((pserv1 == null) || (pserv2 == null)) {
        return;
    }
    if (pserv1.hashCode() != pserv2.hashCode()) {
        throw new RuntimeException("Different hashCodes for equal print " + "services: " + pserv1.hashCode() + " " + pserv2.hashCode());
    }
}
Also used : PrintService(javax.print.PrintService)

Example 47 with PrintService

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

Example 48 with PrintService

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

the class PrintUtil method testSPS.

//	testPS
/**
	 * 	Test Stream Print Services
	 */
private static void testSPS() {
    //	dump (DocFlavor.INPUT_STREAM.GIF, DocFlavor.BYTE_ARRAY.POSTSCRIPT.getMimeType());
    //	dump (DocFlavor.SERVICE_FORMATTED.PAGEABLE, DocFlavor.BYTE_ARRAY.POSTSCRIPT.getMimeType());
    //	dump (DocFlavor.INPUT_STREAM.GIF, DocFlavor.BYTE_ARRAY.PDF.getMimeType());
    //	dump (DocFlavor.SERVICE_FORMATTED.PAGEABLE, DocFlavor.BYTE_ARRAY.GIF.getMediaSubtype());
    //	dump (DocFlavor.SERVICE_FORMATTED.PAGEABLE, DocFlavor.BYTE_ARRAY.JPEG.getMediaSubtype());
    //	dump (DocFlavor.SERVICE_FORMATTED.PAGEABLE);					//	lists devices able to output pageable
    //	dump (DocFlavor.SERVICE_FORMATTED.PRINTABLE);
    //	dump (DocFlavor.INPUT_STREAM.TEXT_PLAIN_HOST);
    //	dump (DocFlavor.INPUT_STREAM.POSTSCRIPT);
    PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
    PrintService[] pss = PrintServiceLookup.lookupPrintServices(DocFlavor.SERVICE_FORMATTED.PAGEABLE, pras);
    for (int i = 0; i < pss.length; i++) {
        PrintService ps = pss[i];
        String name = ps.getName();
        if (name.indexOf("PDF") != -1 || name.indexOf("Acrobat") != -1) {
            System.out.println("----");
            System.out.println(ps);
            Class[] cat = ps.getSupportedAttributeCategories();
            for (int j = 0; j < cat.length; j++) {
                System.out.println("- " + cat[j]);
            }
        }
    }
//	dump (null, DocFlavor.BYTE_ARRAY.PDF.getMimeType());			//	lists PDF output
//	dump (null, DocFlavor.BYTE_ARRAY.POSTSCRIPT.getMediaType());	//	lists PS output
//	dump(null, null);
}
Also used : HashPrintRequestAttributeSet(javax.print.attribute.HashPrintRequestAttributeSet) HashPrintRequestAttributeSet(javax.print.attribute.HashPrintRequestAttributeSet) PrintRequestAttributeSet(javax.print.attribute.PrintRequestAttributeSet) PrintService(javax.print.PrintService)

Aggregations

PrintService (javax.print.PrintService)48 StreamPrintService (javax.print.StreamPrintService)13 HashPrintRequestAttributeSet (javax.print.attribute.HashPrintRequestAttributeSet)13 PrintRequestAttributeSet (javax.print.attribute.PrintRequestAttributeSet)13 PrinterException (java.awt.print.PrinterException)10 PageFormat (java.awt.print.PageFormat)9 IOException (java.io.IOException)8 MultiDocPrintService (javax.print.MultiDocPrintService)8 DocFlavor (javax.print.DocFlavor)7 Copies (javax.print.attribute.standard.Copies)7 MediaSizeName (javax.print.attribute.standard.MediaSizeName)7 HeadlessException (java.awt.HeadlessException)6 File (java.io.File)6 DocPrintJob (javax.print.DocPrintJob)5 PrintException (javax.print.PrintException)5 Destination (javax.print.attribute.standard.Destination)5 Media (javax.print.attribute.standard.Media)5 MediaSize (javax.print.attribute.standard.MediaSize)5 Paper (java.awt.print.Paper)4 ArrayList (java.util.ArrayList)4