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;
30 import java.util.Vector;
38 public class PaintRefresher
40 static Hashtable components;
50 public static void Register(Component comp, String seqSetId)
52 if (components == null)
54 components = new Hashtable();
57 if (components.containsKey(seqSetId))
59 Vector comps = (Vector) components.get(seqSetId);
60 if (!comps.contains(comp))
62 comps.addElement(comp);
67 Vector vcoms = new Vector();
68 vcoms.addElement(comp);
69 components.put(seqSetId, vcoms);
73 public static void RemoveComponent(Component comp)
75 if (components == null)
80 Enumeration en = components.keys();
81 while (en.hasMoreElements())
83 String id = en.nextElement().toString();
84 Vector comps = (Vector) components.get(id);
85 comps.removeElement(comp);
86 if (comps.size() == 0)
88 components.remove(id);
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 comps = (Vector) components.get(id);
114 Enumeration e = comps.elements();
115 while (e.hasMoreElements())
117 comp = (Component) e.nextElement();
126 comps.removeElement(comp);
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 comps = (Vector) components.get(id);
244 Vector 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);