Multiple Views
[jalview.git] / src / jalview / gui / PaintRefresher.java
1 /*\r
2  * Jalview - A Sequence Alignment Editor and Viewer\r
3  * Copyright (C) 2006 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
4  *\r
5  * This program is free software; you can redistribute it and/or\r
6  * modify it under the terms of the GNU General Public License\r
7  * as published by the Free Software Foundation; either version 2\r
8  * of the License, or (at your option) any later version.\r
9  *\r
10  * This program is distributed in the hope that it will be useful,\r
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
13  * GNU General Public License for more details.\r
14  *\r
15  * You should have received a copy of the GNU General Public License\r
16  * along with this program; if not, write to the Free Software\r
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA\r
18  */\r
19 package jalview.gui;\r
20 \r
21 import jalview.datamodel.*;\r
22 \r
23 import java.awt.*;\r
24 \r
25 import java.util.*;\r
26 \r
27 \r
28 /**\r
29  * DOCUMENT ME!\r
30  *\r
31  * @author $author$\r
32  * @version $Revision$\r
33  */\r
34 public class PaintRefresher\r
35 {\r
36     static Hashtable components;\r
37 \r
38     /**\r
39      * DOCUMENT ME!\r
40      *\r
41      * @param comp DOCUMENT ME!\r
42      * @param al DOCUMENT ME!\r
43      */\r
44     public static void Register(Component comp, String seqSetId)\r
45     {\r
46       if (components == null)\r
47         components = new Hashtable();\r
48 \r
49         if (components.containsKey(seqSetId))\r
50         {\r
51             Vector comps = (Vector) components.get(seqSetId);\r
52             if(!comps.contains(comp))\r
53               comps.addElement(comp);\r
54         }\r
55         else\r
56         {\r
57             Vector vcoms = new Vector();\r
58             vcoms.addElement(comp);\r
59             components.put(seqSetId, vcoms);\r
60         }\r
61     }\r
62 \r
63     public static void RemoveComponent(Component comp)\r
64     {\r
65       if (components == null)\r
66         return;\r
67 \r
68       Enumeration en = components.keys();\r
69       while(en.hasMoreElements())\r
70       {\r
71         String id = en.nextElement().toString();\r
72         Vector comps = (Vector) components.get(id);\r
73         comps.remove(comp);\r
74         if(comps.size()==0)\r
75         {\r
76           components.remove(id);\r
77         }\r
78       }\r
79     }\r
80 \r
81     public static void Refresh(Component source, String id)\r
82     {\r
83       Refresh( source, id,  null, null);\r
84     }\r
85 \r
86     public static void Refresh(Component source, String id,\r
87                                     SequenceI removeSeq,\r
88                                     SequenceI addSeq)\r
89     {\r
90       if (components == null)\r
91         return;\r
92 \r
93       Component comp;\r
94       Vector comps = (Vector) components.get(id);\r
95 \r
96       if(comps==null)\r
97       {\r
98         return;\r
99       }\r
100 \r
101       Enumeration e = comps.elements();\r
102       while (e.hasMoreElements())\r
103       {\r
104         comp = (Component) e.nextElement();\r
105 \r
106         if(comp==source)\r
107           continue;\r
108 \r
109         if (!comp.isValid())\r
110         {\r
111           comps.removeElement(comp);\r
112         }\r
113         else if(comp instanceof AlignmentPanel)\r
114         {\r
115           AlignmentPanel ap = (AlignmentPanel)comp;\r
116           if(addSeq!=null)\r
117             ap.av.alignment.addSequence(addSeq);\r
118           if(removeSeq!=null)\r
119             ap.av.alignment.deleteSequence(removeSeq);\r
120 \r
121          // if(source instanceof AlignmentPanel)\r
122           //  ap.av.alignment.setGroups(\r
123          //       ((AlignmentPanel)source).av.alignment.getGroups() );\r
124 \r
125         }\r
126         comp.repaint();\r
127       }\r
128 \r
129     }\r
130 }\r