3 import jalview.datamodel.*;
\r
4 import jalview.schemes.*;
\r
8 public class SequenceRenderer implements RendererI
\r
12 boolean renderGaps = true;
\r
13 SequenceGroup currentSequenceGroup = null;
\r
14 Color resBoxColour = Color.white;
\r
17 public SequenceRenderer(AlignViewport av)
\r
23 public void renderGaps(boolean b)
\r
28 public Color getResidueBoxColour(ColourSchemeI cs, SequenceI seq, int i)
\r
30 getBoxColour(cs, seq, i);
\r
31 return resBoxColour;
\r
34 void getBoxColour(ColourSchemeI cs, SequenceI seq, int i)
\r
38 resBoxColour = cs.findColour(seq.getSequence(i, i + 1), i, av.getConsensus(false));
\r
40 resBoxColour = Color.white;
\r
43 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)
\r
45 currentSequenceGroup = sg;
\r
49 drawBoxes(seq, start, end, x1, y1, (int) width, height, pid);
\r
51 fm = g.getFontMetrics();
\r
52 drawText(seq,start,end,x1,y1,(int)width,height);
\r
56 public void drawBoxes(SequenceI seq,int start, int end, int x1, int y1, int width, int height,Vector freq) {
\r
58 int length = seq.getLength();
\r
61 int curWidth = width;
\r
63 Color tempColour = Color.red;
\r
64 while (i <= end && i < length)
\r
66 if(inCurrentSequenceGroup(i))
\r
68 if( currentSequenceGroup.getDisplayBoxes())
\r
69 getBoxColour(currentSequenceGroup.cs, seq, i);
\r
71 else if(av.getShowBoxes())
\r
72 getBoxColour(av.getGlobalColourScheme(), seq, i);
\r
74 if (resBoxColour != tempColour)
\r
76 graphics.fillRect(x1+width*(curStart-start),y1,curWidth,height);
\r
77 graphics.setColor(resBoxColour);
\r
81 tempColour = resBoxColour;
\r
89 graphics.fillRect(x1+width*(curStart-start),y1,curWidth,height);
\r
92 public void drawText(SequenceI seq,int start, int end, int x1, int y1, int width, int height)
\r
94 int pady = height/5;
\r
97 // Need to find the sequence position here.
\r
98 for (int i = start; i <= end; i++)
\r
100 if(i<seq.getLength())
\r
101 s = seq.getSequence().charAt(i);
\r
105 if(!renderGaps && jalview.util.Comparison.isGap(s))
\r
108 graphics.setColor(Color.black);
\r
110 if (inCurrentSequenceGroup(i))
\r
112 if(!currentSequenceGroup.getDisplayText())
\r
115 if(currentSequenceGroup.getColourText())
\r
116 graphics.setColor(resBoxColour.darker());
\r
120 if(!av.getShowText())
\r
123 if(av.getColourText())
\r
124 graphics.setColor(resBoxColour.darker());
\r
127 charOffset = (width - fm.charWidth(s))/2;
\r
128 graphics.drawString(String.valueOf(s), charOffset + x1 + width * (i - start), y1 + height - pady);
\r
134 boolean inCurrentSequenceGroup(int res)
\r
136 if(currentSequenceGroup==null)
\r
139 return (currentSequenceGroup.getStartRes()<=res && currentSequenceGroup.getEndRes()>=res)?true:false;
\r
142 public void drawHighlightedText(SequenceI seq,int start, int end, int x1, int y1, int width, int height)
\r
144 int pady = height/5;
\r
146 graphics.setColor(Color.BLACK);
\r
147 graphics.fillRect(x1,y1,width*(end-start+1),height);
\r
148 graphics.setColor(Color.white);
\r
151 // Need to find the sequence position here.
\r
152 for (int i = start; i <= end; i++)
\r
154 if(i<seq.getLength())
\r
155 s = seq.getSequence().charAt(i);
\r
157 charOffset = (width - fm.charWidth(s))/2;
\r
158 graphics.drawString(String.valueOf(s), charOffset + x1 + width * (i - start), y1 + height - pady);
\r