PrintService.java 11.3 KB
Newer Older
Tom Tromey committed
1
/* PrintService.java --
2
   Copyright (C) 2004, 2006 Free Software Foundation, Inc.
Tom Tromey committed
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47

This file is part of GNU Classpath.

GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.

GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
General Public License for more details.

You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING.  If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.

Linking this library statically or dynamically with other modules is
making a combined work based on this library.  Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.

As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module.  An independent module is a module which is not derived from
or based on this library.  If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so.  If you do not wish to do so, delete this
exception statement from your version. */


package javax.print;

import javax.print.attribute.Attribute;
import javax.print.attribute.AttributeSet;
import javax.print.attribute.PrintServiceAttribute;
import javax.print.attribute.PrintServiceAttributeSet;
import javax.print.event.PrintServiceAttributeListener;

/**
48 49 50 51 52 53 54 55 56 57
 * A <code>PrintService</code> represents a printer available for printing.
 * <p>
 * The print service hereby may be a real physical printer device, a printer
 * group with same capabilities or a logical print service (like for example 
 * a PDF writer). The print service is used to query the capabilities of the
 * represented printer instance. If a suitable print service is found it is
 * used to create a print job for the actual printing process. 
 * </p>
 * @see javax.print.DocPrintJob
 * 
Tom Tromey committed
58 59 60 61 62
 * @author Michael Koch (konqueror@gmx.de)
 */
public interface PrintService
{
  /**
63 64
   * Creates and returns a new print job which is capable to handle all 
   * the document flavors supported by this print service.
Tom Tromey committed
65
   * 
66
   * @return The created print job object.
Tom Tromey committed
67 68 69 70 71 72 73 74
   */
  DocPrintJob createPrintJob();
  
  /**
   * Determines if two services refer to the same underlying service.
   * 
   * @param obj the service to check against
   * 
75 76
   * @return <code>true</code> if both services refer to the same underlying
   * service, <code>false</code> otherwise.
Tom Tromey committed
77 78 79 80
   */
  boolean equals(Object obj);
  
  /**
81
   * Returns the value of the single specified attribute.
Tom Tromey committed
82 83 84
   * 
   * @param category the category of a <code>PrintServiceAttribute</code>
   * 
85 86
   * @return The value of the attribute, or <code>null</code> if the attribute
   * category is not supported by this print service implementation.
Tom Tromey committed
87
   * 
88
   * @throws NullPointerException if category is <code>null</code>.
Tom Tromey committed
89
   * @throws IllegalArgumentException if category is not a class that
90
   * implements <code>PrintServiceAttribute</code>.
Tom Tromey committed
91 92 93 94
   */
  PrintServiceAttribute getAttribute(Class category);
  
  /**
95 96 97 98 99 100 101 102 103
   * Returns the attributes describing this print service. The returned 
   * attributes set is unmodifiable and represents the current state of
   * the print service. As some print service attributes may change 
   * (depends on the print service implementation) a subsequent call to
   * this method may return a different set. To monitor changes a 
   * <code>PrintServiceAttributeListener</code> may be registered. 
   * 
   * @return All the description attributes of this print service.
   * @see #addPrintServiceAttributeListener(PrintServiceAttributeListener)
Tom Tromey committed
104 105 106 107
   */
  PrintServiceAttributeSet getAttributes();

  /**
108 109 110 111 112 113 114 115 116
   * Determines and returns the default value for a given attribute category
   * of this print service.
   * <p>
   * A return value of <code>null</code> means either that the print service
   * does not support the attribute category or there is no default value
   * available for this category. To distinguish these two case one can test
   * with {@link #isAttributeCategorySupported(Class)} if the category is 
   * supported.
   * </p>
Tom Tromey committed
117 118 119
   * 
   * @param category the category of the attribute
   * 
120
   * @return The default value, or <code>null</code>.
Tom Tromey committed
121
   * 
122
   * @throws NullPointerException if <code>category</code> is <code>null</code>
Tom Tromey committed
123 124 125 126 127 128 129
   * @throws IllegalArgumentException if <code>category</code> is a class
   * not implementing <code>Attribute</code> 
   */
  Object getDefaultAttributeValue(Class category);
  
  /**
   * Returns the name of this print service.
130
   * This may be the value of the <code>PrinterName</code> attribute.
Tom Tromey committed
131
   * 
132
   * @return The print service name.
Tom Tromey committed
133 134 135 136
   */
  String getName();
  
  /**
137
   * Returns a factory for UI components if supported by the print service.
Tom Tromey committed
138
   * 
139
   * @return A factory for UI components or <code>null</code>.
Tom Tromey committed
140 141 142 143 144 145
   */
  ServiceUIFactory getServiceUIFactory();
  
  /**
   * Returns all supported attribute categories.
   * 
146
   * @return The class array of all supported attribute categories.
Tom Tromey committed
147 148 149 150
   */
  Class[] getSupportedAttributeCategories();
  
