From 3f03cc818538d68c829869c6341112c44cf648d9 Mon Sep 17 00:00:00 2001 From: kiramt Date: Tue, 29 Aug 2017 16:27:40 +0100 Subject: [PATCH] JAL-2664 Updates following review --- src/jalview/api/AlignmentColsCollectionI.java | 7 +++ src/jalview/api/AlignmentRowsCollectionI.java | 7 +++ src/jalview/datamodel/AllColsCollection.java | 6 ++ src/jalview/datamodel/AllRowsCollection.java | 6 ++ src/jalview/datamodel/VisibleColsCollection.java | 6 ++ src/jalview/datamodel/VisibleRowsCollection.java | 6 ++ src/jalview/renderer/OverviewRenderer.java | 68 ++++++++++++++++------ 7 files changed, 88 insertions(+), 18 deletions(-) diff --git a/src/jalview/api/AlignmentColsCollectionI.java b/src/jalview/api/AlignmentColsCollectionI.java index 603da98..44cc587 100644 --- a/src/jalview/api/AlignmentColsCollectionI.java +++ b/src/jalview/api/AlignmentColsCollectionI.java @@ -10,4 +10,11 @@ public interface AlignmentColsCollectionI extends Iterable * @return true if the column at the position is hidden */ public boolean isHidden(int c); + + /** + * Answers if any column in this collection is hidden + * + * @return true if there is at least 1 hidden column + */ + public boolean hasHidden(); } diff --git a/src/jalview/api/AlignmentRowsCollectionI.java b/src/jalview/api/AlignmentRowsCollectionI.java index 09b039d..1e8b0b1 100644 --- a/src/jalview/api/AlignmentRowsCollectionI.java +++ b/src/jalview/api/AlignmentRowsCollectionI.java @@ -14,6 +14,13 @@ public interface AlignmentRowsCollectionI extends Iterable public boolean isHidden(int r); /** + * Answers if any row in this collection is hidden + * + * @return true if there is at least 1 hidden row + */ + public boolean hasHidden(); + + /** * Answers the sequence at the given position in the alignment * * @param r diff --git a/src/jalview/datamodel/AllColsCollection.java b/src/jalview/datamodel/AllColsCollection.java index f84ba95..0700ecd 100644 --- a/src/jalview/datamodel/AllColsCollection.java +++ b/src/jalview/datamodel/AllColsCollection.java @@ -49,4 +49,10 @@ public class AllColsCollection implements AlignmentColsCollectionI { return !hidden.isVisible(c); } + + @Override + public boolean hasHidden() + { + return hidden.hasHiddenColumns(); + } } diff --git a/src/jalview/datamodel/AllRowsCollection.java b/src/jalview/datamodel/AllRowsCollection.java index 502ace4..c52cebf 100644 --- a/src/jalview/datamodel/AllRowsCollection.java +++ b/src/jalview/datamodel/AllRowsCollection.java @@ -59,5 +59,11 @@ public class AllRowsCollection implements AlignmentRowsCollectionI { return alignment.getSequenceAtAbsoluteIndex(seq); } + + @Override + public boolean hasHidden() + { + return (hidden.getSize() > 0); + } } diff --git a/src/jalview/datamodel/VisibleColsCollection.java b/src/jalview/datamodel/VisibleColsCollection.java index 86233ab..8ec1a99 100644 --- a/src/jalview/datamodel/VisibleColsCollection.java +++ b/src/jalview/datamodel/VisibleColsCollection.java @@ -50,4 +50,10 @@ public class VisibleColsCollection implements AlignmentColsCollectionI return false; } + @Override + public boolean hasHidden() + { + return false; + } + } diff --git a/src/jalview/datamodel/VisibleRowsCollection.java b/src/jalview/datamodel/VisibleRowsCollection.java index ce8e8da..3119017 100644 --- a/src/jalview/datamodel/VisibleRowsCollection.java +++ b/src/jalview/datamodel/VisibleRowsCollection.java @@ -56,5 +56,11 @@ public class VisibleRowsCollection implements AlignmentRowsCollectionI { return alignment.getSequenceAtAbsoluteIndex(seq); } + + @Override + public boolean hasHidden() + { + return false; + } } diff --git a/src/jalview/renderer/OverviewRenderer.java b/src/jalview/renderer/OverviewRenderer.java index 709816c..1fb2d89 100644 --- a/src/jalview/renderer/OverviewRenderer.java +++ b/src/jalview/renderer/OverviewRenderer.java @@ -84,9 +84,6 @@ public class OverviewRenderer int seqIndex = 0; int pixelRow = 0; - BufferedImage hiddenImage = buildHiddenImage(rows, cols, - miniMe.getWidth(), miniMe.getHeight()); - for (int alignmentRow : rows) { if (redraw) @@ -141,11 +138,20 @@ public class OverviewRenderer seqIndex++; } - return applyMask(hiddenImage, miniMe); + overlayHiddenRegions(rows, cols); + return miniMe; } - /* + /** * Find the colour of a sequence at a specified column position + * + * @param seq + * sequence to get colour for + * @param lastcol + * column position to get colour for + * @param fcfinder + * FeatureColourFinder to use + * @return colour of sequence at this position, as RGB */ private int getColumnColourFromSequence(jalview.datamodel.SequenceI seq, int lastcol, FeatureColourFinder fcfinder) @@ -160,23 +166,42 @@ public class OverviewRenderer return color.getRGB(); } - /* - * Overlay a buffered image (mask) onto another image (image) where mask - * has some transparency so image shows through from below + /** + * Overlay the hidden regions on the overview image + * + * @param rows + * collection of rows the overview is built over + * @param cols + * collection of columns the overview is built over */ - private BufferedImage applyMask(BufferedImage mask, BufferedImage image) + private void overlayHiddenRegions(AlignmentRowsCollectionI rows, + AlignmentColsCollectionI cols) { - Graphics2D g = (Graphics2D) image.getGraphics(); - g.setComposite( - AlphaComposite.getInstance(AlphaComposite.SRC_OVER, - TRANSPARENCY)); - g.drawImage(mask, 0, 0, image.getWidth(), image.getHeight(), null); - return image; + if (cols.hasHidden() || rows.hasHidden()) + { + BufferedImage mask = buildHiddenImage(rows, cols, miniMe.getWidth(), + miniMe.getHeight()); + + Graphics2D g = (Graphics2D) miniMe.getGraphics(); + g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, + TRANSPARENCY)); + g.drawImage(mask, 0, 0, miniMe.getWidth(), miniMe.getHeight(), null); + } } - /* - * Build a masking image of hidden columns and rows to be applied on top - * of the main overview image. + /** + * Build a masking image of hidden columns and rows to be applied on top of + * the main overview image. + * + * @param rows + * collection of rows the overview is built over + * @param cols + * collection of columns the overview is built over + * @param width + * width of overview in pixels + * @param height + * height of overview in pixels + * @return BufferedImage containing mask of hidden regions */ private BufferedImage buildHiddenImage(AlignmentRowsCollectionI rows, AlignmentColsCollectionI cols, int width, int height) @@ -316,6 +341,13 @@ public class OverviewRenderer } } + /** + * Allows redraw flag to be set + * + * @param b + * value to set redraw to: true = redraw is occurring, false = no + * redraw + */ public void setRedraw(boolean b) { synchronized (this) -- 1.7.10.2