X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FOverviewCanvas.java;h=99dba3d97e39ce7b32c741d0895439dc3092eb2c;hb=a5928e2c1b9e2cea8d9c43f3d03f9cce2604f3b2;hp=042f9374f584c1a88fab7869a7050b8a9aba1942;hpb=90f198f9988ef8a98d46b95e21b22a8fcea541d8;p=jalview.git diff --git a/src/jalview/gui/OverviewCanvas.java b/src/jalview/gui/OverviewCanvas.java index 042f937..99dba3d 100644 --- a/src/jalview/gui/OverviewCanvas.java +++ b/src/jalview/gui/OverviewCanvas.java @@ -20,21 +20,35 @@ */ package jalview.gui; -import jalview.api.AlignViewportI; -import jalview.bin.Cache; -import jalview.renderer.OverviewRenderer; -import jalview.renderer.OverviewResColourFinder; -import jalview.viewmodel.OverviewDimensions; - import java.awt.Color; import java.awt.Dimension; import java.awt.Graphics; import java.awt.image.BufferedImage; +import java.awt.image.RasterFormatException; import javax.swing.JPanel; +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 { + public static final Color OVERVIEW_DEFAULT_GAP = Color.lightGray; + + public static final Color OVERVIEW_DEFAULT_LEGACY_GAP = Color.white; + + 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); // This is set true if the alignment view changes whilst @@ -78,10 +92,12 @@ public class OverviewCanvas extends JPanel boolean useLegacy = Cache.getDefault(Preferences.USE_LEGACY_GAP, false); Color gapCol = Cache.getDefaultColour(Preferences.GAP_COLOUR, - jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_GAP); + OVERVIEW_DEFAULT_GAP); Color hiddenCol = Cache.getDefaultColour(Preferences.HIDDEN_COLOUR, - jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_HIDDEN); - cf = new OverviewResColourFinder(useLegacy, gapCol, hiddenCol); + OVERVIEW_DEFAULT_HIDDEN); + Color residueCol = useLegacy ? OVERVIEW_DEFAULT_LEGACY_RESIDUE : OVERVIEW_DEFAULT_RESIDUE; + + cf = new OverviewResColourFinder(gapCol, residueCol, hiddenCol); setSize(od.getWidth(), od.getHeight()); } @@ -132,7 +148,7 @@ public class OverviewCanvas extends JPanel * the renderer to transfer feature colouring from */ public void draw(boolean showSequenceFeatures, boolean showAnnotation, - FeatureRenderer transferRenderer) + FeatureRendererModel transferRenderer) { miniMe = null; @@ -181,7 +197,7 @@ public class OverviewCanvas extends JPanel @Override public void paintComponent(Graphics g) { - //super.paintComponent(g); + // super.paintComponent(g); if (restart) { @@ -206,31 +222,39 @@ public class OverviewCanvas extends JPanel { // if there is annotation, scale the alignment and annotation // separately - if (od.getGraphHeight() > 0 - && od.getSequencesHeight() > 0 // BH 2019 - ) + 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 { @@ -249,16 +273,16 @@ public class OverviewCanvas extends JPanel { g.drawImage(lastMiniMe, 0, 0, getWidth(), getHeight(), this); } - + // draw the box g.setColor(Color.red); od.drawBox(g); } - public void dispose() { dispose = true; + od = null; synchronized (this) { restart = true; @@ -268,4 +292,31 @@ public class OverviewCanvas extends JPanel } } } + + 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); + } }