Jalview Imported Sources
[jalview.git] / src / jalview / gui / DrawableSequence.java
1 package jalview.gui;\r
2 \r
3 import jalview.datamodel.*;\r
4 import jalview.schemes.*;\r
5 import jalview.analysis.*;\r
6 import java.awt.*;\r
7 \r
8 public class DrawableSequence implements SequenceI {\r
9   protected boolean fastDraw = true;\r
10 \r
11   protected Color   color = Color.black;\r
12 \r
13   protected SequenceI sequence;\r
14 \r
15   ColourSchemeI cs = new ZappoColourScheme();\r
16 \r
17   public DrawableSequence(SequenceI s) {\r
18     this.sequence = s;\r
19 \r
20     _init();\r
21   }\r
22 \r
23   public DrawableSequence(String name,String seq, int start, int end) {\r
24     sequence   = new Sequence(name,seq,start,end);\r
25 \r
26     _init();\r
27   }\r
28 \r
29   private void _init() {\r
30 \r
31   }\r
32 \r
33   public void setColourScheme(ColourSchemeI cs) {\r
34     this.cs = cs;\r
35   }\r
36 \r
37   public Color getResidueBoxColour(int i) {\r
38     Color c = cs.findColour(this,sequence.getSequence(i,i+1),i,null);\r
39     return c;\r
40   }\r
41 \r
42   public void drawSequence(Graphics g,int start, int end, int x1, int y1, int width, int height,boolean showScores, boolean displayBoxes, boolean displayText) {\r
43 \r
44     if (displayBoxes == true) {\r
45       drawBoxes(g,start,end,x1,y1,width, height);\r
46     }\r
47     if (displayText == true) {\r
48         drawText(g,start,end,x1,y1,width,height);\r
49     }\r
50   }\r
51 \r
52   public void drawBoxes(Graphics g,int start, int end, int x1, int y1, int width, int height) {\r
53     int i      = start;\r
54     int length = getSequence().length();\r
55 \r
56     Color currentColor = Color.white;\r
57 \r
58     int curStart = x1;\r
59     int curWidth = width;\r
60 \r
61     while (i <= end && i < length) {\r
62       Color c = getResidueBoxColour(i);\r
63 \r
64       if (c != currentColor || c != null) {\r
65         g.fillRect(x1+width*(curStart-start),y1,curWidth,height);\r
66 \r
67         currentColor = c;\r
68         g.setColor(c);\r
69 \r
70         curStart = i;\r
71         curWidth = width;\r
72       } else {\r
73         curWidth += width;\r
74       }\r
75 \r
76       i++;\r
77     }\r
78     g.fillRect(x1+width*(curStart-start),y1,curWidth,height);\r
79   }\r
80 \r
81   public void drawText(Graphics g, int start, int end, int x1, int y1, int width, int height) {\r
82     int pady = 2;\r
83     g.setColor(Color.black);\r
84 System.out.println("drawablesequence is drawing");\r
85     // Need to find the sequence position here.\r
86 \r
87     if (fastDraw) {\r
88         String s;\r
89         if (end < getSequence().length()) {\r
90             s = getSequence().substring(start,end+1);\r
91         } else {\r
92             s = getSequence().substring(start);\r
93         }\r
94         System.out.println(s+" "+x1+" "+y1);\r
95       g.drawString(s,x1,y1+height-pady);\r
96     } else {\r
97 \r
98       for (int i=start; i <= end; i++) {\r
99         String s = "";\r
100 \r
101         if (i < end && i < getSequence().length()) {\r
102           s = getSequence().substring(i,i+1);\r
103         } else {\r
104           s = getSequence().substring(i,i+1);\r
105         }\r
106 \r
107 \r
108         g.drawString(s,x1+width*(i-start),y1+height-pady);\r
109       }\r
110 \r
111     }\r
112   }\r
113 \r
114 \r
115   public int getPosition(int res) {\r
116 \r
117     return res;\r
118   }\r
119 \r
120   public int getResidue(int pos) {\r
121 \r
122     return pos;\r
123   }\r
124 \r
125   // SequenceI methods\r
126 \r
127   public void        setName(String name) {\r
128     sequence.setName(name);\r
129   }\r
130   public String      getName() {\r
131     return sequence.getName();\r
132   }\r
133   public String      getDisplayId() {\r
134     return sequence.getDisplayId();\r
135   }\r
136 \r
137   public void        setStart(int start) {\r
138     sequence.setStart(start);\r
139   }\r
140   public int         getStart() {\r
141     return sequence.getStart();\r
142   }\r
143 \r
144   public void        setEnd(int end) {\r
145     sequence.setEnd(end);\r
146   }\r
147   public int         getEnd() {\r
148     return sequence.getEnd();\r
149   }\r
150 \r
151   public int         getLength() {\r
152     return sequence.getLength();\r
153   }\r
154 \r
155   public void        setSequence(String seq) {\r
156     sequence.setSequence(seq);\r
157   }\r
158   public String      getSequence() {\r
159     return sequence.getSequence();\r
160   }\r
161   public String      getSequence(int start,int end) {\r
162     return sequence.getSequence(start,end);\r
163   }\r
164   public char        getCharAt(int i) {\r
165     return sequence.getCharAt(i);\r
166   }\r
167 \r
168   public void        setDescription(String desc) {\r
169     sequence.setDescription(desc);\r
170   }\r
171   public String      getDescription() {\r
172     return sequence.getDescription();\r
173   }\r
174 \r
175   public int         findIndex(int pos) {\r
176     return sequence.findIndex(pos);\r
177   }\r
178   public int         findPosition(int i) {\r
179     return sequence.findPosition(i);\r
180   }\r
181 \r
182 \r
183   public void deleteCharAt(int i) {\r
184     sequence.deleteCharAt(i);\r
185   }\r
186 \r
187   public void insertCharAt(int i,char c) {\r
188     sequence.insertCharAt(i,c);\r
189 \r
190   }\r
191 \r
192   public void       insertCharAt(int i,char c,boolean chop) {\r
193     sequence.insertCharAt(i,c,chop);\r
194 \r
195   }\r
196   public Color getColor() {\r
197     return this.color;\r
198   }\r
199 \r
200   public void setColor(Color c) {\r
201     this.color = c;\r
202   }\r
203 \r
204 }\r