X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FPaintRefresher.java;h=7e203b22d54066c60870b587050eeb85a3717a44;hb=0751c58086542f9e0466201b624f84d1efd547bb;hp=d731e7084fc15451a775c02bb362ac9175d414d9;hpb=f4766a7bbcfae845fc95923b01fa14ff83d589ff;p=jalview.git diff --git a/src/jalview/gui/PaintRefresher.java b/src/jalview/gui/PaintRefresher.java index d731e70..7e203b2 100755 --- a/src/jalview/gui/PaintRefresher.java +++ b/src/jalview/gui/PaintRefresher.java @@ -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,10 @@ import java.util.Map.Entry; */ public class PaintRefresher { - static Map> components = new HashMap>(); + private static final int ALIGNMENT_CHANGED = 1 << 0; + private static final int VALIDATE_SEQUENCES = 1 << 1; + + static Map> components = new HashMap<>(); /** * Add the given component to those registered under the given sequence set @@ -60,7 +63,7 @@ public class PaintRefresher } else { - List vcoms = new ArrayList(); + List vcoms = new ArrayList<>(); vcoms.add(comp); components.put(seqSetId, vcoms); } @@ -74,26 +77,21 @@ public class PaintRefresher */ public static void RemoveComponent(Component comp) { - List emptied = new ArrayList(); - for (Entry> registered : components.entrySet()) + if (components == null) { - String id = registered.getKey(); - List comps = components.get(id); + return; + } + + Iterator it = components.keySet().iterator(); + while (it.hasNext()) + { + List 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) @@ -106,30 +104,48 @@ public class PaintRefresher { List 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 (validateSequences && comp instanceof AlignmentPanel - && source instanceof AlignmentPanel) + if (comp instanceof AlignmentPanel) + { + if ((mode & VALIDATE_SEQUENCES) != 0 && source instanceof AlignmentPanel) + { + validateSequences(((AlignmentPanel) source).av.getAlignment(), + ((AlignmentPanel) comp).av.getAlignment()); + } + if ((mode & ALIGNMENT_CHANGED) != 0) + { + ((AlignmentPanel) comp).alignmentChanged(); + } + } + else if (comp instanceof IdCanvas) { - validateSequences(((AlignmentPanel) source).av.getAlignment(), - ((AlignmentPanel) comp).av.getAlignment()); + // BH 2019.04.22 fixes JS problem of repaint() consolidation + // that occurs in JavaScript but not Java [JAL-3226] + ((IdCanvas) comp).setNoFastPaint(); } - - if (comp instanceof AlignmentPanel && alignmentChanged) + else if (comp instanceof SeqCanvas) { - ((AlignmentPanel) comp).alignmentChanged(); + // BH 2019.04.22 fixes JS problem of repaint() consolidation + // that occurs in JavaScript but not Java [JAL-3226] + ((SeqCanvas) comp).setNoFastPaint(); } - comp.repaint(); } } @@ -191,8 +207,8 @@ public class PaintRefresher System.err.println( "IMPLEMENTATION PROBLEM: DATASET out of sync due to an insert whilst calling PaintRefresher.validateSequences(AlignmentI, ALignmentI)"); } - List alsq; - synchronized (alsq = comp.getSequences()) + List alsq = comp.getSequences(); + synchronized (alsq) { alsq.add(i, a1[i]); } @@ -245,7 +261,7 @@ public class PaintRefresher { return new AlignmentPanel[0]; } - List tmp = new ArrayList(); + List tmp = new ArrayList<>(); for (Component comp : comps) { if (comp instanceof AlignmentPanel) @@ -256,4 +272,5 @@ public class PaintRefresher return tmp.toArray(new AlignmentPanel[tmp.size()]); } + }