2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.6)
3 * Copyright (C) 2010 J Procter, AM Waterhouse, 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/>.
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);
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();
118 if (validateSequences && comp instanceof AlignmentPanel
119 && source instanceof AlignmentPanel)
121 validateSequences(((AlignmentPanel) source).av.alignment,
122 ((AlignmentPanel) comp).av.alignment);
125 if (comp instanceof AlignmentPanel && alignmentChanged)
127 ((AlignmentPanel) comp).alignmentChanged();
134 static void validateSequences(AlignmentI source, AlignmentI comp)
137 if (source.getHiddenSequences().getSize() > 0)
139 a1 = source.getHiddenSequences().getFullAlignment()
140 .getSequencesArray();
144 a1 = source.getSequencesArray();
148 if (comp.getHiddenSequences().getSize() > 0)
150 a2 = comp.getHiddenSequences().getFullAlignment().getSequencesArray();
154 a2 = comp.getSequencesArray();
157 int i, iSize = a1.length, j, jSize = a2.length;
164 boolean exists = false;
165 for (i = 0; i < iSize; i++)
169 for (j = 0; j < jSize; j++)
180 if (i < comp.getHeight())
182 comp.getSequences().insertElementAt(a1[i], i);
186 comp.addSequence(a1[i]);
189 if (comp.getHiddenSequences().getSize() > 0)
191 a2 = comp.getHiddenSequences().getFullAlignment()
192 .getSequencesArray();
196 a2 = comp.getSequencesArray();
206 for (j = 0; j < jSize; j++)
209 for (i = 0; i < iSize; i++)
220 comp.deleteSequence(a2[j]);
225 static AlignmentPanel[] getAssociatedPanels(String id)
227 Vector comps = (Vector) components.get(id);
228 Vector tmp = new Vector();
229 int i, iSize = comps.size();
230 for (i = 0; i < iSize; i++)
232 if (comps.elementAt(i) instanceof AlignmentPanel)
234 tmp.addElement(((AlignmentPanel) comps.elementAt(i)));
237 AlignmentPanel[] result = new AlignmentPanel[tmp.size()];