8929642a4dcd3f0661b57a80df321603f5d841a2
[jalview.git] / srcjar / fr / orsay / lri / varna / models / rna / VARNAPoint.java
1 package fr.orsay.lri.varna.models.rna;
2
3 import java.awt.geom.Point2D;
4 import java.awt.geom.Point2D.Double;
5 import java.io.Serializable;
6
7 import javax.xml.transform.sax.TransformerHandler;
8
9 import org.xml.sax.SAXException;
10 import org.xml.sax.helpers.AttributesImpl;
11
12 public class VARNAPoint implements Serializable {
13
14         private static final long serialVersionUID = 8815373295131046029L;
15         
16         public double x = 0.0;
17         public double y = 0.0;
18         
19         public void toXML(TransformerHandler hd) throws SAXException
20         {
21                 toXML(hd,"");
22         }       
23         
24
25         public static String XML_ELEMENT_NAME = "p";
26         public static String XML_VAR_ROLE_NAME = "r";
27         public static String XML_VAR_X_NAME = "x";
28         public static String XML_VAR_Y_NAME = "y";
29
30         public void toXML(TransformerHandler hd, String role) throws SAXException
31         {
32                 AttributesImpl atts = new AttributesImpl();
33                 if (!role.equals(""))
34                 {
35                         atts.addAttribute("","",XML_VAR_ROLE_NAME,"CDATA",""+role);
36                 }
37                 atts.addAttribute("","",XML_VAR_X_NAME,"CDATA",""+x);
38                 atts.addAttribute("","",XML_VAR_Y_NAME,"CDATA",""+y);
39                 hd.startElement("","",XML_ELEMENT_NAME,atts);
40                 hd.endElement("","",XML_ELEMENT_NAME);
41         }       
42
43         public VARNAPoint()
44         { this(0.0,0.0); }
45         
46         public VARNAPoint(double px, double py)
47     {
48         x = px; y = py;
49     }
50     public VARNAPoint(Point2D.Double p)
51     {
52         this(p.x,p.y);
53     }
54  
55     public double getX()
56     {
57         return x;
58     }
59     
60     public double getY()
61     {
62         return y;
63     }
64     
65     public Point2D.Double toPoint2D()
66     {
67         return new Point2D.Double(x,y);
68     }
69     
70     public String toString()
71     {
72         return "("+x+","+y+")" ;
73     }
74 }