Search in sources :

Example 6 with PrintRequestAttributeSet

use of javax.print.attribute.PrintRequestAttributeSet 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 7 with PrintRequestAttributeSet

use of javax.print.attribute.PrintRequestAttributeSet in project adempiere by adempiere.

the class CPaper method getPrintRequestAttributeSet.

//	pageSetupDialog
/**
	 *  Return Print Request Attributes
	 *  @return PrintRequestAttributeSet
	 */
public PrintRequestAttributeSet getPrintRequestAttributeSet() {
    PrintRequestAttributeSet pratts = new HashPrintRequestAttributeSet();
    //	media-printable-area = (25.4,25.4)->(165.1,228.6)mm - class javax.print.attribute.standard.MediaPrintableArea
    pratts.add(getMediaPrintableArea());
    //	orientation-requested = landscape - class javax.print.attribute.standard.OrientationRequested
    if (isLandscape())
        pratts.add(OrientationRequested.LANDSCAPE);
    else
        pratts.add(OrientationRequested.PORTRAIT);
    return pratts;
}
Also used : HashPrintRequestAttributeSet(javax.print.attribute.HashPrintRequestAttributeSet) PrintRequestAttributeSet(javax.print.attribute.PrintRequestAttributeSet) HashPrintRequestAttributeSet(javax.print.attribute.HashPrintRequestAttributeSet)

Example 8 with PrintRequestAttributeSet

use of javax.print.attribute.PrintRequestAttributeSet in project adempiere by adempiere.

the class ReportEngine method print.

//	getView
/**************************************************************************
	 * 	Print Report
	 */
public void print() {
    log.info(m_info.toString());
    if (m_layout == null)
        layout();
    //	Paper Attributes: 	media-printable-area, orientation-requested, media
    PrintRequestAttributeSet prats = m_layout.getPaper().getPrintRequestAttributeSet();
    //	add:				copies, job-name, priority
    if (m_info.isDocumentCopy() || m_info.getCopies() < 1)
        prats.add(new Copies(1));
    else
        prats.add(new Copies(m_info.getCopies()));
    Locale locale = Language.getLoginLanguage().getLocale();
    prats.add(new JobName(m_printFormat.getName(), locale));
    prats.add(PrintUtil.getJobPriority(m_layout.getNumberOfPages(), m_info.getCopies(), true));
    try {
        //	PrinterJob
        PrinterJob job = getPrinterJob(m_info.getPrinterName());
        //	job.getPrintService().addPrintServiceAttributeListener(this);
        //	no copy
        job.setPageable(m_layout.getPageable(false));
        //	Dialog
        try {
            if (m_info.isWithDialog() && !job.printDialog(prats))
                return;
        } catch (Exception e) {
            log.log(Level.WARNING, "Operating System Print Issue, check & try again", e);
            return;
        }
        //	submit
        boolean printCopy = m_info.isDocumentCopy() && m_info.getCopies() > 1;
        ArchiveEngine.get().archive(m_layout, m_info);
        PrintUtil.print(job, prats, false, printCopy);
        //	Document: Print Copies
        if (printCopy) {
            log.info("Copy " + (m_info.getCopies() - 1));
            prats.add(new Copies(m_info.getCopies() - 1));
            job = getPrinterJob(m_info.getPrinterName());
            //	job.getPrintService().addPrintServiceAttributeListener(this);
            //	Copy
            job.setPageable(m_layout.getPageable(true));
            PrintUtil.print(job, prats, false, false);
        }
    } catch (Exception e) {
        log.log(Level.SEVERE, "", e);
    }
}
Also used : Locale(java.util.Locale) Copies(javax.print.attribute.standard.Copies) JobName(javax.print.attribute.standard.JobName) FileNotFoundException(java.io.FileNotFoundException) SQLException(java.sql.SQLException) IOException(java.io.IOException) HashPrintRequestAttributeSet(javax.print.attribute.HashPrintRequestAttributeSet) PrintRequestAttributeSet(javax.print.attribute.PrintRequestAttributeSet) PrinterJob(java.awt.print.PrinterJob)

