sun.print.PrintServiceLookupProvider Java Examples

The following examples show how to use sun.print.PrintServiceLookupProvider. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WPrinterJob.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
public PrintService getPrintService() {
    if (myService == null) {
        String printerName = getNativePrintService();

        if (printerName != null) {
            myService = PrintServiceLookupProvider.getWin32PrintLUS().
                getPrintServiceByName(printerName);
            // no need to call setNativePrintService as this name is
            // currently set in native
            if (myService != null) {
                return myService;
            }
        }

        myService = PrintServiceLookup.lookupDefaultPrintService();
        if (myService instanceof Win32PrintService) {
            try {
                setNativePrintServiceIfNeeded(myService.getName());
            } catch (Exception e) {
                myService = null;
            }
        }

      }
      return myService;
}
 
Example #2
Source File: WPrinterJob.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public PrintService getPrintService() {
    if (myService == null) {
        String printerName = getNativePrintService();

        if (printerName != null) {
            myService = PrintServiceLookupProvider.getWin32PrintLUS().
                getPrintServiceByName(printerName);
            // no need to call setNativePrintService as this name is
            // currently set in native
            if (myService != null) {
                return myService;
            }
        }

        myService = PrintServiceLookup.lookupDefaultPrintService();
        if (myService instanceof Win32PrintService) {
            try {
                setNativePrintServiceIfNeeded(myService.getName());
            } catch (Exception e) {
                myService = null;
            }
        }

      }
      return myService;
}
 
Example #3
Source File: WPrinterJob.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@Override
public PrintService getPrintService() {
    if (myService == null) {
        String printerName = getNativePrintService();

        if (printerName != null) {
            myService = PrintServiceLookupProvider.getWin32PrintLUS().
                getPrintServiceByName(printerName);
            // no need to call setNativePrintService as this name is
            // currently set in native
            if (myService != null) {
                return myService;
            }
        }

        myService = PrintServiceLookup.lookupDefaultPrintService();
        if (myService instanceof Win32PrintService) {
            try {
                setNativePrintServiceIfNeeded(myService.getName());
            } catch (Exception e) {
                myService = null;
            }
        }

      }
      return myService;
}
 
Example #4
Source File: WPrinterJob.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public PrintService getPrintService() {
    if (myService == null) {
        String printerName = getNativePrintService();

        if (printerName != null) {
            myService = PrintServiceLookupProvider.getWin32PrintLUS().
                getPrintServiceByName(printerName);
            // no need to call setNativePrintService as this name is
            // currently set in native
            if (myService != null) {
                return myService;
            }
        }

        myService = PrintServiceLookup.lookupDefaultPrintService();
        if (myService instanceof Win32PrintService) {
            try {
                setNativePrintServiceIfNeeded(myService.getName());
            } catch (Exception e) {
                myService = null;
            }
        }

      }
      return myService;
}
 
Example #5
Source File: WPrinterJob.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
public PrintService getPrintService() {
    if (myService == null) {
        String printerName = getNativePrintService();

        if (printerName != null) {
            myService = PrintServiceLookupProvider.getWin32PrintLUS().
                getPrintServiceByName(printerName);
            // no need to call setNativePrintService as this name is
            // currently set in native
            if (myService != null) {
                return myService;
            }
        }

        myService = PrintServiceLookup.lookupDefaultPrintService();
        if (myService instanceof Win32PrintService) {
            try {
                setNativePrintServiceIfNeeded(myService.getName());
            } catch (Exception e) {
                myService = null;
            }
        }

      }
      return myService;
}
 
Example #6
Source File: WPrinterJob.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Display a dialog to the user allowing the modification of a
 * PageFormat instance.
 * The <code>page</code> argument is used to initialize controls
 * in the page setup dialog.
 * If the user cancels the dialog, then the method returns the
 * original <code>page</code> object unmodified.
 * If the user okays the dialog then the method returns a new
 * PageFormat object with the indicated changes.
 * In either case the original <code>page</code> object will
 * not be modified.
 * @param     page    the default PageFormat presented to the user
 *                    for modification
 * @return    the original <code>page</code> object if the dialog
 *            is cancelled, or a new PageFormat object containing
 *            the format indicated by the user if the dialog is
 *            acknowledged
 * @exception HeadlessException if GraphicsEnvironment.isHeadless()
 * returns true.
 * @see java.awt.GraphicsEnvironment#isHeadless
 * @since     JDK1.2
 */
