\r
import jalview.datamodel.*;\r
import jalview.schemes.*;\r
-\r
import java.awt.*;\r
import java.util.*;\r
\r
public class SequenceRenderer implements RendererI\r
{\r
+ AlignViewport av;\r
FontMetrics fm;\r
+ boolean renderGaps = true;\r
+ SequenceGroup currentSequenceGroup = null;\r
+ Color color;\r
+\r
+ public SequenceRenderer(AlignViewport av)\r
+ {\r
+ this.av = av;\r
+ }\r
+\r
+\r
+ public void renderGaps(boolean b)\r
+ {\r
+ renderGaps = b;\r
+ }\r
\r
public Color getResidueBoxColour(ColourSchemeI cs, SequenceI seq, int i)\r
{\r
Color c = Color.white;\r
- try{\r
- c = cs.findColour(seq, seq.getSequence(i, i + 1), i, null);\r
- }catch(Exception ex){}\r
+\r
+ if (cs != null)\r
+ c = cs.findColour(seq, seq.getSequence(i, i + 1), i, av.getConsensus(false));\r
\r
return c;\r
}\r
\r
+ 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)\r
+ {\r
+ currentSequenceGroup = sg;\r
\r
- public void drawSequence(Graphics g,ColourSchemeI cs,SequenceI seq,int start, int end, int x1, int y1, double width, int height,boolean showScores, boolean displayBoxes, boolean displayText, boolean colourText,Vector freq, int seqnum) {\r
-\r
+ drawBoxes(g, seq, start, end, x1, y1, (int) width, height, pid);\r
\r
- if (displayBoxes)\r
- drawBoxes(g,cs,seq,start,end,x1,y1,(int)width, height,freq);\r
+ fm = g.getFontMetrics();\r
+ drawText(g,seq,start,end,x1,y1,(int)width,height);\r
\r
- if (displayText)\r
- {\r
- fm = g.getFontMetrics();\r
- drawText(g,cs,colourText,seq,start,end,x1,y1,(int)width,height);\r
- }\r
}\r
\r
- public void drawBoxes(Graphics g,ColourSchemeI cs, SequenceI seq,int start, int end, int x1, int y1, int width, int height,Vector freq) {\r
+ public void drawBoxes(Graphics g, SequenceI seq,int start, int end, int x1, int y1, int width, int height,Vector freq) {\r
int i = start;\r
int length = seq.getLength();\r
\r
\r
// int threshold = 80;\r
\r
- while (i <= end && i < length) {\r
- Color c = getResidueBoxColour(cs,seq,i);\r
+ while (i <= end && i < length)\r
+ {\r
+ color = color.white;\r
+\r
+ if(inCurrentSequenceGroup(i))\r
+ {\r
+ if( currentSequenceGroup.getDisplayBoxes())\r
+ color = getResidueBoxColour(currentSequenceGroup.cs, seq, i);\r
+ }\r
+ else if(av.getShowBoxes())\r
+ color = getResidueBoxColour(av.getGlobalColourScheme(), seq, i);\r
+\r
\r
// Hashtable hash = (Hashtable)freq.elementAt(i-start);\r
// String s = (String)hash.get("maxResidue");\r
}\r
}*/\r
\r
- if (c != currentColor || c != null)\r
+ if (color != currentColor || color != null)\r
{\r
g.fillRect(x1+width*(curStart-start),y1,curWidth,height);\r
\r
- currentColor = c;\r
- g.setColor(c);\r
+ currentColor = color;\r
+ g.setColor(color);\r
\r
curStart = i;\r
curWidth = width;\r
g.fillRect(x1+width*(curStart-start),y1,curWidth,height);\r
}\r
\r
- public void drawText(Graphics g, ColourSchemeI cs, boolean colText, SequenceI seq,int start, int end, int x1, int y1, int width, int height)\r
+ public void drawText(Graphics g, SequenceI seq,int start, int end, int x1, int y1, int width, int height)\r
{\r
int pady = height/5;\r
int charOffset=0;\r
// Need to find the sequence position here.\r
for (int i = start; i <= end; i++)\r
{\r
- if (i < end && i < seq.getLength())\r
- s = seq.getSequence().charAt(i);\r
- else if(i<seq.getLength())\r
+ if(i<seq.getLength())\r
s = seq.getSequence().charAt(i);\r
else\r
s = ' ';\r
\r
- if (colText)\r
+ if(!renderGaps && (s=='-' || s=='.' || s==' '))\r
+ continue;\r
+\r
+ g.setColor(Color.black);\r
+\r
+ if (inCurrentSequenceGroup(i))\r
{\r
- Color c = getResidueBoxColour(cs, seq, i);\r
- g.setColor(c.darker());\r
+ if(!currentSequenceGroup.getDisplayText())\r
+ continue;\r
+\r
+ if(currentSequenceGroup.getColourText())\r
+ g.setColor(getResidueBoxColour(currentSequenceGroup.cs, seq, i).darker());\r
+ }\r
+ else\r
+ {\r
+ if(!av.getShowText())\r
+ continue;\r
+\r
+ if(av.getColourText())\r
+ g.setColor(getResidueBoxColour(av.getGlobalColourScheme(), seq, i).darker());\r
}\r
\r
charOffset = (width - fm.charWidth(s))/2;\r
+ g.drawString(String.valueOf(s), charOffset + x1 + width * (i - start), y1 + height - pady);\r
+ }\r
+\r
+\r
+ }\r
+\r
+ boolean inCurrentSequenceGroup(int res)\r
+ {\r
+ if(currentSequenceGroup==null)\r
+ return false;\r
+\r
+ return (currentSequenceGroup.getStartRes()<=res && currentSequenceGroup.getEndRes()>=res)?true:false;\r
+ }\r
\r
+ public void drawHighlightedText(Graphics g, SequenceI seq,int start, int end, int x1, int y1, int width, int height)\r
+ {\r
+ int pady = height/5;\r
+ int charOffset=0;\r
+ g.setColor(Color.BLACK);\r
+ g.fillRect(x1,y1,width*(end-start+1),height);\r
+ g.setColor(Color.white);\r
\r
+ char s='~';\r
+ // Need to find the sequence position here.\r
+ for (int i = start; i <= end; i++)\r
+ {\r
+ if(i<seq.getLength())\r
+ s = seq.getSequence().charAt(i);\r
+\r
+ charOffset = (width - fm.charWidth(s))/2;\r
g.drawString(String.valueOf(s), charOffset + x1 + width * (i - start), y1 + height - pady);\r
}\r
}\r
\r
+\r
}\r