@Override
public void paintComponent(Graphics g)
{
+ super.paintComponent(g);
+
updateViewport();
// img is a cached version of the last view we drew
{
return;
}
- BufferedImage lcimg = new BufferedImage(img.getWidth(), img.getHeight(),
- img.getType());
- Graphics2D g2d = lcimg.createGraphics();
- g2d.drawImage(img, 0, 0, null);
- g2d.dispose();
-
-
- // BufferedImage lcimg = img; // take reference since other threads may null
- // img and call later.
- super.paintComponent(g);
BufferedImage selectImage = drawSelectionGroup();
- if (lcimg != null
- && (fastPaint
- || (getVisibleRect().width != g.getClipBounds().width) || (getVisibleRect().height != g
- .getClipBounds().height)))
+ if (fastPaint || (getVisibleRect().width != g.getClipBounds().width)
+ || (getVisibleRect().height != g.getClipBounds().height))
{
- Graphics2D g2 = (Graphics2D) lcimg.getGraphics();
-
- // overlay selection group on lcimg
- if (selectImage != null)
- {
- g2.setComposite(
- AlphaComposite.getInstance(AlphaComposite.SRC_OVER));
- g2.drawImage(selectImage, 0, 0, this);
- }
+ BufferedImage lcimg = buildLocalImage(selectImage);
g.drawImage(lcimg, 0, 0, this);
fastPaint = false;
ranges.getStartSeq(), ranges.getEndSeq(), 0);
}
- lcimg = new BufferedImage(img.getWidth(), img.getHeight(),
+ BufferedImage lcimg = buildLocalImage(selectImage);
+ g.drawImage(lcimg, 0, 0, this);
+ }
+
+ /*
+ * Make a local image by combining the cached image img
+ * with any selection
+ */
+ private BufferedImage buildLocalImage(BufferedImage selectImage)
+ {
+ // clone the cached image
+ BufferedImage lcimg = new BufferedImage(img.getWidth(), img.getHeight(),
img.getType());
- g2d = lcimg.createGraphics();
+ Graphics2D g2d = lcimg.createGraphics();
g2d.drawImage(img, 0, 0, null);
- g2d.dispose();
-
- Graphics2D g2 = (Graphics2D) lcimg.getGraphics();
// overlay selection group on lcimg
if (selectImage != null)
{
- g2.setComposite(
+ g2d.setComposite(
AlphaComposite.getInstance(AlphaComposite.SRC_OVER));
- g2.drawImage(selectImage, 0, 0, this);
+ g2d.drawImage(selectImage, 0, 0, this);
}
- g.drawImage(lcimg, 0, 0, this);
+ g2d.dispose();
+
+ return lcimg;
}
private void paintSeqGroup()