Example 9 with PrintRequestAttributeSet

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

use of javax.print.attribute.PrintRequestAttributeSet in project jdk8u_jdk by JetBrains.

the class ServiceUI method printDialog.

/**
     * Presents a dialog to the user for selecting a print service (printer).
     * It is displayed at the location specified by the application and
     * is modal.
     * If the specification is invalid or would make the dialog not visible it
     * will be displayed at a location determined by the implementation.
     * The dialog blocks its calling thread and is application modal.
     * <p>
     * The dialog may include a tab panel with custom UI lazily obtained from
     * the PrintService's ServiceUIFactory when the PrintService is browsed.
     * The dialog will attempt to locate a MAIN_UIROLE first as a JComponent,
     * then as a Panel. If there is no ServiceUIFactory or no matching role
     * the custom tab will be empty or not visible.
     * <p>
     * The dialog returns the print service selected by the user if the user
     * OK's the dialog and null if the user cancels the dialog.
     * <p>
     * An application must pass in an array of print services to browse.
     * The array must be non-null and non-empty.
     * Typically an application will pass in only PrintServices capable
     * of printing a particular document flavor.
     * <p>
     * An application may pass in a PrintService to be initially displayed.
     * A non-null parameter must be included in the array of browsable
     * services.
     * If this parameter is null a service is chosen by the implementation.
     * <p>
     * An application may optionally pass in the flavor to be printed.
     * If this is non-null choices presented to the user can be better
     * validated against those supported by the services.
     * An application must pass in a PrintRequestAttributeSet for returning
     * user choices.
     * On calling the PrintRequestAttributeSet may be empty, or may contain
     * application-specified values.
     * <p>
     * These are used to set the initial settings for the initially
     * displayed print service. Values which are not supported by the print
     * service are ignored. As the user browses print services, attributes
     * and values are copied to the new display. If a user browses a
     * print service which does not support a particular attribute-value, the
     * default for that service is used as the new value to be copied.
     * <p>
     * If the user cancels the dialog, the returned attributes will not reflect
     * any changes made by the user.
     *
     * A typical basic usage of this method may be :
     * <pre>{@code
     * PrintService[] services = PrintServiceLookup.lookupPrintServices(
     *                            DocFlavor.INPUT_STREAM.JPEG, null);
     * PrintRequestAttributeSet attributes = new HashPrintRequestAttributeSet();
     * if (services.length > 0) {
     *    PrintService service =  ServiceUI.printDialog(null, 50, 50,
     *                                               services, services[0],
     *                                               null,
     *                                               attributes);
     *    if (service != null) {
     *     ... print ...
     *    }
     * }
     * }</pre>
     * <p>

     * @param gc used to select screen. null means primary or default screen.
     * @param x location of dialog including border in screen coordinates
     * @param y location of dialog including border in screen coordinates
     * @param services to be browsable, must be non-null.
     * @param defaultService - initial PrintService to display.
     * @param flavor - the flavor to be printed, or null.
     * @param attributes on input is the initial application supplied
     * preferences. This cannot be null but may be empty.
     * On output the attributes reflect changes made by the user.
     * @return print service selected by the user, or null if the user
     * cancelled the dialog.
     * @throws HeadlessException if GraphicsEnvironment.isHeadless()
     * returns true.
     * @throws IllegalArgumentException if services is null or empty,
     * or attributes is null, or the initial PrintService is not in the
     * list of browsable services.
     */
