2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.5)
3 * Copyright (C) 2010 J Procter, AM Waterhouse, 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.*;
24 import jalview.datamodel.*;
32 public class IdCanvas extends JPanel
34 protected AlignViewport av;
36 protected boolean showScores = true;
38 protected int maxIdLength = -1;
40 protected String maxIdStr = null;
48 boolean fastPaint = false;
50 java.util.Vector searchResults;
54 AnnotationLabels labels = null;
61 * Creates a new IdCanvas object.
66 public IdCanvas(AlignViewport av)
68 setLayout(new BorderLayout());
70 PaintRefresher.Register(this, av.getSequenceSetId());
87 public void drawIdString(Graphics2D gg, SequenceI s, int i, int starty,
91 int panelWidth = getWidth();
92 int charHeight = av.charHeight;
94 if ((searchResults != null) && searchResults.contains(s))
96 gg.setColor(Color.black);
97 gg.fillRect(0, ((i - starty) * charHeight) + ypos, getWidth(),
99 gg.setColor(Color.white);
101 else if ((av.getSelectionGroup() != null)
102 && av.getSelectionGroup().getSequences(null).contains(s))
104 gg.setColor(Color.lightGray);
105 gg.fillRect(0, ((i - starty) * charHeight) + ypos, getWidth(),
107 gg.setColor(Color.white);
111 gg.setColor(av.getSequenceColour(s));
112 gg.fillRect(0, ((i - starty) * charHeight) + ypos, getWidth(),
114 gg.setColor(Color.black);
117 if (av.rightAlignIds)
120 - fm.stringWidth(s.getDisplayId(av.getShowJVSuffix())) - 4;
123 gg.drawString(s.getDisplayId(av.getShowJVSuffix()), xPos,
124 (((i - starty + 1) * charHeight) + ypos) - (charHeight / 5));
126 if (av.hasHiddenRows && av.showHiddenMarkers)
128 drawMarker(i, starty, ypos);
139 public void fastPaint(int vertical)
148 gg.copyArea(0, 0, getWidth(), imgHeight, 0, -vertical * av.charHeight);
150 int ss = av.startSeq;
154 if (vertical > 0) // scroll down
158 if (ss < av.startSeq)
159 { // ie scrolling too fast, more than a page at a time
164 transY = imgHeight - (vertical * av.charHeight);
167 else if (vertical < 0)
177 gg.translate(0, transY);
181 gg.translate(0, -transY);
193 public void paintComponent(Graphics g)
195 g.setColor(Color.white);
196 g.fillRect(0, 0, getWidth(), getHeight());
201 g.drawImage(image, 0, 0, this);
206 int oldHeight = imgHeight;
208 imgHeight = getHeight();
209 imgHeight -= (imgHeight % av.charHeight);
216 if (oldHeight != imgHeight || image.getWidth(this) != getWidth())
218 image = new BufferedImage(getWidth(), imgHeight,
219 BufferedImage.TYPE_INT_RGB);
222 gg = (Graphics2D) image.getGraphics();
224 // Fill in the background
225 gg.setColor(Color.white);
226 gg.fillRect(0, 0, getWidth(), imgHeight);
228 drawIds(av.getStartSeq(), av.endSeq);
230 g.drawImage(image, 0, 0, this);
241 void drawIds(int starty, int endy)
243 if (av.seqNameItalics)
245 idfont = new Font(av.getFont().getName(), Font.ITALIC, av.getFont()
250 idfont = av.getFont();
254 fm = gg.getFontMetrics();
258 gg.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
259 RenderingHints.VALUE_ANTIALIAS_ON);
262 Color currentColor = Color.white;
263 Color currentTextColor = Color.black;
265 if (av.getWrapAlignment())
267 int maxwidth = av.alignment.getWidth();
268 int alheight = av.alignment.getHeight();
270 if (av.hasHiddenColumns)
272 maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1;
275 int annotationHeight = 0;
277 if (av.showAnnotation)
281 ap = new AnnotationPanel(av);
284 annotationHeight = ap.adjustPanelHeight();
287 labels = new AnnotationLabels(av);
291 int hgap = av.charHeight;
292 if (av.scaleAboveWrapped)
294 hgap += av.charHeight;
297 int cHeight = alheight * av.charHeight + hgap + annotationHeight;
299 int rowSize = av.getEndRes() - av.getStartRes();
301 // Draw the rest of the panels
302 for (int ypos = hgap, row = av.startRes; (ypos <= getHeight())
303 && (row < maxwidth); ypos += cHeight, row += rowSize)
305 for (int i = starty; i < alheight; i++)
307 SequenceI s = av.alignment.getSequenceAt(i);
308 if (av.hasHiddenRows)
317 drawIdString(gg, s, i, 0, ypos);
320 if (labels != null && av.showAnnotation)
322 gg.translate(0, ypos + (alheight * av.charHeight));
323 labels.drawComponent(gg, getWidth());
324 gg.translate(0, -ypos - (alheight * av.charHeight));
330 // No need to hang on to labels if we're not wrapped
333 // Now draw the id strings
334 int panelWidth = getWidth();
338 // Now draw the id strings
339 for (int i = starty; i < endy; i++)
341 sequence = av.alignment.getSequenceAt(i);
343 if (sequence == null)
348 if (av.hasHiddenRows)
350 setHiddenFont(sequence);
353 // Selected sequence colours
354 if ((searchResults != null) && searchResults.contains(sequence))
356 currentColor = Color.black;
357 currentTextColor = Color.white;
359 else if ((av.getSelectionGroup() != null)
360 && av.getSelectionGroup().getSequences(null).contains(
363 currentColor = Color.lightGray;
364 currentTextColor = Color.black;
368 currentColor = av.getSequenceColour(sequence);
369 currentTextColor = Color.black;
372 gg.setColor(currentColor);
374 gg.fillRect(0, (i - starty) * av.charHeight, getWidth(),
377 gg.setColor(currentTextColor);
379 String string = sequence.getDisplayId(av.getShowJVSuffix());
381 if (av.rightAlignIds)
383 xPos = panelWidth - fm.stringWidth(string) - 4;
386 gg.drawString(string, xPos,
387 (((i - starty) * av.charHeight) + av.charHeight)
388 - (av.charHeight / 5));
390 if (av.hasHiddenRows && av.showHiddenMarkers)
392 drawMarker(i, starty, 0);
400 void drawMarker(int i, int starty, int yoffset)
403 SequenceI[] hseqs = av.alignment.getHiddenSequences().hiddenSequences;
404 // Use this method here instead of calling hiddenSeq adjust
406 int hSize = hseqs.length;
409 int lastIndex = i - 1;
410 int nextIndex = i + 1;
412 for (int j = 0; j < hSize; j++)
414 if (hseqs[j] != null)
416 if (j - 1 < hiddenIndex)
420 if (j - 1 < lastIndex)
424 if (j - 1 < nextIndex)
431 boolean below = (hiddenIndex > lastIndex + 1);
432 boolean above = (nextIndex > hiddenIndex + 1);
434 gg.setColor(Color.blue);
439 { getWidth() - av.charHeight, getWidth() - av.charHeight,
440 getWidth() }, new int[]
442 (i - starty) * av.charHeight + yoffset,
443 (i - starty) * av.charHeight + yoffset + av.charHeight
444 / 4, (i - starty) * av.charHeight + yoffset }, 3);
450 { getWidth() - av.charHeight, getWidth() - av.charHeight,
451 getWidth() }, new int[]
453 (i - starty + 1) * av.charHeight + yoffset,
454 (i - starty + 1) * av.charHeight + yoffset
456 (i - starty + 1) * av.charHeight + yoffset }, 3);
461 void setHiddenFont(SequenceI seq)
463 Font bold = new Font(av.getFont().getName(), Font.BOLD, av.getFont()
466 if (av.hiddenRepSequences != null
467 && av.hiddenRepSequences.containsKey(seq))
483 public void setHighlighted(java.util.Vector found)
485 searchResults = found;