2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.0b1)
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 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/>.
17 * The Jalview Authors are detailed in the 'AUTHORS' file.
22 import java.awt.image.*;
23 import java.util.List;
27 import jalview.datamodel.*;
35 public class IdCanvas extends JPanel
37 protected AlignViewport av;
39 protected boolean showScores = true;
41 protected int maxIdLength = -1;
43 protected String maxIdStr = null;
51 boolean fastPaint = false;
53 List<SequenceI> searchResults;
57 AnnotationLabels labels = null;
64 * Creates a new IdCanvas object.
69 public IdCanvas(AlignViewport av)
71 setLayout(new BorderLayout());
73 PaintRefresher.Register(this, av.getSequenceSetId());
90 public void drawIdString(Graphics2D gg, SequenceI s, int i, int starty,
94 int panelWidth = getWidth();
95 int charHeight = av.charHeight;
97 if ((searchResults != null) && searchResults.contains(s))
99 gg.setColor(Color.black);
100 gg.fillRect(0, ((i - starty) * charHeight) + ypos, getWidth(),
102 gg.setColor(Color.white);
104 else if ((av.getSelectionGroup() != null)
105 && av.getSelectionGroup().getSequences(null).contains(s))
107 gg.setColor(Color.lightGray);
108 gg.fillRect(0, ((i - starty) * charHeight) + ypos, getWidth(),
110 gg.setColor(Color.white);
114 gg.setColor(av.getSequenceColour(s));
115 gg.fillRect(0, ((i - starty) * charHeight) + ypos, getWidth(),
117 gg.setColor(Color.black);
120 if (av.rightAlignIds)
123 - fm.stringWidth(s.getDisplayId(av.getShowJVSuffix())) - 4;
126 gg.drawString(s.getDisplayId(av.getShowJVSuffix()), xPos,
127 (((i - starty + 1) * charHeight) + ypos) - (charHeight / 5));
129 if (av.hasHiddenRows() && av.showHiddenMarkers)
131 drawMarker(i, starty, ypos);
142 public void fastPaint(int vertical)
151 gg.copyArea(0, 0, getWidth(), imgHeight, 0, -vertical * av.charHeight);
153 int ss = av.startSeq;
157 if (vertical > 0) // scroll down
161 if (ss < av.startSeq)
162 { // ie scrolling too fast, more than a page at a time
167 transY = imgHeight - (vertical * av.charHeight);
170 else if (vertical < 0)
180 gg.translate(0, transY);
184 gg.translate(0, -transY);
196 public void paintComponent(Graphics g)
198 g.setColor(Color.white);
199 g.fillRect(0, 0, getWidth(), getHeight());
204 g.drawImage(image, 0, 0, this);
209 int oldHeight = imgHeight;
211 imgHeight = getHeight();
212 imgHeight -= (imgHeight % av.charHeight);
219 if (oldHeight != imgHeight || image.getWidth(this) != getWidth())
221 image = new BufferedImage(getWidth(), imgHeight,
222 BufferedImage.TYPE_INT_RGB);
225 gg = (Graphics2D) image.getGraphics();
227 // Fill in the background
228 gg.setColor(Color.white);
229 gg.fillRect(0, 0, getWidth(), imgHeight);
231 drawIds(av.getStartSeq(), av.endSeq);
233 g.drawImage(image, 0, 0, this);
244 void drawIds(int starty, int endy)
246 if (av.seqNameItalics)
248 idfont = new Font(av.getFont().getName(), Font.ITALIC, av.getFont()
253 idfont = av.getFont();
257 fm = gg.getFontMetrics();
261 gg.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
262 RenderingHints.VALUE_ANTIALIAS_ON);
265 Color currentColor = Color.white;
266 Color currentTextColor = Color.black;
268 if (av.getWrapAlignment())
270 int maxwidth = av.getAlignment().getWidth();
271 int alheight = av.getAlignment().getHeight();
273 if (av.hasHiddenColumns())
275 maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1;
278 int annotationHeight = 0;
280 if (av.showAnnotation)
284 ap = new AnnotationPanel(av);
287 annotationHeight = ap.adjustPanelHeight();
290 labels = new AnnotationLabels(av);
294 int hgap = av.charHeight;
295 if (av.scaleAboveWrapped)
297 hgap += av.charHeight;
300 int cHeight = alheight * av.charHeight + hgap + annotationHeight;
302 int rowSize = av.getEndRes() - av.getStartRes();
304 // Draw the rest of the panels
305 for (int ypos = hgap, row = av.startRes; (ypos <= getHeight())
306 && (row < maxwidth); ypos += cHeight, row += rowSize)
308 for (int i = starty; i < alheight; i++)
310 SequenceI s = av.getAlignment().getSequenceAt(i);
311 if (av.hasHiddenRows())
320 drawIdString(gg, s, i, 0, ypos);
323 if (labels != null && av.showAnnotation)
325 gg.translate(0, ypos + (alheight * av.charHeight));
326 labels.drawComponent(gg, getWidth());
327 gg.translate(0, -ypos - (alheight * av.charHeight));
333 // No need to hang on to labels if we're not wrapped
336 // Now draw the id strings
337 int panelWidth = getWidth();
341 // Now draw the id strings
342 for (int i = starty; i < endy; i++)
344 sequence = av.getAlignment().getSequenceAt(i);
346 if (sequence == null)
351 if (av.hasHiddenRows())
353 setHiddenFont(sequence);
356 // Selected sequence colours
357 if ((searchResults != null) && searchResults.contains(sequence))
359 currentColor = Color.black;
360 currentTextColor = Color.white;
362 else if ((av.getSelectionGroup() != null)
363 && av.getSelectionGroup().getSequences(null)
366 currentColor = Color.lightGray;
367 currentTextColor = Color.black;
371 currentColor = av.getSequenceColour(sequence);
372 currentTextColor = Color.black;
375 gg.setColor(currentColor);
377 gg.fillRect(0, (i - starty) * av.charHeight, getWidth(),
380 gg.setColor(currentTextColor);
382 String string = sequence.getDisplayId(av.getShowJVSuffix());
384 if (av.rightAlignIds)
386 xPos = panelWidth - fm.stringWidth(string) - 4;
389 gg.drawString(string, xPos,
390 (((i - starty) * av.charHeight) + av.charHeight)
391 - (av.charHeight / 5));
393 if (av.hasHiddenRows() && av.showHiddenMarkers)
395 drawMarker(i, starty, 0);
403 void drawMarker(int i, int starty, int yoffset)
406 SequenceI[] hseqs = av.getAlignment().getHiddenSequences().hiddenSequences;
407 // Use this method here instead of calling hiddenSeq adjust
409 int hSize = hseqs.length;
412 int lastIndex = i - 1;
413 int nextIndex = i + 1;
415 for (int j = 0; j < hSize; j++)
417 if (hseqs[j] != null)
419 if (j - 1 < hiddenIndex)
423 if (j - 1 < lastIndex)
427 if (j - 1 < nextIndex)
434 boolean below = (hiddenIndex > lastIndex + 1);
435 boolean above = (nextIndex > hiddenIndex + 1);
437 gg.setColor(Color.blue);
442 { getWidth() - av.charHeight, getWidth() - av.charHeight,
443 getWidth() }, new int[]
445 (i - starty) * av.charHeight + yoffset,
446 (i - starty) * av.charHeight + yoffset + av.charHeight
447 / 4, (i - starty) * av.charHeight + yoffset }, 3);
453 { getWidth() - av.charHeight, getWidth() - av.charHeight,
454 getWidth() }, new int[]
456 (i - starty + 1) * av.charHeight + yoffset,
457 (i - starty + 1) * av.charHeight + yoffset
459 (i - starty + 1) * av.charHeight + yoffset }, 3);
464 void setHiddenFont(SequenceI seq)
466 Font bold = new Font(av.getFont().getName(), Font.BOLD, av.getFont()
469 if (av.isHiddenRepSequence(seq))
485 public void setHighlighted(List<SequenceI> list)
487 searchResults = list;