src/share/classes/sun/print/PSStreamPrintService.java

Print this page




  45 import javax.print.event.PrintServiceAttributeListener;
  46 import javax.print.attribute.standard.JobName;
  47 import javax.print.attribute.standard.RequestingUserName;
  48 import javax.print.attribute.standard.Chromaticity;
  49 import javax.print.attribute.standard.ColorSupported;
  50 import javax.print.attribute.standard.Copies;
  51 import javax.print.attribute.standard.CopiesSupported;
  52 import javax.print.attribute.standard.Fidelity;
  53 import javax.print.attribute.standard.Media;
  54 import javax.print.attribute.standard.MediaPrintableArea;
  55 import javax.print.attribute.standard.MediaSize;
  56 import javax.print.attribute.standard.MediaSizeName;
  57 import javax.print.attribute.standard.OrientationRequested;
  58 import javax.print.attribute.standard.PageRanges;
  59 import javax.print.attribute.standard.SheetCollate;
  60 import javax.print.attribute.standard.Sides;
  61 
  62 public class PSStreamPrintService extends StreamPrintService
  63     implements SunPrinterJobService {
  64 
  65     private static final Class[] suppAttrCats = {
  66         Chromaticity.class,
  67         Copies.class,
  68         Fidelity.class,
  69         JobName.class,
  70         Media.class,
  71         MediaPrintableArea.class,
  72         OrientationRequested.class,
  73         PageRanges.class,
  74         RequestingUserName.class,
  75         SheetCollate.class,
  76         Sides.class,
  77     };
  78 
  79     private static int MAXCOPIES = 1000;
  80 
  81     private static final MediaSizeName mediaSizes[] = {
  82         MediaSizeName.NA_LETTER,
  83         MediaSizeName.TABLOID,
  84         MediaSizeName.LEDGER,
  85         MediaSizeName.NA_LEGAL,


  91         MediaSizeName.ISO_B5,
  92     };
  93 
  94     public PSStreamPrintService(OutputStream out) {
  95         super(out);
  96     }
  97 
  98     public String getOutputFormat() {
  99         return PSStreamPrinterFactory.psMimeType;
 100     }
 101 
 102 
 103     public DocFlavor[] getSupportedDocFlavors() {
 104         return PSStreamPrinterFactory.getFlavors();
 105     }
 106 
 107     public DocPrintJob createPrintJob() {
 108         return new PSStreamPrintJob(this);
 109     }
 110 
 111     public boolean usesClass(Class c) {
 112         return (c == sun.print.PSPrinterJob.class);
 113     }
 114 
 115     public String getName() {
 116         return "Postscript output";
 117     }
 118 
 119     public void addPrintServiceAttributeListener(
 120                          PrintServiceAttributeListener listener) {
 121         return;
 122     }
 123 
 124     public void removePrintServiceAttributeListener(
 125                             PrintServiceAttributeListener listener) {
 126         return;
 127     }
 128 
 129 
 130     public <T extends PrintServiceAttribute>
 131         T getAttribute(Class<T> category)
 132     {
 133         if (category == null) {
 134             throw new NullPointerException("category");
 135         }
 136         if (!(PrintServiceAttribute.class.isAssignableFrom(category))) {
 137             throw new IllegalArgumentException("Not a PrintServiceAttribute");
 138         }
 139         if (category == ColorSupported.class) {
 140             return (T)ColorSupported.SUPPORTED;


 141         } else {
 142             return null;
 143         }
 144     }
 145     public PrintServiceAttributeSet getAttributes() {
 146         PrintServiceAttributeSet attrs = new HashPrintServiceAttributeSet();
 147         attrs.add(ColorSupported.SUPPORTED);
 148 
 149         return AttributeSetUtilities.unmodifiableView(attrs);
 150     }
 151 
 152     public boolean isDocFlavorSupported(DocFlavor flavor) {
 153         DocFlavor [] flavors = getSupportedDocFlavors();
 154         for (int f=0; f<flavors.length; f++) {
 155             if (flavor.equals(flavors[f])) {
 156                 return true;
 157             }
 158         }
 159         return false;
 160     }
 161 
 162 
 163     public Class<?>[] getSupportedAttributeCategories() {
 164         Class []cats = new Class[suppAttrCats.length];
 165         System.arraycopy(suppAttrCats, 0, cats, 0, cats.length);
 166         return cats;
 167     }
 168 
 169     public boolean
 170         isAttributeCategorySupported(Class<? extends Attribute> category)
 171     {
 172         if (category == null) {
 173             throw new NullPointerException("null category");
 174         }
 175         if (!(Attribute.class.isAssignableFrom(category))) {
 176             throw new IllegalArgumentException(category +
 177                                              " is not an Attribute");
 178         }
 179 
 180         for (int i=0;i<suppAttrCats.length;i++) {
 181             if (category == suppAttrCats[i]) {
 182                 return true;
 183             }
 184         }


 384 
 385     private boolean isSupportedMedia(MediaSizeName msn) {
 386         for (int i=0; i<mediaSizes.length; i++) {
 387             if (msn.equals(mediaSizes[i])) {
 388                 return true;
 389             }
 390         }
 391         return false;
 392     }
 393 
 394     public boolean isAttributeValueSupported(Attribute attr,
 395                                              DocFlavor flavor,
 396                                              AttributeSet attributes) {
 397         if (attr == null) {
 398             throw new NullPointerException("null attribute");
 399         }
 400         if (flavor != null && !isDocFlavorSupported(flavor)) {
 401             throw new IllegalArgumentException(flavor +
 402                                                " is an unsupported flavor");
 403         }
 404         Class category = attr.getCategory();
 405         if (!isAttributeCategorySupported(category)) {
 406             return false;
 407         }
 408         else if (attr.getCategory() == Chromaticity.class) {
 409             return attr == Chromaticity.COLOR;
 410         }
 411         else if (attr.getCategory() == Copies.class) {
 412             return isSupportedCopies((Copies)attr);
 413         } else if (attr.getCategory() == Media.class &&
 414                    attr instanceof MediaSizeName) {
 415             return isSupportedMedia((MediaSizeName)attr);
 416         } else if (attr.getCategory() == OrientationRequested.class) {
 417             if (attr == OrientationRequested.REVERSE_PORTRAIT ||
 418                 (flavor != null) &&
 419                 !(flavor.equals(DocFlavor.SERVICE_FORMATTED.PAGEABLE) ||
 420                 flavor.equals(DocFlavor.SERVICE_FORMATTED.PRINTABLE))) {
 421                 return false;
 422             }
 423         } else if (attr.getCategory() == PageRanges.class) {
 424             if (flavor != null &&




  45 import javax.print.event.PrintServiceAttributeListener;
  46 import javax.print.attribute.standard.JobName;
  47 import javax.print.attribute.standard.RequestingUserName;
  48 import javax.print.attribute.standard.Chromaticity;
  49 import javax.print.attribute.standard.ColorSupported;
  50 import javax.print.attribute.standard.Copies;
  51 import javax.print.attribute.standard.CopiesSupported;
  52 import javax.print.attribute.standard.Fidelity;
  53 import javax.print.attribute.standard.Media;
  54 import javax.print.attribute.standard.MediaPrintableArea;
  55 import javax.print.attribute.standard.MediaSize;
  56 import javax.print.attribute.standard.MediaSizeName;
  57 import javax.print.attribute.standard.OrientationRequested;
  58 import javax.print.attribute.standard.PageRanges;
  59 import javax.print.attribute.standard.SheetCollate;
  60 import javax.print.attribute.standard.Sides;
  61 
  62 public class PSStreamPrintService extends StreamPrintService
  63     implements SunPrinterJobService {
  64 
  65     private static final Class<?>[] suppAttrCats = {
  66         Chromaticity.class,
  67         Copies.class,
  68         Fidelity.class,
  69         JobName.class,
  70         Media.class,
  71         MediaPrintableArea.class,
  72         OrientationRequested.class,
  73         PageRanges.class,
  74         RequestingUserName.class,
  75         SheetCollate.class,
  76         Sides.class,
  77     };
  78 
  79     private static int MAXCOPIES = 1000;
  80 
  81     private static final MediaSizeName mediaSizes[] = {
  82         MediaSizeName.NA_LETTER,
  83         MediaSizeName.TABLOID,
  84         MediaSizeName.LEDGER,
  85         MediaSizeName.NA_LEGAL,


  91         MediaSizeName.ISO_B5,
  92     };
  93 
  94     public PSStreamPrintService(OutputStream out) {
  95         super(out);
  96     }
  97 
  98     public String getOutputFormat() {
  99         return PSStreamPrinterFactory.psMimeType;
 100     }
 101 
 102 
 103     public DocFlavor[] getSupportedDocFlavors() {
 104         return PSStreamPrinterFactory.getFlavors();
 105     }
 106 
 107     public DocPrintJob createPrintJob() {
 108         return new PSStreamPrintJob(this);
 109     }
 110 
 111     public boolean usesClass(Class<?> c) {
 112         return (c == sun.print.PSPrinterJob.class);
 113     }
 114 
 115     public String getName() {
 116         return "Postscript output";
 117     }
 118 
 119     public void addPrintServiceAttributeListener(
 120                          PrintServiceAttributeListener listener) {
 121         return;
 122     }
 123 
 124     public void removePrintServiceAttributeListener(
 125                             PrintServiceAttributeListener listener) {
 126         return;
 127     }
 128 
 129 
 130     public <T extends PrintServiceAttribute>
 131         T getAttribute(Class<T> category)
 132     {
 133         if (category == null) {
 134             throw new NullPointerException("category");
 135         }
 136         if (!(PrintServiceAttribute.class.isAssignableFrom(category))) {
 137             throw new IllegalArgumentException("Not a PrintServiceAttribute");
 138         }
 139         if (category == ColorSupported.class) {
 140             @SuppressWarnings("unchecked")
 141             T tmp = (T)ColorSupported.SUPPORTED;
 142             return tmp;
 143         } else {
 144             return null;
 145         }
 146     }
 147     public PrintServiceAttributeSet getAttributes() {
 148         PrintServiceAttributeSet attrs = new HashPrintServiceAttributeSet();
 149         attrs.add(ColorSupported.SUPPORTED);
 150 
 151         return AttributeSetUtilities.unmodifiableView(attrs);
 152     }
 153 
 154     public boolean isDocFlavorSupported(DocFlavor flavor) {
 155         DocFlavor [] flavors = getSupportedDocFlavors();
 156         for (int f=0; f<flavors.length; f++) {
 157             if (flavor.equals(flavors[f])) {
 158                 return true;
 159             }
 160         }
 161         return false;
 162     }
 163 
 164 
 165     public Class<?>[] getSupportedAttributeCategories() {
 166         Class<?>[] cats = new Class<?>[suppAttrCats.length];
 167         System.arraycopy(suppAttrCats, 0, cats, 0, cats.length);
 168         return cats;
 169     }
 170 
 171     public boolean
 172         isAttributeCategorySupported(Class<? extends Attribute> category)
 173     {
 174         if (category == null) {
 175             throw new NullPointerException("null category");
 176         }
 177         if (!(Attribute.class.isAssignableFrom(category))) {
 178             throw new IllegalArgumentException(category +
 179                                              " is not an Attribute");
 180         }
 181 
 182         for (int i=0;i<suppAttrCats.length;i++) {
 183             if (category == suppAttrCats[i]) {
 184                 return true;
 185             }
 186         }


 386 
 387     private boolean isSupportedMedia(MediaSizeName msn) {
 388         for (int i=0; i<mediaSizes.length; i++) {
 389             if (msn.equals(mediaSizes[i])) {
 390                 return true;
 391             }
 392         }
 393         return false;
 394     }
 395 
 396     public boolean isAttributeValueSupported(Attribute attr,
 397                                              DocFlavor flavor,
 398                                              AttributeSet attributes) {
 399         if (attr == null) {
 400             throw new NullPointerException("null attribute");
 401         }
 402         if (flavor != null && !isDocFlavorSupported(flavor)) {
 403             throw new IllegalArgumentException(flavor +
 404                                                " is an unsupported flavor");
 405         }
 406         Class<? extends Attribute> category = attr.getCategory();
 407         if (!isAttributeCategorySupported(category)) {
 408             return false;
 409         }
 410         else if (attr.getCategory() == Chromaticity.class) {
 411             return attr == Chromaticity.COLOR;
 412         }
 413         else if (attr.getCategory() == Copies.class) {
 414             return isSupportedCopies((Copies)attr);
 415         } else if (attr.getCategory() == Media.class &&
 416                    attr instanceof MediaSizeName) {
 417             return isSupportedMedia((MediaSizeName)attr);
 418         } else if (attr.getCategory() == OrientationRequested.class) {
 419             if (attr == OrientationRequested.REVERSE_PORTRAIT ||
 420                 (flavor != null) &&
 421                 !(flavor.equals(DocFlavor.SERVICE_FORMATTED.PAGEABLE) ||
 422                 flavor.equals(DocFlavor.SERVICE_FORMATTED.PRINTABLE))) {
 423                 return false;
 424             }
 425         } else if (attr.getCategory() == PageRanges.class) {
 426             if (flavor != null &&