X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fjalview%2Fgui%2FAnnotationPanel.java;h=260b771adeeab0b37400587f82ea5f32a6dd0f4f;hb=948bd3bcbacc509da0cefaae3eedd97300a6ccce;hp=3dee5a8c3723d440954a062ed3917e2023cd56ce;hpb=bef980d8536bd7da240abcbf357e3ed3b064b523;p=jalview.git diff --git a/src/jalview/gui/AnnotationPanel.java b/src/jalview/gui/AnnotationPanel.java index 3dee5a8..260b771 100755 --- a/src/jalview/gui/AnnotationPanel.java +++ b/src/jalview/gui/AnnotationPanel.java @@ -31,6 +31,7 @@ import jalview.schemes.ResidueProperties; import jalview.util.Comparison; import jalview.util.MessageManager; import jalview.viewmodel.ViewportListenerI; +import jalview.viewmodel.ViewportRanges; import java.awt.AlphaComposite; import java.awt.Color; @@ -284,7 +285,8 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI, if (anot.length < av.getColumnSelection().getMax()) { - Annotation[] temp = new Annotation[av.getColumnSelection().getMax() + 2]; + Annotation[] temp = new Annotation[av.getColumnSelection().getMax() + + 2]; System.arraycopy(anot, 0, temp, 0, anot.length); anot = temp; aa[activeRow].annotations = anot; @@ -412,8 +414,8 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI, anot[index] = new Annotation(label, "", type, 0); } - anot[index].secondaryStructure = type != 'S' ? type : label - .length() == 0 ? ' ' : label.charAt(0); + anot[index].secondaryStructure = type != 'S' ? type + : label.length() == 0 ? ' ' : label.charAt(0); anot[index].displayCharacter = label; } @@ -657,15 +659,18 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI, { if (graphStretch > -1) { - av.getAlignment().getAlignmentAnnotation()[graphStretch].graphHeight += graphStretchY - - evt.getY(); - if (av.getAlignment().getAlignmentAnnotation()[graphStretch].graphHeight < 0) + av.getAlignment() + .getAlignmentAnnotation()[graphStretch].graphHeight += graphStretchY + - evt.getY(); + if (av.getAlignment() + .getAlignmentAnnotation()[graphStretch].graphHeight < 0) { - av.getAlignment().getAlignmentAnnotation()[graphStretch].graphHeight = 0; + av.getAlignment() + .getAlignmentAnnotation()[graphStretch].graphHeight = 0; } graphStretchY = evt.getY(); adjustPanelHeight(); - ap.paintAlignment(true); + ap.paintAlignment(false, false); } else { @@ -719,7 +724,7 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI, if (av.hasHiddenColumns()) { column = av.getAlignment().getHiddenColumns() - .adjustForHiddenColumns(column); + .visibleToAbsoluteColumn(column); } AlignmentAnnotation ann = aa[row]; @@ -777,6 +782,10 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI, { this.setToolTipText(JvSwingUtils.wrapTooltip(true, description)); } + else + { + this.setToolTipText(null); // no tooltip if null or empty description + } } else { @@ -819,8 +828,7 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI, int seqIndex = av.getAlignment().findIndex(seqref); if (seqIndex != -1) { - text.append(", ") - .append(MessageManager.getString("label.sequence")) + text.append(", ").append(MessageManager.getString("label.sequence")) .append(" ").append(seqIndex + 1); char residue = seqref.getCharAt(column); if (!Comparison.isGap(residue)) @@ -829,16 +837,17 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI, String name; if (av.getAlignment().isNucleotide()) { - name = ResidueProperties.nucleotideName.get(String - .valueOf(residue)); - text.append(" Nucleotide: ").append( - name != null ? name : residue); + name = ResidueProperties.nucleotideName + .get(String.valueOf(residue)); + text.append(" Nucleotide: ") + .append(name != null ? name : residue); } else { - name = 'X' == residue ? "X" : ('*' == residue ? "STOP" - : ResidueProperties.aa2Triplet.get(String - .valueOf(residue))); + name = 'X' == residue ? "X" + : ('*' == residue ? "STOP" + : ResidueProperties.aa2Triplet + .get(String.valueOf(residue))); text.append(" Residue: ").append(name != null ? name : residue); } int residuePos = seqref.findPosition(column); @@ -899,6 +908,8 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI, @Override public void paintComponent(Graphics g) { + super.paintComponent(g); + g.setColor(Color.white); g.fillRect(0, 0, getWidth(), getHeight()); @@ -912,8 +923,8 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI, return; } } - imgWidth = (av.getRanges().getEndRes() - av.getRanges().getStartRes() + 1) - * av.getCharWidth(); + imgWidth = (av.getRanges().getEndRes() - av.getRanges().getStartRes() + + 1) * av.getCharWidth(); if (imgWidth < 1) { return; @@ -923,8 +934,9 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI, { try { - image = new BufferedImage(imgWidth, ap.getAnnotationPanel() - .getHeight(), BufferedImage.TYPE_INT_RGB); + image = new BufferedImage(imgWidth, + ap.getAnnotationPanel().getHeight(), + BufferedImage.TYPE_INT_RGB); } catch (OutOfMemoryError oom) { try @@ -953,9 +965,9 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI, gg.fillRect(0, 0, imgWidth, image.getHeight()); imageFresh = true; } - - drawComponent(gg, av.getRanges().getStartRes(), av.getRanges() - .getEndRes() + 1); + + drawComponent(gg, av.getRanges().getStartRes(), + av.getRanges().getEndRes() + 1); imageFresh = false; g.drawImage(image, 0, 0, this); } @@ -971,7 +983,7 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI, * @param horizontal * repaint with horizontal shift in alignment */ - public void fastPaint(int horizontal, boolean isresize) + public void fastPaint(int horizontal) { if ((horizontal == 0) || gg == null || av.getAlignment().getAlignmentAnnotation() == null @@ -985,45 +997,18 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI, int sr = av.getRanges().getStartRes(); int er = av.getRanges().getEndRes() + 1; int transX = 0; - long stime; - long mtime; - if (isresize) - { - imgWidth = (av.getRanges().getEndRes() - av.getRanges().getStartRes() - + 1) * av.getCharWidth(); - - if (imgWidth > 0) - { - BufferedImage newimage = new BufferedImage(imgWidth, - ap.getAnnotationPanel().getHeight(), - BufferedImage.TYPE_INT_ARGB); + gg.copyArea(0, 0, imgWidth, getHeight(), + -horizontal * av.getCharWidth(), 0); - gg = (Graphics2D) newimage.getGraphics(); - gg.setFont(av.getFont()); - gg.drawImage(image, null, 0, 0); - image = newimage; - - transX = (er - horizontal - sr) * av.getCharWidth(); - sr = er - horizontal - sr; - } + if (horizontal > 0) // scrollbar pulled right, image to the left + { + transX = (er - sr - horizontal) * av.getCharWidth(); + sr = er - horizontal; } - else + else if (horizontal < 0) { - stime = System.currentTimeMillis(); - gg.copyArea(0, 0, imgWidth, getHeight(), - -horizontal * av.getCharWidth(), 0); - mtime = System.currentTimeMillis(); - - if (horizontal > 0) // scrollbar pulled right, image to the left - { - transX = (er - sr - horizontal) * av.getCharWidth(); - sr = er - horizontal; - } - else if (horizontal < 0) - { - er = sr - horizontal; - } + er = sr - horizontal; } gg.translate(transX, 0); @@ -1031,17 +1016,13 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI, drawComponent(gg, sr, er); gg.translate(-transX, 0); - long dtime = System.currentTimeMillis(); + fastPaint = true; - repaint(); - long rtime = System.currentTimeMillis(); - if (debugRedraw) - { - System.err.println("Scroll:\t" + horizontal + "\tCopyArea:\t" - + (mtime - stime) + "\tDraw component:\t" + (dtime - mtime) - + "\tRepaint call:\t" + (rtime - dtime)); - } + // Call repaint on alignment panel so that repaints from other alignment + // panel components can be aggregated. Otherwise performance of the overview + // window and others may be adversely affected. + av.getAlignPanel().repaint(); } private volatile boolean lastImageGood = false; @@ -1070,8 +1051,8 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI, // and draw a faded image until the calculation // has completed if (lastImageGood - && (fadedImage == null || fadedImage.getWidth() != imgWidth || fadedImage - .getHeight() != image.getHeight())) + && (fadedImage == null || fadedImage.getWidth() != imgWidth + || fadedImage.getHeight() != image.getHeight())) { // System.err.println("redraw faded image ("+(fadedImage==null ? // "null image" : "") + " lastGood="+lastImageGood+")"); @@ -1083,8 +1064,8 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI, fadedG.setColor(Color.white); fadedG.fillRect(0, 0, imgWidth, image.getHeight()); - fadedG.setComposite(AlphaComposite.getInstance( - AlphaComposite.SRC_OVER, .3f)); + fadedG.setComposite( + AlphaComposite.getInstance(AlphaComposite.SRC_OVER, .3f)); fadedG.drawImage(image, 0, 0, this); } @@ -1125,8 +1106,8 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI, return; } - lastImageGood = renderer.drawComponent(this, av, g, activeRow, - startRes, endRes); + lastImageGood = renderer.drawComponent(this, av, g, activeRow, startRes, + endRes); if (!lastImageGood && fadedImage == null) { fadedImage = oldFaded; @@ -1195,14 +1176,23 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI, public void propertyChange(PropertyChangeEvent evt) { // Respond to viewport range changes (e.g. alignment panel was scrolled) - if (evt.getPropertyName().equals("startres")) + // Both scrolling and resizing change viewport ranges: scrolling changes + // both start and end points, but resize only changes end values. + // Here we only want to fastpaint on a scroll, with resize using a normal + // paint, so scroll events are identified as changes to the horizontal or + // vertical start value. + if (evt.getPropertyName().equals(ViewportRanges.STARTRES)) { - fastPaint((int) evt.getNewValue() - (int) evt.getOldValue(), false); + fastPaint((int) evt.getNewValue() - (int) evt.getOldValue()); } - else if (evt.getPropertyName().equals("endres")) + else if (evt.getPropertyName().equals(ViewportRanges.STARTRESANDSEQ)) { - // resize - fastPaint((int) evt.getNewValue() - (int) evt.getOldValue(), true); + fastPaint(((int[]) evt.getNewValue())[0] + - ((int[]) evt.getOldValue())[0]); + } + else if (evt.getPropertyName().equals(ViewportRanges.MOVE_VIEWPORT)) + { + repaint(); } } }