2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7)
3 * Copyright (C) 2011 J Procter, AM Waterhouse, J Engelhardt, LM Lui, G Barton, M Clamp, S Searle
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 of the License, or (at your option) any later version.
11 * Jalview is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
18 package jalview.appletgui;
24 import jalview.datamodel.*;
32 public class PaintRefresher
34 static Hashtable components;
44 public static void Register(Component comp, String seqSetId)
46 if (components == null)
48 components = new Hashtable();
51 if (components.containsKey(seqSetId))
53 Vector comps = (Vector) components.get(seqSetId);
54 if (!comps.contains(comp))
56 comps.addElement(comp);
61 Vector vcoms = new Vector();
62 vcoms.addElement(comp);
63 components.put(seqSetId, vcoms);
67 public static void RemoveComponent(Component comp)
69 if (components == null)
74 Enumeration en = components.keys();
75 while (en.hasMoreElements())
77 String id = en.nextElement().toString();
78 Vector comps = (Vector) components.get(id);
79 comps.removeElement(comp);
80 if (comps.size() == 0)
82 components.remove(id);
87 public static void Refresh(Component source, String id)
89 Refresh(source, id, false, false);
92 public static void Refresh(Component source, String id,
93 boolean alignmentChanged, boolean validateSequences)
95 if (components == null)
101 Vector comps = (Vector) components.get(id);
108 Enumeration e = comps.elements();
109 while (e.hasMoreElements())
111 comp = (Component) e.nextElement();
120 comps.removeElement(comp);
122 else if (validateSequences && comp instanceof AlignmentPanel
123 && source instanceof AlignmentPanel)
125 validateSequences(((AlignmentPanel) source).av.getAlignment(),
126 ((AlignmentPanel) comp).av.getAlignment());
129 if (comp instanceof AlignmentPanel && alignmentChanged)
131 ((AlignmentPanel) comp).alignmentChanged();
138 static void validateSequences(AlignmentI source, AlignmentI comp)
141 if (source.getHiddenSequences().getSize() > 0)
143 a1 = source.getHiddenSequences().getFullAlignment()
144 .getSequencesArray();
148 a1 = source.getSequencesArray();
152 if (comp.getHiddenSequences().getSize() > 0)
154 a2 = comp.getHiddenSequences().getFullAlignment().getSequencesArray();
158 a2 = comp.getSequencesArray();
161 int i, iSize = a1.length, j, jSize = a2.length;
168 boolean exists = false;
169 for (i = 0; i < iSize; i++)
173 for (j = 0; j < jSize; j++)
184 if (i < comp.getHeight())
186 comp.getSequences().insertElementAt(a1[i], i);
190 comp.addSequence(a1[i]);
193 if (comp.getHiddenSequences().getSize() > 0)
195 a2 = comp.getHiddenSequences().getFullAlignment()
196 .getSequencesArray();
200 a2 = comp.getSequencesArray();
210 for (j = 0; j < jSize; j++)
213 for (i = 0; i < iSize; i++)
224 comp.deleteSequence(a2[j]);
229 public static AlignmentPanel[] getAssociatedPanels(String id)
231 Vector comps = (Vector) components.get(id);
232 Vector tmp = new Vector();
233 int i, iSize = comps.size();
234 for (i = 0; i < iSize; i++)
236 if (comps.elementAt(i) instanceof AlignmentPanel)
238 tmp.addElement(((AlignmentPanel) comps.elementAt(i)));
241 AlignmentPanel[] result = new AlignmentPanel[tmp.size()];
242 for (int ix=0;ix<result.length;ix++) {
243 result[ix] = (AlignmentPanel) tmp.elementAt(ix);