import jalview.renderer.OverviewRenderer;
import jalview.viewmodel.OverviewDimensions;
+import java.awt.AlphaComposite;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
+import java.awt.Graphics2D;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import javax.swing.JComponent;
+import javax.swing.Timer;
public class OverviewCanvas extends JComponent
{
+ public static final long RUNNING_TIME = 2000;
private static final Color TRANS_GREY = new Color(100, 100, 100, 25);
// This is set true if the alignment view changes whilst
private BufferedImage lastMiniMe = null;
+ private BufferedImage veryLastMiniMe = null;
+
// Can set different properties in this seqCanvas than
// main visible SeqCanvas
private SequenceRenderer sr;
private AlignViewportI av;
+ private boolean resize = false;
+
+ private float alpha = 0f;
+
+ private long startTime = -1;
+
+ private final Timer timer;
+
public OverviewCanvas(OverviewDimensions overviewDims,
AlignViewportI alignvp)
{
sr.renderGaps = false;
sr.forOverview = true;
fr = new jalview.renderer.seqfeatures.FeatureRenderer(av);
+
+ timer = new Timer(40, new ActionListener()
+ {
+
+ @Override
+ public void actionPerformed(ActionEvent e)
+ {
+ if (startTime < 0)
+ {
+ startTime = System.currentTimeMillis();
+ }
+ else
+ {
+
+ long time = System.currentTimeMillis();
+ long duration = time - startTime;
+ if (duration >= RUNNING_TIME)
+ {
+ startTime = -1;
+ ((Timer) e.getSource()).stop();
+ alpha = 0f;
+ }
+ else
+ {
+ alpha = 1f - ((float) duration / (float) RUNNING_TIME);
+ }
+ repaint();
+ }
+ }
+ });
}
/**
FeatureRenderer transferRenderer)
{
miniMe = null;
+ veryLastMiniMe = lastMiniMe;
if (showSequenceFeatures)
{
{
updaterunning = false;
lastMiniMe = miniMe;
+ alpha = 1f;
+ timer.start();
}
}
@Override
public void paintComponent(Graphics g)
{
+
if (restart)
{
if (lastMiniMe == null)
}
else if (lastMiniMe != null)
{
- g.drawImage(lastMiniMe, 0, 0, this);
- if (lastMiniMe != miniMe)
+ if ((getWidth() > 0) && (getHeight() > 0)
+ && ((getWidth() != od.getWidth())
+ || (getHeight() != od.getHeight())))
{
- g.setColor(TRANS_GREY);
- g.fillRect(0, 0, getWidth(), getHeight());
+ // scale the alignment and annotation separately *** if there is
+ // annotation ***
+ if (od.getGraphHeight() > 0)
+ {
+ 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
+ {
+ od.setWidth(getWidth());
+ od.setHeight(getHeight());
+ }
+
+ // 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
+ {
+ if (alpha != 0) // this is a timer triggered dissolve
+ {
+ Graphics2D g2d = (Graphics2D) g.create();
+
+ // draw the original image
+ g2d.drawImage(veryLastMiniMe, 0, 0, getWidth(), getHeight(),
+ this);
+
+ // draw the new image on top with varying degrees of transparency
+ g2d.setComposite(AlphaComposite.SrcOver.derive(1f - alpha));
+ g2d.drawImage(lastMiniMe, 0, 0, getWidth(), getHeight(), this);
+
+ g2d.dispose();
+ }
+ else if (lastMiniMe != miniMe)
+ {
+ g.drawImage(lastMiniMe, 0, 0, getWidth(), getHeight(), this);
+ g.setColor(TRANS_GREY);
+ g.fillRect(0, 0, getWidth(), getHeight());
+ }
+ else
+ {
+ // fall back to normal behaviour
+ g.drawImage(lastMiniMe, 0, 0, getWidth(), getHeight(), this);
+ }
+
}
+
}
+ // draw the box
g.setColor(Color.red);
od.drawBox(g);
}
-
}