use of javax.print.PrintService in project jdk8u_jdk by JetBrains.
the class PrintToDir method doPrinterJob.
public static void doPrinterJob(String fileStr, OrientationRequested o) {
PrinterJob pj = PrinterJob.getPrinterJob();
PrintService ps = pj.getPrintService();
if (ps == null) {
System.out.println("No print service found.");
return;
}
pj.setPrintable(new PrintToDir());
PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
aset.add(o);
File f = new File(fileStr);
// f.deleteOnExit();
URI dest = f.toURI();
Destination d = new Destination(dest);
if (ps.isAttributeValueSupported(d, null, null)) {
aset.add(d);
try {
pj.print(aset);
} catch (PrinterException e) {
System.out.println("PrinterJob passed.");
return;
}
throw new RuntimeException("PrinterJob:PrinterException expected but not thrown. \nTEST FAILED");
} else {
System.out.println("Destination attribute is not a supported value. PrinterJob passed.");
}
}
use of javax.print.PrintService 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]));
//
}
}
use of javax.print.PrintService in project adempiere by adempiere.
the class CPrinter method getPrinterJob.
// getPrinterJob
/**
* Return PrinterJob with selected printer name.
* @param printerName if null, get default printer (Ini)
* @return PrinterJob
*/
public static PrinterJob getPrinterJob(String printerName) {
PrinterJob pj = null;
PrintService ps = null;
try {
pj = PrinterJob.getPrinterJob();
// find printer service
if (printerName == null || printerName.length() == 0)
printerName = Ini.getProperty(Ini.P_PRINTER);
if (printerName != null && printerName.length() != 0) {
// System.out.println("CPrinter.getPrinterJob - searching " + printerName);
for (int i = 0; i < s_services.length; i++) {
String serviceName = s_services[i].getName();
if (printerName.equals(serviceName)) {
ps = s_services[i];
// System.out.println("CPrinter.getPrinterJob - found " + printerName);
break;
}
// System.out.println("CPrinter.getPrinterJob - not: " + serviceName);
}
}
try {
if (ps != null)
pj.setPrintService(ps);
} catch (Exception e) {
log.warning("Could not set Print Service: " + e.toString());
}
//
PrintService psUsed = pj.getPrintService();
if (psUsed == null)
log.warning("Print Service not Found");
else {
String serviceName = psUsed.getName();
if (printerName != null && !printerName.equals(serviceName))
log.warning("Not found: " + printerName + " - Used: " + serviceName);
}
} catch (Exception e) {
log.warning("Could not create for " + printerName + ": " + e.toString());
}
return pj;
}
use of javax.print.PrintService in project adempiere by adempiere.
the class POSClientSide method printOtherOS.
/**
* Print Other S.O
* @param fis
* @return void
*/
private void printOtherOS(FileInputStream fis) {
DocFlavor docFormat = DocFlavor.INPUT_STREAM.AUTOSENSE;
Doc document = new SimpleDoc(fis, docFormat, null);
PrintRequestAttributeSet attributeSet = new HashPrintRequestAttributeSet();
PrintService[] listsPrintService = PrintServiceLookup.lookupPrintServices(docFormat, attributeSet);
try {
DocPrintJob printJob = null;
for (int x = 0; x < listsPrintService.length; x++) {
if (listsPrintService[x].getName().equals(m_Print)) {
printJob = listsPrintService[x].createPrintJob();
}
}
printJob.print(document, attributeSet);
} catch (Exception e) {
e.printStackTrace();
}
}
use of javax.print.PrintService in project adempiere by adempiere.
the class POSClientWindow method init.
private void init() {
container = getContentPane();
container.setLayout(null);
btnConnect = new JButton();
btnConnect.setText("Connect");
btnConnect.setBounds(70, 123, 100, 23);
btnConnect.addActionListener(this);
btnDisconnect = new JButton();
btnDisconnect.setText("Disconnect");
btnDisconnect.setBounds(170, 123, 120, 23);
btnDisconnect.addActionListener(this);
btnDisconnect.setEnabled(false);
lblTitle = new JLabel();
lblTitle.setText("Print POS");
lblTitle.setBounds(120, 13, 180, 23);
lblHost = new JLabel();
lblHost.setText("Host Server");
lblHost.setBounds(55, 40, 190, 23);
fHost = new JTextField();
fHost.setText("localhost");
fHost.setBounds(140, 40, 180, 23);
lblPrint = new JLabel();
lblPrint.setText("Printer");
lblPrint.setBounds(85, 67, 190, 23);
PrintService[] services = PrintServiceLookup.lookupPrintServices(null, null);
cPrint = new JComboBox();
for (PrintService s : services) {
cPrint.addItem(s.getName());
}
cPrint.setBounds(140, 67, 180, 23);
fTerminal.setBounds(0, 190, 300, 300);
fTerminal.setBackground(Color.black);
fTerminal.setForeground(Color.green);
fTerminal.setSelectionColor(Color.red);
fTerminal.setFont(new Font("consolas", 1, 10));
fTerminal.setEnabled(false);
fTerminal.setWrapStyleWord(true);
fTerminal.setLineWrap(true);
container.add(lblTitle);
container.add(lblHost);
container.add(fHost);
container.add(lblPrint);
container.add(cPrint);
container.add(btnConnect);
container.add(btnDisconnect);
JScrollPane scroll = new JScrollPane(fTerminal);
scroll.setBounds(new Rectangle(25, 150, 300, 120));
getContentPane().add(scroll);
}
Aggregations