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
85 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
175 Graphics2D g = (Graphics2D)g1;
\r
176 g.setFont(av.getFont());
\r
177 RendererI sr = av.getRenderer();
\r
179 /*Vector pid = av.getConsensus(false);
\r
180 Vector tmpseq = new Vector();
\r
181 for (int i = 0; i < av.getAlignment().getHeight(); i++)
\r
182 if (!av.getSelection().contains(av.getAlignment().getSequenceAt(i)))
\r
183 tmpseq.addElement(av.getAlignment().getSequenceAt(i));
\r
185 if (sr instanceof SequenceRenderer)
\r
186 pid = AAFrequency.calculate(tmpseq,x1,x2);
\r
188 else if (sr instanceof GraphRenderer)
\r
189 pid = AAFrequency.calculatePID(av.getAlignment().getSequenceAt(0),
\r
190 av.getAlignment().getSequences(),
\r
191 av.getPIDWindow(),x1,x2);
\r
195 /* if (y2 > starty && y1 < av.getEndSeq())
\r
199 (x1-startx)*charWidth,
\r
200 offset + AlignmentUtil.getPixelHeight(starty,y1,av.getCharHeight()),
\r
201 (x2-x1+1)*charWidth,
\r
202 offset + AlignmentUtil.getPixelHeight(y1,y2,av.getCharHeight()));
\r
207 /// First draw the sequences
\r
208 /////////////////////////////
\r
209 for (int i = y1 ; i < y2 ;i++)
\r
211 nextSeq = av.alignment.getSequenceAt(i);
\r
213 sr.drawSequence(g, nextSeq, av.alignment.findAllGroups( nextSeq ),x1,x2,
\r
214 (x1 - startx) * av.charWidth,
\r
215 offset + AlignmentUtil.getPixelHeight(starty, i, av.charHeight),
\r
216 av.charWidth,av.charHeight,null, i);
\r
218 if(av.showSequenceFeatures)
\r
220 fr.drawSequence(g, nextSeq, av.alignment.findAllGroups( nextSeq ), x1, x2,
\r
221 (x1 - startx) * av.charWidth,
\r
223 AlignmentUtil.getPixelHeight(starty, i, av.charHeight),
\r
224 av.charWidth, av.charHeight, null, i);
\r
228 /////////////////////////////////////
\r
230 // Now outline any areas if necessary
\r
231 /////////////////////////////////////
\r
232 SequenceGroup group = av.getSelectionGroup();
\r
233 java.util.Vector groups = av.alignment.getGroups();
\r
235 int sx = -1, sy = -1, ex = -1;
\r
236 int groupIndex = -1;
\r
237 if (group == null && groups.size() > 0)
\r
239 group = (SequenceGroup) groups.elementAt(0);
\r
248 boolean inGroup = false;
\r
249 int top=-1, bottom =-1;
\r
250 for (i = y1; i < y2; i++)
\r
252 sx = (group.getStartRes() - startx) * av.charWidth;
\r
253 sy = offset + AlignmentUtil.getPixelHeight(starty, i, av.charHeight);
\r
254 ex = (group.getEndRes() + 1 - group.getStartRes()) * av.charWidth;
\r
257 if (sx < getWidth()
\r
259 && group.sequences.contains(av.alignment.getSequenceAt(i)))
\r
262 if (bottom == -1 &&
\r
263 !group.sequences.contains(av.alignment.getSequenceAt(i + 1)))
\r
264 bottom = sy + av.charHeight ;
\r
268 if (top == -1 && i==0 ||
\r
269 !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
291 g.drawLine(sx, oldY, sx, sy );
\r
292 g.drawLine(sx+ex, oldY, sx+ex, sy );
\r
296 g.drawLine(sx, top, sx + ex, top);
\r
301 g.drawLine(sx, bottom, sx + ex, bottom);
\r
316 g.drawLine(sx, top, sx + ex, top);
\r
321 g.drawLine(sx, bottom-1, sx + ex, bottom-1);
\r
325 sy = offset + AlignmentUtil.getPixelHeight(starty, i, av.charHeight);
\r
326 g.drawLine(sx, oldY, sx, sy );
\r
327 g.drawLine(sx+ex, oldY, sx+ex, sy );
\r
331 if (groupIndex >= groups.size())
\r
334 group = (SequenceGroup) groups.elementAt(groupIndex);
\r
337 while (groupIndex < groups.size());
\r
340 /// Highlight search Results once all sequences have been drawn
\r
341 //////////////////////////////////////////////////////////
\r
344 for(int r=0; r<searchResults.length; r+=3)
\r
346 int searchSeq = searchResults[r];
\r
347 int searchStart = searchResults[r+1];
\r
348 int searchEnd = searchResults[r+2];
\r
350 if (searchSeq >= y1 && searchSeq < y2)
\r
352 SequenceRenderer ssr = (SequenceRenderer) sr;
\r
353 ssr.drawHighlightedText(av.getAlignment().getSequenceAt(searchSeq),
\r
356 (searchStart - startx) * av.charWidth,
\r
358 AlignmentUtil.getPixelHeight(starty, searchSeq,
\r
369 public int getChunkWidth() {
\r
373 public void highlightSearchResults(int [] results)
\r
375 // results are in the order sequence, startRes, endRes
\r
377 displaySearch = false;
\r
379 displaySearch = true;
\r
381 searchResults = results;
\r