changeset 7855:d2d7da120c37

8006110: pageDialog is showing the swing dialog with DialogTypeSelection.NATIVE Reviewed-by: bae, prr
author jgodinez
date Fri, 22 Feb 2013 11:01:23 -0800
parents 41008f5cef1a
children 99c1f910abcc 934f5f10107d
files src/share/classes/sun/print/RasterPrinterJob.java
diffstat 1 files changed, 96 insertions(+), 73 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/sun/print/RasterPrinterJob.java	Tue Feb 19 22:10:42 2013 -0800
+++ b/src/share/classes/sun/print/RasterPrinterJob.java	Fri Feb 22 11:01:23 2013 -0800
@@ -527,9 +527,92 @@
         }
     }
 
+    private PageFormat attributeToPageFormat(PrintService service,
+                                               PrintRequestAttributeSet attSet) {
+        PageFormat page = defaultPage();
+
+        if (service == null) {
+            return page;
+        }
+
+        OrientationRequested orient = (OrientationRequested)
+                                      attSet.get(OrientationRequested.class);
+        if (orient == null) {
+            orient = (OrientationRequested)
+                    service.getDefaultAttributeValue(OrientationRequested.class);
+        }
+        if (orient == OrientationRequested.REVERSE_LANDSCAPE) {
+            page.setOrientation(PageFormat.REVERSE_LANDSCAPE);
+        } else if (orient == OrientationRequested.LANDSCAPE) {
+            page.setOrientation(PageFormat.LANDSCAPE);
+        } else {
+            page.setOrientation(PageFormat.PORTRAIT);
+        }
+
+        Media media = (Media)attSet.get(Media.class);
+        if (media == null) {
+            media =
+                (Media)service.getDefaultAttributeValue(Media.class);
+        }
+        if (!(media instanceof MediaSizeName)) {
+            media = MediaSizeName.NA_LETTER;
+        }
+        MediaSize size =
+            MediaSize.getMediaSizeForName((MediaSizeName)media);
+        if (size == null) {
+            size = MediaSize.NA.LETTER;
+        }
+        Paper paper = new Paper();
+        float dim[] = size.getSize(1); //units == 1 to avoid FP error
+        double w = Math.rint((dim[0]*72.0)/Size2DSyntax.INCH);
+        double h = Math.rint((dim[1]*72.0)/Size2DSyntax.INCH);
+        paper.setSize(w, h);
+        MediaPrintableArea area =
+             (MediaPrintableArea)
+             attSet.get(MediaPrintableArea.class);
+        double ix, iw, iy, ih;
+
+        if (area != null) {
+            // Should pass in same unit as updatePageAttributes
+            // to avoid rounding off errors.
+            ix = Math.rint(
+                           area.getX(MediaPrintableArea.INCH) * DPI);
+            iy = Math.rint(
+                           area.getY(MediaPrintableArea.INCH) * DPI);
+            iw = Math.rint(
+                           area.getWidth(MediaPrintableArea.INCH) * DPI);
+            ih = Math.rint(
+                           area.getHeight(MediaPrintableArea.INCH) * DPI);
+        }
+        else {
+            if (w >= 72.0 * 6.0) {
+                ix = 72.0;
+                iw = w - 2 * 72.0;
+            } else {
+                ix = w / 6.0;
+                iw = w * 0.75;
+            }
+            if (h >= 72.0 * 6.0) {
+                iy = 72.0;
+                ih = h - 2 * 72.0;
+            } else {
+                iy = h / 6.0;
+                ih = h * 0.75;
+            }
+        }
+        paper.setImageableArea(ix, iy, iw, ih);
+        page.setPaper(paper);
+        return page;
+    }
 
     protected void updatePageAttributes(PrintService service,
                                         PageFormat page) {
+        updateAttributesWithPageFormat(service, page, this.attributes);
+    }
+
+    protected void updateAttributesWithPageFormat(PrintService service,
+                                        PageFormat page,
+                                        PrintRequestAttributeSet attributes) {
         if (service == null || page == null) {
             return;
         }
@@ -659,6 +742,18 @@
             throw new HeadlessException();
         }
 