public static PrintService printDialog(GraphicsConfiguration gc, int x, int y, PrintService[] services, PrintService defaultService, DocFlavor flavor, PrintRequestAttributeSet attributes) throws HeadlessException {
    int defaultIndex = -1;
    if (GraphicsEnvironment.isHeadless()) {
        throw new HeadlessException();
    } else if ((services == null) || (services.length == 0)) {
        throw new IllegalArgumentException("services must be non-null " + "and non-empty");
    } else if (attributes == null) {
        throw new IllegalArgumentException("attributes must be non-null");
    }
    if (defaultService != null) {
        for (int i = 0; i < services.length; i++) {
            if (services[i].equals(defaultService)) {
                defaultIndex = i;
                break;
            }
        }
        if (defaultIndex < 0) {
            throw new IllegalArgumentException("services must contain " + "defaultService");
        }
    } else {
        defaultIndex = 0;
    }
    // For now we set owner to null. In the future, it may be passed
    // as an argument.
    Window owner = null;
    Rectangle gcBounds = (gc == null) ? GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration().getBounds() : gc.getBounds();
    ServiceDialog dialog;
    if (owner instanceof Frame) {
        dialog = new ServiceDialog(gc, x + gcBounds.x, y + gcBounds.y, services, defaultIndex, flavor, attributes, (Frame) owner);
    } else {
        dialog = new ServiceDialog(gc, x + gcBounds.x, y + gcBounds.y, services, defaultIndex, flavor, attributes, (Dialog) owner);
    }
    Rectangle dlgBounds = dialog.getBounds();
    // get union of all GC bounds
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice[] gs = ge.getScreenDevices();
    for (int j = 0; j < gs.length; j++) {
        gcBounds = gcBounds.union(gs[j].getDefaultConfiguration().getBounds());
    }
    // if portion of dialog is not within the gc boundary
    if (!gcBounds.contains(dlgBounds)) {
        // put in the center relative to parent frame/dialog
        dialog.setLocationRelativeTo(owner);
    }
    dialog.show();
    if (dialog.getStatus() == ServiceDialog.APPROVE) {
        PrintRequestAttributeSet newas = dialog.getAttributes();
        Class dstCategory = Destination.class;
        Class amCategory = SunAlternateMedia.class;
        Class fdCategory = Fidelity.class;
        if (attributes.containsKey(dstCategory) && !newas.containsKey(dstCategory)) {
            attributes.remove(dstCategory);
        }
        if (attributes.containsKey(amCategory) && !newas.containsKey(amCategory)) {
            attributes.remove(amCategory);
        }
        attributes.addAll(newas);
        Fidelity fd = (Fidelity) attributes.get(fdCategory);
        if (fd != null) {
            if (fd == Fidelity.FIDELITY_TRUE) {
                removeUnsupportedAttributes(dialog.getPrintService(), flavor, attributes);
            }
        }
    }
    return dialog.getPrintService();
}
Also used : Window(java.awt.Window) ServiceDialog(sun.print.ServiceDialog) Destination(javax.print.attribute.standard.Destination) Fidelity(javax.print.attribute.standard.Fidelity) Frame(java.awt.Frame) HeadlessException(java.awt.HeadlessException) Rectangle(java.awt.Rectangle) SunAlternateMedia(sun.print.SunAlternateMedia) GraphicsEnvironment(java.awt.GraphicsEnvironment) Point(java.awt.Point) PrintRequestAttributeSet(javax.print.attribute.PrintRequestAttributeSet) GraphicsDevice(java.awt.GraphicsDevice) ServiceDialog(sun.print.ServiceDialog) Dialog(java.awt.Dialog)

Aggregations

PrintRequestAttributeSet (javax.print.attribute.PrintRequestAttributeSet)26 HashPrintRequestAttributeSet (javax.print.attribute.HashPrintRequestAttributeSet)21 PrintService (javax.print.PrintService)11 PrinterException (java.awt.print.PrinterException)7 PrinterJob (java.awt.print.PrinterJob)7 Copies (javax.print.attribute.standard.Copies)7 PageFormat (java.awt.print.PageFormat)6 Attribute (javax.print.attribute.Attribute)6 IOException (java.io.IOException)5 HeadlessException (java.awt.HeadlessException)4 Printable (java.awt.print.Printable)4 File (java.io.File)4 DocFlavor (javax.print.DocFlavor)4 JobName (javax.print.attribute.standard.JobName)4 DocPrintJob (javax.print.DocPrintJob)3 PrintException (javax.print.PrintException)3 StreamPrintService (javax.print.StreamPrintService)3 Destination (javax.print.attribute.standard.Destination)3 Rectangle (java.awt.Rectangle)2 Paper (java.awt.print.Paper)2