< prev index next >

src/java.desktop/macosx/classes/sun/lwawt/macosx/CPrinterJob.java

Print this page




  66     //  access to it. It is used by the pageDialog, jobDialog, and printLoop.
  67     //  This way the state of these items is shared across these calls.
  68     //  PageFormat data is passed in and set on the fNSPrintInfo on a per call
  69     //  basis.
  70     private long fNSPrintInfo = -1;
  71     private Object fNSPrintInfoLock = new Object();
  72 
  73     static {
  74         // AWT has to be initialized for the native code to function correctly.
  75         Toolkit.getDefaultToolkit();
  76     }
  77 
  78     /**
  79      * Presents a dialog to the user for changing the properties of
  80      * the print job.
  81      * This method will display a native dialog if a native print
  82      * service is selected, and user choice of printers will be restricted
  83      * to these native print services.
  84      * To present the cross platform print dialog for all services,
  85      * including native ones instead use
  86      * <code>printDialog(PrintRequestAttributeSet)</code>.
  87      * <p>
  88      * PrinterJob implementations which can use PrintService's will update
  89      * the PrintService for this PrinterJob to reflect the new service
  90      * selected by the user.
  91      * @return <code>true</code> if the user does not cancel the dialog;
  92      * <code>false</code> otherwise.
  93      * @exception HeadlessException if GraphicsEnvironment.isHeadless()
  94      * returns true.
  95      * @see java.awt.GraphicsEnvironment#isHeadless
  96      */
  97     @Override
  98     public boolean printDialog() throws HeadlessException {
  99         if (GraphicsEnvironment.isHeadless()) {
 100             throw new HeadlessException();
 101         }
 102 
 103         if (noDefaultPrinter) {
 104             return false;
 105         }
 106 
 107         if (attributes == null) {
 108             attributes = new HashPrintRequestAttributeSet();
 109         }
 110 
 111         if (getPrintService() instanceof StreamPrintService) {
 112             return super.printDialog(attributes);
 113         }
 114 
 115         return jobSetup(getPageable(), checkAllowedToPrintToFile());
 116     }
 117 
 118     /**
 119      * Displays a dialog that allows modification of a
 120      * <code>PageFormat</code> instance.
 121      * The <code>page</code> argument is used to initialize controls
 122      * in the page setup dialog.
 123      * If the user cancels the dialog then this method returns the
 124      * original <code>page</code> object unmodified.
 125      * If the user okays the dialog then this method returns a new
 126      * <code>PageFormat</code> object with the indicated changes.
 127      * In either case, the original <code>page</code> object is
 128      * not modified.
 129      * @param page the default <code>PageFormat</code> presented to the
 130      *            user for modification
 131      * @return    the original <code>page</code> object if the dialog
 132      *            is cancelled; a new <code>PageFormat</code> object
 133      *          containing the format indicated by the user if the
 134      *          dialog is acknowledged.
 135      * @exception HeadlessException if GraphicsEnvironment.isHeadless()
 136      * returns true.
 137      * @see java.awt.GraphicsEnvironment#isHeadless
 138      * @since     1.2
 139      */
 140     @Override
 141     public PageFormat pageDialog(PageFormat page) throws HeadlessException {
 142         if (GraphicsEnvironment.isHeadless()) {
 143             throw new HeadlessException();
 144         }
 145 
 146         if (noDefaultPrinter) {
 147             return page;
 148         }
 149 
 150         if (getPrintService() instanceof StreamPrintService) {
 151             return super.pageDialog(page);
 152         }
 153 
 154         PageFormat pageClone = (PageFormat) page.clone();
 155         boolean doIt = pageSetup(pageClone, null);
 156         return doIt ? pageClone : page;
 157     }
 158 
 159     /**
 160      * Clones the <code>PageFormat</code> argument and alters the
 161      * clone to describe a default page size and orientation.
 162      * @param page the <code>PageFormat</code> to be cloned and altered
 163      * @return clone of <code>page</code>, altered to describe a default
 164      *                      <code>PageFormat</code>.
 165      */
 166     @Override
 167     public PageFormat defaultPage(PageFormat page) {
 168         PageFormat newPage = (PageFormat)page.clone();
 169         getDefaultPage(newPage);
 170         return newPage;
 171     }
 172 
 173     @Override
 174     protected void setAttributes(PrintRequestAttributeSet attributes) throws PrinterException {
 175         super.setAttributes(attributes);
 176 
 177         if (attributes == null) {
 178             return;
 179         }
 180 
 181         // See if this has an NSPrintInfo in it.
 182         NSPrintInfo nsPrintInfo = (NSPrintInfo)attributes.get(NSPrintInfo.class);
 183         if (nsPrintInfo != null) {
 184             fNSPrintInfo = nsPrintInfo.getValue();




  66     //  access to it. It is used by the pageDialog, jobDialog, and printLoop.
  67     //  This way the state of these items is shared across these calls.
  68     //  PageFormat data is passed in and set on the fNSPrintInfo on a per call
  69     //  basis.
  70     private long fNSPrintInfo = -1;
  71     private Object fNSPrintInfoLock = new Object();
  72 
  73     static {
  74         // AWT has to be initialized for the native code to function correctly.
  75         Toolkit.getDefaultToolkit();
  76     }
  77 
  78     /**
  79      * Presents a dialog to the user for changing the properties of
  80      * the print job.
  81      * This method will display a native dialog if a native print
  82      * service is selected, and user choice of printers will be restricted
  83      * to these native print services.
  84      * To present the cross platform print dialog for all services,
  85      * including native ones instead use
  86      * {@code printDialog(PrintRequestAttributeSet)}.
  87      * <p>
  88      * PrinterJob implementations which can use PrintService's will update
  89      * the PrintService for this PrinterJob to reflect the new service
  90      * selected by the user.
  91      * @return {@code true} if the user does not cancel the dialog;
  92      * {@code false} otherwise.
  93      * @exception HeadlessException if GraphicsEnvironment.isHeadless()
  94      * returns true.
  95      * @see java.awt.GraphicsEnvironment#isHeadless
  96      */
  97     @Override
  98     public boolean printDialog() throws HeadlessException {
  99         if (GraphicsEnvironment.isHeadless()) {
 100             throw new HeadlessException();
 101         }
 102 
 103         if (noDefaultPrinter) {
 104             return false;
 105         }
 106 
 107         if (attributes == null) {
 108             attributes = new HashPrintRequestAttributeSet();
 109         }
 110 
 111         if (getPrintService() instanceof StreamPrintService) {
 112             return super.printDialog(attributes);
 113         }
 114 
 115         return jobSetup(getPageable(), checkAllowedToPrintToFile());
 116     }
 117 
 118     /**
 119      * Displays a dialog that allows modification of a
 120      * {@code PageFormat} instance.
 121      * The {@code page} argument is used to initialize controls
 122      * in the page setup dialog.
 123      * If the user cancels the dialog then this method returns the
 124      * original {@code page} object unmodified.
 125      * If the user okays the dialog then this method returns a new
 126      * {@code PageFormat} object with the indicated changes.
 127      * In either case, the original {@code page} object is
 128      * not modified.
 129      * @param page the default {@code PageFormat} presented to the
 130      *            user for modification
 131      * @return    the original {@code page} object if the dialog
 132      *            is cancelled; a new {@code PageFormat} object
 133      *          containing the format indicated by the user if the
 134      *          dialog is acknowledged.
 135      * @exception HeadlessException if GraphicsEnvironment.isHeadless()
 136      * returns true.
 137      * @see java.awt.GraphicsEnvironment#isHeadless
 138      * @since     1.2
 139      */
 140     @Override
 141     public PageFormat pageDialog(PageFormat page) throws HeadlessException {
 142         if (GraphicsEnvironment.isHeadless()) {
 143             throw new HeadlessException();
 144         }
 145 
 146         if (noDefaultPrinter) {
 147             return page;
 148         }
 149 
 150         if (getPrintService() instanceof StreamPrintService) {
 151             return super.pageDialog(page);
 152         }
 153 
 154         PageFormat pageClone = (PageFormat) page.clone();
 155         boolean doIt = pageSetup(pageClone, null);
 156         return doIt ? pageClone : page;
 157     }
 158 
 159     /**
 160      * Clones the {@code PageFormat} argument and alters the
 161      * clone to describe a default page size and orientation.
 162      * @param page the {@code PageFormat} to be cloned and altered
 163      * @return clone of {@code page}, altered to describe a default
 164      *                      {@code PageFormat}.
 165      */
 166     @Override
 167     public PageFormat defaultPage(PageFormat page) {
 168         PageFormat newPage = (PageFormat)page.clone();
 169         getDefaultPage(newPage);
 170         return newPage;
 171     }
 172 
 173     @Override
 174     protected void setAttributes(PrintRequestAttributeSet attributes) throws PrinterException {
 175         super.setAttributes(attributes);
 176 
 177         if (attributes == null) {
 178             return;
 179         }
 180 
 181         // See if this has an NSPrintInfo in it.
 182         NSPrintInfo nsPrintInfo = (NSPrintInfo)attributes.get(NSPrintInfo.class);
 183         if (nsPrintInfo != null) {
 184             fNSPrintInfo = nsPrintInfo.getValue();


< prev index next >