8011069: Printing: NullPointerException since jdk8 b82 showing native Page Setup Dialog

Reviewed-by: bae, prr
This commit is contained in:
Jennifer Godinez 2013-05-07 09:32:37 -07:00
parent dbb7fe4b2a
commit 6bae4c82a9
2 changed files with 22 additions and 8 deletions

View File

@ -35,6 +35,7 @@ import java.security.PrivilegedAction;
import javax.print.*; import javax.print.*;
import javax.print.attribute.PrintRequestAttributeSet; import javax.print.attribute.PrintRequestAttributeSet;
import javax.print.attribute.HashPrintRequestAttributeSet;
import sun.java2d.*; import sun.java2d.*;
import sun.print.*; import sun.print.*;
@ -96,6 +97,14 @@ public class CPrinterJob extends RasterPrinterJob {
return false; return false;
} }
if (attributes == null) {
attributes = new HashPrintRequestAttributeSet();
}
if (getPrintService() instanceof StreamPrintService) {
return super.printDialog(attributes);
}
return jobSetup(getPageable(), checkAllowedToPrintToFile()); return jobSetup(getPageable(), checkAllowedToPrintToFile());
} }
@ -130,6 +139,10 @@ public class CPrinterJob extends RasterPrinterJob {
return page; return page;
} }
if (getPrintService() instanceof StreamPrintService) {
return super.pageDialog(page);
}
PageFormat pageClone = (PageFormat) page.clone(); PageFormat pageClone = (PageFormat) page.clone();
boolean doIt = pageSetup(pageClone, null); boolean doIt = pageSetup(pageClone, null);
return doIt ? pageClone : page; return doIt ? pageClone : page;

View File

@ -607,13 +607,17 @@ public abstract class RasterPrinterJob extends PrinterJob {
protected void updatePageAttributes(PrintService service, protected void updatePageAttributes(PrintService service,
PageFormat page) { PageFormat page) {
if (this.attributes == null) {
this.attributes = new HashPrintRequestAttributeSet();
}
updateAttributesWithPageFormat(service, page, this.attributes); updateAttributesWithPageFormat(service, page, this.attributes);
} }
protected void updateAttributesWithPageFormat(PrintService service, protected void updateAttributesWithPageFormat(PrintService service,
PageFormat page, PageFormat page,
PrintRequestAttributeSet attributes) { PrintRequestAttributeSet pageAttributes) {
if (service == null || page == null) { if (service == null || page == null || pageAttributes == null) {
return; return;
} }
@ -653,13 +657,10 @@ public abstract class RasterPrinterJob extends PrinterJob {
orient = OrientationRequested.PORTRAIT; orient = OrientationRequested.PORTRAIT;
} }
if (attributes == null) {
attributes = new HashPrintRequestAttributeSet();
}
if (media != null) { if (media != null) {
attributes.add(media); pageAttributes.add(media);
} }
attributes.add(orient); pageAttributes.add(orient);
float ix = (float)(page.getPaper().getImageableX()/DPI); float ix = (float)(page.getPaper().getImageableX()/DPI);
float iw = (float)(page.getPaper().getImageableWidth()/DPI); float iw = (float)(page.getPaper().getImageableWidth()/DPI);
@ -667,7 +668,7 @@ public abstract class RasterPrinterJob extends PrinterJob {
float ih = (float)(page.getPaper().getImageableHeight()/DPI); float ih = (float)(page.getPaper().getImageableHeight()/DPI);
if (ix < 0) ix = 0f; if (iy < 0) iy = 0f; if (ix < 0) ix = 0f; if (iy < 0) iy = 0f;
try { try {
attributes.add(new MediaPrintableArea(ix, iy, iw, ih, pageAttributes.add(new MediaPrintableArea(ix, iy, iw, ih,
MediaPrintableArea.INCH)); MediaPrintableArea.INCH));
} catch (IllegalArgumentException iae) { } catch (IllegalArgumentException iae) {
} }