2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8)
3 * Copyright (C) 2012 J Procter, AM Waterhouse, LM Lui, J Engelhardt, G Barton, M Clamp, S Searle
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
11 * Jalview is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
18 package jalview.appletgui;
21 import java.util.List;
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);
80 comps.removeElement(comp);
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();
121 comps.removeElement(comp);
123 else if (validateSequences && comp instanceof AlignmentPanel
124 && source instanceof AlignmentPanel)
126 validateSequences(((AlignmentPanel) source).av.getAlignment(),
127 ((AlignmentPanel) comp).av.getAlignment());
130 if (comp instanceof AlignmentPanel && alignmentChanged)
132 ((AlignmentPanel) comp).alignmentChanged();
139 static void validateSequences(AlignmentI source, AlignmentI comp)
142 if (source.getHiddenSequences().getSize() > 0)
144 a1 = source.getHiddenSequences().getFullAlignment()
145 .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 // TODO: the following does not trigger any recalculation of
188 // height/etc, or maintain the dataset
189 List<SequenceI> alsq;
190 synchronized (alsq = comp.getSequences())
197 comp.addSequence(a1[i]);
200 if (comp.getHiddenSequences().getSize() > 0)
202 a2 = comp.getHiddenSequences().getFullAlignment()
203 .getSequencesArray();
207 a2 = comp.getSequencesArray();
217 for (j = 0; j < jSize; j++)
220 for (i = 0; i < iSize; i++)
231 comp.deleteSequence(a2[j]);
236 public static AlignmentPanel[] getAssociatedPanels(String id)
238 Vector comps = (Vector) components.get(id);
239 Vector tmp = new Vector();
240 int i, iSize = comps.size();
241 for (i = 0; i < iSize; i++)
243 if (comps.elementAt(i) instanceof AlignmentPanel)
245 tmp.addElement(comps.elementAt(i));
248 AlignmentPanel[] result = new AlignmentPanel[tmp.size()];
249 for (int ix = 0; ix < result.length; ix++)
251 result[ix] = (AlignmentPanel) tmp.elementAt(ix);