JAL-3026 srcjar files for VARNA and log4j
[jalview.git] / srcjar / fr / orsay / lri / varna / models / rna / ModeleBPStyle.java
1 /*
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
6
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.
10
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.
14
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.
17  */
18 package fr.orsay.lri.varna.models.rna;
19
20 import java.awt.Color;
21 import java.io.Serializable;
22 import java.util.ArrayList;
23 import java.util.Random;
24
25 import javax.xml.transform.sax.TransformerHandler;
26
27 import org.xml.sax.SAXException;
28 import org.xml.sax.helpers.AttributesImpl;
29
30 import fr.orsay.lri.varna.exceptions.ExceptionModeleStyleBaseSyntaxError;
31 import fr.orsay.lri.varna.exceptions.ExceptionParameterError;
32 import fr.orsay.lri.varna.models.VARNAConfig;
33 import fr.orsay.lri.varna.utils.XMLUtils;
34
35
36 public class ModeleBPStyle implements Serializable {
37
38         /**
39          * 
40          */
41         private static final long serialVersionUID = 3006493290669550139L;
42         /**
43          * 
44          */
45         private boolean _isCustomColored = false;
46         private Color _color = VARNAConfig.DEFAULT_BOND_COLOR;
47
48         private double _thickness = -1.0;
49         private double _bent = 0.0;
50         
51         public static String XML_ELEMENT_NAME = "BPstyle";
52         public static String XML_VAR_CUSTOM_STYLED_NAME = "custom";
53         public static String XML_VAR_COLOR_NAME = "color";
54         public static String XML_VAR_THICKNESS_NAME = "thickness";
55         public static String XML_VAR_BENT_NAME = "bent";
56
57         public void toXML(TransformerHandler hd) throws SAXException
58         {
59                 AttributesImpl atts = new AttributesImpl();
60                 atts.addAttribute("","",XML_VAR_CUSTOM_STYLED_NAME,"CDATA",""+_isCustomColored);
61                 atts.addAttribute("","",XML_VAR_COLOR_NAME,"CDATA",XMLUtils.toHTMLNotation(_color));
62                 atts.addAttribute("","",XML_VAR_THICKNESS_NAME,"CDATA",""+_thickness);
63                 atts.addAttribute("","",XML_VAR_BENT_NAME,"CDATA",""+_bent);
64                 hd.startElement("","",XML_ELEMENT_NAME,atts);
65                 hd.endElement("","",XML_ELEMENT_NAME);
66         }
67
68         
69         public double getBent()
70         {
71                 return _bent;
72         }
73
74         
75         public boolean isBent()
76         {
77                 return (_bent!=0.0);
78         }
79
80         public void setBent(double b)
81         {
82                 _bent = b;
83         }
84
85         
86         public ModeleBPStyle() {
87         }
88
89
90         public void setCustomColor(Color c) {
91                 _isCustomColored = true;
92                 _color = c;
93         }
94
95         public void useDefaultColor() {
96                 _isCustomColored = false;
97         }
98
99         public boolean isCustomColored() {
100                 return _isCustomColored;
101         }
102
103         public Color getCustomColor() {
104                 return _color;
105         }
106
107         /**
108          * Returns the current custom color if such a color is defined to be used
109          * (through setCustomColor), or returns the default color.
110          * 
111          * @param def
112          *            - The default color is no custom color is defined
113          * @return The color to be used to draw this base-pair
114          */
115         public Color getColor(Color def) {
116                 if (isCustomColored()) {
117                         return _color;
118                 } else {
119                         return def;
120                 }
121         }
122
123         public double getThickness(double def) {
124                 if (_thickness > 0)
125                         return _thickness;
126                 else
127                         return def;
128         }
129
130         public void setThickness(double thickness) {
131                 _thickness = thickness;
132         }
133
134 }