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
19 package jalview.gui;
\r
21 import jalview.datamodel.*;
\r
23 import jalview.schemes.*;
\r
32 * @version $Revision$
\r
34 public class SequenceRenderer
\r
38 boolean renderGaps = true;
\r
39 SequenceGroup currentSequenceGroup = null;
\r
40 SequenceGroup[] allGroups = null;
\r
45 * Creates a new SequenceRenderer object.
\r
47 * @param av DOCUMENT ME!
\r
49 public SequenceRenderer(AlignViewport av)
\r
57 * @param b DOCUMENT ME!
\r
59 public void renderGaps(boolean b)
\r
67 * @param cs DOCUMENT ME!
\r
68 * @param seq DOCUMENT ME!
\r
69 * @param i DOCUMENT ME!
\r
71 * @return DOCUMENT ME!
\r
73 public Color getResidueBoxColour(ColourSchemeI cs, SequenceI seq, int i)
\r
75 getBoxColour(cs, seq, i);
\r
77 return resBoxColour;
\r
83 * @param cs DOCUMENT ME!
\r
84 * @param seq DOCUMENT ME!
\r
85 * @param i DOCUMENT ME!
\r
87 void getBoxColour(ColourSchemeI cs, SequenceI seq, int i)
\r
91 resBoxColour = cs.findColour(seq.getSequence(i, i + 1), i);
\r
95 resBoxColour = Color.white;
\r
102 * @param g DOCUMENT ME!
\r
103 * @param seq DOCUMENT ME!
\r
104 * @param sg DOCUMENT ME!
\r
105 * @param start DOCUMENT ME!
\r
106 * @param end DOCUMENT ME!
\r
107 * @param x1 DOCUMENT ME!
\r
108 * @param y1 DOCUMENT ME!
\r
109 * @param width DOCUMENT ME!
\r
110 * @param height DOCUMENT ME!
\r
112 public void drawSequence(Graphics g, SequenceI seq, SequenceGroup[] sg,
\r
113 int start, int end, int x1, int y1, int width, int height)
\r
119 drawBoxes(seq, start, end, x1, y1, (int) width, height);
\r
121 fm = g.getFontMetrics();
\r
122 drawText(seq, start, end, x1, y1, (int) width, height);
\r
128 * @param seq DOCUMENT ME!
\r
129 * @param start DOCUMENT ME!
\r
130 * @param end DOCUMENT ME!
\r
131 * @param x1 DOCUMENT ME!
\r
132 * @param y1 DOCUMENT ME!
\r
133 * @param width DOCUMENT ME!
\r
134 * @param height DOCUMENT ME!
\r
136 public void drawBoxes(SequenceI seq, int start, int end, int x1, int y1,
\r
137 int width, int height)
\r
140 int length = seq.getLength();
\r
143 int curWidth = width;
\r
145 Color tempColour = null;
\r
147 while ((i <= end) && (i < length))
\r
149 if (inCurrentSequenceGroup(i))
\r
151 if (currentSequenceGroup.getDisplayBoxes())
\r
153 getBoxColour(currentSequenceGroup.cs, seq, i);
\r
157 resBoxColour = Color.white;
\r
160 else if (av.getShowBoxes())
\r
162 getBoxColour(av.getGlobalColourScheme(), seq, i);
\r
166 resBoxColour = Color.white;
\r
169 if (resBoxColour != tempColour)
\r
171 if (tempColour != null)
\r
173 graphics.fillRect(x1 + (width * (curStart - start)), y1,
\r
177 graphics.setColor(resBoxColour);
\r
181 tempColour = resBoxColour;
\r
191 graphics.fillRect(x1 + (width * (curStart - start)), y1, curWidth,
\r
198 * @param seq DOCUMENT ME!
\r
199 * @param start DOCUMENT ME!
\r
200 * @param end DOCUMENT ME!
\r
201 * @param x1 DOCUMENT ME!
\r
202 * @param y1 DOCUMENT ME!
\r
203 * @param width DOCUMENT ME!
\r
204 * @param height DOCUMENT ME!
\r
206 public void drawText(SequenceI seq, int start, int end, int x1, int y1,
\r
207 int width, int height)
\r
209 int pady = height / 5;
\r
210 int charOffset = 0;
\r
213 // Need to find the sequence position here.
\r
214 String sequence = seq.getSequence();
\r
216 for (int i = start; i <= end; i++)
\r
218 graphics.setColor(Color.black);
\r
220 if (i < sequence.length())
\r
222 s = sequence.charAt(i);
\r
229 if (!renderGaps && jalview.util.Comparison.isGap(s))
\r
234 if (inCurrentSequenceGroup(i))
\r
236 if (!currentSequenceGroup.getDisplayText())
\r
241 if (currentSequenceGroup.getColourText())
\r
243 getBoxColour(currentSequenceGroup.cs, seq, i);
\r
244 graphics.setColor(resBoxColour.darker());
\r
249 if (!av.getShowText())
\r
254 if (av.getColourText())
\r
256 getBoxColour(av.getGlobalColourScheme(), seq, i);
\r
258 if (av.getShowBoxes())
\r
260 graphics.setColor(resBoxColour.darker());
\r
264 graphics.setColor(resBoxColour);
\r
269 charOffset = (width - fm.charWidth(s)) / 2;
\r
270 graphics.drawString(String.valueOf(s),
\r
271 charOffset + x1 + (width * (i - start)), (y1 + height) - pady);
\r
278 * @param res DOCUMENT ME!
\r
280 * @return DOCUMENT ME!
\r
282 boolean inCurrentSequenceGroup(int res)
\r
284 if (allGroups == null)
\r
289 for (int i = 0; i < allGroups.length; i++)
\r
291 if ((allGroups[i].getStartRes() <= res) &&
\r
292 (allGroups[i].getEndRes() >= res))
\r
294 currentSequenceGroup = allGroups[i];
\r
306 * @param seq DOCUMENT ME!
\r
307 * @param start DOCUMENT ME!
\r
308 * @param end DOCUMENT ME!
\r
309 * @param x1 DOCUMENT ME!
\r
310 * @param y1 DOCUMENT ME!
\r
311 * @param width DOCUMENT ME!
\r
312 * @param height DOCUMENT ME!
\r
314 public void drawHighlightedText(SequenceI seq, int start, int end, int x1,
\r
315 int y1, int width, int height)
\r
317 int pady = height / 5;
\r
318 int charOffset = 0;
\r
319 graphics.setColor(Color.BLACK);
\r
320 graphics.fillRect(x1, y1, width * (end - start + 1), height);
\r
321 graphics.setColor(Color.white);
\r
325 // Need to find the sequence position here.
\r
326 for (int i = start; i <= end; i++)
\r
328 if (i < seq.getLength())
\r
330 s = seq.getSequence().charAt(i);
\r
333 charOffset = (width - fm.charWidth(s)) / 2;
\r
334 graphics.drawString(String.valueOf(s),
\r
335 charOffset + x1 + (width * (i - start)), (y1 + height) - pady);
\r