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.Hashtable;
28 import java.util.Iterator;
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 Iterator<String> it = components.keySet().iterator();
84 Vector<Component> comps = components.get(it.next());
85 comps.removeElement(comp);
93 public static void Refresh(Component source, String id)
95 Refresh(source, id, false, false);
98 public static void Refresh(Component source, String id,
99 boolean alignmentChanged, boolean validateSequences)
101 if (components == null)
107 Vector<Component> comps = components.get(id);
114 Iterator<Component> it = comps.iterator();
128 else if (validateSequences && comp instanceof AlignmentPanel
129 && source instanceof AlignmentPanel)
131 validateSequences(((AlignmentPanel) source).av.getAlignment(),
132 ((AlignmentPanel) comp).av.getAlignment());
135 if (comp instanceof AlignmentPanel && alignmentChanged)
137 ((AlignmentPanel) comp).alignmentChanged();
144 static void validateSequences(AlignmentI source, AlignmentI comp)
147 if (source.getHiddenSequences().getSize() > 0)
149 a1 = source.getHiddenSequences().getFullAlignment()
150 .getSequencesArray();
154 a1 = source.getSequencesArray();
158 if (comp.getHiddenSequences().getSize() > 0)
160 a2 = comp.getHiddenSequences().getFullAlignment().getSequencesArray();
164 a2 = comp.getSequencesArray();
167 int i, iSize = a1.length, j, jSize = a2.length;
174 boolean exists = false;
175 for (i = 0; i < iSize; i++)
179 for (j = 0; j < jSize; j++)
190 if (i < comp.getHeight())
192 // TODO: the following does not trigger any recalculation of
193 // height/etc, or maintain the dataset
194 List<SequenceI> alsq;
195 synchronized (alsq = comp.getSequences())
202 comp.addSequence(a1[i]);
205 if (comp.getHiddenSequences().getSize() > 0)
207 a2 = comp.getHiddenSequences().getFullAlignment()
208 .getSequencesArray();
212 a2 = comp.getSequencesArray();
222 for (j = 0; j < jSize; j++)
225 for (i = 0; i < iSize; i++)
236 comp.deleteSequence(a2[j]);
241 public static AlignmentPanel[] getAssociatedPanels(String id)
243 Vector<Component> comps = components.get(id);
244 Vector<Component> tmp = new Vector<>();
245 int i, iSize = comps.size();
246 for (i = 0; i < iSize; i++)
248 if (comps.elementAt(i) instanceof AlignmentPanel)
250 tmp.addElement(comps.elementAt(i));
253 AlignmentPanel[] result = new AlignmentPanel[tmp.size()];
254 for (int ix = 0; ix < result.length; ix++)
256 result[ix] = (AlignmentPanel) tmp.elementAt(ix);