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
16 public SequenceRenderer(AlignViewport av)
\r
22 public void renderGaps(boolean b)
\r
27 public Color getResidueBoxColour(ColourSchemeI cs, SequenceI seq, int i)
\r
29 Color c = Color.white;
\r
32 c = cs.findColour(seq.getSequence(i, i + 1), i, av.getConsensus(false));
\r
33 }catch(Exception ex){}
\r
38 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
40 currentSequenceGroup = sg;
\r
42 drawBoxes(g, seq, start, end, x1, y1, (int) width, height, pid);
\r
44 fm = g.getFontMetrics();
\r
45 drawText(g,seq,start,end,x1,y1,(int)width,height);
\r
49 public void drawBoxes(Graphics g, SequenceI seq,int start, int end, int x1, int y1, int width, int height,Vector freq) {
\r
51 int length = seq.getLength();
\r
53 Color currentColor = Color.WHITE;
\r
56 int curWidth = width;
\r
58 while (i <= end && i < length)
\r
60 color = color.white;
\r
62 if(inCurrentSequenceGroup(i))
\r
64 if( currentSequenceGroup.getDisplayBoxes())
\r
65 color = getResidueBoxColour(currentSequenceGroup.cs, seq, i);
\r
67 else if(av.getShowBoxes())
\r
68 color = getResidueBoxColour(av.getGlobalColourScheme(), seq, i);
\r
71 if (color != currentColor || color != null)
\r
73 g.fillRect(x1+width*(curStart-start),y1,curWidth,height);
\r
75 currentColor = color;
\r
86 g.fillRect(x1+width*(curStart-start),y1,curWidth,height);
\r
89 public void drawText(Graphics g, SequenceI seq,int start, int end, int x1, int y1, int width, int height)
\r
91 int pady = height/5;
\r
93 g.setColor(Color.black);
\r
96 // Need to find the sequence position here.
\r
97 for (int i = start; i <= end; i++)
\r
99 if(i<seq.getLength())
\r
100 s = seq.getSequence().charAt(i);
\r
104 if(!renderGaps && jalview.util.Comparison.isGap(s))
\r
107 g.setColor(Color.black);
\r
109 if (inCurrentSequenceGroup(i))
\r
111 if(!currentSequenceGroup.getDisplayText())
\r
114 if(currentSequenceGroup.getColourText())
\r
115 g.setColor(getResidueBoxColour(currentSequenceGroup.cs, seq, i).darker());
\r
119 if(!av.getShowText())
\r
122 if(av.getColourText())
\r
123 g.setColor(getResidueBoxColour(av.getGlobalColourScheme(), seq, i).darker());
\r
126 charOffset = (width - fm.charWidth(s))/2;
\r
127 g.drawString(String.valueOf(s), charOffset + x1 + width * (i - start), y1 + height - pady);
\r
133 boolean inCurrentSequenceGroup(int res)
\r
135 if(currentSequenceGroup==null)
\r
138 return (currentSequenceGroup.getStartRes()<=res && currentSequenceGroup.getEndRes()>=res)?true:false;
\r
141 public void drawHighlightedText(Graphics g, SequenceI seq,int start, int end, int x1, int y1, int width, int height)
\r
143 int pady = height/5;
\r
145 g.setColor(Color.BLACK);
\r
146 g.fillRect(x1,y1,width*(end-start+1),height);
\r
147 g.setColor(Color.white);
\r
150 // Need to find the sequence position here.
\r
151 for (int i = start; i <= end; i++)
\r
153 if(i<seq.getLength())
\r
154 s = seq.getSequence().charAt(i);
\r
156 charOffset = (width - fm.charWidth(s))/2;
\r
157 g.drawString(String.valueOf(s), charOffset + x1 + width * (i - start), y1 + height - pady);
\r