2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.4)
3 * Copyright (C) 2008 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;
40 * @param comp DOCUMENT ME!
41 * @param al DOCUMENT ME!
43 public static void Register(Component comp, String seqSetId)
45 if (components == null)
47 components = new Hashtable();
50 if (components.containsKey(seqSetId))
52 Vector comps = (Vector) components.get(seqSetId);
53 if (!comps.contains(comp))
55 comps.addElement(comp);
60 Vector vcoms = new Vector();
61 vcoms.addElement(comp);
62 components.put(seqSetId, vcoms);
66 public static void RemoveComponent(Component comp)
68 if (components == null)
73 Enumeration en = components.keys();
74 while (en.hasMoreElements())
76 String id = en.nextElement().toString();
77 Vector comps = (Vector) components.get(id);
79 if (comps.size() == 0)
81 components.remove(id);
86 public static void Refresh(Component source, String id)
88 Refresh(source, id, false, false);
91 public static void Refresh(Component source,
93 boolean alignmentChanged,
94 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
120 && comp instanceof AlignmentPanel
121 && source instanceof AlignmentPanel)
123 validateSequences( ( (AlignmentPanel) source).av.alignment,
124 ( (AlignmentPanel) comp).av.alignment);
127 if (comp instanceof AlignmentPanel && alignmentChanged)
129 ( (AlignmentPanel) comp).alignmentChanged();
136 static void validateSequences(AlignmentI source, AlignmentI comp)
139 if (source.getHiddenSequences().getSize() > 0)
141 a1 = source.getHiddenSequences().getFullAlignment().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().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()];