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
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.getSequence(i, i + 1), 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
104 drawBoxes(seq, start, end, y1);
\r
106 if(av.validCharWidth)
\r
108 drawText(seq, start, end, y1);
\r
112 public void drawBoxes(SequenceI seq, int start, int end, int y1)
\r
115 int length = seq.getLength();
\r
118 int curWidth = av.charWidth;
\r
120 Color tempColour = null;
\r
123 resBoxColour = Color.white;
\r
126 if (inCurrentSequenceGroup(i))
\r
128 if (currentSequenceGroup.getDisplayBoxes())
\r
130 getBoxColour(currentSequenceGroup.cs, seq, i);
\r
133 else if (av.getShowBoxes())
\r
135 getBoxColour(av.getGlobalColourScheme(), seq, i);
\r
140 if (resBoxColour != tempColour)
\r
142 if (tempColour != null)
\r
144 graphics.fillRect(av.charWidth * (curStart - start), y1, curWidth,
\r
147 graphics.setColor(resBoxColour);
\r
150 curWidth = av.charWidth;
\r
151 tempColour = resBoxColour;
\r
156 curWidth += av.charWidth;
\r
162 graphics.fillRect(av.charWidth * (curStart - start), y1, curWidth, av.charHeight);
\r
165 public void drawText(SequenceI seq, int start, int end, int y1)
\r
168 y1 += av.charHeight - av.charHeight / 5; // height/5 replaces pady
\r
170 int charOffset = 0;
\r
172 // Need to find the sequence position here.
\r
173 if(end+1>=seq.getLength())
\r
174 end = seq.getLength()-1;
\r
178 for (int i = start; i <= end; i++)
\r
180 graphics.setColor(Color.black);
\r
182 s = seq.getCharAt(i);
\r
183 if (!renderGaps && jalview.util.Comparison.isGap(s))
\r
188 if (inCurrentSequenceGroup(i))
\r
190 if (!currentSequenceGroup.getDisplayText())
\r
195 if (currentSequenceGroup.getColourText())
\r
197 getBoxColour(currentSequenceGroup.cs, seq, i);
\r
198 graphics.setColor(resBoxColour.darker());
\r
203 if (!av.getShowText())
\r
208 if (av.getColourText())
\r
210 getBoxColour(av.getGlobalColourScheme(), seq, i);
\r
211 if (av.getShowBoxes())
\r
213 graphics.setColor(resBoxColour.darker());
\r
217 graphics.setColor(resBoxColour);
\r
222 charOffset = (av.charWidth - fm.charWidth(s)) / 2;
\r
223 graphics.drawString(String.valueOf(s),
\r
224 charOffset + av.charWidth * (i - start),
\r
230 boolean inCurrentSequenceGroup(int res)
\r
232 if (allGroups == null)
\r
237 for (int i = 0; i < allGroups.length; i++)
\r
239 if (allGroups[i].getStartRes() <= res && allGroups[i].getEndRes() >= res)
\r
241 currentSequenceGroup = allGroups[i];
\r
249 public void drawHighlightedText(SequenceI seq, int start, int end, int x1, int y1)
\r
251 int pady = av.charHeight / 5;
\r
252 int charOffset = 0;
\r
253 graphics.setColor(Color.black);
\r
254 graphics.fillRect(x1, y1, av.charWidth * (end - start + 1), av.charHeight);
\r
255 graphics.setColor(Color.white);
\r
258 // Need to find the sequence position here.
\r
259 if(av.validCharWidth)
\r
261 for (int i = start; i <= end; i++)
\r
263 if (i < seq.getLength())
\r
265 s = seq.getSequence().charAt(i);
\r
268 charOffset = (av.charWidth - fm.charWidth(s)) / 2;
\r
269 graphics.drawString(String.valueOf(s),
\r
270 charOffset + x1 + av.charWidth * (i - start),
\r
271 y1 + av.charHeight - pady);
\r
276 public void drawCursor(SequenceI seq, int res, int x1, int y1)
\r
278 int pady = av.charHeight / 5;
\r
279 int charOffset = 0;
\r
280 graphics.setColor(Color.black);
\r
281 graphics.fillRect(x1, y1, av.charWidth, av.charHeight);
\r
282 graphics.setColor(Color.white);
\r
284 graphics.setColor(Color.white);
\r
286 char s = seq.getCharAt(res);
\r
287 if (av.validCharWidth)
\r
290 charOffset = (av.charWidth - fm.charWidth(s)) / 2;
\r
291 graphics.drawString(String.valueOf(s),
\r
293 (y1 + av.charHeight) - pady);
\r