graph now has type, not a boolean
[jalview.git] / src / jalview / datamodel / AlignmentAnnotation.java
1 /*\r
2 * Jalview - A Sequence Alignment Editor and Viewer\r
3 * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
4 *\r
5 * This program is free software; you can redistribute it and/or\r
6 * modify it under the terms of the GNU General Public License\r
7 * as published by the Free Software Foundation; either version 2\r
8 * of the License, or (at your option) any later version.\r
9 *\r
10 * This program is distributed in the hope that it will be useful,\r
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
13 * GNU General Public License for more details.\r
14 *\r
15 * You should have received a copy of the GNU General Public License\r
16 * along with this program; if not, write to the Free Software\r
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA\r
18 */\r
19 package jalview.datamodel;\r
20 \r
21 \r
22 /**\r
23  * DOCUMENT ME!\r
24  *\r
25  * @author $author$\r
26  * @version $Revision$\r
27  */\r
28 public class AlignmentAnnotation\r
29 {\r
30     /** DOCUMENT ME!! */\r
31     public String label;\r
32 \r
33     /** DOCUMENT ME!! */\r
34     public String description;\r
35 \r
36     /** DOCUMENT ME!! */\r
37     public Annotation[] annotations;\r
38 \r
39 \r
40     /** DOCUMENT ME!! */\r
41     public float graphMin;\r
42 \r
43     /** DOCUMENT ME!! */\r
44     public float graphMax;\r
45 \r
46 \r
47     // Graphical hints and tips\r
48 \r
49     /** DOCUMENT ME!! */\r
50     public boolean editable = false;\r
51 \r
52     /** DOCUMENT ME!! */\r
53     public boolean hasIcons; //\r
54 \r
55     /** DOCUMENT ME!! */\r
56     public boolean hasText;\r
57 \r
58     /** DOCUMENT ME!! */\r
59     public boolean visible = true;\r
60 \r
61     /** DOCUMENT ME!! */\r
62     public int height = 0;\r
63 \r
64     public int graph = 0;\r
65 \r
66     public static int NO_GRAPH = 0;\r
67 \r
68     public static int BAR_GRAPH = 1;\r
69 \r
70     public static int LINE_GRAPH = 2;\r
71 \r
72     /**\r
73      * Creates a new AlignmentAnnotation object.\r
74      *\r
75      * @param label DOCUMENT ME!\r
76      * @param description DOCUMENT ME!\r
77      * @param annotations DOCUMENT ME!\r
78      */\r
79     public AlignmentAnnotation(String label, String description,\r
80         Annotation[] annotations)\r
81     {\r
82         // always editable?\r
83         editable = true;\r
84         this.label = label;\r
85         this.description = description;\r
86         this.annotations = annotations;\r
87 \r
88         for (int i = 0; i < annotations.length; i++)\r
89         {\r
90             if ((annotations[i] != null) &&\r
91                     ((annotations[i].secondaryStructure == 'H') ||\r
92                     (annotations[i].secondaryStructure == 'E')))\r
93             {\r
94                 hasIcons = true;\r
95             }\r
96 \r
97             if ((annotations[i] != null) &&\r
98                     (annotations[i].displayCharacter.length() > 0))\r
99             {\r
100                 hasText = true;\r
101             }\r
102         }\r
103     }\r
104 \r
105     /**\r
106      * Creates a new AlignmentAnnotation object.\r
107      *\r
108      * @param label DOCUMENT ME!\r
109      * @param description DOCUMENT ME!\r
110      * @param annotations DOCUMENT ME!\r
111      * @param min DOCUMENT ME!\r
112      * @param max DOCUMENT ME!\r
113      * @param winLength DOCUMENT ME!\r
114      */\r
115     public AlignmentAnnotation(String label, String description,\r
116         Annotation[] annotations, float min, float max, int graphType)\r
117     {\r
118         // graphs are not editable\r
119         this.label = label;\r
120         this.description = description;\r
121         this.annotations = annotations;\r
122         graph = graphType;\r
123 \r
124         if (min == max)\r
125         {\r
126             for (int i = 0; i < annotations.length; i++)\r
127             {\r
128                 if (annotations[i] == null)\r
129                 {\r
130                     continue;\r
131                 }\r
132 \r
133                 if (annotations[i].value > max)\r
134                 {\r
135                     max = annotations[i].value;\r
136                 }\r
137 \r
138                 if (annotations[i].value < min)\r
139                 {\r
140                     min = annotations[i].value;\r
141                 }\r
142             }\r
143         }\r
144 \r
145         graphMin = min;\r
146         graphMax = max;\r
147 \r
148         for (int i = 0; i < annotations.length; i++)\r
149         {\r
150             if ((annotations[i] != null) &&\r
151                     ((annotations[i].secondaryStructure == 'H') ||\r
152                     (annotations[i].secondaryStructure == 'E')))\r
153             {\r
154                 hasIcons = true;\r
155             }\r
156 \r
157             if ((annotations[i] != null) &&\r
158                     (annotations[i].displayCharacter.length() > 0))\r
159             {\r
160                 hasText = true;\r
161             }\r
162         }\r
163     }\r
164 \r
165     /**\r
166      * DOCUMENT ME!\r
167      *\r
168      * @return DOCUMENT ME!\r
169      */\r
170     public String toString()\r
171     {\r
172         StringBuffer buffer = new StringBuffer();\r
173 \r
174         for (int i = 0; i < annotations.length; i++)\r
175         {\r
176             if (annotations[i] != null)\r
177             {\r
178                 if (graph!=0)\r
179                 {\r
180                     buffer.append(annotations[i].value);\r
181                 }\r
182                 else if (hasIcons)\r
183                 {\r
184                     buffer.append(annotations[i].secondaryStructure);\r
185                 }\r
186                 else\r
187                 {\r
188                     buffer.append(annotations[i].displayCharacter);\r
189                 }\r
190             }\r
191 \r
192             buffer.append(", ");\r
193         }\r
194 \r
195         if (label.equals("Consensus"))\r
196         {\r
197             buffer.append("\n");\r
198 \r
199             for (int i = 0; i < annotations.length; i++)\r
200             {\r
201                 if (annotations[i] != null)\r
202                 {\r
203                     buffer.append(annotations[i].description);\r
204                 }\r
205 \r
206                 buffer.append(", ");\r
207             }\r
208         }\r
209 \r
210         return buffer.toString();\r
211     }\r
212 }\r