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/>.
21 import java.util.List;
25 import jalview.datamodel.*;
28 * Route datamodel/view update events for a sequence set to any display components involved
29 * TODO: JV3 refactor to abstract gui/view package
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);
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();
120 if (validateSequences && comp instanceof AlignmentPanel
121 && source instanceof AlignmentPanel)
123 validateSequences(((AlignmentPanel) source).av.getAlignment(),
124 ((AlignmentPanel) comp).av.getAlignment());
127 if (comp instanceof AlignmentPanel && alignmentChanged)
129 ((AlignmentPanel) comp).alignmentChanged();
136 static void validateSequences(AlignmentI source, AlignmentI comp)
139 if (source.getHiddenSequences().getSize() > 0)
141 a1 = source.getHiddenSequences().getFullAlignment()
142 .getSequencesArray();
146 a1 = source.getSequencesArray();
150 if (comp.getHiddenSequences().getSize() > 0)
152 a2 = comp.getHiddenSequences().getFullAlignment().getSequencesArray();
156 a2 = comp.getSequencesArray();
159 int i, iSize = a1.length, j, jSize = a2.length;
166 boolean exists = false;
167 for (i = 0; i < iSize; i++)
171 for (j = 0; j < jSize; j++)
182 if (i < comp.getHeight())
184 // TODO: the following does not trigger any recalculation of
185 // height/etc, or maintain the dataset
186 if (comp.getDataset() != source.getDataset())
188 // raise an implementation warning here - not sure if this situation
191 .println("IMPLEMENTATION PROBLEM: DATASET out of sync due to an insert whilst calling PaintRefresher.validateSequences(AlignmentI, ALignmentI)");
193 List<SequenceI> alsq;
194 synchronized (alsq = comp.getSequences())
201 comp.addSequence(a1[i]);
204 if (comp.getHiddenSequences().getSize() > 0)
206 a2 = comp.getHiddenSequences().getFullAlignment()
207 .getSequencesArray();
211 a2 = comp.getSequencesArray();
221 for (j = 0; j < jSize; j++)
224 for (i = 0; i < iSize; i++)
235 comp.deleteSequence(a2[j]);
240 static AlignmentPanel[] getAssociatedPanels(String id)
242 if (components == null)
244 return new AlignmentPanel[0];
247 Vector comps = (Vector) components.get(id);
250 return new AlignmentPanel[0];
253 Vector tmp = new Vector();
254 int i, iSize = comps.size();
255 for (i = 0; i < iSize; i++)
257 if (comps.elementAt(i) instanceof AlignmentPanel)
259 tmp.addElement(comps.elementAt(i));
262 AlignmentPanel[] result = new AlignmentPanel[tmp.size()];