update author list in license for (JAL-826)
[jalview.git] / src / jalview / gui / RNAHelicesColourChooser.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7)
3  * Copyright (C) 2011 J Procter, AM Waterhouse, J Engelhardt, LM Lui, G Barton, M Clamp, S Searle
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 of the License, or (at your option) any later version.
10  * 
11  * Jalview is distributed in the hope that it will be useful, but 
12  * WITHOUT ANY WARRANTY; without even the implied warranty 
13  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
14  * PURPOSE.  See the GNU General Public License for more details.
15  * 
16  * You should have received a copy of the GNU General Public License along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
17  */
18 package jalview.gui;
19
20 import java.util.*;
21 import java.awt.event.*;
22
23 import jalview.datamodel.*;
24 import jalview.schemes.*;
25
26 /**
27  * Helps generate the colors for RNA secondary structure. Future: add option to
28  * change colors based on covariation.
29  * 
30  * @author Lauren Michelle Lui
31  * 
32  */
33 public class RNAHelicesColourChooser
34 {
35
36   AlignViewport av;
37
38   AlignmentPanel ap;
39
40   ColourSchemeI oldcs;
41
42   Hashtable oldgroupColours;
43
44   jalview.datamodel.AlignmentAnnotation currentAnnotation;
45
46   boolean adjusting = false;
47
48   public RNAHelicesColourChooser(AlignViewport av, final AlignmentPanel ap)
49   {
50     oldcs = av.getGlobalColourScheme();
51     if (av.alignment.getGroups() != null)
52     {
53       oldgroupColours = new Hashtable();
54       Vector allGroups = ap.av.alignment.getGroups();
55       SequenceGroup sg;
56       for (int g = 0; g < allGroups.size(); g++)
57       {
58         sg = (SequenceGroup) allGroups.get(g);
59         if (sg.cs != null)
60         {
61           oldgroupColours.put(sg, sg.cs);
62         }
63       }
64     }
65     this.av = av;
66     this.ap = ap;
67
68     if (oldcs instanceof RNAHelicesColour)
69     {
70       RNAHelicesColour rhc = (RNAHelicesColour) oldcs;
71
72     }
73
74     adjusting = true;
75     Vector list = new Vector();
76     int index = 1;
77     for (int i = 0; i < av.alignment.getAlignmentAnnotation().length; i++)
78     {
79       String label = av.alignment.getAlignmentAnnotation()[i].label;
80       if (!list.contains(label))
81         list.addElement(label);
82       else
83         list.addElement(label + "_" + (index++));
84     }
85
86     adjusting = false;
87
88     changeColour();
89
90   }
91
92   void changeColour()
93   {
94     // Check if combobox is still adjusting
95     if (adjusting)
96     {
97       return;
98     }
99
100     currentAnnotation = av.alignment.getAlignmentAnnotation()[0];// annotations.getSelectedIndex()];
101
102     RNAHelicesColour rhc = null;
103
104     rhc = new RNAHelicesColour(currentAnnotation);
105
106     av.setGlobalColourScheme(rhc);
107
108     if (av.alignment.getGroups() != null)
109     {
110       Vector allGroups = ap.av.alignment.getGroups();
111       SequenceGroup sg;
112       for (int g = 0; g < allGroups.size(); g++)
113       {
114         sg = (SequenceGroup) allGroups.get(g);
115
116         if (sg.cs == null)
117         {
118           continue;
119         }
120
121         sg.cs = new RNAHelicesColour(currentAnnotation);
122
123       }
124     }
125
126     ap.paintAlignment(false);
127   }
128
129   void reset()
130   {
131     av.setGlobalColourScheme(oldcs);
132     if (av.alignment.getGroups() != null)
133     {
134       Vector allGroups = ap.av.alignment.getGroups();
135       SequenceGroup sg;
136       for (int g = 0; g < allGroups.size(); g++)
137       {
138         sg = (SequenceGroup) allGroups.get(g);
139         sg.cs = (ColourSchemeI) oldgroupColours.get(sg);
140       }
141     }
142   }
143
144   public void annotations_actionPerformed(ActionEvent e)
145   {
146     changeColour();
147   }
148
149 }