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.appletgui;
\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
78 comps.removeElement(comp);
\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 (!comp.isValid())
\r
121 comps.removeElement(comp);
\r
123 else if (validateSequences
\r
124 && comp instanceof AlignmentPanel
\r
125 && source instanceof AlignmentPanel)
\r
127 validateSequences( ( (AlignmentPanel) source).av.alignment,
\r
128 ( (AlignmentPanel) comp).av.alignment);
\r
131 if (comp instanceof AlignmentPanel && alignmentChanged)
\r
133 ( (AlignmentPanel) comp).alignmentChanged();
\r
140 static void validateSequences(AlignmentI source, AlignmentI comp)
\r
143 if (source.getHiddenSequences().getSize() > 0)
\r
145 a1 = source.getHiddenSequences().getFullAlignment().getSequencesArray();
\r
149 a1 = source.getSequencesArray();
\r
153 if (comp.getHiddenSequences().getSize() > 0)
\r
155 a2 = comp.getHiddenSequences().getFullAlignment().getSequencesArray();
\r
159 a2 = comp.getSequencesArray();
\r
162 int i, iSize = a1.length, j, jSize = a2.length;
\r
164 if (iSize == jSize)
\r
169 boolean exists = false;
\r
170 for (i = 0; i < iSize; i++)
\r
174 for (j = 0; j < jSize; j++)
\r
176 if (a2[j] == a1[i])
\r
187 comp.getSequences().insertElementAt(a1[i], i);
\r
191 comp.addSequence(a1[i]);
\r
196 if (comp.getHiddenSequences().getSize() > 0)
\r
198 a2 = comp.getHiddenSequences().getFullAlignment().getSequencesArray();
\r
202 a2 = comp.getSequencesArray();
\r
210 for (j = 0; j < jSize; j++)
\r
213 for (i = 0; i < iSize; i++)
\r
215 if (a2[j] == a1[i])
\r
224 comp.deleteSequence(a2[j]);
\r