< prev index next >

src/java.desktop/unix/classes/sun/print/UnixPrintService.java

Print this page




  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  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.print;
  27 
  28 import java.io.File;
  29 import java.net.URI;
  30 import java.net.URISyntaxException;
  31 import java.util.ArrayList;
  32 import java.util.Locale;
  33 


  34 import javax.print.DocFlavor;
  35 import javax.print.DocPrintJob;
  36 import javax.print.PrintService;
  37 import javax.print.ServiceUIFactory;
  38 import javax.print.attribute.Attribute;
  39 import javax.print.attribute.AttributeSet;
  40 import javax.print.attribute.AttributeSetUtilities;
  41 import javax.print.attribute.HashAttributeSet;
  42 import javax.print.attribute.PrintServiceAttribute;
  43 import javax.print.attribute.PrintServiceAttributeSet;
  44 import javax.print.attribute.HashPrintServiceAttributeSet;
  45 import javax.print.attribute.Size2DSyntax;
  46 import javax.print.attribute.standard.PrinterName;
  47 import javax.print.attribute.standard.PrinterIsAcceptingJobs;
  48 import javax.print.attribute.standard.QueuedJobCount;
  49 import javax.print.attribute.standard.JobName;
  50 import javax.print.attribute.standard.JobSheets;
  51 import javax.print.attribute.standard.RequestingUserName;
  52 import javax.print.attribute.standard.Chromaticity;
  53 import javax.print.attribute.standard.ColorSupported;
  54 import javax.print.attribute.standard.Copies;
  55 import javax.print.attribute.standard.CopiesSupported;
  56 import javax.print.attribute.standard.Destination;


  57 import javax.print.attribute.standard.Fidelity;
  58 import javax.print.attribute.standard.Media;
  59 import javax.print.attribute.standard.MediaPrintableArea;
  60 import javax.print.attribute.standard.MediaSize;
  61 import javax.print.attribute.standard.MediaSizeName;
  62 import javax.print.attribute.standard.OrientationRequested;
  63 import javax.print.attribute.standard.PageRanges;
  64 import javax.print.attribute.standard.PrinterState;
  65 import javax.print.attribute.standard.PrinterStateReason;
  66 import javax.print.attribute.standard.PrinterStateReasons;
  67 import javax.print.attribute.standard.Severity;
  68 import javax.print.attribute.standard.SheetCollate;
  69 import javax.print.attribute.standard.Sides;
  70 import javax.print.event.PrintServiceAttributeListener;
  71 
  72 
  73 public class UnixPrintService implements PrintService, AttributeUpdater,
  74                                          SunPrinterJobService {
  75 
  76     /* define doc flavors for text types in the default encoding of


 602         int len = supportedDocFlavors.length;
 603         DocFlavor[] flavors = new DocFlavor[len];
 604         System.arraycopy(supportedDocFlavors, 0, flavors, 0, len);
 605 
 606         return flavors;
 607     }
 608 
 609     public boolean isDocFlavorSupported(DocFlavor flavor) {
 610         if (supportedDocFlavors == null) {
 611             initSupportedDocFlavors();
 612         }
 613         for (int f=0; f<supportedDocFlavors.length; f++) {
 614             if (flavor.equals(supportedDocFlavors[f])) {
 615                 return true;
 616             }
 617         }
 618         return false;
 619     }
 620 
 621     public Class<?>[] getSupportedAttributeCategories() {
 622         int totalCats = otherAttrCats.length;
 623         Class<?>[] cats = new Class<?>[totalCats];
 624         System.arraycopy(otherAttrCats, 0, cats, 0, otherAttrCats.length);
 625         return cats;





 626     }
 627 
 628     public boolean
 629         isAttributeCategorySupported(Class<? extends Attribute> category)
 630     {
 631         if (category == null) {
 632             throw new NullPointerException("null category");
 633         }
 634         if (!(Attribute.class.isAssignableFrom(category))) {
 635             throw new IllegalArgumentException(category +
 636                                              " is not an Attribute");
 637         }
 638 
 639         for (int i=0;i<otherAttrCats.length;i++) {
 640             if (category == otherAttrCats[i]) {
 641                 return true;
 642             }
 643         }
 644         return false;
 645     }


1006                 return false;
1007             }
1008         } else if (attr.getCategory() == PageRanges.class) {
1009             if (flavor != null &&
1010                 !(flavor.equals(DocFlavor.SERVICE_FORMATTED.PAGEABLE) ||
1011                 flavor.equals(DocFlavor.SERVICE_FORMATTED.PRINTABLE))) {
1012                 return false;
1013             }
1014         } else if (attr.getCategory() == SheetCollate.class) {
1015             if (flavor != null &&
1016                 !(flavor.equals(DocFlavor.SERVICE_FORMATTED.PAGEABLE) ||
1017                 flavor.equals(DocFlavor.SERVICE_FORMATTED.PRINTABLE))) {
1018                 return false;
1019             }
1020         } else if (attr.getCategory() == Sides.class) {
1021             if (flavor != null &&
1022                 !(flavor.equals(DocFlavor.SERVICE_FORMATTED.PAGEABLE) ||
1023                 flavor.equals(DocFlavor.SERVICE_FORMATTED.PRINTABLE))) {
1024                 return false;
1025             }


















1026         }
1027         return true;
1028     }
1029 
1030     public AttributeSet getUnsupportedAttributes(DocFlavor flavor,
1031                                                  AttributeSet attributes) {
1032 
1033         if (flavor != null && !isDocFlavorSupported(flavor)) {
1034             throw new IllegalArgumentException("flavor " + flavor +
1035                                                "is not supported");
1036         }
1037 
1038         if (attributes == null) {
1039             return null;
1040         }
1041 
1042         Attribute attr;
1043         AttributeSet unsupp = new HashAttributeSet();
1044         Attribute []attrs = attributes.toArray();
1045         for (int i=0; i<attrs.length; i++) {




  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  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.print;
  27 
  28 import java.io.File;
  29 import java.net.URI;
  30 import java.net.URISyntaxException;
  31 import java.util.ArrayList;
  32 import java.util.Locale;
  33 
  34 import java.awt.GraphicsEnvironment;
  35 import java.awt.Toolkit;
  36 import javax.print.DocFlavor;
  37 import javax.print.DocPrintJob;
  38 import javax.print.PrintService;
  39 import javax.print.ServiceUIFactory;
  40 import javax.print.attribute.Attribute;
  41 import javax.print.attribute.AttributeSet;
  42 import javax.print.attribute.AttributeSetUtilities;
  43 import javax.print.attribute.HashAttributeSet;
  44 import javax.print.attribute.PrintServiceAttribute;
  45 import javax.print.attribute.PrintServiceAttributeSet;
  46 import javax.print.attribute.HashPrintServiceAttributeSet;
  47 import javax.print.attribute.Size2DSyntax;
  48 import javax.print.attribute.standard.PrinterName;
  49 import javax.print.attribute.standard.PrinterIsAcceptingJobs;
  50 import javax.print.attribute.standard.QueuedJobCount;
  51 import javax.print.attribute.standard.JobName;
  52 import javax.print.attribute.standard.JobSheets;
  53 import javax.print.attribute.standard.RequestingUserName;
  54 import javax.print.attribute.standard.Chromaticity;
  55 import javax.print.attribute.standard.ColorSupported;
  56 import javax.print.attribute.standard.Copies;
  57 import javax.print.attribute.standard.CopiesSupported;
  58 import javax.print.attribute.standard.Destination;
  59 import javax.print.attribute.standard.DialogOwner;
  60 import javax.print.attribute.standard.DialogTypeSelection;
  61 import javax.print.attribute.standard.Fidelity;
  62 import javax.print.attribute.standard.Media;
  63 import javax.print.attribute.standard.MediaPrintableArea;
  64 import javax.print.attribute.standard.MediaSize;
  65 import javax.print.attribute.standard.MediaSizeName;
  66 import javax.print.attribute.standard.OrientationRequested;
  67 import javax.print.attribute.standard.PageRanges;
  68 import javax.print.attribute.standard.PrinterState;
  69 import javax.print.attribute.standard.PrinterStateReason;
  70 import javax.print.attribute.standard.PrinterStateReasons;
  71 import javax.print.attribute.standard.Severity;
  72 import javax.print.attribute.standard.SheetCollate;
  73 import javax.print.attribute.standard.Sides;
  74 import javax.print.event.PrintServiceAttributeListener;
  75 
  76 
  77 public class UnixPrintService implements PrintService, AttributeUpdater,
  78                                          SunPrinterJobService {
  79 
  80     /* define doc flavors for text types in the default encoding of


 606         int len = supportedDocFlavors.length;
 607         DocFlavor[] flavors = new DocFlavor[len];
 608         System.arraycopy(supportedDocFlavors, 0, flavors, 0, len);
 609 
 610         return flavors;
 611     }
 612 
 613     public boolean isDocFlavorSupported(DocFlavor flavor) {
 614         if (supportedDocFlavors == null) {
 615             initSupportedDocFlavors();
 616         }
 617         for (int f=0; f<supportedDocFlavors.length; f++) {
 618             if (flavor.equals(supportedDocFlavors[f])) {
 619                 return true;
 620             }
 621         }
 622         return false;
 623     }
 624 
 625     public Class<?>[] getSupportedAttributeCategories() {
 626         ArrayList<Class<?>> categList = new ArrayList<>(otherAttrCats.length);
 627         for (Class<?> c : otherAttrCats) {
 628             categList.add(c);
 629         }
 630         if (GraphicsEnvironment.isHeadless() == false) {
 631             categList.add(DialogOwner.class);
 632             categList.add(DialogTypeSelection.class);
 633         }
 634         return categList.toArray(new Class<?>[categList.size()]);
 635     }
 636 
 637     public boolean
 638         isAttributeCategorySupported(Class<? extends Attribute> category)
 639     {
 640         if (category == null) {
 641             throw new NullPointerException("null category");
 642         }
 643         if (!(Attribute.class.isAssignableFrom(category))) {
 644             throw new IllegalArgumentException(category +
 645                                              " is not an Attribute");
 646         }
 647 
 648         for (int i=0;i<otherAttrCats.length;i++) {
 649             if (category == otherAttrCats[i]) {
 650                 return true;
 651             }
 652         }
 653         return false;
 654     }


1015                 return false;
1016             }
1017         } else if (attr.getCategory() == PageRanges.class) {
1018             if (flavor != null &&
1019                 !(flavor.equals(DocFlavor.SERVICE_FORMATTED.PAGEABLE) ||
1020                 flavor.equals(DocFlavor.SERVICE_FORMATTED.PRINTABLE))) {
1021                 return false;
1022             }
1023         } else if (attr.getCategory() == SheetCollate.class) {
1024             if (flavor != null &&
1025                 !(flavor.equals(DocFlavor.SERVICE_FORMATTED.PAGEABLE) ||
1026                 flavor.equals(DocFlavor.SERVICE_FORMATTED.PRINTABLE))) {
1027                 return false;
1028             }
1029         } else if (attr.getCategory() == Sides.class) {
1030             if (flavor != null &&
1031                 !(flavor.equals(DocFlavor.SERVICE_FORMATTED.PAGEABLE) ||
1032                 flavor.equals(DocFlavor.SERVICE_FORMATTED.PRINTABLE))) {
1033                 return false;
1034             }
1035         } else if (attr.getCategory() == DialogOwner.class) {
1036             DialogOwner owner = (DialogOwner)attr;
1037             // ID not supported on any dialog type on Unix platforms.
1038             if (owner.getID() != 0) {
1039                 return false;
1040             }
1041             // UnixPrintService is not used on Mac, so this is
1042             // always some Unix system that does not have CUPS/IPP
1043             // Which means we always use a Swing dialog and we need
1044             // only check if alwaysOnTop is supported by the toolkit.
1045             if (owner.getOwner() != null) {
1046                 return true;
1047             } else {
1048                 return Toolkit.getDefaultToolkit().isAlwaysOnTopSupported();
1049             }
1050         } else if (attr.getCategory() == DialogTypeSelection.class) {
1051             DialogTypeSelection dts = (DialogTypeSelection)attr;
1052             return dts == DialogTypeSelection.COMMON;
1053         }
1054         return true;
1055     }
1056 
1057     public AttributeSet getUnsupportedAttributes(DocFlavor flavor,
1058                                                  AttributeSet attributes) {
1059 
1060         if (flavor != null && !isDocFlavorSupported(flavor)) {
1061             throw new IllegalArgumentException("flavor " + flavor +
1062                                                "is not supported");
1063         }
1064 
1065         if (attributes == null) {
1066             return null;
1067         }
1068 
1069         Attribute attr;
1070         AttributeSet unsupp = new HashAttributeSet();
1071         Attribute []attrs = attributes.toArray();
1072         for (int i=0; i<attrs.length; i++) {


< prev index next >