From d1a0432ceea31261f2df4eb728f58ef4d0a30c90 Mon Sep 17 00:00:00 2001 From: kiramt Date: Thu, 3 Aug 2017 08:56:42 +0100 Subject: [PATCH] JAL-2587 Attempt to add timed dissolve --- src/jalview/gui/OverviewCanvas.java | 86 ++++++++++++++++++++++++++++++----- 1 file changed, 74 insertions(+), 12 deletions(-) diff --git a/src/jalview/gui/OverviewCanvas.java b/src/jalview/gui/OverviewCanvas.java index 694f804..3bd365e 100644 --- a/src/jalview/gui/OverviewCanvas.java +++ b/src/jalview/gui/OverviewCanvas.java @@ -24,15 +24,21 @@ import jalview.api.AlignViewportI; 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 @@ -45,6 +51,8 @@ public class OverviewCanvas extends JComponent private BufferedImage lastMiniMe = null; + private BufferedImage veryLastMiniMe = null; + // Can set different properties in this seqCanvas than // main visible SeqCanvas private SequenceRenderer sr; @@ -59,6 +67,12 @@ public class OverviewCanvas extends JComponent private boolean resize = false; + private float alpha = 0f; + + private long startTime = -1; + + private final Timer timer; + public OverviewCanvas(OverviewDimensions overviewDims, AlignViewportI alignvp) { @@ -69,6 +83,36 @@ public class OverviewCanvas extends JComponent 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(); + } + } + }); } /** @@ -120,6 +164,7 @@ public class OverviewCanvas extends JComponent FeatureRenderer transferRenderer) { miniMe = null; + veryLastMiniMe = lastMiniMe; if (showSequenceFeatures) { @@ -153,17 +198,11 @@ public class OverviewCanvas extends JComponent { updaterunning = false; lastMiniMe = miniMe; + timer.start(); } } @Override - public void setSize(int width, int height) - { - // TODO Auto-generated method stub - super.setSize(width, height); - } - - @Override public void paintComponent(Graphics g) { @@ -199,12 +238,13 @@ public class OverviewCanvas extends JComponent 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 + // event of a repaint - BUT probably not thread safe lastMiniMe = new BufferedImage(od.getWidth(), od.getHeight(), BufferedImage.TYPE_INT_RGB); Graphics lg = lastMiniMe.getGraphics(); @@ -214,6 +254,11 @@ public class OverviewCanvas extends JComponent 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); @@ -224,13 +269,31 @@ public class OverviewCanvas extends JComponent } else { - System.out.println("Same size"); - g.drawImage(lastMiniMe, 0, 0, getWidth(), getHeight(), this); + if (lastMiniMe != miniMe && !resize) { + g.drawImage(lastMiniMe, 0, 0, getWidth(), getHeight(), this); g.setColor(TRANS_GREY); g.fillRect(0, 0, getWidth(), getHeight()); } + else if (veryLastMiniMe != null) + { + Graphics2D g2d = (Graphics2D) g.create(); + + g2d.setComposite(AlphaComposite.SrcOver.derive(alpha)); + g2d.drawImage(veryLastMiniMe, 0, 0, getWidth(), getHeight(), + this); + + g2d.setComposite(AlphaComposite.SrcOver.derive(1f - alpha)); + g2d.drawImage(lastMiniMe, 0, 0, getWidth(), getHeight(), this); + + g2d.dispose(); + } + else + { + // fall back if everything goes wrong somehow + g.drawImage(lastMiniMe, 0, 0, getWidth(), getHeight(), this); + } resize = false; } @@ -238,7 +301,6 @@ public class OverviewCanvas extends JComponent // draw the box g.setColor(Color.red); - od.drawBox(g); } } -- 1.7.10.2