Formatting changes
[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     /** DOCUMENT ME!! */\r
40     public boolean isGraph = false;\r
41 \r
42     /** DOCUMENT ME!! */\r
43     public float graphMin;\r
44 \r
45     /** DOCUMENT ME!! */\r
46     public float graphMax;\r
47 \r
48     /** DOCUMENT ME!! */\r
49     public int windowLength;\r
50 \r
51     // Graphical hints and tips\r
52 \r
53     /** DOCUMENT ME!! */\r
54     public boolean editable = false;\r
55 \r
56     /** DOCUMENT ME!! */\r
57     public boolean hasIcons; //\r
58 \r
59     /** DOCUMENT ME!! */\r
60     public boolean hasText;\r
61 \r
62     /** DOCUMENT ME!! */\r
63     public boolean visible = true;\r
64 \r
65     /** DOCUMENT ME!! */\r
66     public int height = 0;\r
67 \r
68     /**\r
69      * Creates a new AlignmentAnnotation object.\r
70      *\r
71      * @param label DOCUMENT ME!\r
72      * @param description DOCUMENT ME!\r
73      * @param annotations DOCUMENT ME!\r
74      */\r
75     public AlignmentAnnotation(String label, String description,\r
76         Annotation[] annotations)\r
77     {\r
78         // always editable?\r
79         editable = true;\r
80         this.label = label;\r
81         this.description = description;\r
82         this.annotations = annotations;\r
83 \r
84         for (int i = 0; i < annotations.length; i++)\r
85         {\r
86             if ((annotations[i] != null) &&\r
87                     ((annotations[i].secondaryStructure == 'H') ||\r
88                     (annotations[i].secondaryStructure == 'E')))\r
89             {\r
90                 hasIcons = true;\r
91             }\r
92 \r
93             if ((annotations[i] != null) &&\r
94                     (annotations[i].displayCharacter.length() > 0))\r
95             {\r
96                 hasText = true;\r
97             }\r
98         }\r
99     }\r
100 \r
101     /**\r
102      * Creates a new AlignmentAnnotation object.\r
103      *\r
104      * @param label DOCUMENT ME!\r
105      * @param description DOCUMENT ME!\r
106      * @param annotations DOCUMENT ME!\r
107      * @param min DOCUMENT ME!\r
108      * @param max DOCUMENT ME!\r
109      * @param winLength DOCUMENT ME!\r
110      */\r
111     public AlignmentAnnotation(String label, String description,\r
112         Annotation[] annotations, float min, float max, int winLength)\r
113     {\r
114         // graphs are not editable\r
115         this.label = label;\r
116         this.description = description;\r
117         this.annotations = annotations;\r
118         isGraph = true;\r
119 \r
120         if (min == max)\r
121         {\r
122             for (int i = 0; i < annotations.length; i++)\r
123             {\r
124                 if (annotations[i] == null)\r
125                 {\r
126                     continue;\r
127                 }\r
128 \r
129                 if (annotations[i].value > max)\r
130                 {\r
131                     max = annotations[i].value;\r
132                 }\r
133 \r
134                 if (annotations[i].value < min)\r
135                 {\r
136                     min = annotations[i].value;\r
137                 }\r
138             }\r
139         }\r
140 \r
141         graphMin = min;\r
142         graphMax = max;\r
143         windowLength = winLength;\r
144 \r
145         for (int i = 0; i < annotations.length; i++)\r
146         {\r
147             if ((annotations[i] != null) &&\r
148                     ((annotations[i].secondaryStructure == 'H') ||\r
149                     (annotations[i].secondaryStructure == 'E')))\r
150             {\r
151                 hasIcons = true;\r
152             }\r
153 \r
154             if ((annotations[i] != null) &&\r
155                     (annotations[i].displayCharacter.length() > 0))\r
156             {\r
157                 hasText = true;\r
158             }\r
159         }\r
160     }\r
161 \r
162     /**\r
163      * DOCUMENT ME!\r
164      *\r
165      * @return DOCUMENT ME!\r
166      */\r
167     public String toString()\r
168     {\r
169         StringBuffer buffer = new StringBuffer();\r
170 \r
171         for (int i = 0; i < annotations.length; i++)\r
172         {\r
173             if (annotations[i] != null)\r
174             {\r
175                 if (isGraph)\r
176                 {\r
177                     buffer.append(annotations[i].value);\r
178                 }\r
179                 else if (hasIcons)\r
180                 {\r
181                     buffer.append(annotations[i].secondaryStructure);\r
182                 }\r
183                 else\r
184                 {\r
185                     buffer.append(annotations[i].displayCharacter);\r
186                 }\r
187             }\r
188 \r
189             buffer.append(", ");\r
190         }\r
191 \r
192         if (label.equals("Consensus"))\r
193         {\r
194             buffer.append("\n");\r
195 \r
196             for (int i = 0; i < annotations.length; i++)\r
197             {\r
198                 if (annotations[i] != null)\r
199                 {\r
200                     buffer.append(annotations[i].description);\r
201                 }\r
202 \r
203                 buffer.append(", ");\r
204             }\r
205         }\r
206 \r
207         return buffer.toString();\r
208     }\r
209 }\r