7b558c36a80f114defa368566ae04e67dd09a098
[jalview.git] / src / jalview / datamodel / AlignmentAnnotation.java
1 package jalview.datamodel;\r
2 \r
3 public class AlignmentAnnotation\r
4 {\r
5   public String label;\r
6   public String description;\r
7   public Annotation  [] annotations;\r
8   public boolean isGraph = false;\r
9   public float graphMin, graphMax;\r
10   public int windowLength;\r
11 \r
12   // Graphical hints and tips\r
13   public boolean editable = false;\r
14   public boolean hasIcons; //\r
15   public boolean hasText;\r
16   public boolean visible = true;\r
17   public int height=0;\r
18 \r
19   public AlignmentAnnotation(String label, String description, Annotation [] annotations)\r
20   {\r
21     // always editable?\r
22     editable = true;\r
23     this.label = label;\r
24     this.description = description;\r
25     this.annotations = annotations;\r
26     for(int i=0; i<annotations.length; i++)\r
27     {\r
28       if (annotations[i]!=null &&(\r
29           annotations[i].secondaryStructure == 'H' ||\r
30           annotations[i].secondaryStructure == 'E'))\r
31         hasIcons = true;\r
32 \r
33       if (annotations[i]!=null && annotations[i].displayCharacter.length()>0)\r
34         hasText = true;\r
35     }\r
36   }\r
37 \r
38   public AlignmentAnnotation(String label, String description, Annotation [] annotations, float min, float max, int winLength)\r
39   {\r
40     // graphs are not editable\r
41     this.label = label;\r
42     this.description = description;\r
43     this.annotations = annotations;\r
44     isGraph = true;\r
45     if(min==max)\r
46     {\r
47       for(int i=0; i<annotations.length; i++)\r
48       {\r
49         if(annotations[i]==null)\r
50           continue;\r
51         if(annotations[i].value>max)\r
52           max = annotations[i].value;\r
53         if(annotations[i].value<min)\r
54           min = annotations[i].value;\r
55       }\r
56     }\r
57 \r
58     graphMin = min;\r
59     graphMax = max;\r
60     windowLength = winLength;\r
61     for(int i=0; i<annotations.length; i++)\r
62     {\r
63       if (annotations[i]!=null &&(\r
64           annotations[i].secondaryStructure == 'H' ||\r
65           annotations[i].secondaryStructure == 'E'))\r
66         hasIcons = true;\r
67 \r
68       if (annotations[i]!=null && annotations[i].displayCharacter.length()>0)\r
69         hasText = true;\r
70     }\r
71   }\r
72 \r
73   public String toString()\r
74   {\r
75     StringBuffer buffer = new StringBuffer();\r
76     for(int i=0; i<annotations.length; i++)\r
77    {\r
78      if(annotations[i]!=null)\r
79      {\r
80        if(isGraph)\r
81          buffer.append(annotations[i].value);\r
82        else if(hasIcons)\r
83          buffer.append(annotations[i].secondaryStructure);\r
84        else\r
85          buffer.append(annotations[i].displayCharacter);\r
86 \r
87      }\r
88      buffer.append(", ");\r
89    }\r
90    if(label.equals("Consensus"))\r
91    {\r
92      buffer.append("\n");\r
93      for (int i = 0; i < annotations.length; i++)\r
94      {\r
95        if (annotations[i] != null)\r
96            buffer.append(annotations[i].description);\r
97        buffer.append(", ");\r
98      }\r
99    }\r
100    return buffer.toString();\r
101   }\r
102 \r
103 }\r