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(SequenceI seq, int i)
\r
49 allGroups = av.alignment.findAllGroups(seq);
\r
51 if (inCurrentSequenceGroup(i))
\r
53 if (currentSequenceGroup.getDisplayBoxes())
\r
55 getBoxColour(currentSequenceGroup.cs, seq, i);
\r
58 else if (av.getShowBoxes())
\r
60 getBoxColour(av.globalColourScheme, seq, i);
\r
63 return resBoxColour;
\r
66 void getBoxColour(ColourSchemeI cs, SequenceI seq, int i)
\r
70 resBoxColour = cs.findColour(seq.getSequence(i, i + 1), i);
\r
74 resBoxColour = Color.white;
\r
78 public Color findSequenceColour(SequenceI seq, int i)
\r
80 allGroups = av.alignment.findAllGroups(seq);
\r
81 drawBoxes(seq, i,i, 0, 0, 1,1);
\r
82 return resBoxColour;
\r
85 public void drawSequence(Graphics g, SequenceI seq, SequenceGroup[] sg,
\r
86 int start, int end, int x1, int y1, int width,
\r
93 drawBoxes(seq, start, end, x1, y1, (int) width, height);
\r
95 fm = g.getFontMetrics();
\r
96 drawText(seq, start, end, x1, y1, (int) width, height);
\r
100 public void drawBoxes(SequenceI seq, int start, int end, int x1, int y1,
\r
101 int width, int height)
\r
104 int length = seq.getLength();
\r
107 int curWidth = width;
\r
109 Color tempColour = null;
\r
112 resBoxColour = Color.white;
\r
115 if (inCurrentSequenceGroup(i))
\r
117 if (currentSequenceGroup.getDisplayBoxes())
\r
119 getBoxColour(currentSequenceGroup.cs, seq, i);
\r
122 else if (av.getShowBoxes())
\r
124 getBoxColour(av.getGlobalColourScheme(), seq, i);
\r
129 if (resBoxColour != tempColour)
\r
131 if (tempColour != null)
\r
133 graphics.fillRect(x1 + width * (curStart - start), y1, curWidth,
\r
136 graphics.setColor(resBoxColour);
\r
140 tempColour = resBoxColour;
\r
151 graphics.fillRect(x1 + width * (curStart - start), y1, curWidth, height);
\r
154 public void drawText(SequenceI seq, int start, int end, int x1, int y1,
\r
155 int width, int height)
\r
158 y1 += height - height / 5; // height/5 replaces pady
\r
160 int charOffset = 0;
\r
162 // Need to find the sequence position here.
\r
163 if(end+1>=seq.getLength())
\r
164 end = seq.getLength()-1;
\r
168 for (int i = start; i <= end; i++)
\r
170 graphics.setColor(Color.black);
\r
172 s = seq.getCharAt(i);
\r
173 if (!renderGaps && jalview.util.Comparison.isGap(s))
\r
178 if (inCurrentSequenceGroup(i))
\r
180 if (!currentSequenceGroup.getDisplayText())
\r
185 if (currentSequenceGroup.getColourText())
\r
187 getBoxColour(currentSequenceGroup.cs, seq, i);
\r
188 graphics.setColor(resBoxColour.darker());
\r
193 if (!av.getShowText())
\r
198 if (av.getColourText())
\r
200 getBoxColour(av.getGlobalColourScheme(), seq, i);
\r
201 if (av.getShowBoxes())
\r
203 graphics.setColor(resBoxColour.darker());
\r
207 graphics.setColor(resBoxColour);
\r
212 charOffset = (width - fm.charWidth(s)) / 2;
\r
213 graphics.drawString(String.valueOf(s),
\r
214 charOffset + x1 + width * (i - start),
\r
220 boolean inCurrentSequenceGroup(int res)
\r
222 if (allGroups == null)
\r
227 for (int i = 0; i < allGroups.length; i++)
\r
229 if (allGroups[i].getStartRes() <= res && allGroups[i].getEndRes() >= res)
\r
231 currentSequenceGroup = allGroups[i];
\r
239 public void drawHighlightedText(SequenceI seq, int start, int end, int x1,
\r
240 int y1, int width, int height)
\r
242 int pady = height / 5;
\r
243 int charOffset = 0;
\r
244 graphics.setColor(Color.black);
\r
245 graphics.fillRect(x1, y1, width * (end - start + 1), height);
\r
246 graphics.setColor(Color.white);
\r
249 // Need to find the sequence position here.
\r
250 for (int i = start; i <= end; i++)
\r
252 if (i < seq.getLength())
\r
254 s = seq.getSequence().charAt(i);
\r
257 charOffset = (width - fm.charWidth(s)) / 2;
\r
258 graphics.drawString(String.valueOf(s),
\r
259 charOffset + x1 + width * (i - start),
\r
260 y1 + height - pady);
\r