2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
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
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
24 import java.util.List;
28 import jalview.datamodel.*;
31 * Route datamodel/view update events for a sequence set to any display
32 * components involved TODO: JV3 refactor to abstract gui/view package
37 public class PaintRefresher
39 static Hashtable components;
49 public static void Register(Component comp, String seqSetId)
51 if (components == null)
53 components = new Hashtable();
56 if (components.containsKey(seqSetId))
58 Vector comps = (Vector) components.get(seqSetId);
59 if (!comps.contains(comp))
61 comps.addElement(comp);
66 Vector vcoms = new Vector();
67 vcoms.addElement(comp);
68 components.put(seqSetId, vcoms);
72 public static void RemoveComponent(Component comp)
74 if (components == null)
79 Enumeration en = components.keys();
80 while (en.hasMoreElements())
82 String id = en.nextElement().toString();
83 Vector comps = (Vector) components.get(id);
85 if (comps.size() == 0)
87 components.remove(id);
92 public static void Refresh(Component source, String id)
94 Refresh(source, id, false, false);
97 public static void Refresh(Component source, String id,
98 boolean alignmentChanged, boolean validateSequences)
100 if (components == null)
106 Vector comps = (Vector) components.get(id);
113 Enumeration e = comps.elements();
114 while (e.hasMoreElements())
116 comp = (Component) e.nextElement();
123 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 if (comp.getDataset() != source.getDataset())
191 // raise an implementation warning here - not sure if this situation
194 .println("IMPLEMENTATION PROBLEM: DATASET out of sync due to an insert whilst calling PaintRefresher.validateSequences(AlignmentI, ALignmentI)");
196 List<SequenceI> alsq;
197 synchronized (alsq = comp.getSequences())
204 comp.addSequence(a1[i]);
207 if (comp.getHiddenSequences().getSize() > 0)
209 a2 = comp.getHiddenSequences().getFullAlignment()
210 .getSequencesArray();
214 a2 = comp.getSequencesArray();
224 for (j = 0; j < jSize; j++)
227 for (i = 0; i < iSize; i++)
238 comp.deleteSequence(a2[j]);
243 static AlignmentPanel[] getAssociatedPanels(String id)
245 if (components == null)
247 return new AlignmentPanel[0];
250 Vector comps = (Vector) components.get(id);
253 return new AlignmentPanel[0];
256 Vector tmp = new Vector();
257 int i, iSize = comps.size();
258 for (i = 0; i < iSize; i++)
260 if (comps.elementAt(i) instanceof AlignmentPanel)
262 tmp.addElement(comps.elementAt(i));
265 AlignmentPanel[] result = new AlignmentPanel[tmp.size()];