2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 package jalview.appletgui;
23 import jalview.datamodel.AlignmentI;
24 import jalview.datamodel.SequenceI;
26 import java.awt.Component;
27 import java.util.Enumeration;
28 import java.util.Hashtable;
29 import java.util.List;
31 import java.util.Vector;
39 public class PaintRefresher
41 static Map<String, Vector<Component>> components;
51 public static void Register(Component comp, String seqSetId)
53 if (components == null)
55 components = new Hashtable<String, Vector<Component>>();
58 if (components.containsKey(seqSetId))
60 Vector<Component> comps = components.get(seqSetId);
61 if (!comps.contains(comp))
63 comps.addElement(comp);
68 Vector<Component> vcoms = new Vector<>();
69 vcoms.addElement(comp);
70 components.put(seqSetId, vcoms);
74 public static void RemoveComponent(Component comp)
76 if (components == null)
81 for (String id : components.keySet())
83 Vector<Component> comps = components.get(id);
84 comps.removeElement(comp);
85 if (comps.size() == 0)
87 components.remove(id);
92 public static void Refresh(Component source, String id)
94 Refresh(source, id, false, false);
97 public static void Refresh(Component source, String id,
98 boolean alignmentChanged, boolean validateSequences)
100 if (components == null)
106 Vector<Component> comps = components.get(id);
113 Enumeration<Component> e = comps.elements();
114 while (e.hasMoreElements())
116 comp = e.nextElement();
125 comps.removeElement(comp);
127 else if (validateSequences && comp instanceof AlignmentPanel
128 && source instanceof AlignmentPanel)
130 validateSequences(((AlignmentPanel) source).av.getAlignment(),
131 ((AlignmentPanel) comp).av.getAlignment());
134 if (comp instanceof AlignmentPanel && alignmentChanged)
136 ((AlignmentPanel) comp).alignmentChanged();
143 static void validateSequences(AlignmentI source, AlignmentI comp)
146 if (source.getHiddenSequences().getSize() > 0)
148 a1 = source.getHiddenSequences().getFullAlignment()
149 .getSequencesArray();
153 a1 = source.getSequencesArray();
157 if (comp.getHiddenSequences().getSize() > 0)
159 a2 = comp.getHiddenSequences().getFullAlignment().getSequencesArray();
163 a2 = comp.getSequencesArray();
166 int i, iSize = a1.length, j, jSize = a2.length;
173 boolean exists = false;
174 for (i = 0; i < iSize; i++)
178 for (j = 0; j < jSize; j++)
189 if (i < comp.getHeight())
191 // TODO: the following does not trigger any recalculation of
192 // height/etc, or maintain the dataset
193 List<SequenceI> alsq;
194 synchronized (alsq = comp.getSequences())
201 comp.addSequence(a1[i]);
204 if (comp.getHiddenSequences().getSize() > 0)
206 a2 = comp.getHiddenSequences().getFullAlignment()
207 .getSequencesArray();
211 a2 = comp.getSequencesArray();
221 for (j = 0; j < jSize; j++)
224 for (i = 0; i < iSize; i++)
235 comp.deleteSequence(a2[j]);
240 public static AlignmentPanel[] getAssociatedPanels(String id)
242 Vector<Component> comps = components.get(id);
243 Vector<Component> tmp = new Vector<>();
244 int i, iSize = comps.size();
245 for (i = 0; i < iSize; i++)
247 if (comps.elementAt(i) instanceof AlignmentPanel)
249 tmp.addElement(comps.elementAt(i));
252 AlignmentPanel[] result = new AlignmentPanel[tmp.size()];
253 for (int ix = 0; ix < result.length; ix++)
255 result[ix] = (AlignmentPanel) tmp.elementAt(ix);