9491ed8830d06b968df958be26f0f283e106c566
[jalview.git] / src2 / fr / orsay / lri / varna / models / rna / ModeleBase.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.geom.Point2D;
21 import java.io.Serializable;
22
23 import javax.xml.transform.sax.TransformerHandler;
24
25 import org.xml.sax.SAXException;
26 import org.xml.sax.helpers.AttributesImpl;
27
28 import fr.orsay.lri.varna.models.annotations.HighlightRegionAnnotation;
29 import fr.orsay.lri.varna.models.annotations.TextAnnotation;
30
31
32 /**
33  * The abstract rna base model
34  * 
35  * @author darty
36  * 
37  */
38 public abstract class ModeleBase implements Serializable, java.lang.Comparable<ModeleBase> {
39
40         private ModeleBP _BP;
41         /**
42          * The base style.
43          */
44         protected ModelBaseStyle _styleBase = new ModelBaseStyle();
45         /**
46          * TRUE if this InterfaceBase has to be colored, else FALSE.
47          */
48         protected Boolean _colorie = new Boolean(true);
49         /**
50          * The coordinate representation of this InterfaceBase on the final graphic.
51          */
52         protected VARNAPoint _coords = new VARNAPoint();
53         /**
54          * The nearest loop center of this InterfaceBase.
55          */
56         protected VARNAPoint _center = new VARNAPoint();
57
58         /**
59          * The label of this base.
60          */
61         protected String _label = "";
62
63         protected double _value;
64         protected int _realIndex = -1;
65
66         public abstract void toXML(TransformerHandler hd) throws SAXException;
67         
68         
69         
70         /**
71          * The internal index for this Base
72          */
73         public abstract int getIndex();
74
75         public abstract String getContent();
76         public abstract void setContent(String s);
77
78         /**
79          * Gets this InterfaceBase style.
80          * 
81          * @return this InterfaceBase style.
82          */
83         public ModelBaseStyle getStyleBase() {
84                 return _styleBase;
85         }
86
87         public double getValue()
88         {
89                 return _value;
90         }
91
92         public void setValue(double d)
93         {
94                 _value = d;
95         }
96         
97         
98         /**
99          * Sets this InterfaceBase style.
100          * 
101          * @param base
102          *            - This InterfaceBase new style.
103          */
104         public void setStyleBase(ModelBaseStyle base) {
105                 _styleBase = new ModelBaseStyle(base);
106         }
107
108         /**
109          * Gets this InterfaceBase color statement.
110          * 
111          * @return TRUE if this InterfaceBase has to be colored, else FALSE.
112          */
113         public final Boolean getColorie() {
114                 return _colorie;
115         }
116
117         /**
118          * Sets this InterfaceBase color statement.
119          * 
120          * @param _colorie
121          *            - TRUE if you want this InterfaceBase to be colored, else
122          *            FALSE
123          */
124         public final void setColorie(Boolean _colorie) {
125                 this._colorie = _colorie;
126         }
127
128
129         /**
130          * Gets this InterfaceBase associated structure element.
131          * 
132          * @return this InterfaceBase associated structure element.
133          */
134         public int getElementStructure() {
135                 if (_BP==null)
136                         return -1;
137                 else
138                 {
139                   if (_BP.getPartner5()==this)
140                           return _BP.getPartner3().getIndex();
141                   else
142                           return _BP.getPartner5().getIndex();
143                 }
144         }
145
146
147         /**
148          * Sets this InterfaceBase assiocated structure element.
149          * 
150          * @param structure
151          *            - This new assiocated structure element.
152         
153         public void setElementStructure(int structure) {
154                 setElementStructure(structure, new ModeleBP());
155         } */
156
157         /**
158          * Sets this InterfaceBase associated structure element.
159          * 
160          * @param structure
161          *            - This new associated structure element.
162          * @param type
163          *            - The type of this base pair.
164          */
165         public void setElementStructure(int structure, ModeleBP type) {
166 //              _elementStructure = structure;
167                 _BP = type;
168
169         }
170
171         public void removeElementStructure() {
172 //              _elementStructure = -1;
173                 _BP = null;
174         }
175         
176         
177         /**
178          * Gets the base pair type for this element.
179          * 
180          * @return the base pair type for this element.
181          */
182         public ModeleBP getStyleBP() {
183                 return _BP;
184         }
185
186         /**
187          * Sets the base pair type for this element.
188          * 
189          * @param type
190          *            - The new base pair type for this element.
191          */
192         public void setStyleBP(ModeleBP type) {
193                 _BP = type;
194         }
195
196         public int getBaseNumber() {
197                 return _realIndex;
198         }
199
200         public void setBaseNumber(int bn) {
201                 _realIndex = bn;
202         }
203         
204         public Point2D.Double getCoords() {
205                 return new Point2D.Double(_coords.x,_coords.y);
206         }
207
208         public void setCoords(Point2D.Double coords) {
209                 this._coords.x = coords.x;
210                 this._coords.y = coords.y;
211         }
212
213         public Point2D.Double getCenter() {
214                 return new Point2D.Double(_center.x,_center.y);
215         }
216
217         public void setCenter(Point2D.Double center) {
218                 this._center.x = center.x;
219                 this._center.y = center.y;
220         }
221
222         public String getLabel() {
223                 if (_label==null || _label.equals(""))
224                 {
225                         return ""+this.getBaseNumber();
226                 }
227                 else
228                 {
229                         return _label;
230                 }
231                         
232         }
233
234         public void setLabel(String s) {
235                 _label= s;
236         }
237
238         public void setLabel(Point2D.Double center) {
239                 this._center.x = center.x;
240                 this._center.y = center.y;
241         }
242
243
244         public int compareTo(ModeleBase other) { 
245             int nombre1 = ((ModeleBase) other).getIndex(); 
246             int nombre2 = this.getIndex(); 
247             if (nombre1 > nombre2)  return -1; 
248             else if(nombre1 == nombre2) return 0; 
249             else return 1; 
250         } 
251         
252         public static String XML_VAR_TYPE_NAME = "type";
253         public static String XML_VAR_INDEX_NAME = "index";
254         public static String XML_VAR_LABEL_NAME = "label";
255         public static String XML_VAR_VALUE_NAME = "val";
256         public static String XML_VAR_POSITION_NAME = "pos";
257         public static String XML_VAR_CENTER_NAME = "center";
258         public static String XML_VAR_NUMBER_NAME = "num";
259         public static String XML_VAR_CUSTOM_DRAWN_NAME = "custom";
260         
261         
262 }