2 * Jalview - A Sequence Alignment Editor and Viewer
\r
3 * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
\r
5 * This program is free software; you can redistribute it and/or
\r
6 * modify it under the terms of the GNU General Public License
\r
7 * as published by the Free Software Foundation; either version 2
\r
8 * of the License, or (at your option) any later version.
\r
10 * This program is distributed in the hope that it will be useful,
\r
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
13 * GNU General Public License for more details.
\r
15 * You should have received a copy of the GNU General Public License
\r
16 * along with this program; if not, write to the Free Software
\r
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
\r
20 package jalview.appletgui;
\r
22 import jalview.datamodel.*;
\r
23 import jalview.schemes.*;
\r
26 public class SequenceRenderer
\r
30 boolean renderGaps = true;
\r
31 SequenceGroup currentSequenceGroup = null;
\r
32 SequenceGroup [] allGroups = null;
\r
36 public SequenceRenderer(AlignViewport av)
\r
42 public void renderGaps(boolean b)
\r
47 public Color getResidueBoxColour(ColourSchemeI cs, SequenceI seq, int i)
\r
49 getBoxColour(cs, seq, i);
\r
50 return resBoxColour;
\r
53 void getBoxColour(ColourSchemeI cs, SequenceI seq, int i)
\r
56 resBoxColour = cs.findColour(seq.getSequence(i, i + 1), i);
\r
58 resBoxColour = Color.white;
\r
61 public void drawSequence(Graphics g,SequenceI seq,SequenceGroup [] sg, int start, int end, int x1, int y1, int width, int height)
\r
67 drawBoxes(seq, start, end, x1, y1, (int) width, height);
\r
69 fm = g.getFontMetrics();
\r
70 drawText(seq,start,end,x1,y1,(int)width,height);
\r
74 public void drawBoxes(SequenceI seq,int start, int end, int x1, int y1, int width, int height) {
\r
76 int length = seq.getLength();
\r
79 int curWidth = width;
\r
81 Color tempColour = null;
\r
82 while (i <= end && i < length)
\r
84 if(inCurrentSequenceGroup(i))
\r
86 if( currentSequenceGroup.getDisplayBoxes())
\r
87 getBoxColour(currentSequenceGroup.cs, seq, i);
\r
89 resBoxColour = Color.white;
\r
91 else if(av.getShowBoxes())
\r
92 getBoxColour(av.getGlobalColourScheme(), seq, i);
\r
94 resBoxColour = Color.white;
\r
97 if (resBoxColour != tempColour)
\r
99 if(tempColour!=null)
\r
100 graphics.fillRect(x1+width*(curStart-start),y1,curWidth,height);
\r
101 graphics.setColor(resBoxColour);
\r
105 tempColour = resBoxColour;
\r
115 graphics.fillRect(x1+width*(curStart-start),y1,curWidth,height);
\r
118 public void drawText(SequenceI seq,int start, int end, int x1, int y1, int width, int height)
\r
120 int pady = height/5;
\r
123 // Need to find the sequence position here.
\r
125 String sequence = seq.getSequence();
\r
126 for (int i = start; i <= end; i++)
\r
128 graphics.setColor(Color.black);
\r
129 if(i<sequence.length())
\r
130 s = sequence.charAt(i);
\r
134 if(!renderGaps && jalview.util.Comparison.isGap(s))
\r
138 if (inCurrentSequenceGroup(i))
\r
140 if(!currentSequenceGroup.getDisplayText())
\r
143 if (currentSequenceGroup.getColourText())
\r
145 getBoxColour(currentSequenceGroup.cs, seq, i);
\r
146 graphics.setColor(resBoxColour.darker());
\r
151 if(!av.getShowText())
\r
154 if(av.getColourText())
\r
156 getBoxColour(av.getGlobalColourScheme(), seq, i);
\r
157 if(av.getShowBoxes())
\r
158 graphics.setColor(resBoxColour.darker());
\r
160 graphics.setColor(resBoxColour);
\r
164 charOffset = (width - fm.charWidth(s))/2;
\r
165 graphics.drawString(String.valueOf(s),
\r
166 charOffset + x1 + width * (i - start),
\r
167 y1 + height - pady);
\r
173 boolean inCurrentSequenceGroup(int res)
\r
175 if(allGroups ==null)
\r
178 for(int i=0; i<allGroups.length; i++)
\r
179 if(allGroups[i].getStartRes()<=res && allGroups[i].getEndRes()>=res)
\r
181 currentSequenceGroup = allGroups[i];
\r
188 public void drawHighlightedText(SequenceI seq,int start, int end, int x1, int y1, int width, int height)
\r
190 int pady = height/5;
\r
192 graphics.setColor(Color.black);
\r
193 graphics.fillRect(x1,y1,width*(end-start+1),height);
\r
194 graphics.setColor(Color.white);
\r
197 // Need to find the sequence position here.
\r
198 for (int i = start; i <= end; i++)
\r
200 if(i<seq.getLength())
\r
201 s = seq.getSequence().charAt(i);
\r
203 charOffset = (width - fm.charWidth(s))/2;
\r
204 graphics.drawString(String.valueOf(s), charOffset + x1 + width * (i - start), y1 + height - pady);
\r