@Override
public PageFormat pageDialog(PageFormat page) throws HeadlessException {
    if (GraphicsEnvironment.isHeadless()) {
        throw new HeadlessException();
    }

    if (!(getPrintService() instanceof Win32PrintService)) {
        return super.pageDialog(page);
    }

    PageFormat pageClone = (PageFormat) page.clone();
    boolean result = false;

    /*
     * Fix for 4507585: show the native modal dialog the same way printDialog() does so
     * that it won't block event dispatching when called on EventDispatchThread.
     */
    WPageDialog dialog = new WPageDialog((Frame)null, this,
                                 pageClone, null);
    dialog.setRetVal(false);
    dialog.setVisible(true);
    result = dialog.getRetVal();
    dialog.dispose();

    // myService => current PrintService
    if (result && (myService != null)) {
        // It's possible that current printer is changed through
        // the "Printer..." button so we query again from native.
        String printerName = getNativePrintService();
        if (!myService.getName().equals(printerName)) {
            // native printer is different !
            // we update the current PrintService
            try {
                setPrintService(PrintServiceLookupProvider.
                                getWin32PrintLUS().
                                getPrintServiceByName(printerName));
            } catch (PrinterException e) {
            }
        }
        // Update attributes, this will preserve the page settings.
        //  - same code as in RasterPrinterJob.java
        updatePageAttributes(myService, pageClone);

        return pageClone;
    } else {
        return page;
    }
}
 
Example #7
Source File: WPrinterJob.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Display a dialog to the user allowing the modification of a
 * PageFormat instance.
 * The <code>page</code> argument is used to initialize controls
 * in the page setup dialog.
 * If the user cancels the dialog, then the method returns the
 * original <code>page</code> object unmodified.
 * If the user okays the dialog then the method returns a new
 * PageFormat object with the indicated changes.
 * In either case the original <code>page</code> object will
 * not be modified.
 * @param     page    the default PageFormat presented to the user
 *                    for modification
 * @return    the original <code>page</code> object if the dialog
 *            is cancelled, or a new PageFormat object containing
 *            the format indicated by the user if the dialog is
 *            acknowledged
 * @exception HeadlessException if GraphicsEnvironment.isHeadless()
 * returns true.
 * @see java.awt.GraphicsEnvironment#isHeadless
 * @since     JDK1.2
 */
@Override
public PageFormat pageDialog(PageFormat page) throws HeadlessException {
    if (GraphicsEnvironment.isHeadless()) {
        throw new HeadlessException();
    }

    if (!(getPrintService() instanceof Win32PrintService)) {
        return super.pageDialog(page);
    }

    PageFormat pageClone = (PageFormat) page.clone();
    boolean result = false;

    /*
     * Fix for 4507585: show the native modal dialog the same way printDialog() does so
     * that it won't block event dispatching when called on EventDispatchThread.
     */
    WPageDialog dialog = new WPageDialog((Frame)null, this,
                                 pageClone, null);
    dialog.setRetVal(false);
    dialog.setVisible(true);
    result = dialog.getRetVal();
    dialog.dispose();

    // myService => current PrintService
    if (result && (myService != null)) {
        // It's possible that current printer is changed through
        // the "Printer..." button so we query again from native.
        String printerName = getNativePrintService();
        if (!myService.getName().equals(printerName)) {
            // native printer is different !
            // we update the current PrintService
            try {
                setPrintService(PrintServiceLookupProvider.
                                getWin32PrintLUS().
                                getPrintServiceByName(printerName));
            } catch (PrinterException e) {
            }
        }
        // Update attributes, this will preserve the page settings.
        //  - same code as in RasterPrinterJob.java
        updatePageAttributes(myService, pageClone);

        return pageClone;
    } else {
        return page;
    }
}
 
Example #8
Source File: WPrinterJob.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Display a dialog to the user allowing the modification of a
 * PageFormat instance.
 * The <code>page</code> argument is used to initialize controls
 * in the page setup dialog.
 * If the user cancels the dialog, then the method returns the
 * original <code>page</code> object unmodified.
 * If the user okays the dialog then the method returns a new
 * PageFormat object with the indicated changes.
 * In either case the original <code>page</code> object will
 * not be modified.
 * @param     page    the default PageFormat presented to the user
 *                    for modification
 * @return    the original <code>page</code> object if the dialog
 *            is cancelled, or a new PageFormat object containing
 *            the format indicated by the user if the dialog is
 *            acknowledged
 * @exception HeadlessException if GraphicsEnvironment.isHeadless()
 * returns true.
 * @see java.awt.GraphicsEnvironment#isHeadless
 * @since     JDK1.2
 */
@Override
public PageFormat pageDialog(PageFormat page) throws HeadlessException {
    if (GraphicsEnvironment.isHeadless()) {
        throw new HeadlessException();
    }

    if (!(getPrintService() instanceof Win32PrintService)) {
        return super.pageDialog(page);
    }

    PageFormat pageClone = (PageFormat) page.clone();
    boolean result = false;

    /*
     * Fix for 4507585: show the native modal dialog the same way printDialog() does so
     * that it won't block event dispatching when called on EventDispatchThread.
     */
    WPageDialog dialog = new WPageDialog((Frame)null, this,
                                 pageClone, null);
    dialog.setRetVal(false);
    dialog.setVisible(true);
    result = dialog.getRetVal();
    dialog.dispose();

    // myService => current PrintService
    if (result && (myService != null)) {
        // It's possible that current printer is changed through
        // the "Printer..." button so we query again from native.
        String printerName = getNativePrintService();
        if (!myService.getName().equals(printerName)) {
            // native printer is different !
            // we update the current PrintService
            try {
                setPrintService(PrintServiceLookupProvider.
                                getWin32PrintLUS().
                                getPrintServiceByName(printerName));
            } catch (PrinterException e) {
            }
        }
        // Update attributes, this will preserve the page settings.
        //  - same code as in RasterPrinterJob.java
        updatePageAttributes(myService, pageClone);

        return pageClone;
    } else {
        return page;
    }
}
 
