01: package jimm.datavision.layout.swing;
02:
03: import jimm.datavision.UserCancellationException;
04: import jimm.datavision.gui.StatusDialog;
05: import jimm.util.I18N;
06: import java.awt.print.*;
07: import java.util.List;
08:
09: /**
10: * Returns printable pages to a print job.
11: */
12: class SwingPrintBook implements Pageable {
13:
14: protected StatusDialog statusDialog;
15: protected List pageContents;
16: protected PageFormat pageFormat;
17: protected boolean wasBuiltForUs;
18:
19: SwingPrintBook(List pages, PageFormat format) {
20: pageContents = pages;
21: pageFormat = format;
22: }
23:
24: void setStatusDialog(StatusDialog statusDialog) {
25: this .statusDialog = statusDialog;
26: }
27:
28: public int getNumberOfPages() {
29: return pageContents.size();
30: }
31:
32: public PageFormat getPageFormat(int pageIndex) {
33: return pageFormat;
34: }
35:
36: /**
37: * Returns the specified swing page. If the page has already been constructed
38: * for display, we return that page. If it has not, we create and return
39: * a new, temporary page.
40: */
41: public Printable getPrintable(int pageIndex) {
42: SwingPageContents contents;
43:
44: // "Forget" previous page if it was built 'specially for this print job.
45: if (wasBuiltForUs) {
46: contents = (SwingPageContents) pageContents
47: .get(pageIndex - 1);
48: contents.forgetPage();
49: }
50:
51: // If user cancelled, tell the rest of the world.
52: if (statusDialog.isCancelled()) {
53: throw new UserCancellationException();
54: }
55: statusDialog.update(I18N.get("SwingPrintBook.printing_page")
56: + ' ' + (pageIndex + 1) + ' '
57: + I18N.get("SwingPrintBook.of") + ' '
58: + getNumberOfPages());
59:
60: contents = (SwingPageContents) pageContents.get(pageIndex);
61: Printable page = null;
62:
63: page = contents.getPage();
64: wasBuiltForUs = !contents.isPageBuilt();
65:
66: return page;
67: }
68:
69: }
|