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;
import javax.swing.JComponent;
-
public class OverviewCanvas extends JComponent
{
private static final Color TRANS_GREY = new Color(100, 100, 100, 25);
// the overview is being calculated
private volatile boolean restart = false;
- private BufferedImage miniMe;
+ private volatile boolean updaterunning = false;
- private BufferedImage lastMiniMe = null;
+ private boolean dispose = false;
+ private BufferedImage miniMe;
+ private BufferedImage lastMiniMe = null;
// Can set different properties in this seqCanvas than
// main visible SeqCanvas
private jalview.renderer.seqfeatures.FeatureRenderer fr;
- private final AnnotationRenderer renderer = new AnnotationRenderer();
+ private OverviewDimensions od;
+
+ private OverviewRenderer or = null;
- OverviewDimensions od;
+ private AlignViewportI av;
- AlignViewport av;
+ private OverviewResColourFinder cf;
- AlignmentPanel ap;
+ private ProgressPanel progressPanel;
public OverviewCanvas(OverviewDimensions overviewDims,
- AlignViewportI alignvp, AlignmentPanel alignp)
+ AlignViewportI alignvp, ProgressPanel pp)
{
od = overviewDims;
- av = alignp.av;
- ap = alignp;
+ av = alignvp;
+ progressPanel = pp;
sr = new SequenceRenderer(av);
sr.renderGaps = false;
- sr.forOverview = true;
- fr = new FeatureRenderer(ap);
+ 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 restartDraw()
+ public void resetOviewDims(OverviewDimensions overviewDims)
{
- restart = true;
+ od = overviewDims;
+ }
+
+ /**
+ * Signals to drawing code that the associated alignment viewport has changed
+ * and a redraw will be required
+ */
+ public boolean restartDraw()
+ {
+ synchronized (this)
+ {
+ if (updaterunning)
+ {
+ restart = true;
+ if (or != null)
+ {
+ or.setRedraw(true);
+ }
+ }
+ else
+ {
+ updaterunning = true;
+ }
+ return restart;
+ }
}
- public void draw(boolean showSequenceFeatures, boolean showAnnotation)
+ /**
+ * 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)
{
miniMe = null;
if (showSequenceFeatures)
{
- fr.transferSettings(ap.getSeqPanel().seqCanvas.getFeatureRenderer());
+ 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);
-
- Graphics mg = miniMe.getGraphics();
- mg.setColor(Color.orange);
- mg.fillRect(0, 0, od.getWidth(), miniMe.getHeight());
+ or = new OverviewRenderer(fr, od, av.getAlignment(),
+ av.getResidueShading(), cf);
- // 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();
+ or.addPropertyChangeListener(progressPanel);
- // 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();
+ miniMe = or.draw(od.getRows(av.getAlignment()),
+ od.getColumns(av.getAlignment()));
- 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(),
+ 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);
+ if (!dispose)
+ {
+ draw(showSequenceFeatures, showAnnotation, transferRenderer);
+ }
}
else
{
+ updaterunning = false;
lastMiniMe = miniMe;
}
}
@Override
public void paintComponent(Graphics g)
{
+ super.paintComponent(g);
+
if (restart)
{
if (lastMiniMe == null)
}
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);
+ // make sure the box is in the right place
+ od.setBoxPosition(av.getAlignment().getHiddenSequences(),
+ av.getAlignment().getHiddenColumns());
}
+ // fall back to normal behaviour
+ g.drawImage(lastMiniMe, 0, 0, getWidth(), getHeight(), this);
}
- }
-
- /*
- * 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)
- {
- Color color = Color.white;
-
- if ((seq != null) && (seq.getLength() > lastcol))
+ else
{
- color = sr.getResidueColour(seq, lastcol, finder);
+ g.drawImage(lastMiniMe, 0, 0, getWidth(), getHeight(), this);
}
+
+ // draw the box
+ g.setColor(Color.red);
+ od.drawBox(g);
+ }
- if (hiddenRow
- || (hasHiddenCols && !av.getColumnSelection()
- .isVisible(lastcol)))
+
+ public void dispose()
+ {
+ dispose = true;
+ synchronized (this)
{
- color = color.darker().darker();
+ restart = true;
+ if (or != null)
+ {
+ or.setRedraw(true);
+ }
}
-
- return color.getRGB();
}
-
}