+/*\r
+ * Jalview - A Sequence Alignment Editor and Viewer\r
+ * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
+ *\r
+ * This program is free software; you can redistribute it and/or\r
+ * modify it under the terms of the GNU General Public License\r
+ * as published by the Free Software Foundation; either version 2\r
+ * of the License, or (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA\r
+ */\r
+\r
package jalview.appletgui;\r
\r
+import java.awt.*;\r
+\r
import jalview.datamodel.*;\r
import jalview.schemes.*;\r
-import java.awt.*;\r
\r
public class SequenceRenderer\r
{\r
FontMetrics fm;\r
boolean renderGaps = true;\r
SequenceGroup currentSequenceGroup = null;\r
- SequenceGroup [] allGroups = null;\r
+ SequenceGroup[] allGroups = null;\r
Color resBoxColour;\r
Graphics graphics;\r
+ boolean forOverview = false;\r
\r
public SequenceRenderer(AlignViewport av)\r
{\r
this.av = av;\r
}\r
\r
-\r
- public void renderGaps(boolean b)\r
+ /**\r
+ * DOCUMENT ME!\r
+ *\r
+ * @param b DOCUMENT ME!\r
+ */\r
+ public void prepare(Graphics g, boolean renderGaps)\r
{\r
- renderGaps = b;\r
- }\r
+ graphics = g;\r
+ fm = g.getFontMetrics();\r
\r
- public Color getResidueBoxColour(ColourSchemeI cs, SequenceI seq, int i)\r
+ this.renderGaps = renderGaps;\r
+ }\r
+\r
+ public Color getResidueBoxColour(SequenceI seq, int i)\r
{\r
- getBoxColour(cs, seq, i);\r
+ allGroups = av.alignment.findAllGroups(seq);\r
+\r
+ if (inCurrentSequenceGroup(i))\r
+ {\r
+ if (currentSequenceGroup.getDisplayBoxes())\r
+ {\r
+ getBoxColour(currentSequenceGroup.cs, seq, i);\r
+ }\r
+ }\r
+ else if (av.getShowBoxes())\r
+ {\r
+ getBoxColour(av.globalColourScheme, seq, i);\r
+ }\r
+\r
return resBoxColour;\r
- }\r
+ }\r
\r
void getBoxColour(ColourSchemeI cs, SequenceI seq, int i)\r
{\r
- if (cs != null)\r
- resBoxColour = cs.findColour(seq.getSequence(i, i + 1), i);\r
- else\r
- resBoxColour = Color.white;\r
+ if (cs != null)\r
+ {\r
+ resBoxColour = cs.findColour(seq.getSequence(i, i + 1), i);\r
+ }\r
+ else if(forOverview && !jalview.util.Comparison.isGap(seq.getCharAt(i)))\r
+ {\r
+ resBoxColour = Color.lightGray;\r
+ }\r
+ else\r
+ {\r
+ resBoxColour = Color.white;\r
+ }\r
+\r
+ }\r
+\r
+ public Color findSequenceColour(SequenceI seq, int i)\r
+ {\r
+ allGroups = av.alignment.findAllGroups(seq);\r
+ drawBoxes(seq, i,i, 0);\r
+ return resBoxColour;\r
}\r
\r
- public void drawSequence(Graphics g,SequenceI seq,SequenceGroup [] sg, int start, int end, int x1, int y1, int width, int height)\r
+ public void drawSequence(SequenceI seq, SequenceGroup[] sg,\r
+ int start, int end, int y1)\r
{\r
allGroups = sg;\r
\r
- graphics = g;\r
-\r
- drawBoxes(seq, start, end, x1, y1, (int) width, height);\r
-\r
- fm = g.getFontMetrics();\r
- drawText(seq,start,end,x1,y1,(int)width,height);\r
+ drawBoxes(seq, start, end, y1);\r
\r
+ if(av.validCharWidth)\r
+ {\r
+ drawText(seq, start, end, y1);\r
+ }\r
}\r
\r
- public void drawBoxes(SequenceI seq,int start, int end, int x1, int y1, int width, int height) {\r
- int i = start;\r
+ public void drawBoxes(SequenceI seq, int start, int end, int y1)\r
+ {\r
+ int i = start;\r
int length = seq.getLength();\r
\r
int curStart = -1;\r
- int curWidth = width;\r
+ int curWidth = av.charWidth;\r
\r
Color tempColour = null;\r
- while (i <= end && i < length)\r
+ while (i <= end)\r
{\r
- if(inCurrentSequenceGroup(i))\r
+ resBoxColour = Color.white;\r
+ if(i < length)\r
{\r
- if( currentSequenceGroup.getDisplayBoxes())\r
- getBoxColour(currentSequenceGroup.cs, seq, i);\r
+ if (inCurrentSequenceGroup(i))\r
+ {\r
+ if (currentSequenceGroup.getDisplayBoxes())\r
+ {\r
+ getBoxColour(currentSequenceGroup.cs, seq, i);\r
+ }\r
+ }\r
+ else if (av.getShowBoxes())\r
+ {\r
+ getBoxColour(av.getGlobalColourScheme(), seq, i);\r
+ }\r
}\r
- else if(av.getShowBoxes())\r
- getBoxColour(av.getGlobalColourScheme(), seq, i);\r
- else\r
- resBoxColour = Color.white;\r
\r
\r
if (resBoxColour != tempColour)\r
{\r
- if(tempColour!=null)\r
- graphics.fillRect(x1+width*(curStart-start),y1,curWidth,height);\r
+ if (tempColour != null)\r
+ {\r
+ graphics.fillRect(av.charWidth * (curStart - start), y1, curWidth,\r
+ av.charHeight);\r
+ }\r
graphics.setColor(resBoxColour);\r
\r
curStart = i;\r
- curWidth = width;\r
+ curWidth = av.charWidth;\r
tempColour = resBoxColour;\r
\r
}\r
else\r
- curWidth += width;\r
+ {\r
+ curWidth += av.charWidth;\r
+ }\r
\r
i++;\r
}\r
\r
-\r
- graphics.fillRect(x1+width*(curStart-start),y1,curWidth,height);\r
+ graphics.fillRect(av.charWidth * (curStart - start), y1, curWidth, av.charHeight);\r
}\r
\r
- public void drawText(SequenceI seq,int start, int end, int x1, int y1, int width, int height)\r
+ public void drawText(SequenceI seq, int start, int end, int y1)\r
{\r
- int pady = height/5;\r
- int charOffset=0;\r
- char s;\r
+\r
+ y1 += av.charHeight - av.charHeight / 5; // height/5 replaces pady\r
+\r
+ int charOffset = 0;\r
+\r
// Need to find the sequence position here.\r
+ if(end+1>=seq.getLength())\r
+ end = seq.getLength()-1;\r
+\r
+ char s = ' ';\r
\r
- graphics.setColor(Color.black);\r
- String sequence = seq.getSequence();\r
for (int i = start; i <= end; i++)\r
{\r
- if(i<sequence.length())\r
- s = sequence.charAt(i);\r
- else\r
- s = ' ';\r
+ graphics.setColor(Color.black);\r
\r
- if(!renderGaps && jalview.util.Comparison.isGap(s))\r
- continue;\r
+ s = seq.getCharAt(i);\r
+ if (!renderGaps && jalview.util.Comparison.isGap(s))\r
+ {\r
+ continue;\r
+ }\r
\r
+ if (inCurrentSequenceGroup(i))\r
+ {\r
+ if (!currentSequenceGroup.getDisplayText())\r
+ {\r
+ continue;\r
+ }\r
\r
- if (inCurrentSequenceGroup(i))\r
+ if (currentSequenceGroup.getColourText())\r
{\r
- if(!currentSequenceGroup.getDisplayText())\r
- continue;\r
-\r
- if (currentSequenceGroup.getColourText())\r
- {\r
- getBoxColour(currentSequenceGroup.cs, seq, i);\r
- graphics.setColor(resBoxColour.darker());\r
- }\r
+ getBoxColour(currentSequenceGroup.cs, seq, i);\r
+ graphics.setColor(resBoxColour.darker());\r
}\r
- else\r
+ }\r
+ else\r
+ {\r
+ if (!av.getShowText())\r
{\r
- if(!av.getShowText())\r
- continue;\r
-\r
- if(av.getColourText())\r
- {\r
- getBoxColour(av.getGlobalColourScheme(), seq, i);\r
- if(av.getShowBoxes())\r
- graphics.setColor(resBoxColour.darker());\r
- else\r
- graphics.setColor(resBoxColour);\r
- }\r
+ continue;\r
}\r
\r
- charOffset = (width - fm.charWidth(s))/2;\r
- graphics.drawString(String.valueOf(s),\r
- charOffset + x1 + width * (i - start),\r
- y1 + height - pady);\r
+ if (av.getColourText())\r
+ {\r
+ getBoxColour(av.getGlobalColourScheme(), seq, i);\r
+ if (av.getShowBoxes())\r
+ {\r
+ graphics.setColor(resBoxColour.darker());\r
+ }\r
+ else\r
+ {\r
+ graphics.setColor(resBoxColour);\r
+ }\r
}\r
+ }\r
\r
+ charOffset = (av.charWidth - fm.charWidth(s)) / 2;\r
+ graphics.drawString(String.valueOf(s),\r
+ charOffset + av.charWidth * (i - start),\r
+ y1 );\r
+ }\r
\r
}\r
\r
boolean inCurrentSequenceGroup(int res)\r
{\r
- if(allGroups ==null)\r
+ if (allGroups == null)\r
+ {\r
return false;\r
+ }\r
\r
- for(int i=0; i<allGroups.length; i++)\r
- if(allGroups[i].getStartRes()<=res && allGroups[i].getEndRes()>=res)\r
+ for (int i = 0; i < allGroups.length; i++)\r
+ {\r
+ if (allGroups[i].getStartRes() <= res && allGroups[i].getEndRes() >= res)\r
{\r
- currentSequenceGroup = allGroups[i];\r
- return true;\r
+ currentSequenceGroup = allGroups[i];\r
+ return true;\r
}\r
+ }\r
\r
return false;\r
}\r
\r
- public void drawHighlightedText(SequenceI seq,int start, int end, int x1, int y1, int width, int height)\r
+ public void drawHighlightedText(SequenceI seq, int start, int end, int x1, int y1)\r
{\r
- int pady = height/5;\r
- int charOffset=0;\r
+ int pady = av.charHeight / 5;\r
+ int charOffset = 0;\r
graphics.setColor(Color.black);\r
- graphics.fillRect(x1,y1,width*(end-start+1),height);\r
+ graphics.fillRect(x1, y1, av.charWidth * (end - start + 1), av.charHeight);\r
graphics.setColor(Color.white);\r
\r
- char s='~';\r
+ char s = '~';\r
// Need to find the sequence position here.\r
- for (int i = start; i <= end; i++)\r
+ if(av.validCharWidth)\r
{\r
- if(i<seq.getLength())\r
+ for (int i = start; i <= end; i++)\r
+ {\r
+ if (i < seq.getLength())\r
+ {\r
s = seq.getSequence().charAt(i);\r
+ }\r
\r
- charOffset = (width - fm.charWidth(s))/2;\r
- graphics.drawString(String.valueOf(s), charOffset + x1 + width * (i - start), y1 + height - pady);\r
+ charOffset = (av.charWidth - fm.charWidth(s)) / 2;\r
+ graphics.drawString(String.valueOf(s),\r
+ charOffset + x1 + av.charWidth * (i - start),\r
+ y1 + av.charHeight - pady);\r
+ }\r
}\r
}\r
\r
+ public void drawCursor(SequenceI seq, int res, int x1, int y1)\r
+ {\r
+ int pady = av.charHeight / 5;\r
+ int charOffset = 0;\r
+ graphics.setColor(Color.black);\r
+ graphics.fillRect(x1, y1, av.charWidth, av.charHeight);\r
+ graphics.setColor(Color.white);\r
+\r
+ graphics.setColor(Color.white);\r
+\r
+ char s = seq.getCharAt(res);\r
+ if (av.validCharWidth)\r
+ {\r
+\r
+ charOffset = (av.charWidth - fm.charWidth(s)) / 2;\r
+ graphics.drawString(String.valueOf(s),\r
+ charOffset + x1,\r
+ (y1 + av.charHeight) - pady);\r
+ }\r
+ }\r
\r
}\r