2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
3 * Copyright (C) 2014 The Jalview Authors
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
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
24 import java.awt.image.*;
25 import java.util.List;
29 import jalview.datamodel.*;
37 public class IdCanvas extends JPanel
39 protected AlignViewport av;
41 protected boolean showScores = true;
43 protected int maxIdLength = -1;
45 protected String maxIdStr = null;
53 boolean fastPaint = false;
55 List<SequenceI> searchResults;
59 AnnotationLabels labels = null;
66 * Creates a new IdCanvas object.
71 public IdCanvas(AlignViewport av)
73 setLayout(new BorderLayout());
75 PaintRefresher.Register(this, av.getSequenceSetId());
92 public void drawIdString(Graphics2D gg, SequenceI s, int i, int starty,
96 int panelWidth = getWidth();
97 int charHeight = av.getCharHeight();
99 if ((searchResults != null) && searchResults.contains(s))
101 gg.setColor(Color.black);
102 gg.fillRect(0, ((i - starty) * charHeight) + ypos, getWidth(),
104 gg.setColor(Color.white);
106 else if ((av.getSelectionGroup() != null)
107 && av.getSelectionGroup().getSequences(null).contains(s))
109 gg.setColor(Color.lightGray);
110 gg.fillRect(0, ((i - starty) * charHeight) + ypos, getWidth(),
112 gg.setColor(Color.white);
116 gg.setColor(av.getSequenceColour(s));
117 gg.fillRect(0, ((i - starty) * charHeight) + ypos, getWidth(),
119 gg.setColor(Color.black);
122 if (av.isRightAlignIds())
125 - fm.stringWidth(s.getDisplayId(av.getShowJVSuffix())) - 4;
128 gg.drawString(s.getDisplayId(av.getShowJVSuffix()), xPos,
129 (((i - starty + 1) * charHeight) + ypos) - (charHeight / 5));
131 if (av.hasHiddenRows() && av.getShowHiddenMarkers())
133 drawMarker(i, starty, ypos);
144 public void fastPaint(int vertical)
153 gg.copyArea(0, 0, getWidth(), imgHeight, 0,
154 -vertical * av.getCharHeight());
156 int ss = av.startSeq;
160 if (vertical > 0) // scroll down
164 if (ss < av.startSeq)
165 { // ie scrolling too fast, more than a page at a time
170 transY = imgHeight - (vertical * av.getCharHeight());
173 else if (vertical < 0)
183 gg.translate(0, transY);
187 gg.translate(0, -transY);
199 public void paintComponent(Graphics g)
201 g.setColor(Color.white);
202 g.fillRect(0, 0, getWidth(), getHeight());
207 g.drawImage(image, 0, 0, this);
212 int oldHeight = imgHeight;
214 imgHeight = getHeight();
215 imgHeight -= (imgHeight % av.getCharHeight());
222 if (oldHeight != imgHeight || image.getWidth(this) != getWidth())
224 image = new BufferedImage(getWidth(), imgHeight,
225 BufferedImage.TYPE_INT_RGB);
228 gg = (Graphics2D) image.getGraphics();
230 // Fill in the background
231 gg.setColor(Color.white);
232 gg.fillRect(0, 0, getWidth(), imgHeight);
234 drawIds(av.getStartSeq(), av.endSeq);
236 g.drawImage(image, 0, 0, this);
247 void drawIds(int starty, int endy)
249 if (av.isSeqNameItalics())
251 setIdfont(new Font(av.getFont().getName(), Font.ITALIC, av.getFont()
256 setIdfont(av.getFont());
259 gg.setFont(getIdfont());
260 fm = gg.getFontMetrics();
264 gg.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
265 RenderingHints.VALUE_ANTIALIAS_ON);
268 Color currentColor = Color.white;
269 Color currentTextColor = Color.black;
271 if (av.getWrapAlignment())
273 int maxwidth = av.getAlignment().getWidth();
274 int alheight = av.getAlignment().getHeight();
276 if (av.hasHiddenColumns())
278 maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1;
281 int annotationHeight = 0;
283 if (av.isShowAnnotation())
287 ap = new AnnotationPanel(av);
290 annotationHeight = ap.adjustPanelHeight();
293 labels = new AnnotationLabels(av);
297 int hgap = av.getCharHeight();
298 if (av.getScaleAboveWrapped())
300 hgap += av.getCharHeight();
303 int cHeight = alheight * av.getCharHeight() + hgap + annotationHeight;
305 int rowSize = av.getEndRes() - av.getStartRes();
307 // Draw the rest of the panels
308 for (int ypos = hgap, row = av.startRes; (ypos <= getHeight())
309 && (row < maxwidth); ypos += cHeight, row += rowSize)
311 for (int i = starty; i < alheight; i++)
313 SequenceI s = av.getAlignment().getSequenceAt(i);
314 if (av.isDisplayReferenceSeq() || av.hasHiddenRows())
320 gg.setFont(getIdfont());
323 drawIdString(gg, s, i, 0, ypos);
326 if (labels != null && av.isShowAnnotation())
328 gg.translate(0, ypos + (alheight * av.getCharHeight()));
329 labels.drawComponent(gg, getWidth());
330 gg.translate(0, -ypos - (alheight * av.getCharHeight()));
336 // No need to hang on to labels if we're not wrapped
339 // Now draw the id strings
340 int panelWidth = getWidth();
344 // Now draw the id strings
345 for (int i = starty; i < endy; i++)
347 sequence = av.getAlignment().getSequenceAt(i);
349 if (sequence == null)
354 if (av.isDisplayReferenceSeq() || av.hasHiddenRows())
356 setHiddenFont(sequence);
359 // Selected sequence colours
360 if ((searchResults != null) && searchResults.contains(sequence))
362 currentColor = Color.black;
363 currentTextColor = Color.white;
365 else if ((av.getSelectionGroup() != null)
366 && av.getSelectionGroup().getSequences(null)
369 currentColor = Color.lightGray;
370 currentTextColor = Color.black;
374 currentColor = av.getSequenceColour(sequence);
375 currentTextColor = Color.black;
378 gg.setColor(currentColor);
380 gg.fillRect(0, (i - starty) * av.getCharHeight(), getWidth(),
383 gg.setColor(currentTextColor);
385 String string = sequence.getDisplayId(av.getShowJVSuffix());
387 if (av.isRightAlignIds())
389 xPos = panelWidth - fm.stringWidth(string) - 4;
392 gg.drawString(string, xPos,
393 (((i - starty) * av.getCharHeight()) + av.getCharHeight())
394 - (av.getCharHeight() / 5));
396 if (av.hasHiddenRows() && av.getShowHiddenMarkers())
398 drawMarker(i, starty, 0);
406 void drawMarker(int i, int starty, int yoffset)
409 SequenceI[] hseqs = av.getAlignment().getHiddenSequences().hiddenSequences;
410 // Use this method here instead of calling hiddenSeq adjust
412 int hSize = hseqs.length;
415 int lastIndex = i - 1;
416 int nextIndex = i + 1;
418 for (int j = 0; j < hSize; j++)
420 if (hseqs[j] != null)
422 if (j - 1 < hiddenIndex)
426 if (j - 1 < lastIndex)
430 if (j - 1 < nextIndex)
437 boolean below = (hiddenIndex > lastIndex + 1);
438 boolean above = (nextIndex > hiddenIndex + 1);
440 gg.setColor(Color.blue);
445 { getWidth() - av.getCharHeight(),
446 getWidth() - av.getCharHeight(),
447 getWidth() }, new int[]
449 (i - starty) * av.getCharHeight() + yoffset,
450 (i - starty) * av.getCharHeight() + yoffset
451 + av.getCharHeight() / 4,
452 (i - starty) * av.getCharHeight() + yoffset }, 3);
458 { getWidth() - av.getCharHeight(),
459 getWidth() - av.getCharHeight(),
460 getWidth() }, new int[]
462 (i - starty + 1) * av.getCharHeight() + yoffset,
463 (i - starty + 1) * av.getCharHeight() + yoffset
464 - av.getCharHeight() / 4,
465 (i - starty + 1) * av.getCharHeight() + yoffset }, 3);
470 void setHiddenFont(SequenceI seq)
472 Font bold = new Font(av.getFont().getName(), Font.BOLD, av.getFont()
475 if (av.isHiddenRepSequence(seq))
481 gg.setFont(getIdfont());
491 public void setHighlighted(List<SequenceI> list)
493 searchResults = list;
497 public Font getIdfont()
502 public void setIdfont(Font idfont)
504 this.idfont = idfont;