2 * Jalview - A Sequence Alignment Editor and Viewer
\r
3 * Copyright (C) 2006 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
46 * @param b DOCUMENT ME!
\r
48 public void prepare(Graphics g, boolean renderGaps)
\r
51 fm = g.getFontMetrics();
\r
53 this.renderGaps = renderGaps;
\r
56 public Color getResidueBoxColour(SequenceI seq, int i)
\r
58 allGroups = av.alignment.findAllGroups(seq);
\r
60 if (inCurrentSequenceGroup(i))
\r
62 if (currentSequenceGroup.getDisplayBoxes())
\r
64 getBoxColour(currentSequenceGroup.cs, seq, i);
\r
67 else if (av.getShowBoxes())
\r
69 getBoxColour(av.globalColourScheme, seq, i);
\r
72 return resBoxColour;
\r
75 void getBoxColour(ColourSchemeI cs, SequenceI seq, int i)
\r
79 resBoxColour = cs.findColour(seq.getCharAt(i), i);
\r
81 else if(forOverview && !jalview.util.Comparison.isGap(seq.getCharAt(i)))
\r
83 resBoxColour = Color.lightGray;
\r
87 resBoxColour = Color.white;
\r
92 public Color findSequenceColour(SequenceI seq, int i)
\r
94 allGroups = av.alignment.findAllGroups(seq);
\r
95 drawBoxes(seq, i,i, 0);
\r
96 return resBoxColour;
\r
99 public void drawSequence(SequenceI seq, SequenceGroup[] sg,
\r
100 int start, int end, int y1)
\r
107 drawBoxes(seq, start, end, y1);
\r
109 if(av.validCharWidth)
\r
111 drawText(seq, start, end, y1);
\r
115 public void drawBoxes(SequenceI seq, int start, int end, int y1)
\r
118 int length = seq.getLength();
\r
121 int curWidth = av.charWidth;
\r
123 Color tempColour = null;
\r
126 resBoxColour = Color.white;
\r
129 if (inCurrentSequenceGroup(i))
\r
131 if (currentSequenceGroup.getDisplayBoxes())
\r
133 getBoxColour(currentSequenceGroup.cs, seq, i);
\r
136 else if (av.getShowBoxes())
\r
138 getBoxColour(av.getGlobalColourScheme(), seq, i);
\r
143 if (resBoxColour != tempColour)
\r
145 if (tempColour != null)
\r
147 graphics.fillRect(av.charWidth * (curStart - start), y1, curWidth,
\r
150 graphics.setColor(resBoxColour);
\r
153 curWidth = av.charWidth;
\r
154 tempColour = resBoxColour;
\r
159 curWidth += av.charWidth;
\r
165 graphics.fillRect(av.charWidth * (curStart - start), y1, curWidth, av.charHeight);
\r
168 public void drawText(SequenceI seq, int start, int end, int y1)
\r
170 Font boldFont = null;
\r
171 boolean bold = false;
\r
172 if(av.upperCasebold)
\r
174 boldFont = new Font(av.getFont().getName(), Font.BOLD, av.charHeight);
\r
176 graphics.setFont(av.getFont());
\r
179 y1 += av.charHeight - av.charHeight / 5; // height/5 replaces pady
\r
181 int charOffset = 0;
\r
183 // Need to find the sequence position here.
\r
184 if(end+1>=seq.getLength())
\r
185 end = seq.getLength()-1;
\r
189 for (int i = start; i <= end; i++)
\r
191 graphics.setColor(Color.black);
\r
193 s = seq.getCharAt(i);
\r
194 if (!renderGaps && jalview.util.Comparison.isGap(s))
\r
199 if (inCurrentSequenceGroup(i))
\r
201 if (!currentSequenceGroup.getDisplayText())
\r
206 if (currentSequenceGroup.getColourText())
\r
208 getBoxColour(currentSequenceGroup.cs, seq, i);
\r
209 graphics.setColor(resBoxColour.darker());
\r
214 if (!av.getShowText())
\r
219 if (av.getColourText())
\r
221 getBoxColour(av.getGlobalColourScheme(), seq, i);
\r
222 if (av.getShowBoxes())
\r
224 graphics.setColor(resBoxColour.darker());
\r
228 graphics.setColor(resBoxColour);
\r
233 if (av.upperCasebold)
\r
235 fm = graphics.getFontMetrics();
\r
236 if ('A' <= s && s <= 'Z')
\r
241 graphics.setFont(boldFont);
\r
247 graphics.setFont(av.font);
\r
253 charOffset = (av.charWidth - fm.charWidth(s)) / 2;
\r
254 graphics.drawString(String.valueOf(s),
\r
255 charOffset + av.charWidth * (i - start),
\r
261 boolean inCurrentSequenceGroup(int res)
\r
263 if (allGroups == null)
\r
268 for (int i = 0; i < allGroups.length; i++)
\r
270 if (allGroups[i].getStartRes() <= res && allGroups[i].getEndRes() >= res)
\r
272 currentSequenceGroup = allGroups[i];
\r
280 public void drawHighlightedText(SequenceI seq, int start, int end, int x1, int y1)
\r
282 int pady = av.charHeight / 5;
\r
283 int charOffset = 0;
\r
284 graphics.setColor(Color.black);
\r
285 graphics.fillRect(x1, y1, av.charWidth * (end - start + 1), av.charHeight);
\r
286 graphics.setColor(Color.white);
\r
289 // Need to find the sequence position here.
\r
290 if(av.validCharWidth)
\r
292 for (int i = start; i <= end; i++)
\r
294 if (i < seq.getLength())
\r
296 s = seq.getCharAt(i);
\r
299 charOffset = (av.charWidth - fm.charWidth(s)) / 2;
\r
300 graphics.drawString(String.valueOf(s),
\r
301 charOffset + x1 + av.charWidth * (i - start),
\r
302 y1 + av.charHeight - pady);
\r
307 public void drawCursor(SequenceI seq, int res, int x1, int y1)
\r
309 int pady = av.charHeight / 5;
\r
310 int charOffset = 0;
\r
311 graphics.setColor(Color.black);
\r
312 graphics.fillRect(x1, y1, av.charWidth, av.charHeight);
\r
313 graphics.setColor(Color.white);
\r
315 graphics.setColor(Color.white);
\r
317 char s = seq.getCharAt(res);
\r
318 if (av.validCharWidth)
\r
321 charOffset = (av.charWidth - fm.charWidth(s)) / 2;
\r
322 graphics.drawString(String.valueOf(s),
\r
324 (y1 + av.charHeight) - pady);
\r