JAL-3719 Format->Colour Gaps option uses Overview gap colour logic pulled up to align...
authorJim Procter <jprocter@issues.jalview.org>
Wed, 19 Aug 2020 17:43:52 +0000 (18:43 +0100)
committerJim Procter <jprocter@issues.jalview.org>
Wed, 19 Aug 2020 17:43:52 +0000 (18:43 +0100)
resources/lang/Messages.properties
resources/lang/Messages_es.properties
src/jalview/api/ViewStyleI.java
src/jalview/gui/AlignFrame.java
src/jalview/gui/SeqCanvas.java
src/jalview/gui/SequenceRenderer.java
src/jalview/jbgui/GAlignFrame.java
src/jalview/renderer/OverviewResColourFinder.java
src/jalview/renderer/ResidueColourFinder.java
src/jalview/viewmodel/AlignmentViewport.java
src/jalview/viewmodel/styles/ViewStyle.java

index 496fad0..e246e4a 100644 (file)
@@ -1418,3 +1418,4 @@ label.copy_to_clipboard = Copy to clipboard
 label.copy_to_clipboard_tooltip = Copy all of the log text in this console to the system clipboard
 label.ignore_hidden = Ignore hidden columns
 label.ignore_hidden_tooltip = Ignore any characters in hidden columns when matching
+label.colour_gaps = Colour Gaps
\ No newline at end of file
index 6364f5e..543a996 100644 (file)
@@ -1419,3 +1419,4 @@ label.copy_to_clipboard = Copiar en el portapapeles
 label.copy_to_clipboard_tooltip = Copie todo el texto de registro en esta consola al portapapeles del sistema
 label.ignore_hidden = Ignorar columnas ocultas
 label.ignore_hidden_tooltip = Ignorar caracteres en columnas ocultas
+label.colour_gaps = Color del huecos
\ No newline at end of file
index a348300..458c8b8 100644 (file)
@@ -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();
 }
index 5e16397..35e6d3e 100644 (file)
@@ -883,6 +883,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());
@@ -2968,6 +2969,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());
index 2832796..787551f 100755 (executable)
@@ -1007,7 +1007,7 @@ public class SeqCanvas extends JComponent implements ViewportListenerI
     int charWidth = av.getCharWidth();
 
     g.setFont(av.getFont());
-    seqRdr.prepare(g, av.isRenderGaps());
+    seqRdr.prepare(g, av.isRenderGaps(), av.getColourGaps());
 
     SequenceI nextSeq;
 
index fb967ed..33d34a2 100755 (executable)
@@ -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)
index 075b490..3ae3762 100755 (executable)
@@ -85,6 +85,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();
@@ -646,7 +648,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()
@@ -1867,6 +1878,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);
@@ -1887,6 +1899,12 @@ public class GAlignFrame extends JInternalFrame
     // selectMenu.add(listenToViewSelections);
   }
 
+  protected void colourGapsMenuItem_actionPerformed(ActionEvent e)
+  {
+    // TODO Auto-generated method stub
+    
+  }
+
   protected void loadVcf_actionPerformed()
   {
   }
index a497d92..2d9362a 100644 (file)
@@ -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.
index 2da7233..7a1b720 100644 (file)
@@ -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;
   }
 
index c9a3a80..c8b6914 100644 (file)
@@ -451,6 +451,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
index 91f2f0c..1daca08 100644 (file)
@@ -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;
+  }
 }