X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Forg%2Fbiojava%2Fdasobert%2Ffeature%2FAbstractSegment.java;h=12c5e1d3a1ea123f96c383c9fa0230a6a6f37a30;hb=2253f31565d4e96edffce2fac596e2ef0578d596;hp=daa7f75e89d35da7d64b0dbc59359d3547d57424;hpb=d1f6cf53b29322601c621da9a6b3cb09dd28235e;p=jalview.git diff --git a/src/org/biojava/dasobert/feature/AbstractSegment.java b/src/org/biojava/dasobert/feature/AbstractSegment.java index daa7f75..12c5e1d 100644 --- a/src/org/biojava/dasobert/feature/AbstractSegment.java +++ b/src/org/biojava/dasobert/feature/AbstractSegment.java @@ -25,139 +25,232 @@ package org.biojava.dasobert.feature; import java.awt.Color; -public abstract class AbstractSegment implements Segment,Cloneable { - int start ; - int end ; - String name ; - Color color ; - FeatureTrack parent ; - String txtColor ; - String note; - - public abstract Object clone(); - - /* (non-Javadoc) - * @see org.biojava.spice.feature.SegmentIF#toString() - */ - public String toString() { - String str = "Segment: " +name + " " +start + " " + end ; - if ( ( note != null ) && ( ! note.equals("null"))) - if ( note.length() >40) - str += note.substring(0,39)+"..."; - else - str += note; - return str ; - } - - /* (non-Javadoc) - * @see org.biojava.spice.feature.SegmentIF#getNote() - */ - public String getNote() { - return note; - } - - /* (non-Javadoc) - * @see org.biojava.spice.feature.SegmentIF#setNote(java.lang.String) - */ - public void setNote(String note) { - this.note = note; - } - - /* (non-Javadoc) - * @see org.biojava.spice.feature.SegmentIF#setStart(int) - */ - public void setStart(int strt) {start = strt ; } - /* (non-Javadoc) - * @see org.biojava.spice.feature.SegmentIF#getStart() - */ - public int getStart() {return start ;} - - /* (non-Javadoc) - * @see org.biojava.spice.feature.SegmentIF#setEnd(int) - */ - public void setEnd(int ed) { end = ed;} - /* (non-Javadoc) - * @see org.biojava.spice.feature.SegmentIF#getEnd() - */ - public int getEnd() { return end;} - - /* (non-Javadoc) - * @see org.biojava.spice.feature.SegmentIF#setName(java.lang.String) - */ - public void setName(String nam) { name = nam;} - /* (non-Javadoc) - * @see org.biojava.spice.feature.SegmentIF#getName() - */ - public String getName() { return name ; } - - /* (non-Javadoc) - * @see org.biojava.spice.feature.SegmentIF#setColor(java.awt.Color) - */ - public void setColor(Color col) { color = col; } - /* (non-Javadoc) - * @see org.biojava.spice.feature.SegmentIF#getColor() - */ - public Color getColor() { return color ; } - - /* (non-Javadoc) - * @see org.biojava.spice.feature.SegmentIF#setParent(org.biojava.spice.feature.Feature) - */ - public void setParent(FeatureTrack f) { parent = f;} - /* (non-Javadoc) - * @see org.biojava.spice.feature.SegmentIF#getParent() - */ - public FeatureTrack getParent(){ return parent;} - - /* (non-Javadoc) - * @see org.biojava.spice.feature.SegmentIF#setTxtColor(java.lang.String) - */ - public void setTxtColor(String str) { txtColor = str; } - /* (non-Javadoc) - * @see org.biojava.spice.feature.SegmentIF#getTxtColor() - */ - public String getTxtColor() { return txtColor;} - - - /* (non-Javadoc) - * @see org.biojava.spice.feature.SegmentIF#overlaps(int) - */ - public boolean overlaps(int seqPosition){ - if ( ( getStart() <= seqPosition) && ( getEnd() >= seqPosition)){ - return true; - } - return false; - } - - - - /* (non-Javadoc) - * @see org.biojava.spice.feature.SegmentIF#overlaps(org.biojava.spice.feature.Segment) - */ - public boolean overlaps(Segment segment){ - if (! (this.start <= this.end )) - throw new IndexOutOfBoundsException("start > end for segment" + this); - - if ( ! (segment.getStart() <= segment.getEnd() )) - throw new IndexOutOfBoundsException("start > end for segment" + segment); - - // start must be in region of other - if ( this.start >= segment.getStart()){ - if ( this.start <= segment.getEnd()){ - return true; - } - } - // or end must be in region of other.. - if ( this.end >= segment.getStart() ) { - if ( this.end <= segment.getEnd()){ - return true; - } - } - - if ( this.start <= segment.getStart() ) { - if ( this.end >= segment.getEnd() ) { - return true; - } - } - return false; - } +public abstract class AbstractSegment implements Segment, Cloneable +{ + int start; + + int end; + + String name; + + Color color; + + FeatureTrack parent; + + String txtColor; + + String note; + + public abstract Object clone(); + + /* + * (non-Javadoc) + * + * @see org.biojava.spice.feature.SegmentIF#toString() + */ + public String toString() + { + String str = "Segment: " + name + " " + start + " " + end; + if ((note != null) && (!note.equals("null"))) + if (note.length() > 40) + str += note.substring(0, 39) + "..."; + else + str += note; + return str; + } + + /* + * (non-Javadoc) + * + * @see org.biojava.spice.feature.SegmentIF#getNote() + */ + public String getNote() + { + return note; + } + + /* + * (non-Javadoc) + * + * @see org.biojava.spice.feature.SegmentIF#setNote(java.lang.String) + */ + public void setNote(String note) + { + this.note = note; + } + + /* + * (non-Javadoc) + * + * @see org.biojava.spice.feature.SegmentIF#setStart(int) + */ + public void setStart(int strt) + { + start = strt; + } + + /* + * (non-Javadoc) + * + * @see org.biojava.spice.feature.SegmentIF#getStart() + */ + public int getStart() + { + return start; + } + + /* + * (non-Javadoc) + * + * @see org.biojava.spice.feature.SegmentIF#setEnd(int) + */ + public void setEnd(int ed) + { + end = ed; + } + + /* + * (non-Javadoc) + * + * @see org.biojava.spice.feature.SegmentIF#getEnd() + */ + public int getEnd() + { + return end; + } + + /* + * (non-Javadoc) + * + * @see org.biojava.spice.feature.SegmentIF#setName(java.lang.String) + */ + public void setName(String nam) + { + name = nam; + } + + /* + * (non-Javadoc) + * + * @see org.biojava.spice.feature.SegmentIF#getName() + */ + public String getName() + { + return name; + } + + /* + * (non-Javadoc) + * + * @see org.biojava.spice.feature.SegmentIF#setColor(java.awt.Color) + */ + public void setColor(Color col) + { + color = col; + } + + /* + * (non-Javadoc) + * + * @see org.biojava.spice.feature.SegmentIF#getColor() + */ + public Color getColor() + { + return color; + } + + /* + * (non-Javadoc) + * + * @see org.biojava.spice.feature.SegmentIF#setParent(org.biojava.spice.feature.Feature) + */ + public void setParent(FeatureTrack f) + { + parent = f; + } + + /* + * (non-Javadoc) + * + * @see org.biojava.spice.feature.SegmentIF#getParent() + */ + public FeatureTrack getParent() + { + return parent; + } + + /* + * (non-Javadoc) + * + * @see org.biojava.spice.feature.SegmentIF#setTxtColor(java.lang.String) + */ + public void setTxtColor(String str) + { + txtColor = str; + } + + /* + * (non-Javadoc) + * + * @see org.biojava.spice.feature.SegmentIF#getTxtColor() + */ + public String getTxtColor() + { + return txtColor; + } + + /* + * (non-Javadoc) + * + * @see org.biojava.spice.feature.SegmentIF#overlaps(int) + */ + public boolean overlaps(int seqPosition) + { + if ((getStart() <= seqPosition) && (getEnd() >= seqPosition)) + { + return true; + } + return false; + } + + /* + * (non-Javadoc) + * + * @see org.biojava.spice.feature.SegmentIF#overlaps(org.biojava.spice.feature.Segment) + */ + public boolean overlaps(Segment segment) + { + if (!(this.start <= this.end)) + throw new IndexOutOfBoundsException("start > end for segment" + this); + + if (!(segment.getStart() <= segment.getEnd())) + throw new IndexOutOfBoundsException("start > end for segment" + + segment); + + // start must be in region of other + if (this.start >= segment.getStart()) + { + if (this.start <= segment.getEnd()) + { + return true; + } + } + // or end must be in region of other.. + if (this.end >= segment.getStart()) + { + if (this.end <= segment.getEnd()) + { + return true; + } + } + + if (this.start <= segment.getStart()) + { + if (this.end >= segment.getEnd()) + { + return true; + } + } + return false; + } }