X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FSequenceRenderer.java;h=e36160a939d13b843aa20a86dbad19a2116a7115;hb=04651a0a92ea1b6d9ce590a77ade2b90f446d949;hp=6168a56d38ec8aa5982253eda9479af2cb4dbcd6;hpb=c09fde7723756df2217a86fde16f10e0684dd206;p=jalview.git diff --git a/src/jalview/gui/SequenceRenderer.java b/src/jalview/gui/SequenceRenderer.java index 6168a56..e36160a 100755 --- a/src/jalview/gui/SequenceRenderer.java +++ b/src/jalview/gui/SequenceRenderer.java @@ -1,192 +1,338 @@ +/* + * 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.*; + +/** + * DOCUMENT ME! + * + * @author $author$ + * @version $Revision$ + */ public class SequenceRenderer { - AlignViewport av; - FontMetrics fm; - boolean renderGaps = true; - SequenceGroup currentSequenceGroup = null; - SequenceGroup [] allGroups = null; - Color resBoxColour; - Graphics graphics; - - public SequenceRenderer(AlignViewport av) - { - this.av = av; - } - - - public void renderGaps(boolean b) - { - renderGaps = b; - } - - public Color getResidueBoxColour(ColourSchemeI cs, SequenceI seq, int i) - { - getBoxColour(cs, seq, i); - return resBoxColour; - } + AlignViewport av; + FontMetrics fm; + boolean renderGaps = true; + SequenceGroup currentSequenceGroup = null; + SequenceGroup[] allGroups = null; + Color resBoxColour; + Graphics graphics; + + /** + * Creates a new SequenceRenderer object. + * + * @param av DOCUMENT ME! + */ + public SequenceRenderer(AlignViewport av) + { + this.av = av; + } - void getBoxColour(ColourSchemeI cs, SequenceI seq, int i) - { - if (cs != null) - resBoxColour = cs.findColour(seq.getSequence(i, i + 1), i); - else - resBoxColour = Color.white; - } + /** + * DOCUMENT ME! + * + * @param b DOCUMENT ME! + */ + public void renderGaps(boolean b) + { + renderGaps = b; + } - public void drawSequence(Graphics g,SequenceI seq,SequenceGroup [] sg, int start, int end, int x1, int y1, int width, int height) - { - allGroups = sg; + /** + * DOCUMENT ME! + * + * @param cs DOCUMENT ME! + * @param seq DOCUMENT ME! + * @param i DOCUMENT ME! + * + * @return DOCUMENT ME! + */ + public Color getResidueBoxColour(ColourSchemeI cs, SequenceI seq, int i) + { + getBoxColour(cs, seq, i); - graphics = g; + return resBoxColour; + } - drawBoxes(seq, start, end, x1, y1, (int) width, height); + /** + * DOCUMENT ME! + * + * @param cs DOCUMENT ME! + * @param seq DOCUMENT ME! + * @param i DOCUMENT ME! + */ + void getBoxColour(ColourSchemeI cs, SequenceI seq, int i) + { + if (cs != null) + { + resBoxColour = cs.findColour(seq.getSequence(i, i + 1), i); + } + else + { + resBoxColour = Color.white; + } + } - fm = g.getFontMetrics(); - drawText(seq,start,end,x1,y1,(int)width,height); + /** + * 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) + { + allGroups = sg; - } + graphics = g; - public void drawBoxes(SequenceI seq,int start, int end, int x1, int y1, int width, int height) { - int i = start; - int length = seq.getLength(); + drawBoxes(seq, start, end, x1, y1, (int) width, height); - int curStart = -1; - int curWidth = width; + fm = g.getFontMetrics(); + drawText(seq, start, end, x1, y1, (int) width, height); + } - Color tempColour = null; - while (i <= end && i < length) + /** + * DOCUMENT ME! + * + * @param seq 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 drawBoxes(SequenceI seq, int start, int end, int x1, int y1, + int width, int height) { - if(inCurrentSequenceGroup(i)) - { - if( currentSequenceGroup.getDisplayBoxes()) - getBoxColour(currentSequenceGroup.cs, seq, i); - else - resBoxColour = Color.white; - } - else if(av.getShowBoxes()) - getBoxColour(av.getGlobalColourScheme(), seq, i); - else - resBoxColour = Color.white; + int i = start; + int length = seq.getLength(); + int curStart = -1; + int curWidth = width; - if (resBoxColour != tempColour) - { - if(tempColour!=null) - graphics.fillRect(x1+width*(curStart-start),y1,curWidth,height); - graphics.setColor(resBoxColour); + Color tempColour = null; - curStart = i; - curWidth = width; - tempColour = resBoxColour; - - } - else - curWidth += width; + while ((i <= end) && (i < length)) + { + if (inCurrentSequenceGroup(i)) + { + if (currentSequenceGroup.getDisplayBoxes()) + { + getBoxColour(currentSequenceGroup.cs, seq, i); + } + else + { + resBoxColour = Color.white; + } + } + else if (av.getShowBoxes()) + { + getBoxColour(av.getGlobalColourScheme(), seq, i); + } + else + { + resBoxColour = Color.white; + } - i++; - } + if (resBoxColour != tempColour) + { + if (tempColour != null) + { + graphics.fillRect(x1 + (width * (curStart - start)), y1, + curWidth, height); + } + graphics.setColor(resBoxColour); - graphics.fillRect(x1+width*(curStart-start),y1,curWidth,height); - } + curStart = i; + curWidth = width; + tempColour = resBoxColour; + } + else + { + curWidth += width; + } - public void drawText(SequenceI seq,int start, int end, int x1, int y1, int width, int height) - { - int pady = height/5; - int charOffset=0; - char s; - // Need to find the sequence position here. + i++; + } + graphics.fillRect(x1 + (width * (curStart - start)), y1, curWidth, + height); + } - String sequence = seq.getSequence(); - for (int i = start; i <= end; i++) + /** + * DOCUMENT ME! + * + * @param seq 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 drawText(SequenceI seq, int start, int end, int x1, int y1, + int width, int height) { - if(i=res) - { - currentSequenceGroup = allGroups[i]; - return true; - } + for (int i = 0; i < allGroups.length; i++) + { + if ((allGroups[i].getStartRes() <= res) && + (allGroups[i].getEndRes() >= res)) + { + currentSequenceGroup = allGroups[i]; - return false; - } + return true; + } + } - public void drawHighlightedText(SequenceI seq,int start, int end, int x1, int y1, int width, int height) - { - int pady = height/5; - int charOffset=0; - graphics.setColor(Color.BLACK); - graphics.fillRect(x1,y1,width*(end-start+1),height); - graphics.setColor(Color.white); + return false; + } - char s='~'; - // Need to find the sequence position here. - for (int i = start; i <= end; i++) + /** + * DOCUMENT ME! + * + * @param seq 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 drawHighlightedText(SequenceI seq, int start, int end, int x1, + int y1, int width, int height) { - if(i