01: package jimm.datavision.layout.swing;
02:
03: import java.awt.*;
04: import java.awt.print.*;
05: import javax.swing.JPanel;
06:
07: /**
08: * A swing page is a single printable page from a report.
09: *
10: * @see SwingLE
11: * @author Jim Menard, <a href="mailto:jimm@io.com">jimm@io.com</a>
12: */
13: class SwingPage extends JPanel implements Printable {
14:
15: protected Dimension preferredSize;
16:
17: /**
18: * Constructor.
19: */
20: public SwingPage() {
21: setLayout(null);
22: setBackground(Color.white);
23: }
24:
25: /** Needed because we use a null layout. */
26: public void setPreferredSize(Dimension dim) {
27: preferredSize = dim;
28: }
29:
30: /** Needed because we use a null layout. */
31: public Dimension getPreferredSize() {
32: return preferredSize;
33: }
34:
35: /**
36: * Print a single page.
37: */
38: public int print(Graphics g, PageFormat pf, int pageIndex)
39: throws PrinterException {
40: // As suggested by Jaume (Tau Ingenieros <tauinge@menta.net>), use
41: // paint instead of paintComponent and resize to page format.
42: Dimension oldSize = getSize();
43: setSize((int) pf.getWidth(), (int) pf.getHeight());
44: print(g);
45: setSize(oldSize);
46:
47: return Printable.PAGE_EXISTS;
48: }
49:
50: }
|