X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=inline;f=src%2Fjalview%2Fgui%2FOverviewCanvas.java;h=99dba3d97e39ce7b32c741d0895439dc3092eb2c;hb=1f41372a2bda3efcc27abaed092495548135b6b4;hp=57070f2dbe6886c4885c74b141e1d098213fdf4b;hpb=17dbe9d0029460ccd1f21f516e8ca7b8cd1bc449;p=jalview.git diff --git a/src/jalview/gui/OverviewCanvas.java b/src/jalview/gui/OverviewCanvas.java index 57070f2..99dba3d 100644 --- a/src/jalview/gui/OverviewCanvas.java +++ b/src/jalview/gui/OverviewCanvas.java @@ -20,26 +20,34 @@ */ package jalview.gui; -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 java.awt.image.RasterFormatException; -import javax.swing.JComponent; -import javax.swing.Timer; +import javax.swing.JPanel; -public class OverviewCanvas extends JComponent +import jalview.api.AlignViewportI; +import jalview.bin.Cache; +import jalview.bin.Console; +import jalview.renderer.OverviewRenderer; +import jalview.renderer.OverviewResColourFinder; +import jalview.viewmodel.OverviewDimensions; +import jalview.viewmodel.seqfeatures.FeatureRendererModel; + +public class OverviewCanvas extends JPanel { - private static final long RUNNING_TIME = 1000; + public static final Color OVERVIEW_DEFAULT_GAP = Color.lightGray; + + public static final Color OVERVIEW_DEFAULT_LEGACY_GAP = Color.white; - private static final int SPEED = 40; + public static final Color OVERVIEW_DEFAULT_RESIDUE = Color.white; + + public static final Color OVERVIEW_DEFAULT_LEGACY_RESIDUE = Color.lightGray; + + public static final Color OVERVIEW_DEFAULT_HIDDEN = Color.darkGray + .darker(); private static final Color TRANS_GREY = new Color(100, 100, 100, 25); @@ -55,8 +63,6 @@ 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; @@ -69,11 +75,7 @@ public class OverviewCanvas extends JComponent private AlignViewportI av; - private float alpha = 0f; - - private long startTime = -1; - - private final Timer timer; + private OverviewResColourFinder cf; private ProgressPanel progressPanel; @@ -86,40 +88,18 @@ public class OverviewCanvas extends JComponent sr = new SequenceRenderer(av); sr.renderGaps = false; - sr.forOverview = true; fr = new jalview.renderer.seqfeatures.FeatureRenderer(av); - setSize(od.getWidth(), od.getHeight()); - - timer = new Timer(SPEED, new ActionListener() - { + boolean useLegacy = Cache.getDefault(Preferences.USE_LEGACY_GAP, false); + Color gapCol = Cache.getDefaultColour(Preferences.GAP_COLOUR, + OVERVIEW_DEFAULT_GAP); + Color hiddenCol = Cache.getDefaultColour(Preferences.HIDDEN_COLOUR, + OVERVIEW_DEFAULT_HIDDEN); + Color residueCol = useLegacy ? OVERVIEW_DEFAULT_LEGACY_RESIDUE : OVERVIEW_DEFAULT_RESIDUE; + + cf = new OverviewResColourFinder(gapCol, residueCol, hiddenCol); - @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(); - } - } - }); + setSize(od.getWidth(), od.getHeight()); } /** @@ -168,18 +148,22 @@ public class OverviewCanvas extends JComponent * the renderer to transfer feature colouring from */ public void draw(boolean showSequenceFeatures, boolean showAnnotation, - FeatureRenderer transferRenderer) + FeatureRendererModel transferRenderer) { miniMe = null; - veryLastMiniMe = lastMiniMe; if (showSequenceFeatures) { fr.transferSettings(transferRenderer); } - or = new OverviewRenderer(sr, fr, od); + setPreferredSize(new Dimension(od.getWidth(), od.getHeight())); + + or = new OverviewRenderer(fr, od, av.getAlignment(), + av.getResidueShading(), cf); + or.addPropertyChangeListener(progressPanel); + miniMe = or.draw(od.getRows(av.getAlignment()), od.getColumns(av.getAlignment())); @@ -189,11 +173,9 @@ public class OverviewCanvas extends JComponent { mg.translate(0, od.getSequencesHeight()); or.drawGraph(mg, av.getAlignmentConservationAnnotation(), - av.getCharWidth(), od.getGraphHeight(), - od.getColumns(av.getAlignment())); + od.getGraphHeight(), od.getColumns(av.getAlignment())); mg.translate(0, -od.getSequencesHeight()); } - System.gc(); or.removePropertyChangeListener(progressPanel); or = null; @@ -209,14 +191,14 @@ public class OverviewCanvas extends JComponent { updaterunning = false; lastMiniMe = miniMe; - alpha = 1f; - timer.start(); } } @Override public void paintComponent(Graphics g) { + // super.paintComponent(g); + if (restart) { if (lastMiniMe == null) @@ -238,30 +220,41 @@ public class OverviewCanvas extends JComponent && ((getWidth() != od.getWidth()) || (getHeight() != od.getHeight()))) { - // if there is annotation, scale the alignment and annotation separately - if (od.getGraphHeight() > 0) + // if there is annotation, scale the alignment and annotation + // separately + if (od.getGraphHeight() > 0 && od.getSequencesHeight() > 0 // BH 2019 + ) { - 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(); + try + { + 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(); + } catch (RasterFormatException e) + { + Console.debug( + "Scaling miscalculation resizing Overview window"); + od.setWidth(getWidth()); + od.setHeight(getHeight()); + } } else { @@ -269,35 +262,16 @@ public class OverviewCanvas extends JComponent 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 // not a resize - { - 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 - { - // fall back to normal behaviour - g.drawImage(lastMiniMe, 0, 0, getWidth(), getHeight(), this); - } - } + // fall back to normal behaviour + g.drawImage(lastMiniMe, 0, 0, getWidth(), getHeight(), this); + } + else + { + g.drawImage(lastMiniMe, 0, 0, getWidth(), getHeight(), this); } // draw the box @@ -308,6 +282,7 @@ public class OverviewCanvas extends JComponent public void dispose() { dispose = true; + od = null; synchronized (this) { restart = true; @@ -317,4 +292,31 @@ public class OverviewCanvas extends JComponent } } } + + public Color getGapColour() + { + return cf.getGapColour(); + } + + public Color getHiddenColour() + { + return cf.getHiddenColour(); + } + + public Color getResidueColour() + { + return cf.getResidueColour(); + } + + /** + * Sets the colours to use for gaps, residues and hidden regions + * + * @param gaps + * @param residues + * @param hidden + */ + public void setColours(Color gaps, Color residues, Color hidden) + { + cf = new OverviewResColourFinder(gaps, residues, hidden); + } }