package jalview.gui; import jalview.datamodel.*; import jalview.schemes.*; import java.awt.*; import java.util.*; public class FeatureRenderer { 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 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); } 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); } } } } } }