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
24 import jalview.datamodel.*;
\r
25 import jalview.schemes.*;
\r
27 public class SequenceRenderer
\r
31 boolean renderGaps = true;
\r
32 SequenceGroup currentSequenceGroup = null;
\r
33 SequenceGroup[] allGroups = null;
\r
36 boolean forOverview = false;
\r
38 public SequenceRenderer(AlignViewport av)
\r
43 public void renderGaps(boolean b)
\r
48 public Color getResidueBoxColour(SequenceI seq, int i)
\r
50 allGroups = av.alignment.findAllGroups(seq);
\r
52 if (inCurrentSequenceGroup(i))
\r
54 if (currentSequenceGroup.getDisplayBoxes())
\r
56 getBoxColour(currentSequenceGroup.cs, seq, i);
\r
59 else if (av.getShowBoxes())
\r
61 getBoxColour(av.globalColourScheme, seq, i);
\r
64 return resBoxColour;
\r
67 void getBoxColour(ColourSchemeI cs, SequenceI seq, int i)
\r
71 resBoxColour = cs.findColour(seq.getSequence(i, i + 1), i);
\r
73 else if(forOverview && !jalview.util.Comparison.isGap(seq.getCharAt(i)))
\r
75 resBoxColour = Color.lightGray;
\r
79 resBoxColour = Color.white;
\r
84 public Color findSequenceColour(SequenceI seq, int i)
\r
86 allGroups = av.alignment.findAllGroups(seq);
\r
87 drawBoxes(seq, i,i, 0);
\r
88 return resBoxColour;
\r
91 public void drawSequence(Graphics g, SequenceI seq, SequenceGroup[] sg,
\r
92 int start, int end, int y1)
\r
98 drawBoxes(seq, start, end, y1);
\r
100 fm = g.getFontMetrics();
\r
101 drawText(seq, start, end, y1);
\r
105 public void drawBoxes(SequenceI seq, int start, int end, int y1)
\r
108 int length = seq.getLength();
\r
111 int curWidth = av.charWidth;
\r
113 Color tempColour = null;
\r
116 resBoxColour = Color.white;
\r
119 if (inCurrentSequenceGroup(i))
\r
121 if (currentSequenceGroup.getDisplayBoxes())
\r
123 getBoxColour(currentSequenceGroup.cs, seq, i);
\r
126 else if (av.getShowBoxes())
\r
128 getBoxColour(av.getGlobalColourScheme(), seq, i);
\r
133 if (resBoxColour != tempColour)
\r
135 if (tempColour != null)
\r
137 graphics.fillRect(av.charWidth * (curStart - start), y1, curWidth,
\r
140 graphics.setColor(resBoxColour);
\r
143 curWidth = av.charWidth;
\r
144 tempColour = resBoxColour;
\r
149 curWidth += av.charWidth;
\r
155 graphics.fillRect(av.charWidth * (curStart - start), y1, curWidth, av.charHeight);
\r
158 public void drawText(SequenceI seq, int start, int end, int y1)
\r
161 y1 += av.charHeight - av.charHeight / 5; // height/5 replaces pady
\r
163 int charOffset = 0;
\r
165 // Need to find the sequence position here.
\r
166 if(end+1>=seq.getLength())
\r
167 end = seq.getLength()-1;
\r
171 for (int i = start; i <= end; i++)
\r
173 graphics.setColor(Color.black);
\r
175 s = seq.getCharAt(i);
\r
176 if (!renderGaps && jalview.util.Comparison.isGap(s))
\r
181 if (inCurrentSequenceGroup(i))
\r
183 if (!currentSequenceGroup.getDisplayText())
\r
188 if (currentSequenceGroup.getColourText())
\r
190 getBoxColour(currentSequenceGroup.cs, seq, i);
\r
191 graphics.setColor(resBoxColour.darker());
\r
196 if (!av.getShowText())
\r
201 if (av.getColourText())
\r
203 getBoxColour(av.getGlobalColourScheme(), seq, i);
\r
204 if (av.getShowBoxes())
\r
206 graphics.setColor(resBoxColour.darker());
\r
210 graphics.setColor(resBoxColour);
\r
215 charOffset = (av.charWidth - fm.charWidth(s)) / 2;
\r
216 graphics.drawString(String.valueOf(s),
\r
217 charOffset + av.charWidth * (i - start),
\r
223 boolean inCurrentSequenceGroup(int res)
\r
225 if (allGroups == null)
\r
230 for (int i = 0; i < allGroups.length; i++)
\r
232 if (allGroups[i].getStartRes() <= res && allGroups[i].getEndRes() >= res)
\r
234 currentSequenceGroup = allGroups[i];
\r
242 public void drawHighlightedText(SequenceI seq, int start, int end, int x1,
\r
243 int y1, int width, int height)
\r
245 int pady = height / 5;
\r
246 int charOffset = 0;
\r
247 graphics.setColor(Color.black);
\r
248 graphics.fillRect(x1, y1, width * (end - start + 1), height);
\r
249 graphics.setColor(Color.white);
\r
252 // Need to find the sequence position here.
\r
253 for (int i = start; i <= end; i++)
\r
255 if (i < seq.getLength())
\r
257 s = seq.getSequence().charAt(i);
\r
260 charOffset = (width - fm.charWidth(s)) / 2;
\r
261 graphics.drawString(String.valueOf(s),
\r
262 charOffset + x1 + width * (i - start),
\r
263 y1 + height - pady);
\r
267 public void drawCursor(SequenceI seq, int res, int x1, int y1)
\r
269 int pady = av.charHeight / 5;
\r
270 int charOffset = 0;
\r
271 graphics.setColor(Color.black);
\r
272 graphics.fillRect(x1, y1, av.charWidth, av.charHeight);
\r
273 graphics.setColor(Color.white);
\r
275 graphics.setColor(Color.white);
\r
277 char s = seq.getCharAt(res);
\r
279 charOffset = (av.charWidth - fm.charWidth(s)) / 2;
\r
280 graphics.drawString(String.valueOf(s),
\r
282 (y1 + av.charHeight) - pady);
\r