2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.0b1)
3 * Copyright (C) 2014 The Jalview Authors
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/>.
17 * The Jalview Authors are detailed in the 'AUTHORS' file.
19 package jalview.appletgui;
22 import java.util.List;
26 import jalview.datamodel.*;
34 public class PaintRefresher
36 static Hashtable components;
46 public static void Register(Component comp, String seqSetId)
48 if (components == null)
50 components = new Hashtable();
53 if (components.containsKey(seqSetId))
55 Vector comps = (Vector) components.get(seqSetId);
56 if (!comps.contains(comp))
58 comps.addElement(comp);
63 Vector vcoms = new Vector();
64 vcoms.addElement(comp);
65 components.put(seqSetId, vcoms);
69 public static void RemoveComponent(Component comp)
71 if (components == null)
76 Enumeration en = components.keys();
77 while (en.hasMoreElements())
79 String id = en.nextElement().toString();
80 Vector comps = (Vector) components.get(id);
81 comps.removeElement(comp);
82 if (comps.size() == 0)
84 components.remove(id);
89 public static void Refresh(Component source, String id)
91 Refresh(source, id, false, false);
94 public static void Refresh(Component source, String id,
95 boolean alignmentChanged, boolean validateSequences)
97 if (components == null)
103 Vector comps = (Vector) components.get(id);
110 Enumeration e = comps.elements();
111 while (e.hasMoreElements())
113 comp = (Component) e.nextElement();
122 comps.removeElement(comp);
124 else if (validateSequences && comp instanceof AlignmentPanel
125 && source instanceof AlignmentPanel)
127 validateSequences(((AlignmentPanel) source).av.getAlignment(),
128 ((AlignmentPanel) comp).av.getAlignment());
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()
146 .getSequencesArray();
150 a1 = source.getSequencesArray();
154 if (comp.getHiddenSequences().getSize() > 0)
156 a2 = comp.getHiddenSequences().getFullAlignment().getSequencesArray();
160 a2 = comp.getSequencesArray();
163 int i, iSize = a1.length, j, jSize = a2.length;
170 boolean exists = false;
171 for (i = 0; i < iSize; i++)
175 for (j = 0; j < jSize; j++)
186 if (i < comp.getHeight())
188 // TODO: the following does not trigger any recalculation of
189 // height/etc, or maintain the dataset
190 List<SequenceI> alsq;
191 synchronized (alsq = comp.getSequences())
198 comp.addSequence(a1[i]);
201 if (comp.getHiddenSequences().getSize() > 0)
203 a2 = comp.getHiddenSequences().getFullAlignment()
204 .getSequencesArray();
208 a2 = comp.getSequencesArray();
218 for (j = 0; j < jSize; j++)
221 for (i = 0; i < iSize; i++)
232 comp.deleteSequence(a2[j]);
237 public static AlignmentPanel[] getAssociatedPanels(String id)
239 Vector comps = (Vector) components.get(id);
240 Vector tmp = new Vector();
241 int i, iSize = comps.size();
242 for (i = 0; i < iSize; i++)
244 if (comps.elementAt(i) instanceof AlignmentPanel)
246 tmp.addElement(comps.elementAt(i));
249 AlignmentPanel[] result = new AlignmentPanel[tmp.size()];
250 for (int ix = 0; ix < result.length; ix++)
252 result[ix] = (AlignmentPanel) tmp.elementAt(ix);