KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jimm > datavision > layout > swing > SwingPage


1 package jimm.datavision.layout.swing;
2 import java.awt.*;
3 import java.awt.print.*;
4 import javax.swing.JPanel JavaDoc;
5
6 /**
7  * A swing page is a single printable page from a report.
8  *
9  * @see SwingLE
10  * @author Jim Menard, <a HREF="mailto:jimm@io.com">jimm@io.com</a>
11  */

12 class SwingPage extends JPanel JavaDoc implements Printable {
13
14 protected Dimension preferredSize;
15
16 /**
17  * Constructor.
18  */

19 public SwingPage() {
20     setLayout(null);
21     setBackground(Color.white);
22 }
23
24 /** Needed because we use a null layout. */
25 public void setPreferredSize(Dimension dim) {
26     preferredSize = dim;
27 }
28
29 /** Needed because we use a null layout. */
30 public Dimension getPreferredSize() {
31     return preferredSize;
32 }
33
34 /**
35  * Print a single page.
36  */

37 public int print(Graphics g, PageFormat pf, int pageIndex)
38     throws PrinterException
39 {
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 }
51
Popular Tags