| 1 | |
package org.jtheque.utils.print; |
| 2 | |
|
| 3 | |
import java.awt.Component; |
| 4 | |
import java.awt.Graphics; |
| 5 | |
import java.awt.Graphics2D; |
| 6 | |
import java.awt.print.PageFormat; |
| 7 | |
import java.awt.print.Printable; |
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
final class ComponentPrinter implements Printable { |
| 15 | |
private final Component component; |
| 16 | |
|
| 17 | |
|
| 18 | |
|
| 19 | |
|
| 20 | |
|
| 21 | |
|
| 22 | |
ComponentPrinter(Component component) { |
| 23 | 0 | super(); |
| 24 | |
|
| 25 | 0 | this.component = component; |
| 26 | 0 | } |
| 27 | |
|
| 28 | |
@Override |
| 29 | |
public int print(Graphics g, PageFormat pageFormat, int pageIndex) { |
| 30 | 0 | int status = NO_SUCH_PAGE; |
| 31 | |
|
| 32 | 0 | if (pageIndex < PrintUtils.getTotalPageForComponent(pageFormat, component)) { |
| 33 | 0 | Graphics2D g2d = (Graphics2D) g; |
| 34 | 0 | g2d.translate(pageFormat.getImageableX(), |
| 35 | |
pageFormat.getImageableY() - pageIndex * pageFormat.getImageableHeight()); |
| 36 | |
|
| 37 | 0 | PrintUtils.setDoubleBuffered(false, component); |
| 38 | 0 | component.paint(g2d); |
| 39 | 0 | PrintUtils.setDoubleBuffered(true, component); |
| 40 | |
|
| 41 | 0 | status = PAGE_EXISTS; |
| 42 | |
} |
| 43 | |
|
| 44 | 0 | return status; |
| 45 | |
} |
| 46 | |
} |