GPL license added
[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 \r
20 package jalview.datamodel;\r
21 \r
22 public class AlignmentAnnotation\r
23 {\r
24   public String label;\r
25   public String description;\r
26   public Annotation  [] annotations;\r
27   public boolean isGraph = false;\r
28   public float graphMin, graphMax;\r
29   public int windowLength;\r
30 \r
31   // Graphical hints and tips\r
32   public boolean editable = false;\r
33   public boolean hasIcons; //\r
34   public boolean hasText;\r
35   public boolean visible = true;\r
36   public int height=0;\r
37 \r
38   public AlignmentAnnotation(String label, String description, Annotation [] annotations)\r
39   {\r
40     // always editable?\r
41     editable = true;\r
42     this.label = label;\r
43     this.description = description;\r
44     this.annotations = annotations;\r
45     for(int i=0; i<annotations.length; i++)\r
46     {\r
47       if (annotations[i]!=null &&(\r
48           annotations[i].secondaryStructure == 'H' ||\r
49           annotations[i].secondaryStructure == 'E'))\r
50         hasIcons = true;\r
51 \r
52       if (annotations[i]!=null && annotations[i].displayCharacter.length()>0)\r
53         hasText = true;\r
54     }\r
55   }\r
56 \r
57   public AlignmentAnnotation(String label, String description, Annotation [] annotations, float min, float max, int winLength)\r
58   {\r
59     // graphs are not editable\r
60     this.label = label;\r
61     this.description = description;\r
62     this.annotations = annotations;\r
63     isGraph = true;\r
64     if(min==max)\r
65     {\r
66       for(int i=0; i<annotations.length; i++)\r
67       {\r
68         if(annotations[i]==null)\r
69           continue;\r
70         if(annotations[i].value>max)\r
71           max = annotations[i].value;\r
72         if(annotations[i].value<min)\r
73           min = annotations[i].value;\r
74       }\r
75     }\r
76 \r
77     graphMin = min;\r
78     graphMax = max;\r
79     windowLength = winLength;\r
80     for(int i=0; i<annotations.length; i++)\r
81     {\r
82       if (annotations[i]!=null &&(\r
83           annotations[i].secondaryStructure == 'H' ||\r
84           annotations[i].secondaryStructure == 'E'))\r
85         hasIcons = true;\r
86 \r
87       if (annotations[i]!=null && annotations[i].displayCharacter.length()>0)\r
88         hasText = true;\r
89     }\r
90   }\r
91 \r
92   public String toString()\r
93   {\r
94     StringBuffer buffer = new StringBuffer();\r
95     for(int i=0; i<annotations.length; i++)\r
96    {\r
97      if(annotations[i]!=null)\r
98      {\r
99        if(isGraph)\r
100          buffer.append(annotations[i].value);\r
101        else if(hasIcons)\r
102          buffer.append(annotations[i].secondaryStructure);\r
103        else\r
104          buffer.append(annotations[i].displayCharacter);\r
105 \r
106      }\r
107      buffer.append(", ");\r
108    }\r
109    if(label.equals("Consensus"))\r
110    {\r
111      buffer.append("\n");\r
112      for (int i = 0; i < annotations.length; i++)\r
113      {\r
114        if (annotations[i] != null)\r
115            buffer.append(annotations[i].description);\r
116        buffer.append(", ");\r
117      }\r
118    }\r
119    return buffer.toString();\r
120   }\r
121 \r
122 }\r