PrintService.java 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. /* PrintService.java --
  2. Copyright (C) 2004, 2006 Free Software Foundation, Inc.
  3. This file is part of GNU Classpath.
  4. GNU Classpath is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2, or (at your option)
  7. any later version.
  8. GNU Classpath is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GNU Classpath; see the file COPYING. If not, write to the
  14. Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  15. 02110-1301 USA.
  16. Linking this library statically or dynamically with other modules is
  17. making a combined work based on this library. Thus, the terms and
  18. conditions of the GNU General Public License cover the whole
  19. combination.
  20. As a special exception, the copyright holders of this library give you
  21. permission to link this library with independent modules to produce an
  22. executable, regardless of the license terms of these independent
  23. modules, and to copy and distribute the resulting executable under
  24. terms of your choice, provided that you also meet, for each linked
  25. independent module, the terms and conditions of the license of that
  26. module. An independent module is a module which is not derived from
  27. or based on this library. If you modify this library, you may extend
  28. this exception to your version of the library, but you are not
  29. obligated to do so. If you do not wish to do so, delete this
  30. exception statement from your version. */
  31. package javax.print;
  32. import javax.print.attribute.Attribute;
  33. import javax.print.attribute.AttributeSet;
  34. import javax.print.attribute.PrintServiceAttribute;
  35. import javax.print.attribute.PrintServiceAttributeSet;
  36. import javax.print.event.PrintServiceAttributeListener;
  37. /**
  38. * A <code>PrintService</code> represents a printer available for printing.
  39. * <p>
  40. * The print service hereby may be a real physical printer device, a printer
  41. * group with same capabilities or a logical print service (like for example
  42. * a PDF writer). The print service is used to query the capabilities of the
  43. * represented printer instance. If a suitable print service is found it is
  44. * used to create a print job for the actual printing process.
  45. * </p>
  46. * @see javax.print.DocPrintJob
  47. *
  48. * @author Michael Koch (konqueror@gmx.de)
  49. */
  50. public interface PrintService
  51. {
  52. /**
  53. * Creates and returns a new print job which is capable to handle all
  54. * the document flavors supported by this print service.
  55. *
  56. * @return The created print job object.
  57. */
  58. DocPrintJob createPrintJob();
  59. /**
  60. * Determines if two services refer to the same underlying service.
  61. *
  62. * @param obj the service to check against
  63. *
  64. * @return <code>true</code> if both services refer to the same underlying
  65. * service, <code>false</code> otherwise.
  66. */
  67. boolean equals(Object obj);
  68. /**
  69. * Returns the value of the single specified attribute.
  70. *
  71. * @param category the category of a <code>PrintServiceAttribute</code>
  72. *
  73. * @return The value of the attribute, or <code>null</code> if the attribute
  74. * category is not supported by this print service implementation.
  75. *
  76. * @throws NullPointerException if category is <code>null</code>.
  77. * @throws IllegalArgumentException if category is not a class that
  78. * implements <code>PrintServiceAttribute</code>.
  79. */
  80. <T extends PrintServiceAttribute> T getAttribute(Class<T> category);
  81. /**
  82. * Returns the attributes describing this print service. The returned
  83. * attributes set is unmodifiable and represents the current state of
  84. * the print service. As some print service attributes may change
  85. * (depends on the print service implementation) a subsequent call to
  86. * this method may return a different set. To monitor changes a
  87. * <code>PrintServiceAttributeListener</code> may be registered.
  88. *
  89. * @return All the description attributes of this print service.
  90. * @see #addPrintServiceAttributeListener(PrintServiceAttributeListener)
  91. */
  92. PrintServiceAttributeSet getAttributes();
  93. /**
  94. * Determines and returns the default value for a given attribute category
  95. * of this print service.
  96. * <p>
  97. * A return value of <code>null</code> means either that the print service
  98. * does not support the attribute category or there is no default value
  99. * available for this category. To distinguish these two case one can test
  100. * with {@link #isAttributeCategorySupported(Class)} if the category is
  101. * supported.
  102. * </p>
  103. *
  104. * @param category the category of the attribute
  105. *
  106. * @return The default value, or <code>null</code>.
  107. *
  108. * @throws NullPointerException if <code>category</code> is <code>null</code>
  109. * @throws IllegalArgumentException if <code>category</code> is a class
  110. * not implementing <code>Attribute</code>
  111. */
  112. Object getDefaultAttributeValue(Class<? extends Attribute> category);
  113. /**
  114. * Returns the name of this print service.
  115. * This may be the value of the <code>PrinterName</code> attribute.
  116. *
  117. * @return The print service name.
  118. */
  119. String getName();
  120. /**
  121. * Returns a factory for UI components if supported by the print service.
  122. *
  123. * @return A factory for UI components or <code>null</code>.
  124. */
  125. ServiceUIFactory getServiceUIFactory();
  126. /**
  127. * Returns all supported attribute categories.
  128. *
  129. * @return The class array of all supported attribute categories.
  130. */
  131. Class<?>[] getSupportedAttributeCategories();
  132. /**
  133. * Determines and returns all supported attribute values of a given
  134. * attribute category a client can use when setting up a print job
  135. * for this print service.
  136. * <p>
  137. * The returned object may be one of the following types:
  138. * <ul>
  139. * <li>A single instance of the attribute category to indicate that any
  140. * value will be supported.</li>
  141. * <li>An array of the same type as the attribute category to test,
  142. * containing all the supported values for this category.</li>
  143. * <li>A single object (of any other type than the attribute category)
  144. * which indicates bounds on the supported values.</li>
  145. * </ul>
  146. * </p>
  147. *
  148. * @param category the attribute category to test
  149. * @param flavor the document flavor to use, or <code>null</code>
  150. * @param attributes set of attributes for a supposed job,
  151. * or <code>null</code>
  152. *
  153. * @return A object (as defined above) indicating the supported values
  154. * for the given attribute category, or <code>null</code> if this print
  155. * service doesn't support the given attribute category at all.
  156. *
  157. * @throws NullPointerException if <code>category</code> is null
  158. * @throws IllegalArgumentException if <code>category</code> is a class not
  159. * implementing <code>Attribute</code>, or if <code>flavor</code> is not
  160. * supported
  161. */
  162. Object getSupportedAttributeValues(Class<? extends Attribute> category,
  163. DocFlavor flavor,
  164. AttributeSet attributes);
  165. /**
  166. * Determines and returns an array of all supported document flavors which
  167. * can be used to supply print data to this print service.
  168. * <p>
  169. * The supported attribute categories may differ between the supported
  170. * document flavors. To test for supported attributes one can use the
  171. * {@link #getUnsupportedAttributes(DocFlavor, AttributeSet)} method with
  172. * the specific doc flavor and attributes set.
  173. * </p>
  174. *
  175. * @return the supported document flavors
  176. */
  177. DocFlavor[] getSupportedDocFlavors();
  178. /**
  179. * Identifies all the unsupported attributes of the given set of attributes
  180. * in the context of the specified document flavor.
  181. * <p>
  182. * The given flavor has to be supported by the print service (use
  183. * {@link #isDocFlavorSupported(DocFlavor)} to verify). The method will
  184. * return <code>null</code> if all given attributes are supported. Otherwise
  185. * a set of unsupported attributes are returned. The attributes in the
  186. * returned set may be completely unsupported or only the specific requested
  187. * value. If flavor is <code>null</code> the default document flavor of the
  188. * print service is used in the identification process.
  189. * </p>
  190. *
  191. * @param flavor document flavor to test, or <code>null</code>.
  192. * @param attributes set of printing attributes for a supposed job
  193. *
  194. * @return <code>null</code> if this print service supports all the given
  195. * attributes for the specified doc flavor. Otherwise the set of unsupported
  196. * attributes are returned.
  197. *
  198. * @throws IllegalArgumentException if <code>flavor</code> is unsupported
  199. */
  200. AttributeSet getUnsupportedAttributes(DocFlavor flavor, AttributeSet attributes);
  201. /**
  202. * Returns a hashcode for this print service.
  203. *
  204. * @return The hashcode.
  205. */
  206. int hashCode();
  207. /**
  208. * Determines a given attribute category is supported by this
  209. * print service implementation. This only tests for the category
  210. * not for any specific values of this category nor in the context
  211. * of a specific document flavor.
  212. *
  213. * @param category the category to check
  214. *
  215. * @return <code>true</code> if <code>category</code> is supported,
  216. * <code>false</code> otherwise.
  217. *
  218. * @throws NullPointerException if <code>category</code> is <code>null</code>
  219. * @throws IllegalArgumentException if <code>category</code> is a class not
  220. * implementing <code>Attribute</code>.
  221. */
  222. boolean isAttributeCategorySupported(Class<? extends Attribute> category);
  223. /**
  224. * Determines if a given attribute value is supported when creating a print
  225. * job for this print service.
  226. * <p>
  227. * If either the document flavor or the provided attributes are
  228. * <code>null</code> it is determined if the given attribute value is
  229. * supported in some combination of the available document flavors and
  230. * attributes of the print service. Otherwise it is checked for the
  231. * specific context of the given document flavor/attributes set.
  232. * </p>
  233. *
  234. * @param attrval the attribute value to check
  235. * @param flavor the document flavor to use, or <code>null</code>.
  236. * @param attributes set of attributes to use, or <code>null</code>.
  237. *
  238. * @return <code>true</code> if the attribute value is supported in the
  239. * requested context, <code>false</code> otherwise.
  240. *
  241. * @throws NullPointerException if <code>attrval</code> is <code>null</code>.
  242. * @throws IllegalArgumentException if <code>flavor</code> is not supported
  243. * by this print service
  244. */
  245. boolean isAttributeValueSupported(Attribute attrval, DocFlavor flavor, AttributeSet attributes);
  246. /**
  247. * Determines if a given document flavor is supported or not.
  248. *
  249. * @param flavor the document flavor to check
  250. *
  251. * @return <code>true</code> if <code>flavor</code> is supported,
  252. * <code>false</code> otherwise.
  253. *
  254. * @throws NullPointerException if <code>flavor</code> is null.
  255. */
  256. boolean isDocFlavorSupported(DocFlavor flavor);
  257. /**
  258. * Registers a print service attribute listener to this print service.
  259. *
  260. * @param listener the listener to add
  261. */
  262. void addPrintServiceAttributeListener(PrintServiceAttributeListener listener);
  263. /**
  264. * De-registers a print service attribute listener from this print service.
  265. *
  266. * @param listener the listener to remove
  267. */
  268. void removePrintServiceAttributeListener(PrintServiceAttributeListener listener);
  269. }