+ // Paint the track points on top
+ int pointsPainted = 1;
+ try
+ {
+ if (trackOpacity > 0.9f)
+ {
+ // Track is fully opaque, just draw it directly
+ pointsPainted = paintPoints(g);
+ _trackImage = null;
+ }
+ else
+ {
+ // Track is partly transparent, so use a separate BufferedImage
+ if (_trackImage == null || _trackImage.getWidth() != getWidth() || _trackImage.getHeight() != getHeight())
+ {
+ _trackImage = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_ARGB);
+ }
+ // Clear to transparent
+ Graphics2D gTrack = _trackImage.createGraphics();
+ gTrack.setComposite(AlphaComposite.getInstance(AlphaComposite.CLEAR, 0.0f));
+ gTrack.fillRect(0, 0, getWidth(), getHeight());
+ gTrack.setPaintMode();
+ // Draw the track onto this separate image
+ pointsPainted = paintPoints(gTrack);
+ ((Graphics2D) g).setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, trackOpacity));
+ g.drawImage(_trackImage, 0, 0, null);
+ }
+ }
+ catch (NullPointerException npe) {} // ignore, probably due to data being changed during drawing
+ catch (ArrayIndexOutOfBoundsException obe) {} // also ignore
+
+ // Zoom to fit if no points found
+ if (pointsPainted <= 0 && _checkBounds)
+ {
+ zoomToFit();
+ _recalculate = true;
+ repaint();
+ }