JAL-3446 JAL-3401 from JAL-3253 HoldRepaint and SeqCanvas sizing issues.
[jalview.git] / src / jalview / gui / PaintRefresher.java
index 3b0b95b..326bac0 100755 (executable)
@@ -1,6 +1,6 @@
 /*
- * Jalview - A Sequence Alignment Editor and Viewer (Version 2.9.0b1)
- * Copyright (C) 2015 The Jalview Authors
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
  * 
  * This file is part of Jalview.
  * 
@@ -26,9 +26,9 @@ import jalview.datamodel.SequenceI;
 import java.awt.Component;
 import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
-import java.util.Map.Entry;
 
 /**
  * Route datamodel/view update events for a sequence set to any display
@@ -39,7 +39,7 @@ import java.util.Map.Entry;
  */
 public class PaintRefresher
 {
-  static Map<String, List<Component>> components = new HashMap<String, List<Component>>();
+  static Map<String, List<Component>> components = new HashMap<>();
 
   /**
    * Add the given component to those registered under the given sequence set
@@ -60,7 +60,7 @@ public class PaintRefresher
     }
     else
     {
-      List<Component> vcoms = new ArrayList<Component>();
+      List<Component> vcoms = new ArrayList<>();
       vcoms.add(comp);
       components.put(seqSetId, vcoms);
     }
@@ -74,26 +74,21 @@ public class PaintRefresher
    */
   public static void RemoveComponent(Component comp)
   {
-    List<String> emptied = new ArrayList<String>();
-    for (Entry<String, List<Component>> registered : components.entrySet())
+    if (components == null)
     {
-      String id = registered.getKey();
-      List<Component> comps = components.get(id);
+      return;
+    }
+
+    Iterator<String> it = components.keySet().iterator();
+    while (it.hasNext())
+    {
+      List<Component> comps = components.get(it.next());
       comps.remove(comp);
       if (comps.isEmpty())
       {
-        emptied.add(id);
+        it.remove();
       }
     }
-
-    /*
-     * Remove now empty ids after the above (to avoid
-     * ConcurrentModificationException).
-     */
-    for (String id : emptied)
-    {
-      components.remove(id);
-    }
   }
 
   public static void Refresh(Component source, String id)
@@ -117,19 +112,30 @@ public class PaintRefresher
       {
         continue;
       }
-
-      if (validateSequences && comp instanceof AlignmentPanel
-              && source instanceof AlignmentPanel)
+      if (comp instanceof AlignmentPanel)
       {
-        validateSequences(((AlignmentPanel) source).av.getAlignment(),
-                ((AlignmentPanel) comp).av.getAlignment());
+        if (validateSequences && source instanceof AlignmentPanel)
+        {
+          validateSequences(((AlignmentPanel) source).av.getAlignment(),
+                  ((AlignmentPanel) comp).av.getAlignment());
+        }
+        if (alignmentChanged)
+        {
+          ((AlignmentPanel) comp).alignmentChanged();
+        }
       }
-
-      if (comp instanceof AlignmentPanel && alignmentChanged)
+      else if (comp instanceof IdCanvas)
       {
-        ((AlignmentPanel) comp).alignmentChanged();
+        // BH 2019.04.22 fixes JS problem of repaint() consolidation
+        // that occurs in JavaScript but not Java [JAL-3226]
+        ((IdCanvas) comp).setNoFastPaint();
+      }
+      else if (comp instanceof SeqCanvas)
+      {
+        // BH 2019.04.22 fixes JS problem of repaint() consolidation
+        // that occurs in JavaScript but not Java [JAL-3226]
+        ((SeqCanvas) comp).setNoFastPaint();
       }
-
       comp.repaint();
     }
   }
@@ -188,11 +194,11 @@ public class PaintRefresher
           {
             // raise an implementation warning here - not sure if this situation
             // will ever occur
-            System.err
-                    .println("IMPLEMENTATION PROBLEM: DATASET out of sync due to an insert whilst calling PaintRefresher.validateSequences(AlignmentI, ALignmentI)");
+            System.err.println(
+                    "IMPLEMENTATION PROBLEM: DATASET out of sync due to an insert whilst calling PaintRefresher.validateSequences(AlignmentI, ALignmentI)");
           }
-          List<SequenceI> alsq;
-          synchronized (alsq = comp.getSequences())
+          List<SequenceI> alsq = comp.getSequences();
+          synchronized (alsq)
           {
             alsq.add(i, a1[i]);
           }
@@ -245,7 +251,7 @@ public class PaintRefresher
     {
       return new AlignmentPanel[0];
     }
-    List<AlignmentPanel> tmp = new ArrayList<AlignmentPanel>();
+    List<AlignmentPanel> tmp = new ArrayList<>();
     for (Component comp : comps)
     {
       if (comp instanceof AlignmentPanel)