X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FAnnotationPanel.java;h=4ead210a6f4b778975db4bf191e190ae0579b62c;hb=dad6a2d9da7abf2a26add4e862bdee11aedfaf58;hp=5f4e9fa85764a103f2d2f67eeaad142b18f577fc;hpb=fab0afc9e1e7a5ca460f0cbd48545536f989a435;p=jalview.git diff --git a/src/jalview/gui/AnnotationPanel.java b/src/jalview/gui/AnnotationPanel.java index 5f4e9fa..4ead210 100755 --- a/src/jalview/gui/AnnotationPanel.java +++ b/src/jalview/gui/AnnotationPanel.java @@ -21,6 +21,7 @@ package jalview.gui; import jalview.datamodel.AlignmentAnnotation; +import jalview.datamodel.AlignmentI; import jalview.datamodel.Annotation; import jalview.datamodel.ColumnSelection; import jalview.datamodel.HiddenColumns; @@ -113,7 +114,7 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI, public volatile BufferedImage fadedImage; - Graphics2D gg; + // private Graphics2D gg; public FontMetrics fm; @@ -760,30 +761,10 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI, @Override public void mouseMoved(MouseEvent evt) { + int yPos = evt.getY(); AlignmentAnnotation[] aa = av.getAlignment().getAlignmentAnnotation(); - if (aa == null) - { - this.setToolTipText(null); - return; - } - - int row = -1; - int height = 0; - - for (int i = 0; i < aa.length; i++) - { - if (aa[i].visible) - { - height += aa[i].height; - } - - if (evt.getY() < height) - { - row = i; - break; - } - } + int row = getRowIndex(yPos, aa); if (row == -1) { @@ -793,6 +774,7 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI, int column = (evt.getX() / av.getCharWidth()) + av.getRanges().getStartRes(); + column = Math.min(column, av.getRanges().getEndRes()); if (av.hasHiddenColumns()) { @@ -804,8 +786,9 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI, if (row > -1 && ann.annotations != null && column < ann.annotations.length) { - buildToolTip(ann, column, aa); - setStatusMessage(column, ann); + setToolTipText(buildToolTip(ann, column, aa)); + String msg = getStatusMessage(av.getAlignment(), column, ann); + ap.alignFrame.setStatus(msg); } else { @@ -815,15 +798,51 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI, } /** - * Builds a tooltip for the annotation at the current mouse position. + * Answers the index in the annotations array of the visible annotation at the + * given y position. This is done by adding the heights of visible annotations + * until the y position has been exceeded. Answers -1 if no annotations are + * visible, or the y position is below all annotations. + * + * @param yPos + * @param aa + * @return + */ + static int getRowIndex(int yPos, AlignmentAnnotation[] aa) + { + if (aa == null) + { + return -1; + } + int row = -1; + int height = 0; + + for (int i = 0; i < aa.length; i++) + { + if (aa[i].visible) + { + height += aa[i].height; + } + + if (height > yPos) + { + row = i; + break; + } + } + return row; + } + + /** + * Answers a tooltip for the annotation at the current mouse position * * @param ann * @param column * @param anns */ - void buildToolTip(AlignmentAnnotation ann, int column, + static String buildToolTip(AlignmentAnnotation ann, int column, AlignmentAnnotation[] anns) { + String tooltip = null; if (ann.graphGroup > -1) { StringBuilder tip = new StringBuilder(32); @@ -845,35 +864,39 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI, if (tip.length() != 6) { tip.setLength(tip.length() - 4); - this.setToolTipText(tip.toString() + ""); + tooltip = tip.toString() + ""; } } - else if (ann.annotations[column] != null) + else if (column < ann.annotations.length + && ann.annotations[column] != null) { String description = ann.annotations[column].description; if (description != null && description.length() > 0) { - this.setToolTipText(JvSwingUtils.wrapTooltip(true, description)); + tooltip = JvSwingUtils.wrapTooltip(true, description); } else { - this.setToolTipText(null); // no tooltip if null or empty description + tooltip = null; // no tooltip if null or empty description } } else { // clear the tooltip. - this.setToolTipText(null); + tooltip = null; } + return tooltip; } /** - * Constructs and displays the status bar message + * Constructs and returns the status bar message * + * @param al * @param column * @param ann */ - void setStatusMessage(int column, AlignmentAnnotation ann) + static String getStatusMessage(AlignmentI al, int column, + AlignmentAnnotation ann) { /* * show alignment column and annotation description if any @@ -882,7 +905,7 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI, text.append(MessageManager.getString("label.column")).append(" ") .append(column + 1); - if (ann.annotations[column] != null) + if (column < ann.annotations.length && ann.annotations[column] != null) { String description = ann.annotations[column].description; if (description != null && description.trim().length() > 0) @@ -898,7 +921,7 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI, SequenceI seqref = ann.sequenceRef; if (seqref != null) { - int seqIndex = av.getAlignment().findIndex(seqref); + int seqIndex = al.findIndex(seqref); if (seqIndex != -1) { text.append(", ").append(MessageManager.getString("label.sequence")) @@ -908,7 +931,7 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI, { text.append(" "); String name; - if (av.getAlignment().isNucleotide()) + if (al.isNucleotide()) { name = ResidueProperties.nucleotideName .get(String.valueOf(residue)); @@ -929,7 +952,7 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI, } } - ap.alignFrame.setStatus(text.toString()); + return text.toString(); } /** @@ -971,6 +994,7 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI, } private volatile boolean imageFresh = false; + private Rectangle visibleRect = new Rectangle(), clipBounds = new Rectangle(); /** * DOCUMENT ME! @@ -981,17 +1005,27 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI, @Override public void paintComponent(Graphics g) { - super.paintComponent(g); - + + // BH: note that this method is generally recommended to + // call super.paintComponent(g). Otherwise, the children of this + // component will not be rendered. That is not needed here + // because AnnotationPanel does not have any children. It is + // just a JPanel contained in a JViewPort. + + computeVisibleRect(visibleRect); + g.setColor(Color.white); - g.fillRect(0, 0, getWidth(), getHeight()); + g.fillRect(0, 0, visibleRect.width, visibleRect.height); if (image != null) { - if (fastPaint || (getVisibleRect().width != g.getClipBounds().width) - || (getVisibleRect().height != g.getClipBounds().height)) + // BH 2018 optimizing generation of new Rectangle(). + if (fastPaint || (visibleRect.width != (clipBounds = g.getClipBounds(clipBounds)).width) + || (visibleRect.height != clipBounds.height)) { - g.drawImage(image, 0, 0, this); + + + g.drawImage(image, 0, 0, this); fastPaint = false; return; } @@ -1002,6 +1036,7 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI, { return; } + Graphics2D gg; if (image == null || imgWidth != image.getWidth(this) || image.getHeight(this) != getHeight()) { @@ -1037,10 +1072,14 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI, gg.setColor(Color.white); gg.fillRect(0, 0, imgWidth, image.getHeight()); imageFresh = true; + } else { + gg = (Graphics2D) image.getGraphics(); + } drawComponent(gg, av.getRanges().getStartRes(), av.getRanges().getEndRes() + 1); + gg.dispose(); imageFresh = false; g.drawImage(image, 0, 0, this); } @@ -1058,7 +1097,7 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI, */ public void fastPaint(int horizontal) { - if ((horizontal == 0) || gg == null + if ((horizontal == 0) || image == null || av.getAlignment().getAlignmentAnnotation() == null || av.getAlignment().getAlignmentAnnotation().length < 1 || av.isCalcInProgress()) @@ -1071,6 +1110,8 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI, int er = av.getRanges().getEndRes() + 1; int transX = 0; + Graphics2D gg = (Graphics2D) image.getGraphics(); + gg.copyArea(0, 0, imgWidth, getHeight(), -horizontal * av.getCharWidth(), 0); @@ -1090,6 +1131,8 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI, gg.translate(-transX, 0); + gg.dispose(); + fastPaint = true; // Call repaint on alignment panel so that repaints from other alignment @@ -1233,7 +1276,7 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI, ap = null; image = null; fadedImage = null; - gg = null; +// gg = null; _mwl = null; /* @@ -1287,7 +1330,7 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI, * hscroll, status bar, insets. */ int stuff = (ap.getViewName() != null ? 30 : 0) - + (Platform.isAMac() ? 120 : 140); + + (Platform.isAMacAndNotJS() ? 120 : 140); int availableHeight = ap.alignFrame.getHeight() - stuff; int rowHeight = av.getCharHeight();