JAL-2089 patch broken merge to master for Release 2.10.0b1
[jalview.git] / src / jalview / schemes / RNAHelicesColourChooser.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3  * Copyright (C) $$Year-Rel$$ The Jalview Authors
4  * 
5  * This file is part of Jalview.
6  * 
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.
11  *  
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.
16  * 
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.
20  */
21 package jalview.schemes;
22
23 import jalview.api.AlignViewportI;
24 import jalview.api.AlignmentViewPanel;
25 import jalview.datamodel.AlignmentAnnotation;
26 import jalview.datamodel.SequenceGroup;
27
28 import java.awt.event.ActionEvent;
29 import java.util.Hashtable;
30 import java.util.Vector;
31
32 /**
33  * Helps generate the colors for RNA secondary structure. Future: add option to
34  * change colors based on covariation.
35  * 
36  * @author Lauren Michelle Lui
37  * 
38  */
39 public class RNAHelicesColourChooser
40 {
41
42   AlignViewportI av;
43
44   AlignmentViewPanel ap;
45
46   ColourSchemeI oldcs;
47
48   Hashtable oldgroupColours;
49
50   jalview.datamodel.AlignmentAnnotation currentAnnotation;
51
52   boolean adjusting = false;
53
54   public RNAHelicesColourChooser(AlignViewportI av,
55           final AlignmentViewPanel ap)
56   {
57     oldcs = av.getGlobalColourScheme();
58     if (av.getAlignment().getGroups() != null)
59     {
60       oldgroupColours = new Hashtable();
61       for (SequenceGroup sg : ap.getAlignment().getGroups())
62       {
63         if (sg.cs != null)
64         {
65           oldgroupColours.put(sg, sg.cs);
66         }
67       }
68     }
69     this.av = av;
70     this.ap = ap;
71
72     if (oldcs instanceof RNAHelicesColour)
73     {
74       RNAHelicesColour rhc = (RNAHelicesColour) oldcs;
75
76     }
77
78     adjusting = true;
79     Vector list = new Vector();
80     int index = 1;
81     AlignmentAnnotation[] anns = av.getAlignment().getAlignmentAnnotation();
82     if (anns != null)
83     {
84       for (int i = 0; i < anns.length; i++)
85       {
86         String label = anns[i].label;
87         if (!list.contains(label))
88         {
89           list.addElement(label);
90         }
91         else
92         {
93           list.addElement(label + "_" + (index++));
94         }
95       }
96     }
97
98     adjusting = false;
99
100     changeColour();
101
102   }
103
104   void changeColour()
105   {
106     // Check if combobox is still adjusting
107     if (adjusting)
108     {
109       return;
110     }
111     RNAHelicesColour rhc = null;
112
113     rhc = new RNAHelicesColour(av.getAlignment());
114
115     av.setGlobalColourScheme(rhc);
116
117     ap.paintAlignment(true);
118   }
119
120   void reset()
121   {
122     av.setGlobalColourScheme(oldcs);
123     if (av.getAlignment().getGroups() != null)
124     {
125       for (SequenceGroup sg : ap.getAlignment().getGroups())
126       {
127         sg.cs = (ColourSchemeI) oldgroupColours.get(sg);
128       }
129     }
130   }
131
132   public void annotations_actionPerformed(ActionEvent e)
133   {
134     changeColour();
135   }
136
137 }