90cc14f278529a224e0488e049826a6d8bc8f6b3
[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.util.Hashtable;
29 import java.util.Map;
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  * @deprecated this seems to be unfinished - just use RNAHelicesColour
38  */
39 @Deprecated
40 public class RNAHelicesColourChooser
41 {
42
43   AlignViewportI av;
44
45   AlignmentViewPanel ap;
46
47   ColourSchemeI oldcs;
48
49   Map<SequenceGroup, ColourSchemeI> oldgroupColours;
50
51   AlignmentAnnotation currentAnnotation;
52
53   boolean adjusting = false;
54
55   public RNAHelicesColourChooser(AlignViewportI av,
56           final AlignmentViewPanel ap)
57   {
58     oldcs = av.getGlobalColourScheme();
59     if (av.getAlignment().getGroups() != null)
60     {
61       oldgroupColours = new Hashtable<SequenceGroup, ColourSchemeI>();
62       for (SequenceGroup sg : ap.getAlignment().getGroups())
63       {
64         if (sg.cs != null)
65         {
66           oldgroupColours.put(sg, sg.cs);
67         }
68       }
69     }
70     this.av = av;
71     this.ap = ap;
72
73     adjusting = true;
74     Vector<String> list = new Vector<String>();
75     int index = 1;
76     AlignmentAnnotation[] anns = av.getAlignment().getAlignmentAnnotation();
77     if (anns != null)
78     {
79       for (int i = 0; i < anns.length; i++)
80       {
81         String label = anns[i].label;
82         if (!list.contains(label))
83         {
84           list.addElement(label);
85         }
86         else
87         {
88           list.addElement(label + "_" + (index++));
89         }
90       }
91     }
92
93     adjusting = false;
94     changeColour();
95   }
96
97   void changeColour()
98   {
99     // Check if combobox is still adjusting
100     if (adjusting)
101     {
102       return;
103     }
104     RNAHelicesColour rhc = new RNAHelicesColour(av.getAlignment());
105
106     av.setGlobalColourScheme(rhc);
107
108     ap.paintAlignment(true);
109   }
110 }