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.charHeight;
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.rightAlignIds)
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.showHiddenMarkers)
133 drawMarker(i, starty, ypos);
144 public void fastPaint(int vertical)
153 gg.copyArea(0, 0, getWidth(), imgHeight, 0, -vertical * av.charHeight);
155 int ss = av.startSeq;
159 if (vertical > 0) // scroll down
163 if (ss < av.startSeq)
164 { // ie scrolling too fast, more than a page at a time
169 transY = imgHeight - (vertical * av.charHeight);
172 else if (vertical < 0)
182 gg.translate(0, transY);
186 gg.translate(0, -transY);
198 public void paintComponent(Graphics g)
200 g.setColor(Color.white);
201 g.fillRect(0, 0, getWidth(), getHeight());
206 g.drawImage(image, 0, 0, this);
211 int oldHeight = imgHeight;
213 imgHeight = getHeight();
214 imgHeight -= (imgHeight % av.charHeight);
221 if (oldHeight != imgHeight || image.getWidth(this) != getWidth())
223 image = new BufferedImage(getWidth(), imgHeight,
224 BufferedImage.TYPE_INT_RGB);
227 gg = (Graphics2D) image.getGraphics();
229 // Fill in the background
230 gg.setColor(Color.white);
231 gg.fillRect(0, 0, getWidth(), imgHeight);
233 drawIds(av.getStartSeq(), av.endSeq);
235 g.drawImage(image, 0, 0, this);
246 void drawIds(int starty, int endy)
248 if (av.seqNameItalics)
250 idfont = new Font(av.getFont().getName(), Font.ITALIC, av.getFont()
255 idfont = av.getFont();
259 fm = gg.getFontMetrics();
263 gg.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
264 RenderingHints.VALUE_ANTIALIAS_ON);
267 Color currentColor = Color.white;
268 Color currentTextColor = Color.black;
270 if (av.getWrapAlignment())
272 int maxwidth = av.getAlignment().getWidth();
273 int alheight = av.getAlignment().getHeight();
275 if (av.hasHiddenColumns())
277 maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1;
280 int annotationHeight = 0;
282 if (av.showAnnotation)
286 ap = new AnnotationPanel(av);
289 annotationHeight = ap.adjustPanelHeight();
292 labels = new AnnotationLabels(av);
296 int hgap = av.charHeight;
297 if (av.scaleAboveWrapped)
299 hgap += av.charHeight;
302 int cHeight = alheight * av.charHeight + hgap + annotationHeight;
304 int rowSize = av.getEndRes() - av.getStartRes();
306 // Draw the rest of the panels
307 for (int ypos = hgap, row = av.startRes; (ypos <= getHeight())
308 && (row < maxwidth); ypos += cHeight, row += rowSize)
310 for (int i = starty; i < alheight; i++)
312 SequenceI s = av.getAlignment().getSequenceAt(i);
313 if (av.hasHiddenRows())
322 drawIdString(gg, s, i, 0, ypos);
325 if (labels != null && av.showAnnotation)
327 gg.translate(0, ypos + (alheight * av.charHeight));
328 labels.drawComponent(gg, getWidth());
329 gg.translate(0, -ypos - (alheight * av.charHeight));
335 // No need to hang on to labels if we're not wrapped
338 // Now draw the id strings
339 int panelWidth = getWidth();
343 // Now draw the id strings
344 for (int i = starty; i < endy; i++)
346 sequence = av.getAlignment().getSequenceAt(i);
348 if (sequence == null)
353 if (av.hasHiddenRows())
355 setHiddenFont(sequence);
358 // Selected sequence colours
359 if ((searchResults != null) && searchResults.contains(sequence))
361 currentColor = Color.black;
362 currentTextColor = Color.white;
364 else if ((av.getSelectionGroup() != null)
365 && av.getSelectionGroup().getSequences(null)
368 currentColor = Color.lightGray;
369 currentTextColor = Color.black;
373 currentColor = av.getSequenceColour(sequence);
374 currentTextColor = Color.black;
377 gg.setColor(currentColor);
379 gg.fillRect(0, (i - starty) * av.charHeight, getWidth(),
382 gg.setColor(currentTextColor);
384 String string = sequence.getDisplayId(av.getShowJVSuffix());
386 if (av.rightAlignIds)
388 xPos = panelWidth - fm.stringWidth(string) - 4;
391 gg.drawString(string, xPos,
392 (((i - starty) * av.charHeight) + av.charHeight)
393 - (av.charHeight / 5));
395 if (av.hasHiddenRows() && av.showHiddenMarkers)
397 drawMarker(i, starty, 0);
405 void drawMarker(int i, int starty, int yoffset)
408 SequenceI[] hseqs = av.getAlignment().getHiddenSequences().hiddenSequences;
409 // Use this method here instead of calling hiddenSeq adjust
411 int hSize = hseqs.length;
414 int lastIndex = i - 1;
415 int nextIndex = i + 1;
417 for (int j = 0; j < hSize; j++)
419 if (hseqs[j] != null)
421 if (j - 1 < hiddenIndex)
425 if (j - 1 < lastIndex)
429 if (j - 1 < nextIndex)
436 boolean below = (hiddenIndex > lastIndex + 1);
437 boolean above = (nextIndex > hiddenIndex + 1);
439 gg.setColor(Color.blue);
444 { getWidth() - av.charHeight, getWidth() - av.charHeight,
445 getWidth() }, new int[]
447 (i - starty) * av.charHeight + yoffset,
448 (i - starty) * av.charHeight + yoffset + av.charHeight
449 / 4, (i - starty) * av.charHeight + yoffset }, 3);
455 { getWidth() - av.charHeight, getWidth() - av.charHeight,
456 getWidth() }, new int[]
458 (i - starty + 1) * av.charHeight + yoffset,
459 (i - starty + 1) * av.charHeight + yoffset
461 (i - starty + 1) * av.charHeight + yoffset }, 3);
466 void setHiddenFont(SequenceI seq)
468 Font bold = new Font(av.getFont().getName(), Font.BOLD, av.getFont()
471 if (av.isHiddenRepSequence(seq))
487 public void setHighlighted(List<SequenceI> list)
489 searchResults = list;