Source for java.awt.print.PrinterJob

   1: /* PrinterJob.java -- This job is the printer control class
   2:    Copyright (C) 1999, 2004, 2005  Free Software Foundation, Inc.
   3: 
   4: This file is part of GNU Classpath.
   5: 
   6: GNU Classpath is free software; you can redistribute it and/or modify
   7: it under the terms of the GNU General Public License as published by
   8: the Free Software Foundation; either version 2, or (at your option)
   9: any later version.
  10: 
  11: GNU Classpath is distributed in the hope that it will be useful, but
  12: WITHOUT ANY WARRANTY; without even the implied warranty of
  13: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  14: General Public License for more details.
  15: 
  16: You should have received a copy of the GNU General Public License
  17: along with GNU Classpath; see the file COPYING.  If not, write to the
  18: Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  19: 02110-1301 USA.
  20: 
  21: Linking this library statically or dynamically with other modules is
  22: making a combined work based on this library.  Thus, the terms and
  23: conditions of the GNU General Public License cover the whole
  24: combination.
  25: 
  26: As a special exception, the copyright holders of this library give you
  27: permission to link this library with independent modules to produce an
  28: executable, regardless of the license terms of these independent
  29: modules, and to copy and distribute the resulting executable under
  30: terms of your choice, provided that you also meet, for each linked
  31: independent module, the terms and conditions of the license of that
  32: module.  An independent module is a module which is not derived from
  33: or based on this library.  If you modify this library, you may extend
  34: this exception to your version of the library, but you are not
  35: obligated to do so.  If you do not wish to do so, delete this
  36: exception statement from your version. */
  37: 
  38: 
  39: package java.awt.print;
  40: 
  41: import java.awt.HeadlessException;
  42: 
  43: import javax.print.PrintService;
  44: import javax.print.attribute.PrintRequestAttributeSet;
  45: 
  46: /**
  47:  * This class controls printing.
  48:  *
  49:  * @author Aaron M. Renn (arenn@urbanophile.com)
  50:  */
  51: public abstract class PrinterJob
  52: {
  53:   // The print service associated with this job
  54:   private PrintService printer = null;
  55: 
  56:   /**
  57:    * Creates a new print job.
  58:    *
  59:    * @return A <code>PrinterJob</code> object for the newly created print job.
  60:    */
  61:   public static PrinterJob getPrinterJob()
  62:   {
  63:     // FIXME: Need to fix this to load a default implementation instance.
  64:     return null;
  65:   }
  66: 
  67:   /**
  68:    * Initializes a new instance of <code>PrinterJob</code>. 
  69:    */
  70:   public PrinterJob()
  71:   {
  72:   }
  73: 
  74:   /**
  75:    * Returns the number of copies to be printed.
  76:    *
  77:    * @return The number of copies to be printed.
  78:    */
  79:   public abstract int getCopies();
  80: 
  81:   /**
  82:    * Sets the number of copies to be printed.
  83:    *
  84:    * @param copies The number of copies to be printed.
  85:    */
  86:   public abstract void setCopies(int copies);
  87: 
  88:   /**
  89:    * Returns the name of the print job.
  90:    *
  91:    * @return The name of the print job.
  92:    */
  93:   public abstract String getJobName();
  94: 
  95:   /**
  96:    * Sets the name of the print job.
  97:    *
  98:    * @param job_name The name of the print job.
  99:    */
 100:   public abstract void setJobName(String job_name);
 101: 
 102:   /**
 103:    * Returns the printing user name.
 104:    *
 105:    * @return The printing username.
 106:    */
 107:   public abstract String getUserName();
 108: 
 109:   /**
 110:    * Cancels an in progress print job.
 111:    */
 112:   public abstract void cancel();
 113: 
 114:   /**
 115:    * Tests whether or not this job has been cancelled.
 116:    *
 117:    * @return <code>true</code> if this job has been cancelled, <code>false</code>
 118:    * otherwise.
 119:    */
 120:   public abstract boolean isCancelled();
 121: 
 122:   /**
 123:    * Returns an instance of the default page which will have the default
 124:    * paper and orientation.
 125:    *
 126:    * @return A default instance of <code>PageFormat</code>.
 127:    */
 128:   public PageFormat defaultPage()
 129:   {
 130:     return new PageFormat();
 131:   }
 132: 
 133:   /**
 134:    * Clones the specified <code>PageFormat</code> object then alters the
 135:    * clone so that it represents the default page format.
 136:    *
 137:    * @param page_format The <code>PageFormat</code> to clone.
 138:    *
 139:    * @return A new default page format.
 140:    */
 141:   public abstract PageFormat defaultPage(PageFormat page_format);
 142: 
 143:   /**
 144:    * Displays a dialog box to the user which allows the page format
 145:    * attributes to be modified.
 146:    *
 147:    * @param page_format The <code>PageFormat</code> object to modify.
 148:    *
 149:    * @return The modified <code>PageFormat</code>.
 150:    */
 151:   public abstract PageFormat pageDialog(PageFormat page_format)
 152:     throws HeadlessException;
 153: 
 154:   /**
 155:    * @since 1.4
 156:    */
 157:   public PageFormat pageDialog(PrintRequestAttributeSet attributes)
 158:     throws HeadlessException
 159:   {
 160:     // FIXME: Implement this for real.
 161:     return pageDialog((PageFormat) null);
 162:   }
 163:   
 164:   /**
 165:    * Prints the pages.
 166:    */
 167:   public abstract void print () throws PrinterException;
 168: 
 169:   /**
 170:    * Prints the page with given attributes.
 171:    */
 172:   public void print (PrintRequestAttributeSet attributes)
 173:     throws PrinterException
 174:   {
 175:     print ();
 176:   }
 177: 
 178:   /**
 179:    * Displays a dialog box to the user which allows the print job
 180:    * attributes to be modified.
 181:    *
 182:    * @return <code>false</code> if the user cancels the dialog box,
 183:    * <code>true</code> otherwise.
 184:    */
 185:   public abstract boolean printDialog()
 186:     throws HeadlessException;
 187: 
 188:   /**
 189:    * Displays a dialog box to the user which allows the print job
 190:    * attributes to be modified.
 191:    *
 192:    * @return <code>false</code> if the user cancels the dialog box,
 193:    * <code>true</code> otherwise.
 194:    */
 195:   public boolean printDialog(PrintRequestAttributeSet attributes)
 196:     throws HeadlessException
 197:   {
 198:     // FIXME: Implement this for real.
 199:     return printDialog();
 200:   }
 201: 
 202:   /**
 203:    * This sets the pages that are to be printed.
 204:    *
 205:    * @param pageable The pages to be printed, which may not be <code>null</code>.
 206:    */
 207:   public abstract void setPageable(Pageable pageable);
 208: 
 209:   /**
 210:    * Sets this specified <code>Printable</code> as the one to use for
 211:    * rendering the pages on the print device.
 212:    *
 213:    * @param printable The <code>Printable</code> for the print job.
 214:    */
 215:   public abstract void setPrintable(Printable printable);
 216: 
 217:   /**
 218:    * Sets the <code>Printable</code> and the page format for the pages
 219:    * to be printed.
 220:    *
 221:    * @param printable The <code>Printable</code> for the print job.
 222:    * @param page_format The <code>PageFormat</code> for the print job.
 223:    */
 224:   public abstract void setPrintable(Printable printable, PageFormat page_format);
 225: 
 226:   /**
 227:    * Makes any alterations to the specified <code>PageFormat</code>
 228:    * necessary to make it work with the current printer.  The alterations
 229:    * are made to a clone of the input object, which is then returned.
 230:    *
 231:    * @param page_format The <code>PageFormat</code> to validate.
 232:    *
 233:    * @return The validated <code>PageFormat</code>.
 234:    */
 235:   public abstract PageFormat validatePage(PageFormat page_format);
 236: 
 237:   /**
 238:    * Find and return 2D image print services.
 239:    * 
 240:    * This is the same as calling PrintServiceLookup.lookupPrintServices()
 241:    * with Pageable service-specified DocFlavor.
 242:    * @return Array of PrintService objects, could be empty.
 243:    * @since 1.4
 244:    */
 245:   public static PrintService[] lookupPrintServices()
 246:   {
 247:     return new PrintService[0];
 248:     // FIXME:
 249:     // Enable this when javax.print has this implemented.
 250: //    return PrintServiceLookup.lookupPrintServices(
 251: //          new DocFlavor("application/x-java-jvm-local-objectref",
 252: //                        "java.awt.print.Pageable"),
 253: //          null);
 254:   }
 255: 
 256:   /**
 257:    * Find and return 2D image stream print services.
 258:    * 
 259:    * This is the same as calling
 260:    * StreamPrintServiceFactory.lookupStreamPrintServices()
 261:    * with Pageable service-specified DocFlavor.
 262:    * @param mimeType The output format mime type, or null for any type.
 263:    * @return Array of stream print services, could be empty.
 264:    * @since 1.4
 265:    */
 266:       // FIXME:
 267:       // Enable when javax.print has StreamPrintServiceFactory 
 268: //  public static StreamPrintServiceFactory[] lookupStreamPrintServices(String mimeType)
 269: //  {
 270: //    return StreamPrintServiceFactory.lookupStreamServiceFactories(
 271: //      new DocFlavor("application/x-java-jvm-local-objectref",
 272: //      "java.awt.print.Pageable"),
 273: //        mimeType);
 274: //  }
 275: 
 276:   /**
 277:    * Return the printer for this job.  If print services aren't supported by
 278:    * the subclass, returns null.
 279:    * 
 280:    * @return The associated PrintService.
 281:    * @since 1.4
 282:    */
 283:   public PrintService getPrintService()
 284:   {
 285:     return null;
 286:   }
 287: 
 288:   /**
 289:    * Change the printer for this print job to service.  Subclasses that
 290:    * support setting the print service override this method.  Throws
 291:    * PrinterException when the class doesn't support setting the printer,
 292:    * the service doesn't support Pageable or Printable interfaces for 2D
 293:    * print output.
 294:    * @param service The new printer to use.
 295:    * @throws PrinterException if service is not valid.
 296:    */
 297:   public void setPrintService(PrintService service)
 298:     throws PrinterException
 299:   {
 300:     throw new PrinterException();
 301:   }
 302: }