JAL-3390 pull-up refactoring towards functional changes...
[jalview.git] / src / jalview / structures / models / AAStructureBindingModel.java
index 21b0e3d..6159757 100644 (file)
@@ -796,13 +796,20 @@ public abstract class AAStructureBindingModel
   public abstract void colourByCharge();
 
   /**
-   * colour any structures associated with sequences in the given alignment
-   * using the getFeatureRenderer() and getSequenceRenderer() renderers but only
-   * if colourBySequence is enabled.
+   * Recolours the displayed structures, if they are coloured by sequence, or
+   * 'show only visible alignment' is selected. This supports updating structure
+   * colours on either change of alignment colours, or change to the visible
+   * region of the alignment.
    */
   public void colourBySequence(AlignmentViewPanel alignmentv)
   {
-    if (!colourBySequence || !isLoadingFinished())
+    if (!isLoadingFinished())
+    {
+      return;
+    }
+    // todo: property change event for visibleAlignment
+    // to avoid unnecessary redraws here
+    if (!colourBySequence && !isShowAlignmentOnly())
     {
       return;
     }
@@ -856,5 +863,23 @@ public abstract class AAStructureBindingModel
    * 
    * @param alignViewportI
    */
-  public abstract void showStructures(AlignViewportI alignViewportI);
+  public void showStructures(AlignViewportI alignViewportI) 
+  {
+    // override with implementation
+  }
+
+  @Override
+  public void updateColours(Object source)
+  {
+    AlignmentViewPanel ap = (AlignmentViewPanel) source;
+    // ignore events from panels not used to colour this view
+    if (!getViewer().isUsedforcolourby(ap))
+    {
+      return;
+    }
+    if (!isLoadingFromArchive())
+    {
+      colourBySequence(ap);
+    }
+  }
 }