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