X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FOverviewCanvas.java;h=7371eb5e0bf79a44aac37b9a081000d1a58df858;hb=2ff9268291ebf9d1d8d10c0108ea4f8b50c2885f;hp=3ced9eeaff9e4faf64ac1cd9e5684eaaf2b4363b;hpb=3fca8f1a5cebad8b73747d121622d1f63a5f9178;p=jalview.git diff --git a/src/jalview/gui/OverviewCanvas.java b/src/jalview/gui/OverviewCanvas.java index 3ced9ee..7371eb5 100644 --- a/src/jalview/gui/OverviewCanvas.java +++ b/src/jalview/gui/OverviewCanvas.java @@ -21,9 +21,9 @@ package jalview.gui; import jalview.api.AlignViewportI; -import jalview.datamodel.SequenceI; -import jalview.renderer.AnnotationRenderer; -import jalview.renderer.seqfeatures.FeatureColourFinder; +import jalview.bin.Cache; +import jalview.renderer.OverviewRenderer; +import jalview.renderer.OverviewResColourFinder; import jalview.viewmodel.OverviewDimensions; import java.awt.Color; @@ -33,7 +33,6 @@ import java.awt.image.BufferedImage; import javax.swing.JComponent; - public class OverviewCanvas extends JComponent { private static final Color TRANS_GREY = new Color(100, 100, 100, 25); @@ -44,6 +43,8 @@ public class OverviewCanvas extends JComponent private volatile boolean updaterunning = false; + private boolean dispose = false; + private BufferedImage miniMe; private BufferedImage lastMiniMe = null; @@ -54,27 +55,51 @@ public class OverviewCanvas extends JComponent private jalview.renderer.seqfeatures.FeatureRenderer fr; - private final AnnotationRenderer renderer = new AnnotationRenderer(); + private OverviewDimensions od; + + private OverviewRenderer or = null; + + private AlignViewportI av; - OverviewDimensions od; + private OverviewResColourFinder cf; - AlignViewportI av; + private ProgressPanel progressPanel; public OverviewCanvas(OverviewDimensions overviewDims, - AlignViewportI alignvp) + AlignViewportI alignvp, ProgressPanel pp) { od = overviewDims; av = alignvp; + progressPanel = pp; sr = new SequenceRenderer(av); sr.renderGaps = false; - sr.forOverview = true; fr = new jalview.renderer.seqfeatures.FeatureRenderer(av); + + boolean useLegacy = Cache.getDefault(Preferences.USE_LEGACY_GAP, false); + Color gapCol = Cache.getDefaultColour(Preferences.GAP_COLOUR, + jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_GAP); + Color hiddenCol = Cache.getDefaultColour(Preferences.HIDDEN_COLOUR, + jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_HIDDEN); + cf = new OverviewResColourFinder(useLegacy, gapCol, hiddenCol); + + setSize(od.getWidth(), od.getHeight()); } - /* - * Signals to drawing code that the associated alignment viewport - * has changed and a redraw will be required + /** + * Update the overview dimensions object used by the canvas (e.g. if we change + * from showing hidden columns to hiding them or vice versa) + * + * @param overviewDims + */ + public void resetOviewDims(OverviewDimensions overviewDims) + { + od = overviewDims; + } + + /** + * Signals to drawing code that the associated alignment viewport has changed + * and a redraw will be required */ public boolean restartDraw() { @@ -83,6 +108,10 @@ public class OverviewCanvas extends JComponent if (updaterunning) { restart = true; + if (or != null) + { + or.setRedraw(true); + } } else { @@ -92,6 +121,16 @@ public class OverviewCanvas extends JComponent } } + /** + * Draw the overview sequences + * + * @param showSequenceFeatures + * true if sequence features are to be shown + * @param showAnnotation + * true if the annotation is to be shown + * @param transferRenderer + * the renderer to transfer feature colouring from + */ public void draw(boolean showSequenceFeatures, boolean showAnnotation, FeatureRenderer transferRenderer) { @@ -102,53 +141,37 @@ public class OverviewCanvas extends JComponent fr.transferSettings(transferRenderer); } - // why do we need to set preferred size again? was set in - // updateOverviewImage setPreferredSize(new Dimension(od.getWidth(), od.getHeight())); - miniMe = new BufferedImage(od.getWidth(), od.getHeight(), - BufferedImage.TYPE_INT_RGB); + or = new OverviewRenderer(fr, od, av.getAlignment(), + av.getResidueShading(), cf); - Graphics mg = miniMe.getGraphics(); - mg.setColor(Color.orange); - mg.fillRect(0, 0, od.getWidth(), miniMe.getHeight()); + or.addPropertyChangeListener(progressPanel); - // calculate sampleCol and sampleRow - // alignment width is max number of residues/bases - // alignment height is number of sequences - int alwidth = av.getAlignment().getWidth(); - int alheight = av.getAlignment().getAbsoluteHeight(); + miniMe = or.draw(od.getRows(av.getAlignment()), + od.getColumns(av.getAlignment())); - // sampleCol or sampleRow is the width/height allocated to each residue - // in particular, sometimes we may need more than one row/col of the - // BufferedImage allocated - // sampleCol is how much of a residue to assign to each pixel - // sampleRow is how many sequences to assign to each pixel - float sampleCol = alwidth / (float) od.getWidth(); - float sampleRow = alheight / (float) od.getSequencesHeight(); - - buildImage(sampleRow, sampleCol); + Graphics mg = miniMe.getGraphics(); if (showAnnotation) { - renderer.updateFromAlignViewport(av); - for (int col = 0; col < od.getWidth() && !restart; col++) - { - mg.translate(col, od.getSequencesHeight()); - renderer.drawGraph(mg, av.getAlignmentConservationAnnotation(), - av.getAlignmentConservationAnnotation().annotations, - (int) (sampleCol) + 1, od.getGraphHeight(), - (int) (col * sampleCol), (int) (col * sampleCol) + 1); - mg.translate(-col, -od.getSequencesHeight()); - - } + mg.translate(0, od.getSequencesHeight()); + or.drawGraph(mg, av.getAlignmentConservationAnnotation(), + av.getCharWidth(), od.getGraphHeight(), + od.getColumns(av.getAlignment())); + mg.translate(0, -od.getSequencesHeight()); } System.gc(); + or.removePropertyChangeListener(progressPanel); + or = null; if (restart) { restart = false; - draw(showSequenceFeatures, showAnnotation, transferRenderer); + if (!dispose) + { + draw(showSequenceFeatures, showAnnotation, transferRenderer); + } } else { @@ -176,93 +199,71 @@ public class OverviewCanvas extends JComponent } else if (lastMiniMe != null) { - g.drawImage(lastMiniMe, 0, 0, this); - if (lastMiniMe != miniMe) + // is this a resize? + if ((getWidth() > 0) && (getHeight() > 0) + && ((getWidth() != od.getWidth()) + || (getHeight() != od.getHeight()))) { - g.setColor(TRANS_GREY); - g.fillRect(0, 0, getWidth(), getHeight()); - } - } - - g.setColor(Color.red); - od.drawBox(g); - } - - /* - * Build the overview panel image - */ - private void buildImage(float sampleRow, float sampleCol) - { - int lastcol = -1; - int lastrow = -1; - int rgbcolor = Color.white.getRGB(); - - SequenceI seq = null; - FeatureColourFinder finder = new FeatureColourFinder(fr); - - final boolean hasHiddenCols = av.hasHiddenColumns(); - boolean hiddenRow = false; - // get hidden row and hidden column map once at beginning. - // clone featureRenderer settings to avoid race conditions... if state is - // updated just need to refresh again - for (int row = 0; row < od.getSequencesHeight() && !restart; row++) - { - boolean doCopy = true; - int currentrow = (int) (row * sampleRow); - if (currentrow != lastrow) - { - doCopy = false; - - lastrow = currentrow; - - // get the sequence which would be at alignment index 'lastrow' if no - // rows were hidden, and determine whether it is hidden or not - hiddenRow = av.getAlignment().isHidden(lastrow); - seq = av.getAlignment().getSequenceAtAbsoluteIndex(lastrow); - } - - for (int col = 0; col < od.getWidth() && !restart; col++) - { - if (doCopy) + // if there is annotation, scale the alignment and annotation separately + if (od.getGraphHeight() > 0) { - rgbcolor = miniMe.getRGB(col, row - 1); + BufferedImage topImage = lastMiniMe.getSubimage(0, 0, + od.getWidth(), od.getSequencesHeight()); + BufferedImage bottomImage = lastMiniMe.getSubimage(0, + od.getSequencesHeight(), od.getWidth(), + od.getGraphHeight()); + + // must be done at this point as we rely on using old width/height + // above, and new width/height below + od.setWidth(getWidth()); + od.setHeight(getHeight()); + + // stick the images back together so lastMiniMe is consistent in the + // event of a repaint - BUT probably not thread safe + lastMiniMe = new BufferedImage(od.getWidth(), od.getHeight(), + BufferedImage.TYPE_INT_RGB); + Graphics lg = lastMiniMe.getGraphics(); + lg.drawImage(topImage, 0, 0, od.getWidth(), + od.getSequencesHeight(), null); + lg.drawImage(bottomImage, 0, od.getSequencesHeight(), + od.getWidth(), od.getGraphHeight(), this); + lg.dispose(); } - else if ((int) (col * sampleCol) != lastcol - || (int) (row * sampleRow) != lastrow) + else { - lastcol = (int) (col * sampleCol); - rgbcolor = getColumnColourFromSequence(seq, hiddenRow, - hasHiddenCols, lastcol, finder); + od.setWidth(getWidth()); + od.setHeight(getHeight()); } - // else we just use the color we already have , so don't need to set it - miniMe.setRGB(col, row, rgbcolor); + // scale lastMiniMe to the new size + g.drawImage(lastMiniMe, 0, 0, getWidth(), getHeight(), this); + + // make sure the box is in the right place + od.setBoxPosition(av.getAlignment().getHiddenSequences(), + av.getAlignment().getHiddenColumns()); + } + else // not a resize + { + // fall back to normal behaviour + g.drawImage(lastMiniMe, 0, 0, getWidth(), getHeight(), this); } } + + // draw the box + g.setColor(Color.red); + od.drawBox(g); } - /* - * Find the colour of a sequence at a specified column position - */ - private int getColumnColourFromSequence(jalview.datamodel.SequenceI seq, - boolean hiddenRow, boolean hasHiddenCols, int lastcol, - FeatureColourFinder finder) + public void dispose() { - Color color = Color.white; - - if ((seq != null) && (seq.getLength() > lastcol)) - { - color = sr.getResidueColour(seq, lastcol, finder); - } - - if (hiddenRow - || (hasHiddenCols && !av.getColumnSelection() - .isVisible(lastcol))) + dispose = true; + synchronized (this) { - color = color.darker().darker(); + restart = true; + if (or != null) + { + or.setRedraw(true); + } } - - return color.getRGB(); } - }