2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8)
3 * Copyright (C) 2012 J Procter, AM Waterhouse, LM Lui, J Engelhardt, G Barton, M Clamp, S Searle
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
11 * Jalview is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
21 import java.awt.image.*;
22 import java.util.List;
26 import jalview.datamodel.*;
34 public class IdCanvas extends JPanel
36 protected AlignViewport av;
38 protected boolean showScores = true;
40 protected int maxIdLength = -1;
42 protected String maxIdStr = null;
50 boolean fastPaint = false;
52 List<SequenceI> searchResults;
56 AnnotationLabels labels = null;
63 * Creates a new IdCanvas object.
68 public IdCanvas(AlignViewport av)
70 setLayout(new BorderLayout());
72 PaintRefresher.Register(this, av.getSequenceSetId());
89 public void drawIdString(Graphics2D gg, SequenceI s, int i, int starty,
93 int panelWidth = getWidth();
94 int charHeight = av.charHeight;
96 if ((searchResults != null) && searchResults.contains(s))
98 gg.setColor(Color.black);
99 gg.fillRect(0, ((i - starty) * charHeight) + ypos, getWidth(),
101 gg.setColor(Color.white);
103 else if ((av.getSelectionGroup() != null)
104 && av.getSelectionGroup().getSequences(null).contains(s))
106 gg.setColor(Color.lightGray);
107 gg.fillRect(0, ((i - starty) * charHeight) + ypos, getWidth(),
109 gg.setColor(Color.white);
113 gg.setColor(av.getSequenceColour(s));
114 gg.fillRect(0, ((i - starty) * charHeight) + ypos, getWidth(),
116 gg.setColor(Color.black);
119 if (av.rightAlignIds)
122 - fm.stringWidth(s.getDisplayId(av.getShowJVSuffix())) - 4;
125 gg.drawString(s.getDisplayId(av.getShowJVSuffix()), xPos,
126 (((i - starty + 1) * charHeight) + ypos) - (charHeight / 5));
128 if (av.hasHiddenRows() && av.showHiddenMarkers)
130 drawMarker(i, starty, ypos);
141 public void fastPaint(int vertical)
150 gg.copyArea(0, 0, getWidth(), imgHeight, 0, -vertical * av.charHeight);
152 int ss = av.startSeq;
156 if (vertical > 0) // scroll down
160 if (ss < av.startSeq)
161 { // ie scrolling too fast, more than a page at a time
166 transY = imgHeight - (vertical * av.charHeight);
169 else if (vertical < 0)
179 gg.translate(0, transY);
183 gg.translate(0, -transY);
195 public void paintComponent(Graphics g)
197 g.setColor(Color.white);
198 g.fillRect(0, 0, getWidth(), getHeight());
203 g.drawImage(image, 0, 0, this);
208 int oldHeight = imgHeight;
210 imgHeight = getHeight();
211 imgHeight -= (imgHeight % av.charHeight);
218 if (oldHeight != imgHeight || image.getWidth(this) != getWidth())
220 image = new BufferedImage(getWidth(), imgHeight,
221 BufferedImage.TYPE_INT_RGB);
224 gg = (Graphics2D) image.getGraphics();
226 // Fill in the background
227 gg.setColor(Color.white);
228 gg.fillRect(0, 0, getWidth(), imgHeight);
230 drawIds(av.getStartSeq(), av.endSeq);
232 g.drawImage(image, 0, 0, this);
243 void drawIds(int starty, int endy)
245 if (av.seqNameItalics)
247 idfont = new Font(av.getFont().getName(), Font.ITALIC, av.getFont()
252 idfont = av.getFont();
256 fm = gg.getFontMetrics();
260 gg.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
261 RenderingHints.VALUE_ANTIALIAS_ON);
264 Color currentColor = Color.white;
265 Color currentTextColor = Color.black;
267 if (av.getWrapAlignment())
269 int maxwidth = av.getAlignment().getWidth();
270 int alheight = av.getAlignment().getHeight();
272 if (av.hasHiddenColumns())
274 maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1;
277 int annotationHeight = 0;
279 if (av.showAnnotation)
283 ap = new AnnotationPanel(av);
286 annotationHeight = ap.adjustPanelHeight();
289 labels = new AnnotationLabels(av);
293 int hgap = av.charHeight;
294 if (av.scaleAboveWrapped)
296 hgap += av.charHeight;
299 int cHeight = alheight * av.charHeight + hgap + annotationHeight;
301 int rowSize = av.getEndRes() - av.getStartRes();
303 // Draw the rest of the panels
304 for (int ypos = hgap, row = av.startRes; (ypos <= getHeight())
305 && (row < maxwidth); ypos += cHeight, row += rowSize)
307 for (int i = starty; i < alheight; i++)
309 SequenceI s = av.getAlignment().getSequenceAt(i);
310 if (av.hasHiddenRows())
319 drawIdString(gg, s, i, 0, ypos);
322 if (labels != null && av.showAnnotation)
324 gg.translate(0, ypos + (alheight * av.charHeight));
325 labels.drawComponent(gg, getWidth());
326 gg.translate(0, -ypos - (alheight * av.charHeight));
332 // No need to hang on to labels if we're not wrapped
335 // Now draw the id strings
336 int panelWidth = getWidth();
340 // Now draw the id strings
341 for (int i = starty; i < endy; i++)
343 sequence = av.getAlignment().getSequenceAt(i);
345 if (sequence == null)
350 if (av.hasHiddenRows())
352 setHiddenFont(sequence);
355 // Selected sequence colours
356 if ((searchResults != null) && searchResults.contains(sequence))
358 currentColor = Color.black;
359 currentTextColor = Color.white;
361 else if ((av.getSelectionGroup() != null)
362 && av.getSelectionGroup().getSequences(null)
365 currentColor = Color.lightGray;
366 currentTextColor = Color.black;
370 currentColor = av.getSequenceColour(sequence);
371 currentTextColor = Color.black;
374 gg.setColor(currentColor);
376 gg.fillRect(0, (i - starty) * av.charHeight, getWidth(),
379 gg.setColor(currentTextColor);
381 String string = sequence.getDisplayId(av.getShowJVSuffix());
383 if (av.rightAlignIds)
385 xPos = panelWidth - fm.stringWidth(string) - 4;
388 gg.drawString(string, xPos,
389 (((i - starty) * av.charHeight) + av.charHeight)
390 - (av.charHeight / 5));
392 if (av.hasHiddenRows() && av.showHiddenMarkers)
394 drawMarker(i, starty, 0);
402 void drawMarker(int i, int starty, int yoffset)
405 SequenceI[] hseqs = av.getAlignment().getHiddenSequences().hiddenSequences;
406 // Use this method here instead of calling hiddenSeq adjust
408 int hSize = hseqs.length;
411 int lastIndex = i - 1;
412 int nextIndex = i + 1;
414 for (int j = 0; j < hSize; j++)
416 if (hseqs[j] != null)
418 if (j - 1 < hiddenIndex)
422 if (j - 1 < lastIndex)
426 if (j - 1 < nextIndex)
433 boolean below = (hiddenIndex > lastIndex + 1);
434 boolean above = (nextIndex > hiddenIndex + 1);
436 gg.setColor(Color.blue);
441 { getWidth() - av.charHeight, getWidth() - av.charHeight,
442 getWidth() }, new int[]
444 (i - starty) * av.charHeight + yoffset,
445 (i - starty) * av.charHeight + yoffset + av.charHeight
446 / 4, (i - starty) * av.charHeight + yoffset }, 3);
452 { getWidth() - av.charHeight, getWidth() - av.charHeight,
453 getWidth() }, new int[]
455 (i - starty + 1) * av.charHeight + yoffset,
456 (i - starty + 1) * av.charHeight + yoffset
458 (i - starty + 1) * av.charHeight + yoffset }, 3);
463 void setHiddenFont(SequenceI seq)
465 Font bold = new Font(av.getFont().getName(), Font.BOLD, av.getFont()
468 if (av.isHiddenRepSequence(seq))
484 public void setHighlighted(List<SequenceI> list)
486 searchResults = list;