X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FFeatureRenderer.java;h=fc31fdfe8b2139db0627b5b51a33c26320b67ccd;hb=e7ed63f1ea56432246a6ed1553f0fe56d26f56ea;hp=cd754c706a87aa38570ce6b9ebdd063b2ca6f0d2;hpb=1ecf6419aba86993b3c223bf5ec0fa79427baf85;p=jalview.git diff --git a/src/jalview/gui/FeatureRenderer.java b/src/jalview/gui/FeatureRenderer.java index cd754c7..fc31fdf 100755 --- a/src/jalview/gui/FeatureRenderer.java +++ b/src/jalview/gui/FeatureRenderer.java @@ -5,81 +5,76 @@ import jalview.schemes.*; import java.awt.*; import java.util.*; -public class FeatureRenderer implements RendererI { +public class FeatureRenderer implements RendererI +{ + AlignViewport av; + + SequenceGroup currentSequenceGroup = null; + SequenceGroup [] allGroups = null; + Color resBoxColour; + Graphics graphics; + + public FeatureRenderer(AlignViewport av) + { + this.av = av; + } + + + public void drawSequence(Graphics g,SequenceI seq,SequenceGroup [] sg, int start, int end, int x1, int y1, int width, int height, Vector pid, int seqnum) + { + Vector features = seq.getSequenceFeatures(); + Enumeration e = features.elements(); + while( e.hasMoreElements() ) + { + SequenceFeature sf = (SequenceFeature)e.nextElement(); + if(sf.getStart()>seq.getEnd()) + continue; + + int fstart = seq.findIndex(sf.getStart())-1; + int fend = seq.findIndex(sf.getEnd())-1; + + if( (fstart<=end && fend>=start) ) + { + if(fstart<0) // fix for if the feature we have starts before the sequence start, + fstart = 0;// but the feature end is still valid!! + + if(fstart==fend) + { + g.setColor(Color.red); + g.fillRoundRect( (fstart - start) * width, y1, width, height, 4,4); + g.setColor(Color.white); + + char s = seq.getSequence().charAt(fstart); + FontMetrics fm = g.getFontMetrics(); + int charOffset = (width - fm.charWidth(s))/2; + int pady = height/5; + g.drawString(String.valueOf(s), charOffset + x1 + width * (fstart - start), y1 + height - pady); - - public Color getResidueBoxColour(ColourSchemeI cs, SequenceI seq, int i) { - Color c = cs.findColour(seq,seq.getSequence(i,i+1),i,null); - return c; - } - - public void drawSequence(Graphics g,ColourSchemeI cs,SequenceI seq,int start, int end, int x1, int y1, double width, int height,boolean showScores, boolean displayBoxes, boolean displayText,Vector pid, int seqnum,AlignViewport av) { - - int i = start; - int length = seq.getLength(); - - Color currentColor = Color.black; - - - int prev = -1; - int fstart = 0; - char prevc = '-'; - - g.setColor(Color.magenta); - - while (i <= end && i < length) { - char c = seq.getCharAt(i); - if (c != '-') { - - if (prevc != c) { - - if (prevc == 'F') { - g.setColor(Color.green); - } else if (prevc == 'R') { - g.setColor(Color.cyan); - } else if (prevc == 'M') { - g.setColor(Color.magenta); - } else if (prevc == 'P') { - g.setColor(Color.yellow); - } - g.fillRect(x1+(int)(width*(i-fstart)),y1+height/4,(int)((prev-fstart+1)*width),height/2); - - prevc = c; - fstart = i; - } - } else if (prevc != '-') { - if (prevc == 'F') { - g.setColor(Color.green); - } else if (prevc == 'R') { - g.setColor(Color.cyan); - } else if (prevc == 'M') { - g.setColor(Color.magenta); - } else if (prevc == 'P') { - g.setColor(Color.yellow); - } - g.fillRect(x1+(int)(width*(fstart-start)),y1+height/4,(int)((i-fstart+1)*width),height/2); - - prevc = c; - } else { - fstart = -1; + } + else + { + for (int i = fstart; i <= fend; i++) + { + char s = seq.getSequence().charAt(i); + if( jalview.util.Comparison.isGap(s) ) + continue; + + g.setColor(Color.blue); + g.fillRect( (i-start) * width, y1, width, height); + + g.setColor(Color.white); + + FontMetrics fm = g.getFontMetrics(); + int charOffset = (width - fm.charWidth(s)) / 2; + int pady = height / 5; + g.drawString(String.valueOf(s), + charOffset + x1 + width * (i-start), + y1 + height - pady); } - i++; - } - - if (fstart != -1) { - if (prevc == 'F') { - g.setColor(Color.green); - } else if (prevc == 'R') { - g.setColor(Color.cyan); - } else if (prevc == 'M') { - g.setColor(Color.magenta); - } else if (prevc == 'P') { - g.setColor(Color.yellow); } + } - //g.fillRect(x1+(int)(width*(fstart-start)),y1+height/4,(int)((end-fstart+1)*width),height/2); - - } } + } }