Category: | Bug report |
Priority: | Low |
Status: | Assigned |
Project: | Severity: | Trivial |
Resolution: | Open |
|
Component: | Reproducibility: | Always |
Assigned to: |
Issue moved from: https://sourceforge.net/tracker/index.php?func=detail&aid=1351327&group_...
[ 1351327 ] The paint- and scroll-performance is slow
Submitted By: Dirk Ziegenbalg - kotzbrocken2
Date Submitted: 2005-11-08 06:59
Last Updated By: Item Submitter - Tracker Item Submitted
Date Last Updated: No updates since submission
Number of Comments: 0
Number of Attachments: 0
Assigned To: Nobody/Anonymous
Priority: 5
Summary:
The paint- and scroll-performance is slow
The paint- and scroll-performance is very slow if you have a zoom greater than 200% and the grid is visible. Otherwise it is only slow (not very ;).
I've found the bottleneck within the classit.businesslogic.ireport.gui.JReportFrame in the method public void drawVoidDoc(Graphics2D g).
After line 3037 the painting of the grid will be done. This is be done by draw vertical and horizintal lines with the distance of the grid. And this can be very
slow. A better way to draw a grid is to create a pattern and fill the content with this pattern. This can be accelerated under most circumstands. And I've changed the method to draw the grid that way. This will speedup the painting about 10 times.
My code looks like this:
<------------------------------ snip
------------------------------->
if (this.isShowGrid()) {
float[] fArray = {2f,2f};
BasicStroke m_Dashed3 = new BasicStroke(1,
BasicStroke.CAP_SQUARE,
BasicStroke.JOIN_BEVEL, 1.0f, fArray, 0.0f);
g.setStroke(m_Dashed3);
int zoomed_grid_size = getZoomedDim(this.gridSize);
// mGridTexture is a member of type TexturePaint
if ( mGridTexture == null ||
mGridTexture.getImage().getWidth() != zoomed_grid_size ) {
BufferedImage img = new BufferedImage(
zoomed_grid_size, zoomed_grid_size,
BufferedImage.TYPE_INT_RGB );
Graphics2D g2 = img.createGraphics();
g2.setColor(Color.WHITE);
g2.fillRect( 0, 0, zoomed_grid_size,
zoomed_grid_size );
g2.setColor( new Color(230,230,230) );
g2.setStroke( m_Dashed3 );
g2.drawLine( zoomed_grid_size-1, 0,
zoomed_grid_size-1, zoomed_grid_size-1 );
g2.drawLine( 0, zoomed_grid_size-1,
zoomed_grid_size-1, zoomed_grid_size-1 );
mGridTexture = new TexturePaint( img, new
Rectangle( 0, 0, zoomed_grid_size, zoomed_grid_size ) );
} // if
g.setPaint( mGridTexture );
g.translate( -horizontal_scroll, -vertical_scroll );
g.fillRect( 10, 10, zoomed_width-1, zoomed_height-1 );
g.translate( horizontal_scroll, vertical_scroll );
}
<------------------------------ snap
------------------------------->
This code replaces this original code:
<------------------------------ snip
------------------------------->
if (this.isShowGrid()) {
Stroke defaultStroke = g.getStroke();
//g.setStroke(new BasicStroke(1, BasicStroke.CAP_BUTT,
// BasicStroke.JOIN_MITER, 1,
// dashPattern, 0));
float[] fArray = {2f,2f};
BasicStroke m_Dashed3 = new BasicStroke(1,
BasicStroke.CAP_SQUARE,
BasicStroke.JOIN_BEVEL, 1.0f, fArray, 0.0f);
g.setStroke(m_Dashed3);
int zoomed_grid_size = getZoomedDim(this.gridSize);
int grid_left = 10+ zoomed_grid_size -
horizontal_scroll;
int line_top = 10-vertical_scroll+1;
int line_bottom =
getZoomedDim(design_height)+10-vertical_scroll-2;
if (zoomed_grid_size>2) {
int i=1;
grid_left = 10 - horizontal_scroll +
getZoomedDim(i*this.gridSize);
while (grid_left <
zoomed_width+10-horizontal_scroll) {
g.drawLine(grid_left, line_top, grid_left,
line_bottom);
i++;
grid_left = 10 - horizontal_scroll +
getZoomedDim(i*this.gridSize);
}
}
int grid_top = 10 - vertical_scroll;
int line_left = 10-horizontal_scroll+1;
int line_right = zoomed_width+10-horizontal_scroll-1;
if (zoomed_grid_size>2) {
int i=1;
grid_top = 10 - vertical_scroll +
getZoomedDim(i*this.gridSize);
while (grid_top < line_bottom ) {
g.drawLine(line_left,grid_top,line_right,grid_top);
i++;
grid_top = 10 - vertical_scroll +
getZoomedDim(i*this.gridSize);
}
}
g.setStroke(defaultStroke);
}
<------------------------------ snap
------------------------------->
Can you integrate this into your code please?
A note beside:
Real performance-speedup will be gained if you use a image as Buffer as you prepared in your code. When you need help with this I could help you.
Regards,
Dirk