2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
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.
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.
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.
21 package jalview.datamodel;
23 import java.awt.Color;
25 import jalview.datamodel.annotations.AnnotationColouringI;
28 * Holds all annotation values for a position in an AlignmentAnnotation row
33 public class Annotation
36 * the empty annotation - proxy for null entries in annotation row
38 public static final Annotation EMPTY_ANNOTATION = new Annotation("", "",
41 /** Character label - also shown below histogram */
42 public String displayCharacter = "";
45 * Text label for position: shown in mouse over and displayed on secondary
48 public String description = "";
51 * Secondary structure symbol: Protein symbols are H, E and S(?), RNA are
52 * WUSS/Vienna plus extended pseudoknot symbols
54 public char secondaryStructure = ' ';
57 * Score for the position - used in histograms, line graphs and for shading
61 /** Colour for position */
65 * link back to the AnnotationRowBuilder
67 private AnnotationColouringI annotationColouring = null;
70 * Creates a new Annotation object.
81 public Annotation(String displayChar, String desc, char ss, float val)
83 displayCharacter = displayChar;
85 secondaryStructure = ss;
91 * Creates a new Annotation object.
104 public Annotation(String displayChar, String desc, char ss, float val,
107 this(displayChar, desc, ss, val);
108 this.colour = colour;
112 * Copy constructor New annotation takes on the same (or duplicated)
113 * attributes as the given template
116 * template annotation
118 public Annotation(Annotation that)
120 if (that == null || this == that)
124 if (that.displayCharacter != null)
126 displayCharacter = new String(that.displayCharacter);
128 if (that.description != null)
130 description = new String(that.description);
132 secondaryStructure = that.secondaryStructure;
134 colour = that.colour;
135 annotationColouring = that.getAnnotationColouring();
139 * Value only annotation.
142 * value at this annotation position
144 public Annotation(float val)
146 this(null, null, ' ', val, null);
150 * human readable representation of an annotation row element.
152 * Format is 'display Char','secondary Structure
153 * Char',"description",score,[colourstring]
155 * fields may be missing if they are null, whitespace, or equivalent to
159 public String toString()
161 StringBuffer sb = new StringBuffer();
162 if (displayCharacter != null)
165 sb.append(displayCharacter);
171 if (secondaryStructure != 0
172 && !("" + displayCharacter).equals("" + secondaryStructure))
175 sb.append(secondaryStructure);
181 if (description != null && description.length() > 0)
184 sb.append(description);
190 if (!Float.isNaN(value))
201 sb.append(colour.getRed());
203 sb.append(colour.getGreen());
205 sb.append(colour.getBlue());
208 return sb.toString();
212 * @return true if annot is 'whitespace' annotation (zero score, whitespace or
213 * zero length display character, label, description
215 public boolean isWhitespace()
217 return ((value == 0f)
218 && ((description == null) || (description.trim().length() == 0))
219 && ((displayCharacter == null)
220 || (displayCharacter.trim().length() == 0)
221 || (displayCharacter.equals(" ."))) // RNA Stockholm blank
222 // displayCharacter can
224 && (secondaryStructure == '\0' || (secondaryStructure == ' '))
228 public void setAnnotationColouring(AnnotationColouringI a)
230 this.annotationColouring = a;
233 public AnnotationColouringI getAnnotationColouring()
235 return annotationColouring;