1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
|
public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) throws PrinterException {
if (table == null) {
createTable();
}
int pageWidth = (int) pageFormat.getImageableWidth();
int pageHeight = (int) pageFormat.getImageableHeight();
if (!layoutDone) {
centerHeight = pageHeight - (headerHeight + footerHeight);
table.setSize(pageWidth, table.getHeight());
layoutDone = true;
}
double pageX = pageFormat.getImageableX();
double pageY = pageFormat.getImageableY();
Graphics2D g1 = (Graphics2D) graphics;
int fontHeight = g1.getFontMetrics().getHeight();
int fontDescent = g1.getFontMetrics().getDescent();
g1.translate(pageX, pageY);
g1.drawString("GROUPE DSI ", pageWidth / 2 - 35, headerHeight - fontHeight);
g1.translate(0, headerHeight);
int centerY = pageIndex * centerHeight;
g1.translate(0, -centerY);
Shape oldClip = g1.getClip();
g1.setClip(0, centerY, pageWidth, centerHeight);
table.print(g1);
g1.setClip(oldClip);
g1.translate(0, centerY);
g1.translate(0, centerHeight);
g1.drawString("Page : " + (pageIndex + 1), pageWidth / 2 - 35, centerHeight + fontHeight + fontDescent);
g1.translate(0, -(headerHeight + centerHeight));
g1.translate(-pageX, -pageY);
if (pageIndex >= 1) {
return NO_SUCH_PAGE;
}
return PAGE_EXISTS;
} |
Partager