  /**
151 152 153 154 155 156 157 158 159 160 161 162 163 164
   * Determines and returns all supported attribute values of a given 
   * attribute category a client can use when setting up a print job 
   * for this print service. 
   * <p>
   * The returned object may be one of the following types:
   * <ul>
   * <li>A single instance of the attribute category to indicate that any 
   * value will be supported.</li>
   * <li>An array of the same type as the attribute category to test, 
   * containing all the supported values for this category.</li>
   * <li>A single object (of any other type than the attribute category) 
   * which indicates bounds on the supported values.</li> 
   * </ul> 
   * </p>
Tom Tromey committed
165 166
   * 
   * @param category the attribute category to test
167 168 169
   * @param flavor the document flavor to use, or <code>null</code>
   * @param attributes set of attributes for a supposed job, 
   * or <code>null</code>
Tom Tromey committed
170
   * 
171 172 173
   * @return A object (as defined above) indicating the supported values 
   * for the given attribute category, or <code>null</code> if this print 
   * service doesn't support the given attribute category at all.
Tom Tromey committed
174 175 176 177 178 179 180 181 182
   * 
   * @throws NullPointerException if <code>category</code> is null
   * @throws IllegalArgumentException if <code>category</code> is a class not
   * implementing <code>Attribute</code>, or if <code>flavor</code> is not
   * supported
   */
  Object getSupportedAttributeValues(Class category, DocFlavor flavor, AttributeSet attributes);
  
  /**
183 184 185 186 187 188 189 190 191 192
   * Determines and returns an array of all supported document flavors which
   * can be used to supply print data to this print service. 
   * <p>
   * The supported attribute categories may differ between the supported
   * document flavors. To test for supported attributes one can use the
   * {@link #getUnsupportedAttributes(DocFlavor, AttributeSet)} method with
   * the specific doc flavor and attributes set.
   * </p>
   * 
   * @return The supported document flavors.
Tom Tromey committed
193 194 195 196
   */
  DocFlavor[] getSupportedDocFlavors();
  
  /**
197 198 199 200 201 202 203 204 205 206 207 208 209
   * Identifies all the unsupported attributes of the given set of attributes
   * in the context of the specified document flavor. 
   * <p>
   * The given flavor has to be supported by the print service (use 
   * {@link #isDocFlavorSupported(DocFlavor)} to verify). The method will 
   * return <code>null</code> if all given attributes are supported. Otherwise
   * a set of unsupported attributes are returned. The attributes in the
   * returned set may be completely unsupported or only the specific requested
   * value. If flavor is <code>null</code> the default document flavor of the 
   * print service is used in the identification process.
   * </p>
   * 
   * @param flavor document flavor to test, or <code>null</code>.
Tom Tromey committed
210 211
   * @param attributes set of printing attributes for a supposed job
   * 
212 213 214
   * @return <code>null</code> if this print service supports all the given 
   * attributes for the specified doc flavor. Otherwise the set of unsupported
   * attributes are returned.
Tom Tromey committed
215 216 217 218
   * 
   * @throws IllegalArgumentException if <code>flavor</code> is unsupported
   */
  AttributeSet getUnsupportedAttributes(DocFlavor flavor, AttributeSet attributes);
219

Tom Tromey committed
220 221
  
  /**
222
   * Returns a hashcode for this print service.
Tom Tromey committed
223
   * 
224
   * @return The hashcode.
Tom Tromey committed
225 226 227 228
   */
  int hashCode();
  
  /**
229 230 231 232
   * Determines a given attribute category is supported by this 
   * print service implementation. This only tests for the category
   * not for any specific values of this category nor in the context
   * of a specific document flavor.
Tom Tromey committed
233 234 235 236
   * 
   * @param category the category to check
   * 
   * @return <code>true</code> if <code>category</code> is supported,
237
   * <code>false</code> otherwise.
Tom Tromey committed
238
   * 
239
   * @throws NullPointerException if <code>category</code> is <code>null</code>
Tom Tromey committed
240 241 242 243 244 245
   * @throws IllegalArgumentException if <code>category</code> is a class not
   * implementing <code>Attribute</code>.
   */
  boolean isAttributeCategorySupported(Class category);
  
  /**
246 247 248 249 250 251 252 253 254
   * Determines if a given attribute value is supported when creating a print 
   * job for this print service. 
   * <p>
   * If either the document flavor or the provided attributes are 
   * <code>null</code> it is determined if the given attribute value is 
   * supported in some combination of the available document flavors and
   * attributes of the print service. Otherwise it is checked for the
   * specific context of the given document flavor/attributes set.
   * </p>
Tom Tromey committed
255 256
   * 
   * @param attrval the attribute value to check
257 258
   * @param flavor the document flavor to use, or <code>null</code>.
   * @param attributes set of attributes to use, or <code>null</code>.
Tom Tromey committed
259
   * 
260 261
   * @return <code>true</code> if the attribute value is supported in the
   * requested context, <code>false</code> otherwise.
Tom Tromey committed
262
   * 
263
   * @throws NullPointerException if <code>attrval</code> is <code>null</code>.
Tom Tromey committed
264 265 266 267 268 269
   * @throws IllegalArgumentException if <code>flavor</code> is not supported
   * by this print service
   */
  boolean isAttributeValueSupported(Attribute attrval, DocFlavor flavor, AttributeSet attributes);
  
  /**
270
   * Determines if a given document flavor is supported or not.
Tom Tromey committed
271 272 273 274
   * 
   * @param flavor the document flavor to check
   * 
   * @return <code>true</code> if <code>flavor</code> is supported,
275
   * <code>false</code> otherwise.
Tom Tromey committed
276
   * 
277
   * @throws NullPointerException if <code>flavor</code> is null.
Tom Tromey committed
278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294
   */
  boolean isDocFlavorSupported(DocFlavor flavor);
  
  /**
   * Registers a print service attribute listener to this print service.
   * 
   * @param listener the listener to add
   */
  void addPrintServiceAttributeListener(PrintServiceAttributeListener listener);
  
  /**
   * De-registers a print service attribute listener from this print service.
   * 
   * @param listener the listener to remove
   */
  void removePrintServiceAttributeListener(PrintServiceAttributeListener listener);
}