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 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
| int x = (int)Math.ceil( pageFormat.getImageableX( ) );
int y = (int)Math.ceil( pageFormat.getImageableY( ) );
int width = (int)Math.ceil( pageFormat.getImageableWidth( ) );
int height = (int)Math.ceil( pageFormat.getImageableHeight( ) );
int orientation = pageFormat.getOrientation( );
scale = width / (double)c_list.getTable( )
.getColumnModel( )
.getTotalColumnWidth( );
if( !layoutDone ) {
columnHeaderHeight = c_list.getTable( )
.getTableHeader( )
.getHeight( );
headerHeight = 40;
footerHeight = 40;
int rowHeight = ( c_list.getTable( )
.getRowHeight( ) + c_list.getTable( )
.getRowMargin( ) );
int rowNumber = c_list.getModel( )
.getRowCount( );
// Dimension de l'image
int imageWidth = width;
int imageHeight = headerHeight + ( rowNumber * rowHeight );
// Changer la taille de la Jtable
Dimension oldSize = getSize( );
setSize( imageWidth,imageHeight );
// Créer l'image.
image = new BufferedImage( imageWidth,imageHeight,BufferedImage.TYPE_INT_RGB );
Graphics2D g2d = image.createGraphics( );
g2d.scale( scale,scale );
// Ajouter le header à l'image
c_list.getTable( )
.getTableHeader( )
.paint( g2d );
g2d.translate( 0,columnHeaderHeight );
// Ajouter la table à l'image
c_list.getComponent( )
.paint( g2d );
// ou paintAll(g2d);
g2d.dispose( );
setSize( oldSize );
// calculate view port dimensions.
columnHeaderViewPortWidth = imageWidth;
columnHeaderViewPortHeight = columnHeaderHeight;
rowViewPortWidth = imageWidth;
rowViewPortHeight = rowHeight;
int tableImageableHeightForEachPage = height
- ( headerHeight + columnHeaderHeight + footerHeight );
pageNumber = Math.max(
1,
( rowNumber * rowHeight ) / tableImageableHeightForEachPage );
numberOfRowsPerPage = tableImageableHeightForEachPage / rowHeight;
layoutDone = true;
} // end if
// Fin de l'édition de la page en cours du tableau
if( pageIndex>=pageNumber )
return NO_SUCH_PAGE;
g.translate( x,y );
//On imprime le header
g.drawString( nom,0,(int)( headerHeight / 2 ) );
DateFormat dateFormat = DateFormat.getDateInstance( DateFormat.FULL,locale );
g.drawString(
dateFormat.format( new Date( ) ),
(int)( ( 7 * width ) / 10 ),
(int)( headerHeight / 2 ) );
g.translate( 0,headerHeight );
g.drawImage( image,0,0,null );
/*BufferedImage columnHeaderImage = image.getSubimage(
0,
0,
columnHeaderViewPortWidth,
columnHeaderViewPortHeight );
g.drawImage( columnHeaderImage,0,0,null );
g.translate( 0,columnHeaderViewPortHeight );
*/
/** @todo Tester ca quand le reste de l'image est plus petit que ce qui s'affiche dans une page (rowViewPortHeight)*/
/*
//int chunkHeight = Math.min(rowViewPortHeight, );
//BufferedImage rowImage = image.getSubimage ( 0 , columnHeaderViewPortHeight + pageIndex * numberOfRowsPerPage , rowViewPortWidth , rowViewPortHeight );
*/
/** @todo Tester ca quand le reste de l'image est plus grand que ce qui s'affiche dans une page (rowViewPortHeight)*/
/*
int chunkHeight = Math.min(
rowViewPortHeight,
image.getHeight( ) - ( columnHeaderHeight + ( pageIndex * rowViewPortHeight ) ) );
BufferedImage rowImage = image.getSubimage(
0,
columnHeaderViewPortHeight + ( pageIndex * numberOfRowsPerPage ),
rowViewPortWidth,
chunkHeight );
g.drawImage( rowImage,0,0,null );*/
g.translate( 0,rowViewPortHeight );
// On imprime le footer
g.drawString( "Page : " + ( pageIndex + 1 ),( (int)width / 2 ) - 35,rowViewPortHeight );
//Retour en haut de la page
g.translate( -x,-y ); |
Partager