4 import javax.swing.*;
\r
5 import java.awt.event.*;
\r
6 import jalview.datamodel.*;
\r
7 import jalview.schemes.*;
\r
8 import jalview.analysis.*;
\r
11 public class SeqCanvas extends JPanel
\r
20 public boolean paintFlag = false;
\r
22 boolean showScores = false;
\r
23 boolean displaySearch = false;
\r
24 int [] searchResults = null;
\r
30 public SeqCanvas(AlignViewport av)
\r
33 setLayout(new BorderLayout());
\r
37 public void drawScale(int startx, int endx,int charWidth, int charHeight,int ypos) {
\r
38 int scalestartx = startx - startx%10 + 10;
\r
40 gg.setColor(Color.black);
\r
42 for (int i=scalestartx;i < endx;i+= 10) {
\r
43 String string = String.valueOf(i);
\r
44 gg.drawString(string,(int)((i-startx-1)*charWidth),ypos+15 - charHeight*(2));
\r
50 * Definitions of startx and endx (hopefully):
\r
51 * SMJS This is what I'm working towards!
\r
52 * startx is the first residue (starting at 0) to display.
\r
53 * endx is the last residue to display (starting at 0).
\r
54 * starty is the first sequence to display (starting at 0).
\r
55 * endy is the last sequence to display (starting at 0).
\r
56 * NOTE 1: The av limits are set in setFont in this class and
\r
57 * in the adjustment listener in SeqPanel when the scrollbars move.
\r
60 public void paintComponent(Graphics g) {
\r
62 AlignmentI da = av.getAlignment();
\r
65 imgWidth != getWidth() ||
\r
66 imgHeight != getHeight()
\r
70 imgWidth = getWidth();
\r
71 imgHeight = getHeight();
\r
73 img = createImage(imgWidth,imgHeight);
\r
74 gg = img.getGraphics();
\r
76 gg.setFont(av.getFont());
\r
81 chunkWidth = getWidth()/av.charWidth;
\r
82 chunkHeight = (da.getHeight() + 2)*av.charHeight;
\r
84 av.setChunkHeight(chunkHeight);
\r
85 av.setChunkWidth(chunkWidth);
\r
89 fillBackground(gg,Color.WHITE,0,0,imgWidth,imgHeight);
\r
91 /* if (av.getWrapAlignment()) {
\r
92 int offy = av.getStartSeq();
\r
93 startx = (int)(offy/chunkWidth)*chunkWidth;
\r
94 endx = startx + chunkWidth;
\r
95 starty = offy%chunkHeight;
\r
96 endy = starty + da.getHeight();
\r
99 int rowstart = starty;
\r
102 ypos = 2*charHeight;
\r
103 } else if (starty == 1) {
\r
108 if (endy > da.getHeight()) {
\r
109 endy = da.getHeight();
\r
112 if (endx > da.getWidth()) {
\r
113 endx = da.getWidth();
\r
116 if (rowstart < 2) {
\r
117 drawScale(startx,endx,charWidth,charHeight,ypos);
\r
120 drawPanel(gg,startx,endx,starty,endy,startx,starty,ypos);
\r
122 if (rowstart == 0) {
\r
123 ypos = ypos + chunkHeight;
\r
124 } else if (rowstart == 1) {
\r
125 ypos = ypos + chunkHeight;
\r
127 ypos = ypos + chunkHeight - rowstart*charHeight;
\r
130 startx += chunkWidth;
\r
131 endx = startx + chunkWidth;
\r
134 if (endx > da.getWidth()) {
\r
135 endx = da.getWidth();
\r
137 // Draw the rest of the panels
\r
139 while (ypos <= getHeight()) {
\r
140 drawScale(startx,endx,charWidth,charHeight,ypos);
\r
141 drawPanel(gg,startx,endx,0,da.getHeight(),startx,starty,ypos);
\r
143 ypos += chunkHeight;
\r
144 startx += chunkWidth;
\r
145 endx = startx + chunkWidth;
\r
147 if (endy > da.getHeight()) {
\r
148 endy = da.getHeight();
\r
151 if (endx > da.getWidth()) {
\r
152 endx = da.getWidth();
\r
159 drawPanel(gg,av.startRes,av.endRes,av.startSeq,av.endSeq,av.startRes,av.startSeq,0);
\r
163 /* if ((oldendy -oldstarty) > (getWidth() / av.getCharWidth())) {
\r
164 System.out.println("LIMITS ERROR LIMITS ERROR");
\r
165 System.out.println("Corrds " + (oldendy-oldstarty) + " " + (getWidth()/av.getCharWidth()) + " " + getWidth() + " " + av.getCharWidth());
\r
168 g.drawImage(img,0,0,this);
\r
175 public void drawPanel(Graphics g,int x1,int x2, int y1, int y2,int startx, int starty,int offset) {
\r
178 g.setFont(av.getFont());
\r
179 int charWidth = av.getCharWidth();
\r
180 int charHeight = av.getCharHeight();
\r
181 RendererI sr = av.getRenderer();
\r
183 /*Vector pid = av.getConsensus(false);
\r
184 Vector tmpseq = new Vector();
\r
185 for (int i = 0; i < av.getAlignment().getHeight(); i++)
\r
186 if (!av.getSelection().contains(av.getAlignment().getSequenceAt(i)))
\r
187 tmpseq.addElement(av.getAlignment().getSequenceAt(i));
\r
189 if (sr instanceof SequenceRenderer)
\r
190 pid = AAFrequency.calculate(tmpseq,x1,x2);
\r
192 else if (sr instanceof GraphRenderer)
\r
193 pid = AAFrequency.calculatePID(av.getAlignment().getSequenceAt(0),
\r
194 av.getAlignment().getSequences(),
\r
195 av.getPIDWindow(),x1,x2);
\r
199 if (y2 > starty && y1 < av.getEndSeq())
\r
203 (x1-startx)*charWidth,
\r
204 offset + AlignmentUtil.getPixelHeight(starty,y1,av.getCharHeight()),
\r
205 (x2-x1+1)*charWidth,
\r
206 offset + AlignmentUtil.getPixelHeight(y1,y2,av.getCharHeight()));
\r
210 SequenceGroup group=null;
\r
211 boolean inGroup=false; // are we in a defined group?
\r
212 boolean inRB=false; //Are we in a rubberband group?
\r
213 int sx=-1, sy=-1, ex=-1, ey=-1;
\r
214 int oldStartX=0,oldEndX=0,oldY=0;
\r
215 int oldRStartX=0,oldREndX=0,oldRY=0;
\r
216 for (int i = y1 ; i < y2 ;i++)
\r
218 nextSeq = av.getAlignment().getSequenceAt(i);
\r
220 group = av.alignment.findGroup( nextSeq );
\r
222 sr.drawSequence(g, nextSeq, group,x1,x2,
\r
223 (x1 - startx) * charWidth,
\r
224 offset + AlignmentUtil.getPixelHeight(starty, i, av.getCharHeight()),
\r
225 charWidth,charHeight,null, i);
\r
231 g.setColor(Color.lightGray);
\r
233 sx = (group.getStartRes()-startx)*charWidth;
\r
234 sy = offset + AlignmentUtil.getPixelHeight(starty, i, av.getCharHeight());
\r
235 ex = (group.getEndRes()+1-startx)*charWidth;
\r
236 ey = offset + AlignmentUtil.getPixelHeight(starty, i+1, av.getCharHeight());
\r
241 g.drawLine(sx, sy, ex, sy); // Horizontal, top of new box
\r
245 g.drawLine(sx, sy, sx, ey ); // vertical line, left hand side
\r
246 g.drawLine( ex,sy,ex,ey); // vertical line, right hand side
\r
247 if (i == y2 - 1)// last line of alignment, seal the box
\r
248 g.drawLine(sx, ey, ex, ey); // Horizontal, bottom of old box
\r
257 g.setColor(Color.lightGray);
\r
258 g.drawLine(oldStartX, oldY, oldEndX, oldY); // Horizontal, bottom of old box
\r
263 group = av.getRubberbandGroup();
\r
264 if( group != null && group.sequences.contains(nextSeq) )
\r
266 g.setColor(Color.RED.brighter());
\r
267 sx = (group.getStartRes() - startx) * charWidth;
\r
269 AlignmentUtil.getPixelHeight(starty, i, av.getCharHeight());
\r
270 ex = (group.getEndRes() + 1 - startx) * charWidth;
\r
272 AlignmentUtil.getPixelHeight(starty, i + 1, av.getCharHeight());
\r
277 g.drawLine(sx, sy, ex, sy); // Horizontal, top of new box
\r
281 g.drawLine(sx, sy, sx, ey); // vertical line, left hand side
\r
282 g.drawLine(ex, sy, ex, ey); // vertical line, right hand side
\r
283 if (i == y2 - 1) // last line of alignment, seal the box
\r
284 g.drawLine(sx, ey, ex, ey); // Horizontal, bottom of old box
\r
292 g.setColor(Color.RED.brighter());
\r
293 g.drawLine(oldRStartX, oldRY, oldREndX, oldRY); // Horizontal, bottom of old box
\r
301 /// Highlight search Results once all sequences have been drawn
\r
304 for(int r=0; r<searchResults.length; r+=3)
\r
306 int searchSeq = searchResults[r];
\r
307 int searchStart = searchResults[r+1];
\r
308 int searchEnd = searchResults[r+2];
\r
310 if (searchSeq >= y1 && searchSeq <= y2)
\r
312 SequenceRenderer ssr = (SequenceRenderer) sr;
\r
313 ssr.drawHighlightedText(g, av.getAlignment().getSequenceAt(searchSeq),
\r
316 (searchStart - startx) * charWidth,
\r
318 AlignmentUtil.getPixelHeight(starty, searchSeq,
\r
328 public void fillBackground(Graphics g,Color c, int x1,int y1,int width,int height) {
\r
330 g.fillRect(x1,y1,width,height);
\r
333 public int getChunkWidth() {
\r
337 public void highlightSearchResults(int [] results)
\r
339 // results are in the order sequence, startRes, endRes
\r
341 displaySearch = false;
\r
343 displaySearch = true;
\r
345 searchResults = results;
\r