Example #9
Source File: WPrinterJob.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Display a dialog to the user allowing the modification of a
 * PageFormat instance.
 * The {@code page} argument is used to initialize controls
 * in the page setup dialog.
 * If the user cancels the dialog, then the method returns the
 * original {@code page} object unmodified.
 * If the user okays the dialog then the method returns a new
 * PageFormat object with the indicated changes.
 * In either case the original {@code page} object will
 * not be modified.
 * @param     page    the default PageFormat presented to the user
 *                    for modification
 * @return    the original {@code page} object if the dialog
 *            is cancelled, or a new PageFormat object containing
 *            the format indicated by the user if the dialog is
 *            acknowledged
 * @exception HeadlessException if GraphicsEnvironment.isHeadless()
 * returns true.
 * @see java.awt.GraphicsEnvironment#isHeadless
 * @since     1.2
 */
@Override
public PageFormat pageDialog(PageFormat page) throws HeadlessException {
    if (GraphicsEnvironment.isHeadless()) {
        throw new HeadlessException();
    }

    if (!(getPrintService() instanceof Win32PrintService)) {
        return super.pageDialog(page);
    }

    PageFormat pageClone = (PageFormat) page.clone();
    boolean result = false;

    /*
     * Fix for 4507585: show the native modal dialog the same way printDialog() does so
     * that it won't block event dispatching when called on EventDispatchThread.
     */
    WPageDialog dialog = new WPageDialog((Frame)null, this,
                                 pageClone, null);
    dialog.setRetVal(false);
    dialog.setVisible(true);
    result = dialog.getRetVal();
    dialog.dispose();

    // myService => current PrintService
    if (result && (myService != null)) {
        // It's possible that current printer is changed through
        // the "Printer..." button so we query again from native.
        String printerName = getNativePrintService();
        if (!myService.getName().equals(printerName)) {
            // native printer is different !
            // we update the current PrintService
            try {
                setPrintService(PrintServiceLookupProvider.
                                getWin32PrintLUS().
                                getPrintServiceByName(printerName));
            } catch (PrinterException e) {
            }
        }
        // Update attributes, this will preserve the page settings.
        //  - same code as in RasterPrinterJob.java
        updatePageAttributes(myService, pageClone);

        return pageClone;
    } else {
        return page;
    }
}
 
Example #10
Source File: WPrinterJob.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Display a dialog to the user allowing the modification of a
 * PageFormat instance.
 * The <code>page</code> argument is used to initialize controls
 * in the page setup dialog.
 * If the user cancels the dialog, then the method returns the
 * original <code>page</code> object unmodified.
 * If the user okays the dialog then the method returns a new
 * PageFormat object with the indicated changes.
 * In either case the original <code>page</code> object will
 * not be modified.
 * @param     page    the default PageFormat presented to the user
 *                    for modification
 * @return    the original <code>page</code> object if the dialog
 *            is cancelled, or a new PageFormat object containing
 *            the format indicated by the user if the dialog is
 *            acknowledged
 * @exception HeadlessException if GraphicsEnvironment.isHeadless()
 * returns true.
 * @see java.awt.GraphicsEnvironment#isHeadless
 * @since     JDK1.2
 */
@Override
public PageFormat pageDialog(PageFormat page) throws HeadlessException {
    if (GraphicsEnvironment.isHeadless()) {
        throw new HeadlessException();
    }

    if (!(getPrintService() instanceof Win32PrintService)) {
        return super.pageDialog(page);
    }

    PageFormat pageClone = (PageFormat) page.clone();
    boolean result = false;

    /*
     * Fix for 4507585: show the native modal dialog the same way printDialog() does so
     * that it won't block event dispatching when called on EventDispatchThread.
     */
    WPageDialog dialog = new WPageDialog((Frame)null, this,
                                 pageClone, null);
    dialog.setRetVal(false);
    dialog.setVisible(true);
    result = dialog.getRetVal();
    dialog.dispose();

    // myService => current PrintService
    if (result && (myService != null)) {
        // It's possible that current printer is changed through
        // the "Printer..." button so we query again from native.
        String printerName = getNativePrintService();
        if (!myService.getName().equals(printerName)) {
            // native printer is different !
            // we update the current PrintService
            try {
                setPrintService(PrintServiceLookupProvider.
                                getWin32PrintLUS().
                                getPrintServiceByName(printerName));
            } catch (PrinterException e) {
            }
        }
        // Update attributes, this will preserve the page settings.
        //  - same code as in RasterPrinterJob.java
        updatePageAttributes(myService, pageClone);

        return pageClone;
    } else {
        return page;
    }
}