JAL-3446 from applet -- reload; also fixes some repaint issues
[jalview.git] / src / jalview / gui / PaintRefresher.java
index 326bac0..7e203b2 100755 (executable)
@@ -39,6 +39,9 @@ import java.util.Map;
  */
 public class PaintRefresher
 {
+  private static final int ALIGNMENT_CHANGED = 1 << 0;
+  private static final int VALIDATE_SEQUENCES = 1 << 1;
+  
   static Map<String, List<Component>> components = new HashMap<>();
 
   /**
@@ -101,25 +104,32 @@ public class PaintRefresher
   {
     List<Component> comps = components.get(id);
 
+    int mode = (alignmentChanged ? ALIGNMENT_CHANGED : 0) | (validateSequences ? VALIDATE_SEQUENCES : 0);
     if (comps == null)
     {
       return;
     }
+    repaintComponents(source, mode, comps.toArray(new Component[comps.size()]));
+  }
 
-    for (Component comp : comps)
+  public static void repaintComponents(Component source, int mode,
+          Component... comps)
+  {
+    for (int i = 0; i < comps.length; i++)
     {
-      if (comp == source)
+      Component comp = comps[i];
+      if (comp == null)
       {
         continue;
       }
       if (comp instanceof AlignmentPanel)
       {
-        if (validateSequences && source instanceof AlignmentPanel)
+        if ((mode & VALIDATE_SEQUENCES) != 0 && source instanceof AlignmentPanel)
         {
           validateSequences(((AlignmentPanel) source).av.getAlignment(),
                   ((AlignmentPanel) comp).av.getAlignment());
         }
-        if (alignmentChanged)
+        if ((mode & ALIGNMENT_CHANGED) != 0)
         {
           ((AlignmentPanel) comp).alignmentChanged();
         }
@@ -262,4 +272,5 @@ public class PaintRefresher
     return tmp.toArray(new AlignmentPanel[tmp.size()]);
   }
 
+  
 }