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
37 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
57 resBoxColour = cs.findColour(seq.getSequence(i, i + 1), i);
\r
61 resBoxColour = Color.white;
\r
66 public Color findSequenceColour(SequenceI seq, int i)
\r
68 allGroups = av.alignment.findAllGroups(seq);
\r
69 drawBoxes(seq, i,i, 0, 0, 1,1);
\r
70 return resBoxColour;
\r
73 public void drawSequence(Graphics g, SequenceI seq, SequenceGroup[] sg,
\r
74 int start, int end, int x1, int y1, int width,
\r
81 drawBoxes(seq, start, end, x1, y1, (int) width, height);
\r
83 fm = g.getFontMetrics();
\r
84 drawText(seq, start, end, x1, y1, (int) width, height);
\r
88 public void drawBoxes(SequenceI seq, int start, int end, int x1, int y1,
\r
89 int width, int height)
\r
92 int length = seq.getLength();
\r
95 int curWidth = width;
\r
97 Color tempColour = null;
\r
100 resBoxColour = Color.white;
\r
103 if (inCurrentSequenceGroup(i))
\r
105 if (currentSequenceGroup.getDisplayBoxes())
\r
107 getBoxColour(currentSequenceGroup.cs, seq, i);
\r
110 else if (av.getShowBoxes())
\r
112 getBoxColour(av.getGlobalColourScheme(), seq, i);
\r
117 if (resBoxColour != tempColour)
\r
119 if (tempColour != null)
\r
121 graphics.fillRect(x1 + width * (curStart - start), y1, curWidth,
\r
124 graphics.setColor(resBoxColour);
\r
128 tempColour = resBoxColour;
\r
139 graphics.fillRect(x1 + width * (curStart - start), y1, curWidth, height);
\r
142 public void drawText(SequenceI seq, int start, int end, int x1, int y1,
\r
143 int width, int height)
\r
145 int pady = height / 5;
\r
146 int charOffset = 0;
\r
148 // Need to find the sequence position here.
\r
150 String sequence = seq.getSequence();
\r
152 if(end+1>=seq.getLength())
\r
153 end = seq.getLength()-1;
\r
155 for (int i = start; i <= end; i++)
\r
157 graphics.setColor(Color.black);
\r
159 s = sequence.charAt(i);
\r
161 if (!renderGaps && jalview.util.Comparison.isGap(s))
\r
166 if (inCurrentSequenceGroup(i))
\r
168 if (!currentSequenceGroup.getDisplayText())
\r
173 if (currentSequenceGroup.getColourText())
\r
175 getBoxColour(currentSequenceGroup.cs, seq, i);
\r
176 graphics.setColor(resBoxColour.darker());
\r
181 if (!av.getShowText())
\r
186 if (av.getColourText())
\r
188 getBoxColour(av.getGlobalColourScheme(), seq, i);
\r
189 if (av.getShowBoxes())
\r
191 graphics.setColor(resBoxColour.darker());
\r
195 graphics.setColor(resBoxColour);
\r
200 charOffset = (width - fm.charWidth(s)) / 2;
\r
201 graphics.drawString(String.valueOf(s),
\r
202 charOffset + x1 + width * (i - start),
\r
203 y1 + height - pady);
\r
208 boolean inCurrentSequenceGroup(int res)
\r
210 if (allGroups == null)
\r
215 for (int i = 0; i < allGroups.length; i++)
\r
217 if (allGroups[i].getStartRes() <= res && allGroups[i].getEndRes() >= res)
\r
219 currentSequenceGroup = allGroups[i];
\r
227 public void drawHighlightedText(SequenceI seq, int start, int end, int x1,
\r
228 int y1, int width, int height)
\r
230 int pady = height / 5;
\r
231 int charOffset = 0;
\r
232 graphics.setColor(Color.black);
\r
233 graphics.fillRect(x1, y1, width * (end - start + 1), height);
\r
234 graphics.setColor(Color.white);
\r
237 // Need to find the sequence position here.
\r
238 for (int i = start; i <= end; i++)
\r
240 if (i < seq.getLength())
\r
242 s = seq.getSequence().charAt(i);
\r
245 charOffset = (width - fm.charWidth(s)) / 2;
\r
246 graphics.drawString(String.valueOf(s),
\r
247 charOffset + x1 + width * (i - start),
\r
248 y1 + height - pady);
\r