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
32 * @version $Revision$
\r
34 public class FeatureRenderer
\r
37 SequenceGroup currentSequenceGroup = null;
\r
38 SequenceGroup[] allGroups = null;
\r
43 * Creates a new FeatureRenderer object.
\r
45 * @param av DOCUMENT ME!
\r
47 public FeatureRenderer(AlignViewport av)
\r
55 * @param g DOCUMENT ME!
\r
56 * @param seq DOCUMENT ME!
\r
57 * @param sg DOCUMENT ME!
\r
58 * @param start DOCUMENT ME!
\r
59 * @param end DOCUMENT ME!
\r
60 * @param x1 DOCUMENT ME!
\r
61 * @param y1 DOCUMENT ME!
\r
62 * @param width DOCUMENT ME!
\r
63 * @param height DOCUMENT ME!
\r
65 public void drawSequence(Graphics g, SequenceI seq, SequenceGroup[] sg,
\r
66 int start, int end, int x1, int y1, int width, int height)
\r
68 Vector features = seq.getSequenceFeatures();
\r
69 Enumeration e = features.elements();
\r
71 while (e.hasMoreElements())
\r
73 SequenceFeature sf = (SequenceFeature) e.nextElement();
\r
75 if (sf.getStart() > seq.getEnd())
\r
80 int fstart = seq.findIndex(sf.getStart()) - 1;
\r
81 int fend = seq.findIndex(sf.getEnd()) - 1;
\r
83 if (((fstart <= end) && (fend >= start)))
\r
86 { // fix for if the feature we have starts before the sequence start,
\r
87 fstart = start; // but the feature end is still valid!!
\r
97 g.setColor(Color.red);
\r
98 g.fillRoundRect((fstart - start) * width, y1, width,
\r
100 g.setColor(Color.white);
\r
102 char s = seq.getSequence().charAt(fstart);
\r
103 FontMetrics fm = g.getFontMetrics();
\r
104 int charOffset = (width - fm.charWidth(s)) / 2;
\r
105 int pady = height / 5;
\r
106 g.drawString(String.valueOf(s),
\r
107 charOffset + x1 + (width * (fstart - start)),
\r
108 (y1 + height) - pady);
\r
112 for (int i = fstart; i <= fend; i++)
\r
114 char s = seq.getSequence().charAt(i);
\r
116 if (jalview.util.Comparison.isGap(s))
\r
121 g.setColor(Color.blue);
\r
122 g.fillRect((i - start) * width, y1, width, height);
\r
124 g.setColor(Color.white);
\r
126 FontMetrics fm = g.getFontMetrics();
\r
127 int charOffset = (width - fm.charWidth(s)) / 2;
\r
128 int pady = height / 5;
\r
129 g.drawString(String.valueOf(s),
\r
130 charOffset + x1 + (width * (i - start)),
\r
131 (y1 + height) - pady);
\r