package jalview.gui; import jalview.datamodel.*; import jalview.schemes.*; import java.awt.*; public class DrawableSequence implements SequenceI { protected boolean fastDraw = true; protected Color color = Color.black; protected SequenceI sequence; ColourSchemeI cs = null; public DrawableSequence(SequenceI s) { this.sequence = s; _init(); } public DrawableSequence(String name,String seq, int start, int end) { sequence = new Sequence(name,seq,start,end); _init(); } private void _init() { } public void setColourScheme(ColourSchemeI cs) { this.cs = cs; } public Color getResidueBoxColour(int i) { Color c = cs.findColour( sequence.getSequence(i,i+1),i,null); return c; } public void drawSequence(Graphics g,int start, int end, int x1, int y1, int width, int height,boolean showScores, boolean displayBoxes, boolean displayText) { if (displayBoxes == true) { drawBoxes(g,start,end,x1,y1,width, height); } if (displayText == true) { drawText(g,start,end,x1,y1,width,height); } } public void drawBoxes(Graphics g,int start, int end, int x1, int y1, int width, int height) { int i = start; int length = getSequence().length(); Color currentColor = Color.white; int curStart = x1; int curWidth = width; while (i <= end && i < length) { Color c = getResidueBoxColour(i); 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, int start, int end, int x1, int y1, int width, int height) { int pady = 2; g.setColor(Color.black); System.out.println("drawablesequence is drawing"); // Need to find the sequence position here. if (fastDraw) { String s; if (end < getSequence().length()) { s = getSequence().substring(start,end+1); } else { s = getSequence().substring(start); } System.out.println(s+" "+x1+" "+y1); g.drawString(s,x1,y1+height-pady); } else { for (int i=start; i <= end; i++) { String s = ""; if (i < end && i < getSequence().length()) { s = getSequence().substring(i,i+1); } else { s = getSequence().substring(i,i+1); } g.drawString(s,x1+width*(i-start),y1+height-pady); } } } public int getPosition(int res) { return res; } public int getResidue(int pos) { return pos; } // SequenceI methods public void setName(String name) { sequence.setName(name); } public String getName() { return sequence.getName(); } public String getDisplayId() { return sequence.getDisplayId(); } public void setStart(int start) { sequence.setStart(start); } public int getStart() { return sequence.getStart(); } public void setEnd(int end) { sequence.setEnd(end); } public int getEnd() { return sequence.getEnd(); } public int getLength() { return sequence.getLength(); } public void setSequence(String seq) { sequence.setSequence(seq); } public String getSequence() { return sequence.getSequence(); } public String getSequence(int start,int end) { return sequence.getSequence(start,end); } public char getCharAt(int i) { return sequence.getCharAt(i); } public void setDescription(String desc) { sequence.setDescription(desc); } public String getDescription() { return sequence.getDescription(); } public int findIndex(int pos) { return sequence.findIndex(pos); } public int findPosition(int i) { return sequence.findPosition(i); } public void deleteCharAt(int i) { sequence.deleteCharAt(i); } public void insertCharAt(int i,char c) { sequence.insertCharAt(i,c); } public void insertCharAt(int i,char c,boolean chop) { sequence.insertCharAt(i,c,chop); } public Color getColor() { return this.color; } public void setColor(Color c) { this.color = c; } }