2 * Jalview - A Sequence Alignment Editor and Viewer (Development Version 2.4.1)
3 * Copyright (C) 2009 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 import java.awt.image.*;
25 import jalview.datamodel.*;
33 public class IdCanvas extends JPanel
35 protected AlignViewport av;
37 protected boolean showScores = true;
39 protected int maxIdLength = -1;
41 protected String maxIdStr = null;
49 boolean fastPaint = false;
51 java.util.Vector searchResults;
55 AnnotationLabels labels = null;
62 * Creates a new IdCanvas object.
67 public IdCanvas(AlignViewport av)
69 setLayout(new BorderLayout());
71 PaintRefresher.Register(this, av.getSequenceSetId());
88 public void drawIdString(Graphics2D gg, SequenceI s, int i, int starty,
92 int panelWidth = getWidth();
93 int charHeight = av.charHeight;
95 if ((searchResults != null) && searchResults.contains(s))
97 gg.setColor(Color.black);
98 gg.fillRect(0, ((i - starty) * charHeight) + ypos, getWidth(),
100 gg.setColor(Color.white);
102 else if ((av.getSelectionGroup() != null)
103 && av.getSelectionGroup().getSequences(null).contains(s))
105 gg.setColor(Color.lightGray);
106 gg.fillRect(0, ((i - starty) * charHeight) + ypos, getWidth(),
108 gg.setColor(Color.white);
112 gg.setColor(av.getSequenceColour(s));
113 gg.fillRect(0, ((i - starty) * charHeight) + ypos, getWidth(),
115 gg.setColor(Color.black);
118 if (av.rightAlignIds)
121 - fm.stringWidth(s.getDisplayId(av.getShowJVSuffix())) - 4;
124 gg.drawString(s.getDisplayId(av.getShowJVSuffix()), xPos,
125 (((i - starty + 1) * charHeight) + ypos) - (charHeight / 5));
127 if (av.hasHiddenRows && av.showHiddenMarkers)
129 drawMarker(i, starty, ypos);
140 public void fastPaint(int vertical)
149 gg.copyArea(0, 0, getWidth(), imgHeight, 0, -vertical * av.charHeight);
151 int ss = av.startSeq;
155 if (vertical > 0) // scroll down
159 if (ss < av.startSeq)
160 { // ie scrolling too fast, more than a page at a time
165 transY = imgHeight - (vertical * av.charHeight);
168 else if (vertical < 0)
178 gg.translate(0, transY);
182 gg.translate(0, -transY);
194 public void paintComponent(Graphics g)
196 g.setColor(Color.white);
197 g.fillRect(0, 0, getWidth(), getHeight());
202 g.drawImage(image, 0, 0, this);
207 int oldHeight = imgHeight;
209 imgHeight = getHeight();
210 imgHeight -= (imgHeight % av.charHeight);
217 if (oldHeight != imgHeight || image.getWidth(this) != getWidth())
219 image = new BufferedImage(getWidth(), imgHeight,
220 BufferedImage.TYPE_INT_RGB);
223 gg = (Graphics2D) image.getGraphics();
225 // Fill in the background
226 gg.setColor(Color.white);
227 gg.fillRect(0, 0, getWidth(), imgHeight);
229 drawIds(av.getStartSeq(), av.endSeq);
231 g.drawImage(image, 0, 0, this);
242 void drawIds(int starty, int endy)
244 if (av.seqNameItalics)
246 idfont = new Font(av.getFont().getName(), Font.ITALIC, av.getFont()
251 idfont = av.getFont();
255 fm = gg.getFontMetrics();
259 gg.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
260 RenderingHints.VALUE_ANTIALIAS_ON);
263 Color currentColor = Color.white;
264 Color currentTextColor = Color.black;
266 if (av.getWrapAlignment())
268 int maxwidth = av.alignment.getWidth();
269 int alheight = av.alignment.getHeight();
271 if (av.hasHiddenColumns)
273 maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1;
276 int annotationHeight = 0;
278 if (av.showAnnotation)
282 ap = new AnnotationPanel(av);
285 annotationHeight = ap.adjustPanelHeight();
288 labels = new AnnotationLabels(av);
292 int hgap = av.charHeight;
293 if (av.scaleAboveWrapped)
295 hgap += av.charHeight;
298 int cHeight = alheight * av.charHeight + hgap + annotationHeight;
300 int rowSize = av.getEndRes() - av.getStartRes();
302 // Draw the rest of the panels
303 for (int ypos = hgap, row = av.startRes; (ypos <= getHeight())
304 && (row < maxwidth); ypos += cHeight, row += rowSize)
306 for (int i = starty; i < alheight; i++)
308 SequenceI s = av.alignment.getSequenceAt(i);
309 if (av.hasHiddenRows)
318 drawIdString(gg, s, i, 0, ypos);
321 if (labels != null && av.showAnnotation)
323 gg.translate(0, ypos + (alheight * av.charHeight));
324 labels.drawComponent(gg, getWidth());
325 gg.translate(0, -ypos - (alheight * av.charHeight));
331 // No need to hang on to labels if we're not wrapped
334 // Now draw the id strings
335 int panelWidth = getWidth();
339 // Now draw the id strings
340 for (int i = starty; i < endy; i++)
342 sequence = av.alignment.getSequenceAt(i);
344 if (sequence == null)
349 if (av.hasHiddenRows)
351 setHiddenFont(sequence);
354 // Selected sequence colours
355 if ((searchResults != null) && searchResults.contains(sequence))
357 currentColor = Color.black;
358 currentTextColor = Color.white;
360 else if ((av.getSelectionGroup() != null)
361 && av.getSelectionGroup().getSequences(null).contains(
364 currentColor = Color.lightGray;
365 currentTextColor = Color.black;
369 currentColor = av.getSequenceColour(sequence);
370 currentTextColor = Color.black;
373 gg.setColor(currentColor);
375 gg.fillRect(0, (i - starty) * av.charHeight, getWidth(),
378 gg.setColor(currentTextColor);
380 String string = sequence.getDisplayId(av.getShowJVSuffix());
382 if (av.rightAlignIds)
384 xPos = panelWidth - fm.stringWidth(string) - 4;
387 gg.drawString(string, xPos,
388 (((i - starty) * av.charHeight) + av.charHeight)
389 - (av.charHeight / 5));
391 if (av.hasHiddenRows && av.showHiddenMarkers)
393 drawMarker(i, starty, 0);
401 void drawMarker(int i, int starty, int yoffset)
404 SequenceI[] hseqs = av.alignment.getHiddenSequences().hiddenSequences;
405 // Use this method here instead of calling hiddenSeq adjust
407 int hSize = hseqs.length;
410 int lastIndex = i - 1;
411 int nextIndex = i + 1;
413 for (int j = 0; j < hSize; j++)
415 if (hseqs[j] != null)
417 if (j - 1 < hiddenIndex)
421 if (j - 1 < lastIndex)
425 if (j - 1 < nextIndex)
432 boolean below = (hiddenIndex > lastIndex + 1);
433 boolean above = (nextIndex > hiddenIndex + 1);
435 gg.setColor(Color.blue);
440 { getWidth() - av.charHeight, getWidth() - av.charHeight,
441 getWidth() }, new int[]
443 (i - starty) * av.charHeight + yoffset,
444 (i - starty) * av.charHeight + yoffset + av.charHeight
445 / 4, (i - starty) * av.charHeight + yoffset }, 3);
451 { getWidth() - av.charHeight, getWidth() - av.charHeight,
452 getWidth() }, new int[]
454 (i - starty + 1) * av.charHeight + yoffset,
455 (i - starty + 1) * av.charHeight + yoffset
457 (i - starty + 1) * av.charHeight + yoffset }, 3);
462 void setHiddenFont(SequenceI seq)
464 Font bold = new Font(av.getFont().getName(), Font.BOLD, av.getFont()
467 if (av.hiddenRepSequences != null
468 && av.hiddenRepSequences.containsKey(seq))
484 public void setHighlighted(java.util.Vector found)
486 searchResults = found;