2 * Jalview - A Sequence Alignment Editor and Viewer (Development Version 2.4.1)
3 * Copyright (C) 2009 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
25 import jalview.datamodel.*;
33 public class PaintRefresher
35 static Hashtable components;
45 public static void Register(Component comp, String seqSetId)
47 if (components == null)
49 components = new Hashtable();
52 if (components.containsKey(seqSetId))
54 Vector comps = (Vector) components.get(seqSetId);
55 if (!comps.contains(comp))
57 comps.addElement(comp);
62 Vector vcoms = new Vector();
63 vcoms.addElement(comp);
64 components.put(seqSetId, vcoms);
68 public static void RemoveComponent(Component comp)
70 if (components == null)
75 Enumeration en = components.keys();
76 while (en.hasMoreElements())
78 String id = en.nextElement().toString();
79 Vector comps = (Vector) components.get(id);
81 if (comps.size() == 0)
83 components.remove(id);
88 public static void Refresh(Component source, String id)
90 Refresh(source, id, false, false);
93 public static void Refresh(Component source, String id,
94 boolean alignmentChanged, boolean validateSequences)
96 if (components == null)
102 Vector comps = (Vector) components.get(id);
109 Enumeration e = comps.elements();
110 while (e.hasMoreElements())
112 comp = (Component) e.nextElement();
119 if (validateSequences && comp instanceof AlignmentPanel
120 && source instanceof AlignmentPanel)
122 validateSequences(((AlignmentPanel) source).av.alignment,
123 ((AlignmentPanel) comp).av.alignment);
126 if (comp instanceof AlignmentPanel && alignmentChanged)
128 ((AlignmentPanel) comp).alignmentChanged();
135 static void validateSequences(AlignmentI source, AlignmentI comp)
138 if (source.getHiddenSequences().getSize() > 0)
140 a1 = source.getHiddenSequences().getFullAlignment()
141 .getSequencesArray();
145 a1 = source.getSequencesArray();
149 if (comp.getHiddenSequences().getSize() > 0)
151 a2 = comp.getHiddenSequences().getFullAlignment().getSequencesArray();
155 a2 = comp.getSequencesArray();
158 int i, iSize = a1.length, j, jSize = a2.length;
165 boolean exists = false;
166 for (i = 0; i < iSize; i++)
170 for (j = 0; j < jSize; j++)
181 if (i < comp.getHeight())
183 comp.getSequences().insertElementAt(a1[i], i);
187 comp.addSequence(a1[i]);
190 if (comp.getHiddenSequences().getSize() > 0)
192 a2 = comp.getHiddenSequences().getFullAlignment()
193 .getSequencesArray();
197 a2 = comp.getSequencesArray();
207 for (j = 0; j < jSize; j++)
210 for (i = 0; i < iSize; i++)
221 comp.deleteSequence(a2[j]);
226 static AlignmentPanel[] getAssociatedPanels(String id)
228 Vector comps = (Vector) components.get(id);
229 Vector tmp = new Vector();
230 int i, iSize = comps.size();
231 for (i = 0; i < iSize; i++)
233 if (comps.elementAt(i) instanceof AlignmentPanel)
235 tmp.addElement(((AlignmentPanel) comps.elementAt(i)));
238 AlignmentPanel[] result = new AlignmentPanel[tmp.size()];