X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FFeatureRenderer.java;h=e80d01a3c039d4fce9446a3a043b4b893414afe8;hb=b14411143cbfb4d311f68b3d3b73a645bf8200e8;hp=6e38f1b9eabfb7788d78e4ecba5547283e7b7224;hpb=22be3f466cd70cb03d5eae619ede8589ae69716a;p=jalview.git diff --git a/src/jalview/gui/FeatureRenderer.java b/src/jalview/gui/FeatureRenderer.java index 6e38f1b..e80d01a 100755 --- a/src/jalview/gui/FeatureRenderer.java +++ b/src/jalview/gui/FeatureRenderer.java @@ -1,16 +1,34 @@ +/* + * 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 +import java.awt.*; + +import jalview.datamodel.*; + +public class FeatureRenderer { AlignViewport av; - SequenceGroup currentSequenceGroup = null; - SequenceGroup [] allGroups = null; + SequenceGroup[] allGroups = null; Color resBoxColour; Graphics graphics; @@ -19,53 +37,72 @@ public class FeatureRenderer implements RendererI this.av = av; } - - 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) + 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() ) + + while (e.hasMoreElements()) { - SequenceFeature sf = (SequenceFeature)e.nextElement(); - int fstart = seq.findIndex(sf.getStart())-1; - int fend = seq.findIndex(sf.getEnd())-1; + 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>=start&&fstart<=end) || (fend>=start&&fend<=end)) + if ( ( (fstart <= end) && (fend >= start))) { - if(fstart==fend) + 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 == fend) { g.setColor(Color.red); - g.fillRoundRect( (fstart - start) * width, y1, width, height, 4,4); + 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); - + 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.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); - + charOffset + x1 + (width * (i - start)), + (y1 + height) - pady); } } } - } - } - + } }