Search in sources :

Example 6 with PrintService

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.");
    }
}
Also used : PrintService(javax.print.PrintService)

Example 7 with PrintService

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]));
    //
    }
}
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 8 with PrintService

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;
}
Also used : PrinterJob(java.awt.print.PrinterJob) PrintService(javax.print.PrintService)

Example 9 with PrintService

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();
    }
}
Also used : SimpleDoc(javax.print.SimpleDoc) SimpleDoc(javax.print.SimpleDoc) Doc(javax.print.Doc) DocPrintJob(javax.print.DocPrintJob) DocFlavor(javax.print.DocFlavor) HashPrintRequestAttributeSet(javax.print.attribute.HashPrintRequestAttributeSet) IOException(java.io.IOException) PrintRequestAttributeSet(javax.print.attribute.PrintRequestAttributeSet) HashPrintRequestAttributeSet(javax.print.attribute.HashPrintRequestAttributeSet) PrintService(javax.print.PrintService)

Example 10 with PrintService

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);
}
Also used : JScrollPane(javax.swing.JScrollPane) JComboBox(javax.swing.JComboBox) JButton(javax.swing.JButton) Rectangle(java.awt.Rectangle) JLabel(javax.swing.JLabel) JTextField(javax.swing.JTextField) Font(java.awt.Font) 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