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
23 import jalview.datamodel.*;
\r
24 import jalview.schemes.*;
\r
26 public class SequenceRenderer
\r
30 boolean renderGaps = true;
\r
31 SequenceGroup currentSequenceGroup = null;
\r
32 SequenceGroup[] allGroups = null;
\r
36 public SequenceRenderer(AlignViewport av)
\r
41 public void renderGaps(boolean b)
\r
46 public Color getResidueBoxColour(ColourSchemeI cs, SequenceI seq, int i)
\r
48 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
65 public void drawSequence(Graphics g, SequenceI seq, SequenceGroup[] sg,
\r
66 int start, int end, int x1, int y1, int width,
\r
73 drawBoxes(seq, start, end, x1, y1, (int) width, height);
\r
75 fm = g.getFontMetrics();
\r
76 drawText(seq, start, end, x1, y1, (int) width, height);
\r
79 public void drawBoxes(SequenceI seq, int start, int end, int x1, int y1,
\r
80 int width, int height)
\r
83 int length = seq.getLength();
\r
86 int curWidth = width;
\r
88 Color tempColour = null;
\r
90 while ( (i <= end) && (i < length))
\r
92 if (inCurrentSequenceGroup(i))
\r
94 if (currentSequenceGroup.getDisplayBoxes())
\r
96 getBoxColour(currentSequenceGroup.cs, seq, i);
\r
100 resBoxColour = Color.white;
\r
103 else if (av.getShowBoxes())
\r
105 getBoxColour(av.getGlobalColourScheme(), seq, i);
\r
109 resBoxColour = Color.white;
\r
112 if (resBoxColour != tempColour)
\r
114 if (tempColour != null)
\r
116 graphics.fillRect(x1 + (width * (curStart - start)), y1,
\r
120 graphics.setColor(resBoxColour);
\r
124 tempColour = resBoxColour;
\r
134 graphics.fillRect(x1 + (width * (curStart - start)), y1, curWidth,
\r
138 public void drawText(SequenceI seq, int start, int end, int x1, int y1,
\r
139 int width, int height)
\r
141 int pady = height / 5;
\r
142 int charOffset = 0;
\r
145 // Need to find the sequence position here.
\r
146 String sequence = seq.getSequence();
\r
148 for (int i = start; i <= end; i++)
\r
150 graphics.setColor(Color.black);
\r
152 if (i < sequence.length())
\r
154 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
190 if (av.getShowBoxes())
\r
192 graphics.setColor(resBoxColour.darker());
\r
196 graphics.setColor(resBoxColour);
\r
201 charOffset = (width - fm.charWidth(s)) / 2;
\r
202 graphics.drawString(String.valueOf(s),
\r
203 charOffset + x1 + (width * (i - start)),
\r
204 (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) &&
\r
218 (allGroups[i].getEndRes() >= res))
\r
220 currentSequenceGroup = allGroups[i];
\r
229 public void drawHighlightedText(SequenceI seq, int start, int end, int x1,
\r
230 int y1, int width, int height)
\r
232 int pady = height / 5;
\r
233 int charOffset = 0;
\r
234 graphics.setColor(Color.BLACK);
\r
235 graphics.fillRect(x1, y1, width * (end - start + 1), height);
\r
236 graphics.setColor(Color.white);
\r
240 // Need to find the sequence position here.
\r
241 for (int i = start; i <= end; i++)
\r
243 if (i < seq.getLength())
\r
245 s = seq.getSequence().charAt(i);
\r
248 charOffset = (width - fm.charWidth(s)) / 2;
\r
249 graphics.drawString(String.valueOf(s),
\r
250 charOffset + x1 + (width * (i - start)),
\r
251 (y1 + height) - pady);
\r