X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FFeatureRenderer.java;h=8a94a895aadded33776f94672513d8ec8d7cb52e;hb=019042a9f87d94260b3060cdf45ab93ca714a46d;hp=59f446e4028e9dd9d1caefb18627575407fdf6dc;hpb=feb00a2deac901163f9d130b0ed0195b9ae73bfa;p=jalview.git diff --git a/src/jalview/gui/FeatureRenderer.java b/src/jalview/gui/FeatureRenderer.java index 59f446e..8a94a89 100755 --- a/src/jalview/gui/FeatureRenderer.java +++ b/src/jalview/gui/FeatureRenderer.java @@ -1,76 +1,137 @@ +/* + * 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 jalview.schemes.*; + import java.awt.*; + import java.util.*; -public class FeatureRenderer implements RendererI + +/** + * DOCUMENT ME! + * + * @author $author$ + * @version $Revision$ + */ +public class FeatureRenderer { - AlignViewport av; + AlignViewport av; + SequenceGroup currentSequenceGroup = null; + SequenceGroup[] allGroups = null; + Color resBoxColour; + Graphics graphics; - 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; + } - 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(); - public void drawSequence(Graphics g,SequenceI seq,SequenceGroup [] sg, int start, int end, int x1, int y1, int width, int height, Vector pid, int seqnum) - { - Vector features = seq.getSequenceFeatures(); - Enumeration e = features.elements(); - while( e.hasMoreElements() ) - { - SequenceFeature sf = (SequenceFeature)e.nextElement(); - if(sf.getStart()>seq.getEnd()) - continue; + if (sf.getStart() > seq.getEnd()) + { + continue; + } - int fstart = seq.findIndex(sf.getStart())-1; - int fend = seq.findIndex(sf.getEnd())-1; + int fstart = seq.findIndex(sf.getStart()) - 1; + int fend = seq.findIndex(sf.getEnd()) - 1; - if( (fstart<=end && fend>=start) ) - { - if(fstart<0) // fix for if the feature we have starts before the sequence start, - fstart = 0;// but the feature end is still valid!! + 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(fstart==fend) - { - g.setColor(Color.red); - g.fillRoundRect( (fstart - start) * width, y1, width, height, 4,4); - g.setColor(Color.white); + if (fend >= end) + { + fend = end; + } - 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); + if (fstart == fend) + { + g.setColor(Color.red); + g.fillRoundRect((fstart - start) * width, y1, width, + height, 4, 4); + g.setColor(Color.white); - } - else - { - for (int i = fstart; i <= fend; i++) - { - g.setColor(Color.blue); - g.fillRect( (i-start) * width, y1, width, height); - - g.setColor(Color.white); - char s = seq.getSequence().charAt(i); - 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); - } - } - } + 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); + } + } + } + } + } }