updated jalview version of dasobert 1.53e client and added Das Sequence Source discov...
[jalview.git] / src / org / biojava / dasobert / feature / AbstractSegment.java
1 /*
2  *                  BioJava development code
3  *
4  * This code may be freely distributed and modified under the
5  * terms of the GNU Lesser General Public Licence.  This should
6  * be distributed with the code.  If you do not have a copy,
7  * see:
8  *
9  *      http://www.gnu.org/copyleft/lesser.html
10  *
11  * Copyright for this code is held jointly by the individual
12  * authors.  These should be listed in @author doc comments.
13  *
14  * For more information on the BioJava project and its aims,
15  * or to join the biojava-l mailing list, visit the home page
16  * at:
17  *
18  *      http://www.biojava.org/
19  * 
20  * Created on May 22, 2007
21  * 
22  */
23
24 package org.biojava.dasobert.feature;
25
26 import java.awt.Color;
27
28 public abstract class AbstractSegment implements Segment,Cloneable {
29         int start   ;
30         int end     ;
31         String name ;
32         Color color ;
33         FeatureTrack parent ;
34         String txtColor ;
35         String note;
36
37         public abstract Object clone();
38         
39         /* (non-Javadoc)
40          * @see org.biojava.spice.feature.SegmentIF#toString()
41          */
42         public String toString() {
43                 String str = "Segment: " +name + " " +start + " " + end ;
44                 if ( ( note != null ) && ( ! note.equals("null")))
45                         if ( note.length() >40)
46                                 str += note.substring(0,39)+"...";
47                         else
48                                 str += note;
49                 return str ;
50         }
51
52         /* (non-Javadoc)
53          * @see org.biojava.spice.feature.SegmentIF#getNote()
54          */
55         public String getNote() {
56                 return note;
57         }
58
59         /* (non-Javadoc)
60          * @see org.biojava.spice.feature.SegmentIF#setNote(java.lang.String)
61          */
62         public void setNote(String note) {
63                 this.note = note;
64         }
65
66         /* (non-Javadoc)
67          * @see org.biojava.spice.feature.SegmentIF#setStart(int)
68          */
69         public void setStart(int strt) {start = strt ; }
70         /* (non-Javadoc)
71          * @see org.biojava.spice.feature.SegmentIF#getStart()
72          */
73         public int  getStart() {return start ;}
74
75         /* (non-Javadoc)
76          * @see org.biojava.spice.feature.SegmentIF#setEnd(int)
77          */
78         public void setEnd(int ed) { end = ed;}
79         /* (non-Javadoc)
80          * @see org.biojava.spice.feature.SegmentIF#getEnd()
81          */
82         public int getEnd() { return end;}
83
84         /* (non-Javadoc)
85          * @see org.biojava.spice.feature.SegmentIF#setName(java.lang.String)
86          */
87         public void setName(String nam) { name = nam;}
88         /* (non-Javadoc)
89          * @see org.biojava.spice.feature.SegmentIF#getName()
90          */
91         public String getName() { return name ; }
92
93         /* (non-Javadoc)
94          * @see org.biojava.spice.feature.SegmentIF#setColor(java.awt.Color)
95          */
96         public void setColor(Color col) { color = col; }
97         /* (non-Javadoc)
98          * @see org.biojava.spice.feature.SegmentIF#getColor()
99          */
100         public Color getColor() { return color ; }
101
102         /* (non-Javadoc)
103          * @see org.biojava.spice.feature.SegmentIF#setParent(org.biojava.spice.feature.Feature)
104          */
105         public void setParent(FeatureTrack f) { parent = f;}
106         /* (non-Javadoc)
107          * @see org.biojava.spice.feature.SegmentIF#getParent()
108          */
109         public FeatureTrack getParent(){ return parent;}
110
111         /* (non-Javadoc)
112          * @see org.biojava.spice.feature.SegmentIF#setTxtColor(java.lang.String)
113          */
114         public void setTxtColor(String str) { txtColor = str; }
115         /* (non-Javadoc)
116          * @see org.biojava.spice.feature.SegmentIF#getTxtColor()
117          */
118         public String getTxtColor() { return txtColor;}
119
120
121         /* (non-Javadoc)
122          * @see org.biojava.spice.feature.SegmentIF#overlaps(int)
123          */
124         public boolean overlaps(int seqPosition){
125                 if ( ( getStart() <= seqPosition) && ( getEnd() >= seqPosition)){
126                         return true;             
127                 }   
128                 return false;
129         }
130
131
132
133         /* (non-Javadoc)
134          * @see org.biojava.spice.feature.SegmentIF#overlaps(org.biojava.spice.feature.Segment)
135          */
136         public boolean overlaps(Segment segment){
137                 if (! (this.start <= this.end )) 
138                         throw new IndexOutOfBoundsException("start > end for segment" + this);
139
140                 if ( ! (segment.getStart() <= segment.getEnd() ))
141                         throw new IndexOutOfBoundsException("start > end for segment" + segment);
142
143                 // start must be in region of other
144                 if ( this.start >= segment.getStart()){
145                         if ( this.start <= segment.getEnd()){
146                                 return true;
147                         }
148                 }
149                 // or end must be in region of other..
150                 if ( this.end >= segment.getStart() ) {
151                         if ( this.end <= segment.getEnd()){
152                                 return true;
153                         }
154                 }
155
156                 if ( this.start <= segment.getStart() ) {
157                         if ( this.end >= segment.getEnd() ) {
158                                 return true;
159                         }
160                 }
161                 return false;
162         }
163 }