4a10099c0e51ef5b5b6e0df1ced158d0380a2984
[jalview.git] / src / jalview / appletgui / PaintRefresher.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer
3  * Copyright (C) 2006 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
18  */
19
20
21
22 package jalview.appletgui;
23
24 import java.awt.*;
25 import java.util.*;
26 import jalview.datamodel.*;
27
28 public class PaintRefresher
29 {
30   static Hashtable components = new Hashtable();
31
32   public static void Register(Component comp, AlignmentI al)
33   {
34     if(components.containsKey(al))
35     {
36       Vector comps = (Vector)components.get(al);
37       comps.addElement(comp);
38     }
39     else
40     {
41       Vector vcoms = new Vector();
42       vcoms.addElement(comp);
43       components.put(al, vcoms);
44     }
45   }
46
47   public static void Refresh(AlignmentI al)
48   {
49     Refresh(null, al);
50   }
51
52   public static void Refresh(Component c, AlignmentI al)
53   {
54     Component temp;
55     Vector coms = (Vector)components.get(al);
56     Enumeration e = coms.elements();
57     while( e.hasMoreElements() )
58     {
59       temp = (Component)e.nextElement();
60
61       if(!temp.isValid())
62         coms.removeElement( temp );
63       else if( temp == c )
64         continue;
65       else
66         temp.repaint();
67     }
68
69   }
70
71 }
72