2 * (C) Copyright IBM Corp. 1998-2004. All Rights Reserved.
\r
4 * The program is provided "as is" without any warranty express or
\r
5 * implied, including the warranty of non-infringement and the implied
\r
6 * warranties of merchantibility and fitness for a particular purpose.
\r
7 * IBM will not be liable for any damages suffered by you as a result
\r
8 * of using the Program. In no event will IBM be liable for any
\r
9 * special, indirect or consequential damages or lost profits even if
\r
10 * IBM has been advised of the possibility of their occurrence. IBM
\r
11 * will not be liable for any third party claims against you.
\r
15 package com.ibm.richtext.print;
\r
17 import com.ibm.richtext.styledtext.MConstText;
\r
18 import com.ibm.richtext.textlayout.attributes.AttributeMap;
\r
20 import java.awt.Frame;
\r
21 import java.awt.Graphics;
\r
22 import java.awt.Rectangle;
\r
24 import java.awt.print.PageFormat;
\r
25 import java.awt.print.Printable;
\r
26 import java.awt.print.PrinterJob;
\r
27 import java.awt.print.PrinterException;
\r
29 final class PrintContext implements Printable {
\r
31 static final String COPYRIGHT =
\r
32 "(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
\r
34 private MConstTextPrintable fPrintable;
\r
36 PrintContext(MConstText text, AttributeMap defaultStyles, PageFormat pf) {
\r
38 int width = (int) Math.round(pf.getImageableWidth());
\r
39 int height = (int) Math.round(pf.getImageableHeight());
\r
40 int left = (((int)Math.round(pf.getWidth())) - width) / 2;
\r
41 int top = (((int)Math.round(pf.getHeight())) - height) / 2;
\r
43 Rectangle pageRect = new Rectangle(left, top, width, height);
\r
44 fPrintable = new MConstTextPrintable(text, defaultStyles, pageRect);
\r
47 public int print(Graphics graphics,
\r
49 int pageIndex) throws PrinterException {
\r
52 throw new PrinterException("save trees");
\r
54 if (fPrintable.print(graphics, pageIndex) == MConstTextPrintable.PAGE_EXISTS) {
\r
58 return NO_SUCH_PAGE;
\r
62 static void userPrintText(MConstText text,
\r
63 AttributeMap defaultStyles,
\r
67 PrinterJob job = PrinterJob.getPrinterJob();
\r
68 job.setJobName(jobTitle);
\r
69 if (job.printDialog()) {
\r
70 job.setPrintable(new PrintContext(text, defaultStyles, job.defaultPage()));
\r
74 catch(PrinterException e) {
\r
75 System.out.println("Printer exception: " + e);
\r