[no commit message]
authorPreston L. Bannister <preston@bannister.us>
Wed Dec 02 09:06:07 2009 -0800 (2 years ago)
changeset 29fa7cc86690bf
parent 28 40fc64f87f52
child 30 c8af6c546274
[no commit message]
src/us/bannister/printing/explorer/Controller.java
     1.1 --- a/src/us/bannister/printing/explorer/Controller.java	Tue Dec 01 15:43:25 2009 -0800
     1.2 +++ b/src/us/bannister/printing/explorer/Controller.java	Wed Dec 02 09:06:07 2009 -0800
     1.3 @@ -86,13 +86,15 @@
     1.4          new JobName("test printer job",Locale.US),
     1.5          new RequestingUserName("A Test User",Locale.US)
     1.6      };
     1.7 +    PrintRequestAttribute attributeDialogType = sun.print.DialogTypeSelection.COMMON;
     1.8      PrintRequestAttributeSet printRequestAttributeSet;
     1.9      PrinterJob printerJob;
    1.10      String sPrinterJobRender;
    1.11      // For page rendering in PrinterJob.
    1.12      Printable printable = new Printable() {
    1.13          public int print(Graphics graphics,PageFormat pageFormat,int pageIndex) throws PrinterException {
    1.14 -            if (0 < pageIndex) {
    1.15 +            if (pageable.getNumberOfPages() <= pageIndex) {
    1.16 +                Log.out("PRINT page: " + pageIndex + " returns: NOT_SUCH_PAGE");
    1.17                  return Printable.NO_SUCH_PAGE;
    1.18              }
    1.19              Html html = new Html();
    1.20 @@ -151,6 +153,7 @@
    1.21       */
    1.22      public Controller() {
    1.23          Log.openLogFile("print-test-log");
    1.24 +        Log.out("java.awt.printerjob = " + System.getProperty("java.awt.printerjob",null));
    1.25          ui.setVisible(true);
    1.26          queryListOfPrintService();
    1.27          resetJobAttributes();
    1.28 @@ -203,9 +206,16 @@
    1.29                  updatePrintJobBefore();
    1.30                  toAction("Toolkit.getPrintJob()");
    1.31                  Toolkit toolkit = Toolkit.getDefaultToolkit();
    1.32 -                PrintJob job = toolkit.getPrintJob(ui,"test print job",jobAttributes,pageAttributes);
    1.33 -                updatePrintJobAfter(job);
    1.34 -                job.end();
    1.35 +                try {
    1.36 +                    PrintJob job = toolkit.getPrintJob(ui,"test print job",jobAttributes,pageAttributes);
    1.37 +                    updatePrintJobAfter(job);
    1.38 +                    job.end();
    1.39 +                } catch (Throwable ex) {
    1.40 +                    // User-entered values in the dialog (at least page range) can cause exceptions.
    1.41 +                    // Yes, really (at least on Linux).
    1.42 +                    toStatus(ex.getMessage());
    1.43 +                    Log.printStackTrace(ex);
    1.44 +                }
    1.45              }
    1.46          });
    1.47          ui.buttonPrintTestPage.addActionListener(new ActionListener() {
    1.48 @@ -213,14 +223,21 @@
    1.49                  updatePrintJobBefore();
    1.50                  toAction("Print Test Page");
    1.51                  Toolkit toolkit = Toolkit.getDefaultToolkit();
    1.52 -                PrintJob job = toolkit.getPrintJob(ui,"test print job",jobAttributes,pageAttributes);
    1.53 -                updatePrintJobAfter(job);
    1.54 -                if (null != job) {
    1.55 -                    Dimension pageSize = job.getPageDimension();
    1.56 -                    Graphics g = job.getGraphics();
    1.57 -                    renderPage(g,0,0,(int) pageSize.getWidth(),(int) pageSize.getHeight());
    1.58 -                    g.dispose();
    1.59 -                    job.end();
    1.60 +                try {
    1.61 +                    PrintJob job = toolkit.getPrintJob(ui,"test print job",jobAttributes,pageAttributes);
    1.62 +                    updatePrintJobAfter(job);
    1.63 +                    if (null != job) {
    1.64 +                        Dimension pageSize = job.getPageDimension();
    1.65 +                        Graphics g = job.getGraphics();
    1.66 +                        renderPage(g,0,0,(int) pageSize.getWidth(),(int) pageSize.getHeight());
    1.67 +                        g.dispose();
    1.68 +                        job.end();
    1.69 +                    }
    1.70 +                } catch (Throwable ex) {
    1.71 +                    // User-entered values in the dialog (at least page range) can cause exceptions.
    1.72 +                    // Yes, really (at least on Linux).
    1.73 +                    toStatus(ex.getMessage());
    1.74 +                    Log.printStackTrace(ex);
    1.75                  }
    1.76              }
    1.77          });
    1.78 @@ -373,7 +390,8 @@
    1.79              public void actionPerformed(ActionEvent e) {
    1.80                  boolean wantNative = ui.checkboxNativeDialogHack.isSelected();
    1.81                  toAction("NativeDialogHack: " + wantNative);
    1.82 -                printRequestAttributeSet.add(wantNative ? sun.print.DialogTypeSelection.NATIVE : sun.print.DialogTypeSelection.COMMON);
    1.83 +                attributeDialogType = (wantNative ? sun.print.DialogTypeSelection.NATIVE : sun.print.DialogTypeSelection.COMMON);
    1.84 +                printRequestAttributeSet.add(attributeDialogType);
    1.85                  updatePrinterJobBefore();
    1.86              }
    1.87          });
    1.88 @@ -443,7 +461,7 @@
    1.89                              }
    1.90                              String s = sb.toString();
    1.91                              char[] a = s.toCharArray();
    1.92 -                            int n = Math.min(a.length,len-off);
    1.93 +                            int n = Math.min(a.length,len - off);
    1.94                              System.arraycopy(a,0,cbuf,off,n);
    1.95                              Log.out("docReader offset: " + off + " length: " + len + " return: " + n);
    1.96                              return n;
    1.97 @@ -611,6 +629,7 @@
    1.98      }
    1.99      private void resetPrintRequestAttributeSet() {
   1.100          printRequestAttributeSet = new HashPrintRequestAttributeSet(arrayPrintRequestAttribute);
   1.101 +        printRequestAttributeSet.add(attributeDialogType);
   1.102      }
   1.103      private void resetPrinterJob() {
   1.104          printerJob = PrinterJob.getPrinterJob();