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
26 import jalview.datamodel.*;
\r
28 public class FeatureRenderer
\r
32 SequenceGroup currentSequenceGroup = null;
\r
33 SequenceGroup[] allGroups = null;
\r
37 public FeatureRenderer(AlignViewport av)
\r
42 public void drawSequence(Graphics g, SequenceI seq, SequenceGroup[] sg,
\r
43 int start, int end, int x1, int y1, int width,
\r
46 Vector features = seq.getSequenceFeatures();
\r
47 Enumeration e = features.elements();
\r
48 while (e.hasMoreElements())
\r
50 SequenceFeature sf = (SequenceFeature) e.nextElement();
\r
51 if (sf.getStart() > seq.getEnd())
\r
56 int fstart = seq.findIndex(sf.getStart()) - 1;
\r
57 int fend = seq.findIndex(sf.getEnd()) - 1;
\r
59 if ( (fstart <= end && fend >= start))
\r
61 if (fstart < 0) // fix for if the feature we have starts before the sequence start,
\r
63 fstart = 0; // but the feature end is still valid!!
\r
68 g.setColor(Color.red);
\r
69 g.fillRoundRect( (fstart - start) * width, y1, width, height, 4, 4);
\r
70 g.setColor(Color.white);
\r
72 char s = seq.getSequence().charAt(fstart);
\r
73 FontMetrics fm = g.getFontMetrics();
\r
74 int charOffset = (width - fm.charWidth(s)) / 2;
\r
75 int pady = height / 5;
\r
76 g.drawString(String.valueOf(s),
\r
77 charOffset + x1 + width * (fstart - start),
\r
78 y1 + height - pady);
\r
83 for (int i = fstart; i <= fend; i++)
\r
85 char s = seq.getSequence().charAt(i);
\r
86 if (jalview.util.Comparison.isGap(s))
\r
91 g.setColor(Color.blue);
\r
92 g.fillRect( (i - start) * width, y1, width, height);
\r
94 g.setColor(Color.white);
\r
96 FontMetrics fm = g.getFontMetrics();
\r
97 int charOffset = (width - fm.charWidth(s)) / 2;
\r
98 int pady = height / 5;
\r
99 g.drawString(String.valueOf(s),
\r
100 charOffset + x1 + width * (i - start),
\r
101 y1 + height - pady);
\r