2 * Jalview - A Sequence Alignment Editor and Viewer
\r
3 * Copyright (C) 2007 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
\r
5 * This program is free software; you can redistribute it and/or
\r
6 * modify it under the terms of the GNU General Public License
\r
7 * as published by the Free Software Foundation; either version 2
\r
8 * of the License, or (at your option) any later version.
\r
10 * This program is distributed in the hope that it will be useful,
\r
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
13 * GNU General Public License for more details.
\r
15 * You should have received a copy of the GNU General Public License
\r
16 * along with this program; if not, write to the Free Software
\r
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
\r
19 package jalview.gui;
\r
25 import jalview.datamodel.*;
\r
31 * @version $Revision$
\r
33 public class PaintRefresher
\r
35 static Hashtable components;
\r
40 * @param comp DOCUMENT ME!
\r
41 * @param al DOCUMENT ME!
\r
43 public static void Register(Component comp, String seqSetId)
\r
45 if (components == null)
\r
47 components = new Hashtable();
\r
50 if (components.containsKey(seqSetId))
\r
52 Vector comps = (Vector) components.get(seqSetId);
\r
53 if (!comps.contains(comp))
\r
55 comps.addElement(comp);
\r
60 Vector vcoms = new Vector();
\r
61 vcoms.addElement(comp);
\r
62 components.put(seqSetId, vcoms);
\r
66 public static void RemoveComponent(Component comp)
\r
68 if (components == null)
\r
73 Enumeration en = components.keys();
\r
74 while (en.hasMoreElements())
\r
76 String id = en.nextElement().toString();
\r
77 Vector comps = (Vector) components.get(id);
\r
79 if (comps.size() == 0)
\r
81 components.remove(id);
\r
86 public static void Refresh(Component source, String id)
\r
88 Refresh(source, id, false, false);
\r
91 public static void Refresh(Component source,
\r
93 boolean alignmentChanged,
\r
94 boolean validateSequences)
\r
96 if (components == null)
\r
102 Vector comps = (Vector) components.get(id);
\r
109 Enumeration e = comps.elements();
\r
110 while (e.hasMoreElements())
\r
112 comp = (Component) e.nextElement();
\r
114 if (comp == source)
\r
119 if (validateSequences
\r
120 && comp instanceof AlignmentPanel
\r
121 && source instanceof AlignmentPanel)
\r
123 validateSequences( ( (AlignmentPanel) source).av.alignment,
\r
124 ( (AlignmentPanel) comp).av.alignment);
\r
127 if (comp instanceof AlignmentPanel && alignmentChanged)
\r
129 ( (AlignmentPanel) comp).alignmentChanged();
\r
136 static void validateSequences(AlignmentI source, AlignmentI comp)
\r
139 if (source.getHiddenSequences().getSize() > 0)
\r
141 a1 = source.getHiddenSequences().getFullAlignment().getSequencesArray();
\r
145 a1 = source.getSequencesArray();
\r
149 if (comp.getHiddenSequences().getSize() > 0)
\r
151 a2 = comp.getHiddenSequences().getFullAlignment().getSequencesArray();
\r
155 a2 = comp.getSequencesArray();
\r
158 int i, iSize = a1.length, j, jSize = a2.length;
\r
160 if (iSize == jSize)
\r
165 boolean exists = false;
\r
166 for (i = 0; i < iSize; i++)
\r
170 for (j = 0; j < jSize; j++)
\r
172 if (a2[j] == a1[i])
\r
181 if (i < comp.getHeight())
\r
183 comp.getSequences().insertElementAt(a1[i], i);
\r
187 comp.addSequence(a1[i]);
\r
190 if (comp.getHiddenSequences().getSize() > 0)
\r
192 a2 = comp.getHiddenSequences().getFullAlignment().getSequencesArray();
\r
196 a2 = comp.getSequencesArray();
\r
206 for (j = 0; j < jSize; j++)
\r
209 for (i = 0; i < iSize; i++)
\r
211 if (a2[j] == a1[i])
\r
220 comp.deleteSequence(a2[j]);
\r
225 static AlignmentPanel[] getAssociatedPanels(String id)
\r
227 Vector comps = (Vector) components.get(id);
\r
228 Vector tmp = new Vector();
\r
229 int i, iSize = comps.size();
\r
230 for (i = 0; i < iSize; i++)
\r
232 if (comps.elementAt(i) instanceof AlignmentPanel)
\r
234 tmp.addElement( ( (AlignmentPanel) comps.elementAt(i)));
\r
237 AlignmentPanel[] result = new AlignmentPanel[tmp.size()];
\r
238 tmp.toArray(result);
\r