Re: speed up print(Graphics g, PageFormat pf, int pageIndex)
My drawGantt method look like this:
public void drawGantt(Graphics2D g2d) {
Graphics komponentPart;
AffineTransform original =g2d.getTransform();
g2d.translate(xFaktor.intValue(), yFaktor.intValue());
g2d.scale(zoomFaktor.doubleValue()/2,zoomFaktor.doubleValue()/2);//zoomFaktor.doubleValue()
int visZaglavlja = drvo.getRowHeight();
g2d.setColor(Color.blue);
g2d.setFont(new Font(pismoStampati, Font.PLAIN, 23));
g2d.drawString(new String("gradilite: "+imeGradilistaPrihvat),50,50);
g2d.setFont(new Font(pismoStampati, Font.PLAIN, 14));
g2d.drawString(new String("voditelj gradilita:
___________________"),50,80);
g2d.drawString(new String("Dana: "+
new java.util.Date(System.currentTimeMillis()).toString()),50,120);
//tree
komponentPart =
g2d.create(30,10+naslov,treePrihvat.getWidth(),treePrihvat.getHeight());
bufferPaint(treePrihvat, komponentPart);
komponentPart =
g2d.create(30+treePrihvat.getWidth(),10+naslov,tablicaPrihvat.getWidth(),zaglavljePrihvat.getHeight());
//header of a JTable
bufferPaint(zaglavljePrihvat, komponentPart);
komponentPart =
g2d.create(30+treePrihvat.getWidth(),10+naslov+zaglavljePrihvat.getHeight(),tablicaPrihvat.getWidth
(),tablicaPrihvat.getHeight());
//table
bufferPaint(tablicaPrihvat, komponentPart);
komponentPart.dispose();
g2d.translate(30+treePrihvat.getWidth()+tablicaPrihvat.getWidth(),20+naslov-zaglGrafa);
//the next methods are drawing gantt.
//It counts coordinates(according to a data from JTable) and
draws fill3DRect.
if (grafikon.prekidacDnMjPreview == true) {
grafikon.iscrtajMjerilo(g2d);
} else {
grafikon.iscrtajMjeriloMjesecno(g2d);
}
}
I got huge chart which I need to cut on a page and I will with the counting
of a Xaxis and Yaxis variables and use it in a code below, but I have one
question for you and I hope it is a last one to not to drag you any more
with my stupid question and also with the bad english.:). So if you be so
kind to look in a code bellow, which is rough draft, and see if I shot the
point you tryijng to describe to me.
BufferedImage bimg2 ;
....
public int print(Graphics g, PageFormat pf, int pageIndex)
throws PrinterException {
Graphics2D g2d = (Graphics2D) g;
g2d.translate((-(int)pf.getImageableWidth())*Xaxis,-(int)pf.getImageableHeight()*Yaxis);
g2d.setClip(((int)pf.getImageableWidth())*Xaxis,(int)pf.getImageableHeight()*Yaxis,(int)pf.getImageableWidth(),(int)
pf.getImageableHeight());
//radovi trenutni
int postojiDaNe = 0;
if (pageIndex > numberOfPages) {
curIndex = 0;
postojiDaNe = Printable.NO_SUCH_PAGE;
} else {
if (currIndex == pageIndex) {
bimg2 = new BufferedImage(xSizeAsPage,ySizeAsPage,
BufferedImage.TYPE_BYTE_GRAY);
g2d = bimg2.createGraphics();
g2d.setColor(Color.white);
g2d.fillRect(0, 0,xSizeAsPage,ySizeAsPage);
drawGantt(g2d);
curIndex = curIndex+1;
} else {
// probably dispose buffer if isn't null and
buffer = (Image)bimg2;
//Does this will speed up the printing ???
g2d.drawImage(buffer,0,0,this);
}
System.gc();
postojiDaNe = Printable.PAGE_EXISTS;
}
return postojiDaNe;
}