package jalview.gui; import jalview.datamodel.*; import jalview.schemes.*; import java.awt.*; import java.util.*; public class SequenceRenderer implements RendererI { FontMetrics fm; boolean renderGaps = true; public void renderGaps(boolean b) { renderGaps = b; } public Color getResidueBoxColour(ColourSchemeI cs, SequenceI seq, int i) { Color c = Color.white; try{ c = cs.findColour(seq, seq.getSequence(i, i + 1), i, null); }catch(Exception ex){} return c; } 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) { if (displayBoxes) drawBoxes(g,cs,seq,start,end,x1,y1,(int)width, height,freq); if (displayText) { fm = g.getFontMetrics(); drawText(g,cs,colourText,seq,start,end,x1,y1,(int)width,height); } } public void drawBoxes(Graphics g,ColourSchemeI cs, SequenceI seq,int start, int end, int x1, int y1, int width, int height,Vector freq) { int i = start; int length = seq.getLength(); Color currentColor = Color.WHITE; int curStart = x1; int curWidth = width; // int threshold = 80; while (i <= end && i < length) { Color c = getResidueBoxColour(cs,seq,i); // Hashtable hash = (Hashtable)freq.elementAt(i-start); // String s = (String)hash.get("maxResidue"); // int count = ((Integer)hash.get("maxCount")).intValue(); // int max = ((Integer)hash.get("size")).intValue(); // int nongap = ((Integer)hash.get("nongap")).intValue(); // float frac = (float)(count*1.0/(1.0*nongap)); //System.out.println("Frac/count/nongap " + frac + " " + count + " " + nongap); /* if (!seq.getSequence().substring(i,i+1).equals(s) || s.equals("-") || s.equals(".") || s.equals(" ")) { c = Color.white; } else { if (frac > 0.9) { c = Color.red; } else if (frac > 0.8) { c = Color.orange; } else if (frac > 0.7) { c = Color.pink; } else if (frac > 0.5) { c = Color.yellow; } else if (frac> 0.3) { c = Color.lightGray; } }*/ if (c != currentColor || c != null) { g.fillRect(x1+width*(curStart-start),y1,curWidth,height); currentColor = c; g.setColor(c); curStart = i; curWidth = width; } else curWidth += width; i++; } g.fillRect(x1+width*(curStart-start),y1,curWidth,height); } public void drawText(Graphics g, ColourSchemeI cs, boolean colText, SequenceI seq,int start, int end, int x1, int y1, int width, int height) { int pady = height/5; int charOffset=0; g.setColor(Color.black); char s; // Need to find the sequence position here. for (int i = start; i <= end; i++) { if(i