From 2abeb29371cdf22173026ec89ea5d3a3fd50faae Mon Sep 17 00:00:00 2001 From: Jim Procter Date: Wed, 19 Aug 2020 18:43:52 +0100 Subject: [PATCH] JAL-3719 Format->Colour Gaps option uses Overview gap colour logic pulled up to alignment viewport sequence renderer Conflicts: resources/lang/Messages.properties resources/lang/Messages_es.properties --- resources/lang/Messages.properties | 1 + resources/lang/Messages_es.properties | 1 + src/jalview/api/ViewStyleI.java | 12 +++++++ src/jalview/gui/AlignFrame.java | 13 ++++++++ src/jalview/gui/SeqCanvas.java | 2 +- src/jalview/gui/SequenceRenderer.java | 25 ++++++++++---- src/jalview/jbgui/GAlignFrame.java | 20 ++++++++++- src/jalview/renderer/OverviewResColourFinder.java | 32 ------------------ src/jalview/renderer/ResidueColourFinder.java | 37 ++++++++++++++++++--- src/jalview/viewmodel/AlignmentViewport.java | 20 +++++++++++ src/jalview/viewmodel/styles/ViewStyle.java | 22 +++++++++++- 11 files changed, 140 insertions(+), 45 deletions(-) diff --git a/resources/lang/Messages.properties b/resources/lang/Messages.properties index 308876b..f9db9ba 100644 --- a/resources/lang/Messages.properties +++ b/resources/lang/Messages.properties @@ -1375,3 +1375,4 @@ label.include_linked_features = Include {0} features label.include_linked_tooltip = Include visible {0} features
converted to local sequence coordinates label.features_not_shown = {0} feature(s) not shown label.no_features_to_sort_by = No features to sort by +label.colour_gaps = Colour Gaps diff --git a/resources/lang/Messages_es.properties b/resources/lang/Messages_es.properties index ef40e97..4a454ca 100644 --- a/resources/lang/Messages_es.properties +++ b/resources/lang/Messages_es.properties @@ -1376,3 +1376,4 @@ label.include_linked_features = Incluir caracter label.include_linked_tooltip = Incluir características de {0}
convertidas a coordenadas de secuencia local label.features_not_shown = {0} característica(s) no mostradas label.no_features_to_sort_by = No hay características para ordenar +label.colour_gaps = Color del huecos diff --git a/src/jalview/api/ViewStyleI.java b/src/jalview/api/ViewStyleI.java index a348300..458c8b8 100644 --- a/src/jalview/api/ViewStyleI.java +++ b/src/jalview/api/ViewStyleI.java @@ -278,4 +278,16 @@ public interface ViewStyleI * @return */ void setProteinFontAsCdna(boolean b); + + /** + * Set flag indicating that gaps should be coloured with the overview gap + * colour in the alignment view + */ + void setColourGaps(boolean b); + + /** + * @return true if gaps should be coloured according to the overview gap + * colour + */ + boolean getColourGaps(); } diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index 910ab63..90a3532 100644 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -907,6 +907,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, { padGapsMenuitem.setSelected(av.isPadGaps()); colourTextMenuItem.setSelected(av.isShowColourText()); + colourGapsMenuItem.setSelected(av.getColourGaps()); abovePIDThreshold.setSelected(av.getAbovePIDThreshold()); modifyPID.setEnabled(abovePIDThreshold.isSelected()); conservationMenuItem.setSelected(av.getConservationSelected()); @@ -3001,6 +3002,18 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * DOCUMENT ME! */ @Override + protected void colourGapsMenuItem_actionPerformed(ActionEvent e) + { + viewport.setColourGaps(colourGapsMenuItem.isSelected()); + alignPanel.paintAlignment(false, false); + } + /** + * DOCUMENT ME! + * + * @param e + * DOCUMENT ME! + */ + @Override public void wrapMenuItem_actionPerformed(ActionEvent e) { scaleAbove.setVisible(wrapMenuItem.isSelected()); diff --git a/src/jalview/gui/SeqCanvas.java b/src/jalview/gui/SeqCanvas.java index b27208a..fef3c96 100755 --- a/src/jalview/gui/SeqCanvas.java +++ b/src/jalview/gui/SeqCanvas.java @@ -1044,7 +1044,7 @@ public class SeqCanvas extends JPanel implements ViewportListenerI int charWidth = av.getCharWidth(); g.setFont(av.getFont()); - seqRdr.prepare(g, av.isRenderGaps()); + seqRdr.prepare(g, av.isRenderGaps(), av.getColourGaps()); SequenceI nextSeq; diff --git a/src/jalview/gui/SequenceRenderer.java b/src/jalview/gui/SequenceRenderer.java index fb967ed..33d34a2 100755 --- a/src/jalview/gui/SequenceRenderer.java +++ b/src/jalview/gui/SequenceRenderer.java @@ -21,6 +21,7 @@ package jalview.gui; import jalview.api.AlignViewportI; +import jalview.bin.Cache; import jalview.datamodel.SequenceGroup; import jalview.datamodel.SequenceI; import jalview.renderer.ResidueColourFinder; @@ -53,6 +54,9 @@ public class SequenceRenderer implements jalview.api.SequenceRenderer ResidueColourFinder resColourFinder; + private boolean colourGaps; + private Color gapColour=Color.white; + /** * Creates a new SequenceRenderer object * @@ -65,12 +69,11 @@ public class SequenceRenderer implements jalview.api.SequenceRenderer } /** - * DOCUMENT ME! - * - * @param b - * DOCUMENT ME! + * initialise state for a render + * @param renderGaps - whether gap symbols are shown + * @param colourGaps - whether boxes for gaps are to be coloured */ - public void prepare(Graphics g, boolean renderGaps) + public void prepare(Graphics g, boolean renderGaps, boolean colourGaps) { graphics = g; fm = g.getFontMetrics(); @@ -82,6 +85,14 @@ public class SequenceRenderer implements jalview.api.SequenceRenderer && av.getCharWidth() == dwidth); this.renderGaps = renderGaps; + this.colourGaps = colourGaps; + this.gapColour = Color.white; + if (colourGaps) + { + this.gapColour = Cache.getDefaultColour(Preferences.GAP_COLOUR, + jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_GAP); + } + resColourFinder = new ResidueColourFinder(gapColour); } /** @@ -161,7 +172,7 @@ public class SequenceRenderer implements jalview.api.SequenceRenderer public synchronized void drawBoxes(SequenceI seq, int start, int end, int y1) { - Color resBoxColour = Color.white; + Color resBoxColour = gapColour; if (seq == null) { @@ -199,6 +210,8 @@ public class SequenceRenderer implements jalview.api.SequenceRenderer resBoxColour = resColourFinder .getBoxColour(av.getResidueShading(), seq, i); } + } else { + resBoxColour = gapColour; } if (resBoxColour != tempColour) diff --git a/src/jalview/jbgui/GAlignFrame.java b/src/jalview/jbgui/GAlignFrame.java index 6685c67..ab8653d 100755 --- a/src/jalview/jbgui/GAlignFrame.java +++ b/src/jalview/jbgui/GAlignFrame.java @@ -90,6 +90,8 @@ public class GAlignFrame extends JInternalFrame protected JCheckBoxMenuItem colourTextMenuItem = new JCheckBoxMenuItem(); + protected JCheckBoxMenuItem colourGapsMenuItem = new JCheckBoxMenuItem(); + protected JCheckBoxMenuItem showNonconservedMenuItem = new JCheckBoxMenuItem(); protected JMenuItem undoMenuItem = new JMenuItem(); @@ -657,7 +659,16 @@ public class GAlignFrame extends JInternalFrame colourTextMenuItem_actionPerformed(e); } }); - + colourGapsMenuItem = new JCheckBoxMenuItem( + MessageManager.getString("label.colour_gaps")); + colourGapsMenuItem.addActionListener(new ActionListener() + { + @Override + public void actionPerformed(ActionEvent e) + { + colourGapsMenuItem_actionPerformed(e); + } + }); JMenuItem htmlMenuItem = new JMenuItem( MessageManager.getString("label.html")); htmlMenuItem.addActionListener(new ActionListener() @@ -1898,6 +1909,7 @@ public class GAlignFrame extends JInternalFrame formatMenu.add(viewTextMenuItem); formatMenu.add(colourTextMenuItem); formatMenu.add(renderGapsMenuItem); + formatMenu.add(colourGapsMenuItem); formatMenu.add(centreColumnLabelsMenuItem); formatMenu.add(showNonconservedMenuItem); selectMenu.add(findMenuItem); @@ -1918,6 +1930,12 @@ public class GAlignFrame extends JInternalFrame // selectMenu.add(listenToViewSelections); } + protected void colourGapsMenuItem_actionPerformed(ActionEvent e) + { + // TODO Auto-generated method stub + + } + protected void loadVcf_actionPerformed() { } diff --git a/src/jalview/renderer/OverviewResColourFinder.java b/src/jalview/renderer/OverviewResColourFinder.java index a497d92..2d9362a 100644 --- a/src/jalview/renderer/OverviewResColourFinder.java +++ b/src/jalview/renderer/OverviewResColourFinder.java @@ -28,9 +28,6 @@ import java.awt.Color; public class OverviewResColourFinder extends ResidueColourFinder { - final Color GAP_COLOUR; // default colour to use at gaps - - final Color RESIDUE_COLOUR; // default colour to use at residues final Color HIDDEN_COLOUR; // colour for hidden regions @@ -78,35 +75,6 @@ public class OverviewResColourFinder extends ResidueColourFinder } } - @Override - public Color getBoxColour(ResidueShaderI shader, SequenceI seq, int i) - { - Color resBoxColour = RESIDUE_COLOUR; - char currentChar = seq.getCharAt(i); - - // In the overview window, gaps are coloured grey, unless the colour scheme - // specifies a gap colour, in which case gaps honour the colour scheme - // settings - if (shader.getColourScheme() != null) - { - if (Comparison.isGap(currentChar) - && (!shader.getColourScheme().hasGapColour())) - { - resBoxColour = GAP_COLOUR; - } - else - { - resBoxColour = shader.findColour(currentChar, i, seq); - } - } - else if (Comparison.isGap(currentChar)) - { - resBoxColour = GAP_COLOUR; - } - - return resBoxColour; - } - /** * {@inheritDoc} In the overview, the showBoxes setting is ignored, as the * overview displays the colours regardless. diff --git a/src/jalview/renderer/ResidueColourFinder.java b/src/jalview/renderer/ResidueColourFinder.java index 2da7233..7a1b720 100644 --- a/src/jalview/renderer/ResidueColourFinder.java +++ b/src/jalview/renderer/ResidueColourFinder.java @@ -23,14 +23,25 @@ package jalview.renderer; import jalview.datamodel.SequenceGroup; import jalview.datamodel.SequenceI; import jalview.renderer.seqfeatures.FeatureColourFinder; +import jalview.util.Comparison; import java.awt.Color; public class ResidueColourFinder { + private static final Color BACKGROUND_COLOUR = Color.white; + + protected Color GAP_COLOUR=Color.white; // default colour to use at gaps + + protected Color RESIDUE_COLOUR=BACKGROUND_COLOUR; // default colour to use at residues + public ResidueColourFinder() { } + public ResidueColourFinder(Color gapColour) + { + GAP_COLOUR = gapColour; + } /** * Get the colour of a residue in a sequence @@ -100,7 +111,7 @@ public class ResidueColourFinder return getBoxColour(shader, seq, i); } - return Color.white; + return BACKGROUND_COLOUR; } /** @@ -134,7 +145,7 @@ public class ResidueColourFinder } /** - * DOCUMENT ME! + * Find the colour for a sequence's position in the alignment * * @param shader * the viewport's colour scheme @@ -145,11 +156,29 @@ public class ResidueColourFinder */ public Color getBoxColour(ResidueShaderI shader, SequenceI seq, int i) { - Color resBoxColour = Color.white; + Color resBoxColour = RESIDUE_COLOUR; + char currentChar = seq.getCharAt(i); + + // In the overview window, gaps are coloured grey, unless the colour scheme + // specifies a gap colour, in which case gaps honour the colour scheme + // settings if (shader.getColourScheme() != null) { - resBoxColour = shader.findColour(seq.getCharAt(i), i, seq); + if (Comparison.isGap(currentChar) + && (!shader.getColourScheme().hasGapColour())) + { + resBoxColour = GAP_COLOUR; + } + else + { + resBoxColour = shader.findColour(currentChar, i, seq); + } } + else if (Comparison.isGap(currentChar)) + { + resBoxColour = GAP_COLOUR; + } + return resBoxColour; } diff --git a/src/jalview/viewmodel/AlignmentViewport.java b/src/jalview/viewmodel/AlignmentViewport.java index 0d26db1..2cbf433 100644 --- a/src/jalview/viewmodel/AlignmentViewport.java +++ b/src/jalview/viewmodel/AlignmentViewport.java @@ -453,6 +453,26 @@ public abstract class AlignmentViewport /** * @return + * @see jalview.api.ViewStyleI#getColourGaps() + */ + @Override + public boolean getColourGaps() + { + return viewStyle.getColourGaps(); + } + + /** + * @param state + * @see jalview.api.ViewStyleI#setColourGaps(boolean) + */ + @Override + public void setColourGaps(boolean state) + { + viewStyle.setColourGaps(state); + } + + /** + * @return * @see jalview.api.ViewStyleI#getWrapAlignment() */ @Override diff --git a/src/jalview/viewmodel/styles/ViewStyle.java b/src/jalview/viewmodel/styles/ViewStyle.java index 91f2f0c..1daca08 100644 --- a/src/jalview/viewmodel/styles/ViewStyle.java +++ b/src/jalview/viewmodel/styles/ViewStyle.java @@ -129,6 +129,10 @@ public class ViewStyle implements ViewStyleI boolean showText = true; /** + * colour gaps in the alignment view according to the overview gap colour + */ + boolean colourGaps = false; + /** * show non-conserved residues only */ protected boolean showUnconserved = false; @@ -224,6 +228,7 @@ public class ViewStyle implements ViewStyleI setUpperCasebold(vs.isUpperCasebold()); setWrapAlignment(vs.getWrapAlignment()); setWrappedWidth(vs.getWrappedWidth()); + setColourGaps(vs.getColourGaps()); // ViewStyle.configureFrom(this, viewStyle); } @@ -286,7 +291,8 @@ public class ViewStyle implements ViewStyleI && getThresholdTextColour() == vs.getThresholdTextColour() && isUpperCasebold() == vs.isUpperCasebold() && getWrapAlignment() == vs.getWrapAlignment() - && getWrappedWidth() == vs.getWrappedWidth()); + && getWrappedWidth() == vs.getWrappedWidth() + && getColourGaps() == vs.getColourGaps()); /* * and compare non-primitive types; syntax below will match null with null * values @@ -330,6 +336,8 @@ public class ViewStyle implements ViewStyleI hash += m++ * Boolean.valueOf(this.showSequenceFeatures).hashCode(); hash += m++ * Boolean.valueOf(this.showUnconserved).hashCode(); hash += m++ * Boolean.valueOf(this.wrapAlignment).hashCode(); + hash += m++ * Boolean.valueOf(this.colourGaps).hashCode(); + hash += m++ * Boolean.valueOf(this.showColourText).hashCode(); hash += m++ * this.charHeight; hash += m++ * this.charWidth; hash += m++ * fontSize; @@ -1144,4 +1152,16 @@ public class ViewStyle implements ViewStyleI { return showComplementFeaturesOnTop; } + + @Override + public void setColourGaps(boolean b) + { + colourGaps = b; + } + + @Override + public boolean getColourGaps() + { + return colourGaps; + } } -- 1.7.10.2