Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4886087

PrinterJob's dialog ignores any Pageable object's getNumberOfPages() method

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 1.4.1
    • client-libs
    • 2d
    • x86
    • linux, windows_98



      Name: jk109818 Date: 07/02/2003


      FULL PRODUCT VERSION :
      java version "1.4.1_02"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1_02-b06)
      Java HotSpot(TM) Client VM (build 1.4.1_02-b06, mixed mode)

      FULL OS VERSION :
      Linux 2.4.19-4GB i686

      A DESCRIPTION OF THE PROBLEM :
      See closed bug #4716419.

      Using the code supplied below (which has been modified from bug #4716419 to use more than one page), I would expect the page range selection on the print dialog to a) be active and b) display the maximum number of pages in the "page to" field.

      This bug is apparent whether using the Book object which implements the Pageable interface or any opther custom object which implements the Pageable interface.


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.awt.*;
      import java.awt.print.*;

      // PrintBook -- use setPageable
      // --> Print Dialog shows up with "Page 1 to xxxxx" disabled

      public class PrintBook {

         public static void main(String[] args) {
            try {
               Book bk = new Book();
               bk.append(new PaintMultiple(), new PageFormat());
               bk.append(new PaintMultiple(), new PageFormat());

               PrinterJob job = PrinterJob.getPrinterJob();
               job.setPageable(bk);

               // Put up the dialog box
               if (job.printDialog()) {
                  job.print();
               }
            }
            catch (Exception e) {
               System.out.println(e.getClass().getName() + ": " + e.getMessage());
               e.printStackTrace();
            }
            System.exit(0);
         }
      }

      class PaintMultiple implements Printable {
         Font fnt = new Font("Monospaced", Font.PLAIN, 8);

         final static String[] content = {
            "line 1: Hello ABCDEFGHIJK",
            "line 2: Gee, another line",
            "line 3: last line"};

         public int print(Graphics g, PageFormat pf, int pageIndex)
         throws PrinterException {
            if (pageIndex > 1)
               return Printable.NO_SUCH_PAGE;
            g.setFont(fnt);
            g.setColor(Color.black);
            int xo = (int) pf.getImageableX();
            int yo = (int) pf.getImageableY();
            int width = (int) pf.getImageableWidth();
            int height = (int) pf.getImageableHeight();

            int posY = yo + 8;
            for (int i = 0; i < content.length; i++) {
               g.drawString(content[i], xo, posY);
               posY += 8;
            }

            g.drawRect(xo, yo, width, height);
            return Printable.PAGE_EXISTS;
         }

         public int getNumberOfPages() {
            return 1;
         }
      }
      ---------- END SOURCE ----------
      (Review ID: 189225)
      ======================================================================

      Name: jk109818 Date: 07/22/2003


      FULL PRODUCT VERSION :
      java version "1.4.1"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1-b21)
      Java HotSpot(TM) Client VM (build 1.4.1-b21, mixed mode)


      FULL OPERATING SYSTEM VERSION :
      Windows 98 [Version 4.10.2222]


      A DESCRIPTION OF THE PROBLEM :
      When printing using the JDK 1.4 cross-platform print dialog,
      the page range comes up as Pages 1 to 1 rather than the
      upper bound being the number of pages in the Pageable. This
      is unlike the behavior for the native print dialog which
      diplays the number of pages in the Pageable correctly.

      This behavior is confusing to users who rely on this display
      to tell them how many pages they will get, even though it is
      not selected and they intend to go with the default "All"
      option. The "All option should be the default and the
      non-selected page range should report the correct range,
      exactly as in the native print dialog.

      Perhaps this was an intended improvement on the "9999"
      display for Printables, but the right thing to do for the
      Printables case is to leave them blank. In any event they
      shouldn't be filled in wrong for Pageables since the
      Pageable provides you with the correct number.

      The PageRanges print request attribute can be used to force
      the page range display to the desired values. The problem
      is that then the page range option becomes the default, not
      "All" as it should be. Also, if this is done, since a
      forced PageRanges attribute will always be returned in the
      print request attribute set, it is no longer possible for
      the program to distinguish if the user actually specified
      the "All" option.



      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. Compile and run the program below, number of pages in the
      Pageable is 2.
      2. Cross-platform print dialog comes up first. You can
      Print or cancel this dialog.
      3. Native print dialog comes up next for comparison.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      Expected: Both cross-platform and native print dialogs
      should have "All" as the default and a page range "Pages 1
      to 2".

      Actual: Native print dialog is correct, but the
      cross-platform print dialog says "Pages 1 to 1".

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.awt.*;
      import java.awt.print.*;
      import javax.print.attribute.*;

      public class Test {
      static public void main(String args[]) {
      PrinterJob pj = PrinterJob.getPrinterJob();
      pj.setPageable(new MyPageable());
      pj.printDialog(new HashPrintRequestAttributeSet());
      pj.printDialog();
      System.exit(0);
      }
      }

      class MyPageable implements Pageable {
      public int getNumberOfPages() { return 2; }
      public PageFormat getPageFormat(int i) { return
      PrinterJob.getPrinterJob().defaultPage(); }
      public Printable getPrintable(int i) { return new MyPrintable(); }
      }

      class MyPrintable implements Printable {
      public int print(Graphics g, PageFormat pf, int pi) {
      if (pageIndex>=2) return Printable.NO_SUCH_PAGE;
      Graphics2D g2d = (Graphics2D) g;
      g2d.translate(pf.getImageableX(), pf.getImageableY());
      g2d.drawString("This is page " + (pi+1), 100, 100);
      return Printable.PAGE_EXISTS;
      }
      }


      ---------- END SOURCE ----------

      CUSTOMER WORKAROUND :
      The PageRanges print request attribute can be used to force
      the page range display to the desired values. But then the
      page range option incorrectly becomes the default instead of
      "All" and the program can no longer distinguish if the user
      actually specified the "All" option.
      (Review ID: 165082)
      ======================================================================

            jgodinez Jennifer Godinez (Inactive)
            jkimsunw Jeffrey Kim (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: