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());
}
}
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();
}
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);
}
Aggregations