/* * Jalview - A Sequence Alignment Editor and Viewer * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ package jalview.gui; import jalview.datamodel.*; import java.awt.*; import java.util.*; /** * DOCUMENT ME! * * @author $author$ * @version $Revision$ */ public class FeatureRenderer { AlignViewport av; SequenceGroup currentSequenceGroup = null; SequenceGroup[] allGroups = null; Color resBoxColour; Graphics graphics; /** * Creates a new FeatureRenderer object. * * @param av DOCUMENT ME! */ public FeatureRenderer(AlignViewport av) { this.av = av; } /** * DOCUMENT ME! * * @param g DOCUMENT ME! * @param seq DOCUMENT ME! * @param sg DOCUMENT ME! * @param start DOCUMENT ME! * @param end DOCUMENT ME! * @param x1 DOCUMENT ME! * @param y1 DOCUMENT ME! * @param width DOCUMENT ME! * @param height DOCUMENT ME! */ public void drawSequence(Graphics g, SequenceI seq, SequenceGroup[] sg, int start, int end, int x1, int y1, int width, int height) { Vector features = seq.getSequenceFeatures(); Enumeration e = features.elements(); while (e.hasMoreElements()) { SequenceFeature sf = (SequenceFeature) e.nextElement(); if (sf.getStart() > seq.getEnd()) { continue; } int fstart = seq.findIndex(sf.getStart()) - 1; int fend = seq.findIndex(sf.getEnd()) - 1; if (((fstart <= end) && (fend >= start))) { if (fstart < start) { // fix for if the feature we have starts before the sequence start, fstart = start; // but the feature end is still valid!! } if (fend >= end) { fend = end; } if (fstart == fend) { g.setColor(Color.red); g.fillRoundRect((fstart - start) * width, y1, width, height, 4, 4); g.setColor(Color.white); char s = seq.getSequence().charAt(fstart); FontMetrics fm = g.getFontMetrics(); int charOffset = (width - fm.charWidth(s)) / 2; int pady = height / 5; g.drawString(String.valueOf(s), charOffset + x1 + (width * (fstart - start)), (y1 + height) - pady); } else { for (int i = fstart; i <= fend; i++) { char s = seq.getSequence().charAt(i); if (jalview.util.Comparison.isGap(s)) { continue; } g.setColor(Color.blue); g.fillRect((i - start) * width, y1, width, height); g.setColor(Color.white); FontMetrics fm = g.getFontMetrics(); int charOffset = (width - fm.charWidth(s)) / 2; int pady = height / 5; g.drawString(String.valueOf(s), charOffset + x1 + (width * (i - start)), (y1 + height) - pady); } } } } } }