< prev index next >

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

Print this page




  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package sun.lwawt.macosx;
  27 
  28 
  29 import java.awt.*;
  30 import java.awt.geom.Rectangle2D;
  31 import java.awt.image.BufferedImage;
  32 import java.awt.print.*;
  33 import java.security.AccessController;
  34 import java.security.PrivilegedAction;
  35 
  36 import javax.print.*;
  37 import javax.print.attribute.PrintRequestAttributeSet;
  38 import javax.print.attribute.HashPrintRequestAttributeSet;

  39 import javax.print.attribute.standard.Media;
  40 import javax.print.attribute.standard.MediaPrintableArea;
  41 import javax.print.attribute.standard.MediaSize;
  42 import javax.print.attribute.standard.MediaSizeName;
  43 import javax.print.attribute.standard.PageRanges;
  44 
  45 import sun.java2d.*;
  46 import sun.misc.ManagedLocalsThread;
  47 import sun.print.*;
  48 
  49 public final class CPrinterJob extends RasterPrinterJob {
  50     // NOTE: This uses RasterPrinterJob as a base, but it doesn't use
  51     // all of the RasterPrinterJob functions. RasterPrinterJob will
  52     // break down printing to pieces that aren't necessary under MacOSX
  53     // printing, such as controlling the # of copies and collating. These
  54     // are handled by the native printing. RasterPrinterJob is kept for
  55     // future compatibility and the state keeping that it handles.
  56 
  57     private static String sShouldNotReachHere = "Should not reach here.";
  58 


 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();
 185         }
 186 
 187         PageRanges pageRangesAttr =  (PageRanges)attributes.get(PageRanges.class);
 188         if (isSupportedValue(pageRangesAttr, attributes)) {
 189             SunPageSelection rangeSelect = (SunPageSelection)attributes.get(SunPageSelection.class);
 190             // If rangeSelect is not null, we are using AWT's print dialog that has
 191             // All, Selection, and Range radio buttons
 192             if (rangeSelect == null || rangeSelect == SunPageSelection.RANGE) {
 193                 int[][] range = pageRangesAttr.getMembers();
 194                 // setPageRange will set firstPage and lastPage as called in getFirstPage
 195                 // and getLastPage
 196                 setPageRange(range[0][0] - 1, range[0][1] - 1);






 197             }













 198         }

 199     }









 200 
 201     volatile boolean onEventThread;
 202 
 203     @Override
 204     protected void cancelDoc() throws PrinterAbortException {
 205         super.cancelDoc();
 206         if (printingLoop != null) {
 207             printingLoop.exit();
 208         }
 209     }
 210 
 211     private void completePrintLoop() {
 212         Runnable r = new Runnable() { public void run() {
 213             synchronized(this) {
 214                 performingPrinting = false;
 215             }
 216             if (printingLoop != null) {
 217                 printingLoop.exit();
 218             }
 219         }};




  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package sun.lwawt.macosx;
  27 
  28 
  29 import java.awt.*;
  30 import java.awt.geom.Rectangle2D;
  31 import java.awt.image.BufferedImage;
  32 import java.awt.print.*;
  33 import java.security.AccessController;
  34 import java.security.PrivilegedAction;
  35 
  36 import javax.print.*;
  37 import javax.print.attribute.PrintRequestAttributeSet;
  38 import javax.print.attribute.HashPrintRequestAttributeSet;
  39 import javax.print.attribute.standard.Copies;
  40 import javax.print.attribute.standard.Media;
  41 import javax.print.attribute.standard.MediaPrintableArea;
  42 import javax.print.attribute.standard.MediaSize;
  43 import javax.print.attribute.standard.MediaSizeName;
  44 import javax.print.attribute.standard.PageRanges;
  45 
  46 import sun.java2d.*;
  47 import sun.misc.ManagedLocalsThread;
  48 import sun.print.*;
  49 
  50 public final class CPrinterJob extends RasterPrinterJob {
  51     // NOTE: This uses RasterPrinterJob as a base, but it doesn't use
  52     // all of the RasterPrinterJob functions. RasterPrinterJob will
  53     // break down printing to pieces that aren't necessary under MacOSX
  54     // printing, such as controlling the # of copies and collating. These
  55     // are handled by the native printing. RasterPrinterJob is kept for
  56     // future compatibility and the state keeping that it handles.
  57 
  58     private static String sShouldNotReachHere = "Should not reach here.";
  59 


 178         if (attributes == null) {
 179             return;
 180         }
 181 
 182         // See if this has an NSPrintInfo in it.
 183         NSPrintInfo nsPrintInfo = (NSPrintInfo)attributes.get(NSPrintInfo.class);
 184         if (nsPrintInfo != null) {
 185             fNSPrintInfo = nsPrintInfo.getValue();
 186         }
 187 
 188         PageRanges pageRangesAttr =  (PageRanges)attributes.get(PageRanges.class);
 189         if (isSupportedValue(pageRangesAttr, attributes)) {
 190             SunPageSelection rangeSelect = (SunPageSelection)attributes.get(SunPageSelection.class);
 191             // If rangeSelect is not null, we are using AWT's print dialog that has
 192             // All, Selection, and Range radio buttons
 193             if (rangeSelect == null || rangeSelect == SunPageSelection.RANGE) {
 194                 int[][] range = pageRangesAttr.getMembers();
 195                 // setPageRange will set firstPage and lastPage as called in getFirstPage
 196                 // and getLastPage
 197                 setPageRange(range[0][0] - 1, range[0][1] - 1);
 198             } else {
 199                 // if rangeSelect is SunPageSelection.ALL 
 200                 // then setPageRange appropriately
 201                 setPageRange(-1, -1);
 202             }
 203         }
 204     }
 205 
 206     private void setPageRangeAttribute(int from, int to, boolean isRangeSet) {
 207         if (attributes != null) {
 208             // since native Print use zero-based page indices,
 209             // we need to store in 1-based format in attributes set
 210             // but setPageRange again uses zero-based indices so it should be 
 211             // 1 less than pageRanges attribute
 212             if (isRangeSet) {
 213                 attributes.add(new PageRanges(from+1, to+1));
 214                 attributes.add(SunPageSelection.RANGE);        
 215                 setPageRange(from, to);
 216             } else {
 217                 attributes.add(SunPageSelection.ALL);
 218             }
 219   
 220         }
 221     }
 222     
 223     private void setCopiesAttribute(int copies) {
 224         if (attributes != null) {
 225             attributes.add(new Copies(copies));
 226             super.setCopies(copies);
 227         }
 228     }
 229     
 230     
 231     volatile boolean onEventThread;
 232 
 233     @Override
 234     protected void cancelDoc() throws PrinterAbortException {
 235         super.cancelDoc();
 236         if (printingLoop != null) {
 237             printingLoop.exit();
 238         }
 239     }
 240 
 241     private void completePrintLoop() {
 242         Runnable r = new Runnable() { public void run() {
 243             synchronized(this) {
 244                 performingPrinting = false;
 245             }
 246             if (printingLoop != null) {
 247                 printingLoop.exit();
 248             }
 249         }};


< prev index next >