X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FPaintRefresher.java;h=c6d3b588755f5a457a51045aebead9e1ba3ae3d2;hb=2de36153a84ca246643cd28b2ce05e9f4159dd89;hp=de1d5d847c165f7027071c5647d374bc71765af1;hpb=6e52c3f5f6679026d2adccab3dc15e90faebf8f7;p=jalview.git diff --git a/src/jalview/gui/PaintRefresher.java b/src/jalview/gui/PaintRefresher.java index de1d5d8..c6d3b58 100755 --- a/src/jalview/gui/PaintRefresher.java +++ b/src/jalview/gui/PaintRefresher.java @@ -1,6 +1,6 @@ /* * Jalview - A Sequence Alignment Editor and Viewer - * Copyright (C) 2006 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle + * Copyright (C) 2007 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -18,12 +18,11 @@ */ package jalview.gui; -import jalview.datamodel.*; +import java.util.*; import java.awt.*; -import java.util.*; - +import jalview.datamodel.*; /** * DOCUMENT ME! @@ -33,171 +32,212 @@ import java.util.*; */ public class PaintRefresher { - static Hashtable components; - - /** - * DOCUMENT ME! - * - * @param comp DOCUMENT ME! - * @param al DOCUMENT ME! - */ - public static void Register(Component comp, String seqSetId) + static Hashtable components; + + /** + * DOCUMENT ME! + * + * @param comp DOCUMENT ME! + * @param al DOCUMENT ME! + */ + public static void Register(Component comp, String seqSetId) + { + if (components == null) { - if (components == null) - components = new Hashtable(); + components = new Hashtable(); + } - if (components.containsKey(seqSetId)) - { - Vector comps = (Vector) components.get(seqSetId); - if(!comps.contains(comp)) - { - comps.addElement(comp); - } - } - else - { - Vector vcoms = new Vector(); - vcoms.addElement(comp); - components.put(seqSetId, vcoms); - } + if (components.containsKey(seqSetId)) + { + Vector comps = (Vector) components.get(seqSetId); + if (!comps.contains(comp)) + { + comps.addElement(comp); + } } + else + { + Vector vcoms = new Vector(); + vcoms.addElement(comp); + components.put(seqSetId, vcoms); + } + } - public static void RemoveComponent(Component comp) + public static void RemoveComponent(Component comp) + { + if (components == null) { - if (components == null) - return; + return; + } - Enumeration en = components.keys(); - while(en.hasMoreElements()) + Enumeration en = components.keys(); + while (en.hasMoreElements()) + { + String id = en.nextElement().toString(); + Vector comps = (Vector) components.get(id); + comps.remove(comp); + if (comps.size() == 0) { - String id = en.nextElement().toString(); - Vector comps = (Vector) components.get(id); - comps.remove(comp); - if(comps.size()==0) - { - components.remove(id); - } + components.remove(id); } } + } + + public static void Refresh(Component source, String id) + { + Refresh(source, id, false, false); + } + + public static void Refresh(Component source, + String id, + boolean alignmentChanged, + boolean validateSequences) + { + if (components == null) + { + return; + } - public static void Refresh(Component source, String id) + Component comp; + Vector comps = (Vector) components.get(id); + + if (comps == null) { - Refresh( source, id, false, false); + return; } - public static void Refresh(Component source, - String id, - boolean alignmentChanged, - boolean validateSequences) + Enumeration e = comps.elements(); + while (e.hasMoreElements()) { - if (components == null) - return; + comp = (Component) e.nextElement(); - Component comp; - Vector comps = (Vector) components.get(id); + if (comp == source) + { + continue; + } - if(comps==null) + if (validateSequences + && comp instanceof AlignmentPanel + && source instanceof AlignmentPanel) { - return; + validateSequences( ( (AlignmentPanel) source).av.alignment, + ( (AlignmentPanel) comp).av.alignment); } - Enumeration e = comps.elements(); - while (e.hasMoreElements()) + if (comp instanceof AlignmentPanel && alignmentChanged) { - comp = (Component) e.nextElement(); + ( (AlignmentPanel) comp).alignmentChanged(); + } - if(comp==source) + comp.repaint(); + } + } + + static void validateSequences(AlignmentI source, AlignmentI comp) + { + SequenceI[] a1; + if (source.getHiddenSequences().getSize() > 0) + { + a1 = source.getHiddenSequences().getFullAlignment().getSequencesArray(); + } + else + { + a1 = source.getSequencesArray(); + } + + SequenceI[] a2; + if (comp.getHiddenSequences().getSize() > 0) + { + a2 = comp.getHiddenSequences().getFullAlignment().getSequencesArray(); + } + else + { + a2 = comp.getSequencesArray(); + } + + int i, iSize = a1.length, j, jSize = a2.length; + + if (iSize == jSize) + { + return; + } + + boolean exists = false; + for (i = 0; i < iSize; i++) + { + exists = false; + + for (j = 0; j < jSize; j++) + { + if (a2[j] == a1[i]) { - continue; + exists = true; + break; } + } - if (!comp.isValid()) + if (!exists) + { + if (i < comp.getHeight()) { - comps.removeElement(comp); + comp.getSequences().insertElementAt(a1[i], i); } - else if(validateSequences - && comp instanceof AlignmentPanel - && source instanceof AlignmentPanel ) + else { - validateSequences( ((AlignmentPanel)source).av.alignment, - ((AlignmentPanel)comp).av.alignment); + comp.addSequence(a1[i]); } - if(comp instanceof AlignmentPanel && alignmentChanged) + if (comp.getHiddenSequences().getSize() > 0) { - ((AlignmentPanel)comp).alignmentChanged(); + a2 = comp.getHiddenSequences().getFullAlignment().getSequencesArray(); + } + else + { + a2 = comp.getSequencesArray(); } - comp.repaint(); + jSize = a2.length; } } - static void validateSequences(AlignmentI source, AlignmentI comp) - { - SequenceI[] a1; - if(source.getHiddenSequences().getSize()>0) - a1 = source.getHiddenSequences().getFullAlignment().getSequencesArray(); - else - a1 = source.getSequencesArray(); - - SequenceI[] a2; - if (comp.getHiddenSequences().getSize() > 0) - a2 = comp.getHiddenSequences().getFullAlignment().getSequencesArray(); - else - a2 = comp.getSequencesArray(); - - int i, iSize=a1.length, j, jSize=a2.length; + iSize = a1.length; + jSize = a2.length; - if(iSize == jSize) - return; - - boolean exists = false; - for(i=0; i 0) - a2 = comp.getHiddenSequences().getFullAlignment().getSequencesArray(); - else - a2 = comp.getSequencesArray(); + exists = true; + break; } } - iSize=a1.length; - jSize=a2.length; - - for(j=0; j