Search in sources :

Example 1 with DialogOwner

use of sun.print.DialogOwner in project jdk8u_jdk by JetBrains.

the class WPrinterJob method displayNativeDialog.

private boolean displayNativeDialog() {
    // "attributes" is required for getting the updated attributes
    if (attributes == null) {
        return false;
    }
    DialogOwner dlgOwner = (DialogOwner) attributes.get(DialogOwner.class);
    Frame ownerFrame = (dlgOwner != null) ? dlgOwner.getOwner() : null;
    WPrintDialog dialog = new WPrintDialog(ownerFrame, this);
    dialog.setRetVal(false);
    dialog.setVisible(true);
    boolean prv = dialog.getRetVal();
    dialog.dispose();
    Destination dest = (Destination) attributes.get(Destination.class);
    if ((dest == null) || !prv) {
        return prv;
    } else {
        String title = null;
        String strBundle = "sun.print.resources.serviceui";
        ResourceBundle rb = ResourceBundle.getBundle(strBundle);
        try {
            title = rb.getString("dialog.printtofile");
        } catch (MissingResourceException e) {
        }
        FileDialog fileDialog = new FileDialog(ownerFrame, title, FileDialog.SAVE);
        URI destURI = dest.getURI();
        // Old code destURI.getPath() would return null for "file:out.prn"
        // so we use getSchemeSpecificPart instead.
        String pathName = (destURI != null) ? destURI.getSchemeSpecificPart() : null;
        if (pathName != null) {
            File file = new File(pathName);
            fileDialog.setFile(file.getName());
            File parent = file.getParentFile();
            if (parent != null) {
                fileDialog.setDirectory(parent.getPath());
            }
        } else {
            fileDialog.setFile("out.prn");
        }
        fileDialog.setVisible(true);
        String fileName = fileDialog.getFile();
        if (fileName == null) {
            fileDialog.dispose();
            return false;
        }
        String fullName = fileDialog.getDirectory() + fileName;
        File f = new File(fullName);
        File pFile = f.getParentFile();
        while ((f.exists() && (!f.isFile() || !f.canWrite())) || ((pFile != null) && (!pFile.exists() || (pFile.exists() && !pFile.canWrite())))) {
            (new PrintToFileErrorDialog(ownerFrame, ServiceDialog.getMsg("dialog.owtitle"), ServiceDialog.getMsg("dialog.writeerror") + " " + fullName, ServiceDialog.getMsg("button.ok"))).setVisible(true);
            fileDialog.setVisible(true);
            fileName = fileDialog.getFile();
            if (fileName == null) {
                fileDialog.dispose();
                return false;
            }
            fullName = fileDialog.getDirectory() + fileName;
            f = new File(fullName);
            pFile = f.getParentFile();
        }
        fileDialog.dispose();
        attributes.add(new Destination(f.toURI()));
        return true;
    }
}
Also used : Destination(javax.print.attribute.standard.Destination) Frame(java.awt.Frame) MissingResourceException(java.util.MissingResourceException) DialogOwner(sun.print.DialogOwner) ResourceBundle(java.util.ResourceBundle) FileDialog(java.awt.FileDialog) URI(java.net.URI) File(java.io.File)

Aggregations

FileDialog (java.awt.FileDialog)1 Frame (java.awt.Frame)1 File (java.io.File)1 URI (java.net.URI)1 MissingResourceException (java.util.MissingResourceException)1 ResourceBundle (java.util.ResourceBundle)1 Destination (javax.print.attribute.standard.Destination)1 DialogOwner (sun.print.DialogOwner)1