2 VARNA is a tool for the automated drawing, visualization and annotation of the secondary structure of RNA, designed as a companion software for web servers and databases.
3 Copyright (C) 2008 Kevin Darty, Alain Denise and Yann Ponty.
4 electronic mail : Yann.Ponty@lri.fr
5 paper mail : LRI, bat 490 Université Paris-Sud 91405 Orsay Cedex France
7 This file is part of VARNA version 3.1.
8 VARNA version 3.1 is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
11 VARNA version 3.1 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
12 without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 See the GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License along with VARNA version 3.1.
16 If not, see http://www.gnu.org/licenses.
18 package fr.orsay.lri.varna.models.rna;
20 import java.awt.Color;
22 import java.io.Serializable;
23 import java.util.ArrayList;
25 import javax.xml.transform.sax.TransformerHandler;
27 import org.xml.sax.SAXException;
28 import org.xml.sax.helpers.AttributesImpl;
31 import fr.orsay.lri.varna.exceptions.ExceptionModeleStyleBaseSyntaxError;
32 import fr.orsay.lri.varna.exceptions.ExceptionParameterError;
33 import fr.orsay.lri.varna.models.VARNAConfig;
34 import fr.orsay.lri.varna.utils.XMLUtils;
37 * The display Style of a rna base with the base name font, the ouline,
38 * innerline, number and name color
43 public class ModelBaseStyle implements Cloneable, Serializable {
48 private static final long serialVersionUID = -4331494086323517208L;
50 private Color _base_outline_color, _base_inner_color, _base_number_color,
53 private boolean _selected;
56 public static String XML_ELEMENT_NAME = "basestyle";
57 public static String XML_VAR_OUTLINE_NAME = "outline";
58 public static String XML_VAR_INNER_NAME = "inner";
59 public static String XML_VAR_NUMBER_NAME = "num";
60 public static String XML_VAR_NAME_NAME = "name";
62 public void toXML(TransformerHandler hd) throws SAXException
64 AttributesImpl atts = new AttributesImpl();
65 atts.addAttribute("","",XML_VAR_OUTLINE_NAME,"CDATA",""+XMLUtils.toHTMLNotation(_base_outline_color));
66 atts.addAttribute("","",XML_VAR_INNER_NAME,"CDATA",""+XMLUtils.toHTMLNotation(_base_inner_color));
67 atts.addAttribute("","",XML_VAR_NUMBER_NAME,"CDATA",""+XMLUtils.toHTMLNotation(_base_number_color));
68 atts.addAttribute("","",XML_VAR_NAME_NAME,"CDATA",""+XMLUtils.toHTMLNotation(_base_name_color));
70 hd.startElement("","",XML_ELEMENT_NAME,atts);
71 hd.endElement("","",XML_ELEMENT_NAME);
74 public ModelBaseStyle clone()
76 ModelBaseStyle result = new ModelBaseStyle();
77 result._base_inner_color = this._base_inner_color;
78 result._base_name_color = this._base_name_color;
79 result._base_number_color = this._base_number_color;
80 result._base_outline_color = this._base_outline_color;
81 result._selected = this._selected;
88 * Creates a new base style with default colors and font
90 * @see VARNAConfig#BASE_OUTLINE_COLOR_DEFAULT
91 * @see VARNAConfig#BASE_INNER_COLOR_DEFAULT
92 * @see VARNAConfig#BASE_NUMBER_COLOR_DEFAULT
93 * @see VARNAConfig#BASE_NAME_COLOR_DEFAULT
96 public ModelBaseStyle() {
97 _base_outline_color = VARNAConfig.BASE_OUTLINE_COLOR_DEFAULT;
98 _base_inner_color = VARNAConfig.BASE_INNER_COLOR_DEFAULT;
99 _base_number_color = VARNAConfig.BASE_NUMBER_COLOR_DEFAULT;
100 _base_name_color = VARNAConfig.BASE_NAME_COLOR_DEFAULT;
105 * Creates a new base style with custom colors and custom font
108 * The out line color of the base
110 * The inner line color of the base
112 * The number color of the base
114 * The name color of the base
116 * The name font of the base
118 public ModelBaseStyle(Color outline, Color inner, Color number,
119 Color name, Font font) {
120 _base_outline_color = outline;
121 _base_inner_color = inner;
122 _base_number_color = number;
123 _base_name_color = name;
126 public ModelBaseStyle(String parameterValue)
127 throws ExceptionModeleStyleBaseSyntaxError, ExceptionParameterError {
129 assignParameters(parameterValue);
132 public ModelBaseStyle(ModelBaseStyle msb) {
133 _base_outline_color = msb.getBaseOutlineColor();
134 _base_inner_color = msb.getBaseInnerColor();
135 _base_number_color = msb.getBaseNumberColor();
136 _base_name_color = msb.getBaseNameColor();
139 public Color getBaseOutlineColor() {
140 return _base_outline_color;
143 public void setBaseOutlineColor(Color _base_outline_color) {
144 this._base_outline_color = _base_outline_color;
147 public Color getBaseInnerColor() {
148 return _base_inner_color;
151 public void setBaseInnerColor(Color _base_inner_color) {
152 this._base_inner_color = _base_inner_color;
155 public Color getBaseNumberColor() {
156 return _base_number_color;
159 public void setBaseNumberColor(Color _base_numbers_color) {
160 this._base_number_color = _base_numbers_color;
163 public Color getBaseNameColor() {
164 return _base_name_color;
167 public void setBaseNameColor(Color _base_name_color) {
168 this._base_name_color = _base_name_color;
171 public static final String PARAM_INNER_COLOR = "fill";
172 public static final String PARAM_OUTLINE_COLOR = "outline";
173 public static final String PARAM_TEXT_COLOR = "label";
174 public static final String PARAM_NUMBER_COLOR = "number";
176 public static Color getSafeColor(String col) {
179 result = Color.decode(col);
181 } catch (NumberFormatException e) {
183 result = Color.getColor(col, Color.green);
188 public void assignParameters(String parametersValue)
189 throws ExceptionModeleStyleBaseSyntaxError, ExceptionParameterError {
190 if (parametersValue.equals(""))
193 String[] parametersL = parametersValue.split(",");
195 ArrayList<String> namesArray = new ArrayList<String>();
196 ArrayList<String> valuesArray = new ArrayList<String>();
198 for (int i = 0; i < parametersL.length; i++) {
199 param = parametersL[i].split("=");
200 if (param.length != 2)
201 throw new ExceptionModeleStyleBaseSyntaxError(
202 "Bad parameter: '" + param[0] + "' ...");
203 namesArray.add(param[0].replace(" ", ""));
204 valuesArray.add(param[1].replace(" ", ""));
208 for (int i = 0; i < namesArray.size(); i++) {
209 if (namesArray.get(i).toLowerCase().equals(PARAM_INNER_COLOR)) {
211 setBaseInnerColor(getSafeColor(valuesArray.get(i)));
212 } catch (NumberFormatException e) {
213 throw new ExceptionParameterError(e.getMessage(),
214 "Bad inner color Syntax:" + valuesArray.get(i));
216 } else if (namesArray.get(i).toLowerCase().equals(PARAM_TEXT_COLOR)) {
218 setBaseNameColor(getSafeColor(valuesArray.get(i)));
219 } catch (NumberFormatException e) {
220 throw new ExceptionParameterError(e.getMessage(),
221 "Bad name color Syntax:" + valuesArray.get(i));
223 } else if (namesArray.get(i).toLowerCase().equals(
224 PARAM_NUMBER_COLOR)) {
226 setBaseNumberColor(getSafeColor(valuesArray.get(i)));
227 } catch (NumberFormatException e) {
228 throw new ExceptionParameterError(e.getMessage(),
229 "Bad numbers color Syntax:" + valuesArray.get(i));
231 } else if (namesArray.get(i).toLowerCase().equals(
232 PARAM_OUTLINE_COLOR)) {
234 setBaseOutlineColor(getSafeColor(valuesArray.get(i)));
235 } catch (NumberFormatException e) {
236 throw new ExceptionParameterError(e.getMessage(),
237 "Bad outline color Syntax:" + valuesArray.get(i));
240 throw new ExceptionModeleStyleBaseSyntaxError(
241 "Unknown parameter:" + namesArray.get(i));
246 * Find the font style integer from a string. Return <code>null</code> if
247 * the font style is unknown.
250 * The <code>string</code> to decode
251 * @return The font style integer as <code>Font.PLAIN<code>.
253 public static Integer StyleToInteger(String s) {
255 if (s.toLowerCase().equals("italic"))
257 else if (s.toLowerCase().equals("bold"))
259 else if (s.toLowerCase().equals("plain"))