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;
}
}
Aggregations