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;
24 import java.util.List;
28 import jalview.datamodel.*;
36 public class PaintRefresher
38 static Hashtable components;
48 public static void Register(Component comp, String seqSetId)
50 if (components == null)
52 components = new Hashtable();
55 if (components.containsKey(seqSetId))
57 Vector comps = (Vector) components.get(seqSetId);
58 if (!comps.contains(comp))
60 comps.addElement(comp);
65 Vector vcoms = new Vector();
66 vcoms.addElement(comp);
67 components.put(seqSetId, vcoms);
71 public static void RemoveComponent(Component comp)
73 if (components == null)
78 Enumeration en = components.keys();
79 while (en.hasMoreElements())
81 String id = en.nextElement().toString();
82 Vector comps = (Vector) components.get(id);
83 comps.removeElement(comp);
84 if (comps.size() == 0)
86 components.remove(id);
91 public static void Refresh(Component source, String id)
93 Refresh(source, id, false, false);
96 public static void Refresh(Component source, String id,
97 boolean alignmentChanged, boolean validateSequences)
99 if (components == null)
105 Vector comps = (Vector) components.get(id);
112 Enumeration e = comps.elements();
113 while (e.hasMoreElements())
115 comp = (Component) e.nextElement();
124 comps.removeElement(comp);
126 else if (validateSequences && comp instanceof AlignmentPanel
127 && source instanceof AlignmentPanel)
129 validateSequences(((AlignmentPanel) source).av.getAlignment(),
130 ((AlignmentPanel) comp).av.getAlignment());
133 if (comp instanceof AlignmentPanel && alignmentChanged)
135 ((AlignmentPanel) comp).alignmentChanged();
142 static void validateSequences(AlignmentI source, AlignmentI comp)
145 if (source.getHiddenSequences().getSize() > 0)
147 a1 = source.getHiddenSequences().getFullAlignment()
148 .getSequencesArray();
152 a1 = source.getSequencesArray();
156 if (comp.getHiddenSequences().getSize() > 0)
158 a2 = comp.getHiddenSequences().getFullAlignment().getSequencesArray();
162 a2 = comp.getSequencesArray();
165 int i, iSize = a1.length, j, jSize = a2.length;
172 boolean exists = false;
173 for (i = 0; i < iSize; i++)
177 for (j = 0; j < jSize; j++)
188 if (i < comp.getHeight())
190 // TODO: the following does not trigger any recalculation of
191 // height/etc, or maintain the dataset
192 List<SequenceI> alsq;
193 synchronized (alsq = comp.getSequences())
200 comp.addSequence(a1[i]);
203 if (comp.getHiddenSequences().getSize() > 0)
205 a2 = comp.getHiddenSequences().getFullAlignment()
206 .getSequencesArray();
210 a2 = comp.getSequencesArray();
220 for (j = 0; j < jSize; j++)
223 for (i = 0; i < iSize; i++)
234 comp.deleteSequence(a2[j]);
239 public static AlignmentPanel[] getAssociatedPanels(String id)
241 Vector comps = (Vector) components.get(id);
242 Vector tmp = new Vector();
243 int i, iSize = comps.size();
244 for (i = 0; i < iSize; i++)
246 if (comps.elementAt(i) instanceof AlignmentPanel)
248 tmp.addElement(comps.elementAt(i));
251 AlignmentPanel[] result = new AlignmentPanel[tmp.size()];
252 for (int ix = 0; ix < result.length; ix++)
254 result[ix] = (AlignmentPanel) tmp.elementAt(ix);