25b65b339152cccee91ddd0d62eb2c66750d6b04
[jalview.git] / src / jalview / schemes / RNAHelicesColourChooser.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8)
3  * Copyright (C) 2012 J Procter, AM Waterhouse, LM Lui, J Engelhardt, 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.schemes;
19
20 import java.util.*;
21 import java.awt.event.*;
22
23 import jalview.api.AlignViewportI;
24 import jalview.api.AlignmentViewPanel;
25 import jalview.datamodel.*;
26 import jalview.schemes.*;
27
28 /**
29  * Helps generate the colors for RNA secondary structure. Future: add option to
30  * change colors based on covariation.
31  * 
32  * @author Lauren Michelle Lui
33  * 
34  */
35 public class RNAHelicesColourChooser
36 {
37
38   AlignViewportI av;
39
40   AlignmentViewPanel ap;
41
42   ColourSchemeI oldcs;
43
44   Hashtable oldgroupColours;
45
46   jalview.datamodel.AlignmentAnnotation currentAnnotation;
47
48   boolean adjusting = false;
49
50   public RNAHelicesColourChooser(AlignViewportI av,
51           final AlignmentViewPanel ap)
52   {
53     oldcs = av.getGlobalColourScheme();
54     if (av.getAlignment().getGroups() != null)
55     {
56       oldgroupColours = new Hashtable();
57       for (SequenceGroup sg : ap.getAlignment().getGroups())
58       {
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.getAlignment().getAlignmentAnnotation().length; i++)
78     {
79       String label = av.getAlignment().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.getAlignment().getAlignmentAnnotation()[0];// annotations.getSelectedIndex()];
101
102     RNAHelicesColour rhc = null;
103
104     rhc = new RNAHelicesColour(currentAnnotation);
105
106     av.setGlobalColourScheme(rhc);
107
108     if (av.getAlignment().getGroups() != null)
109     {
110       for (SequenceGroup sg : ap.getAlignment().getGroups())
111       {
112         if (sg.cs == null)
113         {
114           continue;
115         }
116
117         sg.cs = new RNAHelicesColour(currentAnnotation);
118
119       }
120     }
121
122     ap.paintAlignment(false);
123   }
124
125   void reset()
126   {
127     av.setGlobalColourScheme(oldcs);
128     if (av.getAlignment().getGroups() != null)
129     {
130       for (SequenceGroup sg : ap.getAlignment().getGroups())
131       {
132         sg.cs = (ColourSchemeI) oldgroupColours.get(sg);
133       }
134     }
135   }
136
137   public void annotations_actionPerformed(ActionEvent e)
138   {
139     changeColour();
140   }
141
142 }