JAL-3026 srcjar files for VARNA and log4j
[jalview.git] / srcjar / fr / orsay / lri / varna / models / rna / ModeleBackbone.java
1 package fr.orsay.lri.varna.models.rna;
2
3 import java.awt.Color;
4 import java.io.Serializable;
5 import java.util.ArrayList;
6 import java.util.Hashtable;
7
8 import javax.xml.transform.sax.TransformerHandler;
9
10 import org.xml.sax.SAXException;
11 import org.xml.sax.helpers.AttributesImpl;
12
13 import fr.orsay.lri.varna.models.rna.ModeleBackboneElement.BackboneType;
14 import fr.orsay.lri.varna.utils.XMLUtils;
15
16 public class ModeleBackbone  implements Serializable{
17
18         /**
19          * 
20          */
21         private Hashtable<Integer,ModeleBackboneElement> elems = new Hashtable<Integer,ModeleBackboneElement>();
22         
23         private static final long serialVersionUID = -614968737102943216L;
24
25         
26         
27         public static String XML_ELEMENT_NAME = "backbone";
28         
29         public void toXML(TransformerHandler hd) throws SAXException
30         {
31                 AttributesImpl atts = new AttributesImpl();
32                 hd.startElement("","",XML_ELEMENT_NAME,atts);
33                 for (ModeleBackboneElement bck:elems.values())
34                 {
35                         bck.toXML(hd);
36                 }
37                 hd.endElement("","",XML_ELEMENT_NAME);
38                 atts.clear();
39         }
40
41         public void addElement(ModeleBackboneElement mbe)
42         {
43                 elems.put(mbe.getIndex(),mbe);
44         }
45
46          public BackboneType getTypeBefore(int indexBase)
47          {
48                  return getTypeAfter(indexBase-1);
49          }
50         
51          public BackboneType getTypeAfter(int indexBase)
52          {
53                  if (elems.containsKey(indexBase))
54                          return elems.get(indexBase).getType();
55                  else
56                          return BackboneType.SOLID_TYPE;
57          }
58
59          public Color getColorBefore(int indexBase, Color defCol)
60          {
61                  return getColorAfter(indexBase-1,defCol);
62          }
63         
64          public Color getColorAfter(int indexBase, Color defCol)
65          {
66                  if (elems.containsKey(indexBase))
67                  {
68                          Color c = elems.get(indexBase).getColor();
69                          if (c != null)
70                                  return c;
71                  }
72                  return defCol;
73          }
74          
75 }