4 import javax.swing.*;
\r
5 import jalview.datamodel.*;
\r
6 import jalview.analysis.*;
\r
9 public class SeqCanvas extends JPanel
\r
19 boolean showScores = false;
\r
20 boolean displaySearch = false;
\r
21 int [] searchResults = null;
\r
26 boolean fastPaint = false;
\r
29 public SeqCanvas(AlignViewport av)
\r
32 fr = new FeatureRenderer(av);
\r
33 setLayout(new BorderLayout());
\r
34 PaintRefresher.Register(this);
\r
38 public void drawScale(Graphics g, int startx, int endx,int ypos) {
\r
39 int scalestartx = startx - startx%10 + 10;
\r
41 g.setColor(Color.black);
\r
43 for (int i=scalestartx;i < endx;i+= 10)
\r
45 String string = String.valueOf(i);
\r
46 g.drawString(string,(i-startx-1)*av.charWidth,ypos - av.charHeight/2);
\r
48 g.drawLine( (i-startx-1)*av.charWidth +av.charWidth/2, ypos+2 - av.charHeight/2,
\r
49 (i-startx-1)*av.charWidth +av.charWidth/2, ypos-2 );
\r
56 public void fastPaint(int horizontal, int vertical)
\r
58 if (horizontal == 0 && vertical == 0)
\r
61 gg.copyArea(0, 0, imgWidth, imgHeight, -horizontal * av.charWidth,
\r
62 -vertical * av.charHeight);
\r
64 int sr = av.startRes, er = av.endRes + 1, ss = av.startSeq, es = av.endSeq,
\r
65 transX = 0, transY = 0;
\r
66 if (horizontal > 0) // scrollbar pulled right, image to the left
\r
68 transX = (er - sr - horizontal) * av.charWidth;
\r
69 sr = er - horizontal;
\r
71 else if (horizontal < 0)
\r
72 er = sr - horizontal;
\r
74 else if (vertical > 0) // scroll down
\r
76 transY = imgHeight - vertical * av.charHeight;
\r
79 else if (vertical < 0)
\r
82 gg.translate(transX, transY);
\r
84 drawPanel(gg, sr, er, ss, es, sr, ss, 0);
\r
86 gg.translate( -transX, -transY);
\r
94 * Definitions of startx and endx (hopefully):
\r
95 * SMJS This is what I'm working towards!
\r
96 * startx is the first residue (starting at 0) to display.
\r
97 * endx is the last residue to display (starting at 0).
\r
98 * starty is the first sequence to display (starting at 0).
\r
99 * endy is the last sequence to display (starting at 0).
\r
100 * NOTE 1: The av limits are set in setFont in this class and
\r
101 * in the adjustment listener in SeqPanel when the scrollbars move.
\r
104 public void paintComponent(Graphics g)
\r
106 g.setColor(Color.white);
\r
107 g.fillRect(0, 0, getWidth(), getHeight());
\r
111 g.drawImage(img, 0, 0, this);
\r
116 // this draws the whole of the alignment
\r
117 imgWidth = getWidth();
\r
118 imgHeight = getHeight();
\r
120 imgWidth -= imgWidth%av.charWidth;
\r
121 imgHeight-= imgHeight%av.charHeight;
\r
123 img = createImage(imgWidth,imgHeight);
\r
124 gg = (Graphics2D)img.getGraphics();
\r
125 gg.setFont(av.getFont());
\r
126 gg.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
\r
128 gg.setColor(Color.white);
\r
129 gg.fillRect(0,0,imgWidth,imgHeight);
\r
131 chunkWidth = getWidth()/av.charWidth;
\r
132 chunkHeight = (av.getAlignment().getHeight() + 2)*av.charHeight;
\r
134 av.setChunkHeight(chunkHeight);
\r
135 av.setChunkWidth(chunkWidth);
\r
138 if (av.getWrapAlignment())
\r
139 drawWrappedPanel(gg, getWidth(), getHeight(), av.startRes);
\r
141 drawPanel(gg, av.startRes, av.endRes, av.startSeq, av.endSeq, av.startRes, av.startSeq, 0);
\r
143 g.drawImage(img, 0, 0, this);
\r
147 public void drawWrappedPanel(Graphics g, int canvasWidth, int canvasHeight, int startRes)
\r
149 AlignmentI da = av.getAlignment();
\r
151 int cWidth = canvasWidth/av.charWidth;
\r
152 int cHeight = (av.getAlignment().getHeight() + 2)*av.charHeight;
\r
154 int endx = startRes+cWidth-1;
\r
155 int ypos = 2*av.charHeight;
\r
157 while (ypos <= canvasHeight)
\r
159 drawScale(g, startRes, endx, ypos);
\r
160 drawPanel(g, startRes, endx, 0, da.getHeight(), startRes, 0, ypos);
\r
163 startRes += cWidth;
\r
164 endx = startRes + cWidth - 1;
\r
166 if (endx > da.getWidth())
\r
167 endx = da.getWidth();
\r
173 public void drawPanel(Graphics g1,int x1,int x2, int y1, int y2,int startx, int starty,int offset) {
\r
176 Graphics2D g = (Graphics2D)g1;
\r
177 g.setFont(av.getFont());
\r
178 RendererI sr = av.getRenderer();
\r
180 /*Vector pid = av.getConsensus(false);
\r
181 Vector tmpseq = new Vector();
\r
182 for (int i = 0; i < av.getAlignment().getHeight(); i++)
\r
183 if (!av.getSelection().contains(av.getAlignment().getSequenceAt(i)))
\r
184 tmpseq.addElement(av.getAlignment().getSequenceAt(i));
\r
186 if (sr instanceof SequenceRenderer)
\r
187 pid = AAFrequency.calculate(tmpseq,x1,x2);
\r
189 else if (sr instanceof GraphRenderer)
\r
190 pid = AAFrequency.calculatePID(av.getAlignment().getSequenceAt(0),
\r
191 av.getAlignment().getSequences(),
\r
192 av.getPIDWindow(),x1,x2);
\r
196 /* if (y2 > starty && y1 < av.getEndSeq())
\r
200 (x1-startx)*charWidth,
\r
201 offset + AlignmentUtil.getPixelHeight(starty,y1,av.getCharHeight()),
\r
202 (x2-x1+1)*charWidth,
\r
203 offset + AlignmentUtil.getPixelHeight(y1,y2,av.getCharHeight()));
\r
208 /// First draw the sequences
\r
209 /////////////////////////////
\r
210 for (int i = y1 ; i < y2 ;i++)
\r
212 nextSeq = av.getAlignment().getSequenceAt(i);
\r
214 sr.drawSequence(g, nextSeq, av.alignment.findAllGroups( nextSeq ),x1,x2,
\r
215 (x1 - startx) * av.charWidth,
\r
216 offset + AlignmentUtil.getPixelHeight(starty, i, av.charHeight),
\r
217 av.charWidth,av.charHeight,null, i);
\r
219 if(av.showSequenceFeatures)
\r
221 fr.drawSequence(g, nextSeq, av.alignment.findAllGroups( nextSeq ), x1, x2,
\r
222 (x1 - startx) * av.charWidth,
\r
224 AlignmentUtil.getPixelHeight(starty, i, av.charHeight),
\r
225 av.charWidth, av.charHeight, null, i);
\r
229 /////////////////////////////////////
\r
231 // Now outline any areas if necessary
\r
232 /////////////////////////////////////
\r
233 SequenceGroup group = av.getSelectionGroup();
\r
234 java.util.Vector groups = av.alignment.getGroups();
\r
236 int sx = -1, sy = -1, ex = -1;
\r
237 int groupIndex = -1;
\r
238 if (group == null && groups.size() > 0)
\r
240 group = (SequenceGroup) groups.elementAt(0);
\r
249 boolean inGroup = false;
\r
250 int top=-1, bottom =-1;
\r
251 for (i = y1; i < y2; i++)
\r
253 sx = (group.getStartRes() - startx) * av.charWidth;
\r
254 sy = offset + AlignmentUtil.getPixelHeight(starty, i, av.charHeight);
\r
255 ex = (group.getEndRes() + 1 - group.getStartRes()) * av.charWidth;
\r
258 if (sx < getWidth()
\r
260 && group.sequences.contains(av.alignment.getSequenceAt(i)))
\r
263 if (bottom == -1 &&
\r
264 !group.sequences.contains(av.alignment.getSequenceAt(i + 1)))
\r
265 bottom = sy + av.charHeight -1;
\r
269 if (top == -1 && i==0 ||
\r
270 !group.sequences.contains(av.alignment.getSequenceAt(i - 1)))
\r
275 if (group == av.getSelectionGroup())
\r
277 g.setStroke(new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND, 3f, new float[]{5f,3f}, 0f ));
\r
278 g.setColor(Color.RED);
\r
282 g.setStroke(new BasicStroke());
\r
283 g.setColor(group.getOutlineColour());
\r
292 g.drawLine(sx, oldY, sx, sy );
\r
293 g.drawLine(sx+ex, oldY, sx+ex, sy );
\r
295 g.drawLine(sx, top, sx + ex, top);
\r
297 g.drawLine(sx, bottom, sx + ex, bottom);
\r
308 g.drawLine(sx,top, sx+ex, top);
\r
310 g.drawLine(sx,bottom, sx+ex, bottom);
\r
312 sy = offset + AlignmentUtil.getPixelHeight(starty, i, av.charHeight);
\r
313 g.drawLine(sx, oldY, sx, sy );
\r
314 g.drawLine(sx+ex, oldY, sx+ex, sy );
\r
318 if (groupIndex >= groups.size())
\r
321 group = (SequenceGroup) groups.elementAt(groupIndex);
\r
324 while (groupIndex < groups.size());
\r
327 /// Highlight search Results once all sequences have been drawn
\r
328 //////////////////////////////////////////////////////////
\r
331 for(int r=0; r<searchResults.length; r+=3)
\r
333 int searchSeq = searchResults[r];
\r
334 int searchStart = searchResults[r+1];
\r
335 int searchEnd = searchResults[r+2];
\r
337 if (searchSeq >= y1 && searchSeq < y2)
\r
339 SequenceRenderer ssr = (SequenceRenderer) sr;
\r
340 ssr.drawHighlightedText(av.getAlignment().getSequenceAt(searchSeq),
\r
343 (searchStart - startx) * av.charWidth,
\r
345 AlignmentUtil.getPixelHeight(starty, searchSeq,
\r
356 public int getChunkWidth() {
\r
360 public void highlightSearchResults(int [] results)
\r
362 // results are in the order sequence, startRes, endRes
\r
364 displaySearch = false;
\r
366 displaySearch = true;
\r
368 searchResults = results;
\r