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