+        DialogTypeSelection dlg =
+            (DialogTypeSelection)attributes.get(DialogTypeSelection.class);
+
+        // Check for native, note that default dialog is COMMON.
+        if (dlg == DialogTypeSelection.NATIVE) {
+            PrintService pservice = getPrintService();
+            PageFormat page = pageDialog(attributeToPageFormat(pservice,
+                                                               attributes));
+            updateAttributesWithPageFormat(pservice, page, attributes);
+            return page;
+        }
+
         final GraphicsConfiguration gc =
             GraphicsEnvironment.getLocalGraphicsEnvironment().
             getDefaultScreenDevice().getDefaultConfiguration();
@@ -698,77 +793,7 @@
                 attributes.remove(amCategory);
             }
             attributes.addAll(newas);
-
-            PageFormat page = defaultPage();
-
-            OrientationRequested orient =
-                (OrientationRequested)
-                attributes.get(OrientationRequested.class);
-            int pfOrient =  PageFormat.PORTRAIT;
-            if (orient != null) {
-                if (orient == OrientationRequested.REVERSE_LANDSCAPE) {
-                    pfOrient = PageFormat.REVERSE_LANDSCAPE;
-                } else if (orient == OrientationRequested.LANDSCAPE) {
-                    pfOrient = PageFormat.LANDSCAPE;
-                }
-            }
-            page.setOrientation(pfOrient);
-
-            Media media = (Media)attributes.get(Media.class);
-            if (media == null) {
-                media =
-                    (Media)service.getDefaultAttributeValue(Media.class);
-            }
-            if (!(media instanceof MediaSizeName)) {
-                media = MediaSizeName.NA_LETTER;
-            }
-            MediaSize size =
-                MediaSize.getMediaSizeForName((MediaSizeName)media);
-            if (size == null) {
-                size = MediaSize.NA.LETTER;
-            }
-            Paper paper = new Paper();
-            float dim[] = size.getSize(1); //units == 1 to avoid FP error
-            double w = Math.rint((dim[0]*72.0)/Size2DSyntax.INCH);
-            double h = Math.rint((dim[1]*72.0)/Size2DSyntax.INCH);
-            paper.setSize(w, h);
-            MediaPrintableArea area =
-                (MediaPrintableArea)
-                attributes.get(MediaPrintableArea.class);
-            double ix, iw, iy, ih;
-
-            if (area != null) {
-                // Should pass in same unit as updatePageAttributes
-                // to avoid rounding off errors.
-                ix = Math.rint(
-                               area.getX(MediaPrintableArea.INCH) * DPI);
-                iy = Math.rint(
-                               area.getY(MediaPrintableArea.INCH) * DPI);
-                iw = Math.rint(
-                               area.getWidth(MediaPrintableArea.INCH) * DPI);
-                ih = Math.rint(
-                               area.getHeight(MediaPrintableArea.INCH) * DPI);
-            }
-            else {
-                if (w >= 72.0 * 6.0) {
-                    ix = 72.0;
-                    iw = w - 2 * 72.0;
-                } else {
-                    ix = w / 6.0;
-                    iw = w * 0.75;
-                }
-                if (h >= 72.0 * 6.0) {
-                    iy = 72.0;
-                    ih = h - 2 * 72.0;
-                } else {
-                    iy = h / 6.0;
-                    ih = h * 0.75;
-                }
-            }
-            paper.setImageableArea(ix, iy, iw, ih);
-            page.setPaper(paper);
-
-            return page;
+            return attributeToPageFormat(service, attributes);
         } else {
             return null;
         }
@@ -795,7 +820,6 @@
             throw new HeadlessException();
         }
 
-
         DialogTypeSelection dlg =
             (DialogTypeSelection)attributes.get(DialogTypeSelection.class);
 
@@ -816,7 +840,6 @@
 
         }
 
-
         /* A security check has already been performed in the
          * java.awt.print.printerJob.getPrinterJob method.
          * So by the time we get here, it is OK for the current thread