X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Frenderer%2FOverviewRenderer.java;h=b126465ea99817ff7671c34c3c15570dfbbb4f68;hb=7e04981d43b16398bd5bd2fad98a5216035d90bb;hp=1f3f663e8337af9c5421311d3fe553cd094edf26;hpb=29b74ec57dfed68ee26a19edfd55987c28870241;p=jalview.git diff --git a/src/jalview/renderer/OverviewRenderer.java b/src/jalview/renderer/OverviewRenderer.java index 1f3f663..b126465 100644 --- a/src/jalview/renderer/OverviewRenderer.java +++ b/src/jalview/renderer/OverviewRenderer.java @@ -24,19 +24,26 @@ import jalview.api.AlignmentColsCollectionI; import jalview.api.AlignmentRowsCollectionI; import jalview.api.RendererListenerI; import jalview.datamodel.AlignmentAnnotation; +import jalview.datamodel.AlignmentI; import jalview.datamodel.Annotation; +import jalview.datamodel.SequenceGroup; import jalview.datamodel.SequenceI; import jalview.renderer.seqfeatures.FeatureColourFinder; import jalview.renderer.seqfeatures.FeatureRenderer; import jalview.viewmodel.OverviewDimensions; +import java.awt.AlphaComposite; import java.awt.Color; import java.awt.Graphics; +import java.awt.Graphics2D; import java.awt.image.BufferedImage; import java.beans.PropertyChangeSupport; public class OverviewRenderer { + // transparency of hidden cols/seqs overlay + private final float TRANSPARENCY = 0.5f; + public static final String UPDATE = "OverviewUpdate"; private static final int MAX_PROGRESS = 100; @@ -46,8 +53,6 @@ public class OverviewRenderer private FeatureColourFinder finder; - private jalview.api.SequenceRenderer sr; - // image to render on private BufferedImage miniMe; @@ -63,11 +68,22 @@ public class OverviewRenderer // flag to indicate whether to halt drawing private volatile boolean redraw = false; - public OverviewRenderer(jalview.api.SequenceRenderer seqRenderer, - FeatureRenderer fr, OverviewDimensions od) + // reference to alignment, needed to get sequence groups + private AlignmentI al; + + private ResidueShaderI shader; + + private OverviewResColourFinder resColFinder; + + public OverviewRenderer(FeatureRenderer fr, OverviewDimensions od, + AlignmentI alignment, + ResidueShaderI resshader, OverviewResColourFinder colFinder) { - sr = seqRenderer; finder = new FeatureColourFinder(fr); + resColFinder = colFinder; + + al = alignment; + shader = resshader; pixelsPerCol = od.getPixelsPerCol(); pixelsPerSeq = od.getPixelsPerSeq(); @@ -104,15 +120,17 @@ public class OverviewRenderer { break; } - + // get details of this alignment row - boolean hidden = rows.isHidden(alignmentRow); SequenceI seq = rows.getSequence(alignmentRow); + // rate limiting step when rendering overview for lots of groups + SequenceGroup[] allGroups = al.findAllGroups(seq); + // calculate where this row extends to in pixels int endRow = Math.min(Math.round((seqIndex + 1) * pixelsPerSeq) - 1, miniMe.getHeight() - 1); - + int colIndex = 0; int pixelCol = 0; for (int alignmentCol : cols) @@ -121,22 +139,19 @@ public class OverviewRenderer { break; } - + // calculate where this column extends to in pixels - int endCol = Math.min( - Math.round((colIndex + 1) * pixelsPerCol) - 1, + int endCol = Math.min(Math.round((colIndex + 1) * pixelsPerCol) - 1, miniMe.getWidth() - 1); - + // don't do expensive colour determination if we're not going to use it // NB this is important to avoid performance issues in the overview // panel if (pixelCol <= endCol) { - // determine the colour based on the sequence and column position - rgbcolor = getColumnColourFromSequence(seq, - hidden || cols.isHidden(alignmentCol), alignmentCol, - finder); - + rgbcolor = getColumnColourFromSequence(allGroups, seq, + alignmentCol); + // fill in the appropriate number of pixels for (int row = pixelRow; row <= endRow; ++row) { @@ -150,6 +165,7 @@ public class OverviewRenderer lastUpdate = sendProgressUpdate( (pixelCol + 1) * (endRow - pixelRow), totalPixels, lastRowUpdate, lastUpdate); + pixelCol = endCol + 1; } colIndex++; @@ -166,6 +182,7 @@ public class OverviewRenderer seqIndex++; } + overlayHiddenRegions(rows, cols); // final update to progress bar if present if (redraw) { @@ -197,24 +214,136 @@ public class OverviewRenderer } /* - * Find the colour of a sequence at a specified column position + * Find the RGB value of 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 + * @return colour of sequence at this position, as RGB */ - private int getColumnColourFromSequence(jalview.datamodel.SequenceI seq, - boolean isHidden, int lastcol, FeatureColourFinder fcfinder) + int getColumnColourFromSequence(SequenceGroup[] allGroups, + SequenceI seq, int lastcol) { - Color color = Color.white; + Color color = resColFinder.gapColour; if ((seq != null) && (seq.getLength() > lastcol)) { - color = sr.getResidueColour(seq, lastcol, fcfinder); + color = resColFinder.getResidueColour(true, shader, allGroups, seq, + lastcol, finder); } - if (isHidden) + return color.getRGB(); + } + + /** + * 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 void overlayHiddenRegions(AlignmentRowsCollectionI rows, + AlignmentColsCollectionI cols) + { + if (cols.hasHidden() || rows.hasHidden()) { - color = color.darker().darker(); + 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); } + } - return color.getRGB(); + /** + * 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) + { + // new masking image + BufferedImage hiddenImage = new BufferedImage(width, height, + BufferedImage.TYPE_INT_ARGB); + + int colIndex = 0; + int pixelCol = 0; + + Color hidden = resColFinder.getHiddenColour(); + + Graphics2D g2d = (Graphics2D) hiddenImage.getGraphics(); + + // set background to transparent + // g2d.setComposite(AlphaComposite.Clear); + // g2d.fillRect(0, 0, width, height); + + // set next colour to opaque + g2d.setComposite(AlphaComposite.Src); + + for (int alignmentCol : cols) + { + if (redraw) + { + break; + } + + // calculate where this column extends to in pixels + int endCol = Math.min(Math.round((colIndex + 1) * pixelsPerCol) - 1, + hiddenImage.getWidth() - 1); + + if (pixelCol <= endCol) + { + // determine the colour based on the sequence and column position + if (cols.isHidden(alignmentCol)) + { + g2d.setColor(hidden); + g2d.fillRect(pixelCol, 0, endCol - pixelCol + 1, height); + } + + pixelCol = endCol + 1; + } + colIndex++; + + } + + int seqIndex = 0; + int pixelRow = 0; + for (int alignmentRow : rows) + { + if (redraw) + { + break; + } + + // calculate where this row extends to in pixels + int endRow = Math.min(Math.round((seqIndex + 1) * pixelsPerSeq) - 1, + miniMe.getHeight() - 1); + + // get details of this alignment row + if (rows.isHidden(alignmentRow)) + { + g2d.setColor(hidden); + g2d.fillRect(0, pixelRow, width, endRow - pixelRow + 1); + } + pixelRow = endRow + 1; + seqIndex++; + } + + return hiddenImage; } /** @@ -224,15 +353,13 @@ public class OverviewRenderer * the graphics object to draw on * @param anno * alignment annotation information - * @param charWidth - * alignment character width value * @param y * y-position for the annotation graph * @param cols * the collection of columns used in the overview panel */ - public void drawGraph(Graphics g, AlignmentAnnotation anno, int charWidth, - int y, AlignmentColsCollectionI cols) + public void drawGraph(Graphics g, AlignmentAnnotation anno, int y, + AlignmentColsCollectionI cols) { Annotation[] annotations = anno.annotations; g.setColor(Color.white); @@ -255,8 +382,7 @@ public class OverviewRenderer } else { - int endCol = Math.min( - Math.round((colIndex + 1) * pixelsPerCol) - 1, + int endCol = Math.min(Math.round((colIndex + 1) * pixelsPerCol) - 1, miniMe.getWidth() - 1); if (annotations[alignmentCol] != null) @@ -270,7 +396,8 @@ public class OverviewRenderer g.setColor(annotations[alignmentCol].colour); } - height = (int) ((annotations[alignmentCol].value / anno.graphMax) * y); + height = (int) ((annotations[alignmentCol].value / anno.graphMax) + * y); if (height > y) { height = y; @@ -287,6 +414,13 @@ public class OverviewRenderer MAX_PROGRESS); } + /** + * 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)