JAL-1503 update version in GPL header
[jalview.git] / src / jalview / schemes / RNAHelicesColourChooser.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.1)
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     RNAHelicesColour rhc = null;
101
102     rhc = new RNAHelicesColour(av.getAlignment());
103
104     av.setGlobalColourScheme(rhc);
105
106     if (av.getAlignment().getGroups() != null)
107     {
108       for (SequenceGroup sg : ap.getAlignment().getGroups())
109       {
110         if (sg.cs == null)
111         {
112           continue;
113         }
114
115         sg.cs = new RNAHelicesColour(sg);
116
117       }
118     }
119
120     ap.paintAlignment(false);
121   }
122
123   void reset()
124   {
125     av.setGlobalColourScheme(oldcs);
126     if (av.getAlignment().getGroups() != null)
127     {
128       for (SequenceGroup sg : ap.getAlignment().getGroups())
129       {
130         sg.cs = (ColourSchemeI) oldgroupColours.get(sg);
131       }
132     }
133   }
134
135   public void annotations_actionPerformed(ActionEvent e)
136   {
137     changeColour();
138   }
139
140 }