2 * Jalview - A Sequence Alignment Editor and Viewer
\r
3 * Copyright (C) 2007 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
\r
5 * This program is free software; you can redistribute it and/or
\r
6 * modify it under the terms of the GNU General Public License
\r
7 * as published by the Free Software Foundation; either version 2
\r
8 * of the License, or (at your option) any later version.
\r
10 * This program is distributed in the hope that it will be useful,
\r
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
13 * GNU General Public License for more details.
\r
15 * You should have received a copy of the GNU General Public License
\r
16 * along with this program; if not, write to the Free Software
\r
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
\r
19 package jalview.gui;
\r
22 import java.awt.image.*;
\r
23 import javax.swing.*;
\r
25 import jalview.datamodel.*;
\r
31 * @version $Revision$
\r
33 public class IdCanvas
\r
36 protected AlignViewport av;
\r
37 protected boolean showScores = true;
\r
38 protected int maxIdLength = -1;
\r
39 protected String maxIdStr = null;
\r
40 BufferedImage image;
\r
43 boolean fastPaint = false;
\r
44 java.util.Vector searchResults;
\r
46 AnnotationLabels labels = null;
\r
51 * Creates a new IdCanvas object.
\r
53 * @param av DOCUMENT ME!
\r
55 public IdCanvas(AlignViewport av)
\r
57 setLayout(new BorderLayout());
\r
59 PaintRefresher.Register(this, av.getSequenceSetId());
\r
65 * @param gg DOCUMENT ME!
\r
66 * @param s DOCUMENT ME!
\r
67 * @param i DOCUMENT ME!
\r
68 * @param starty DOCUMENT ME!
\r
69 * @param ypos DOCUMENT ME!
\r
71 public void drawIdString(Graphics2D gg, SequenceI s, int i, int starty,
\r
75 int panelWidth = getWidth();
\r
76 int charHeight = av.charHeight;
\r
78 if ( (searchResults != null) && searchResults.contains(s))
\r
80 gg.setColor(Color.black);
\r
81 gg.fillRect(0, ( (i - starty) * charHeight) + ypos, getWidth(),
\r
83 gg.setColor(Color.white);
\r
85 else if ( (av.getSelectionGroup() != null) &&
\r
86 av.getSelectionGroup().getSequences(null).contains(s))
\r
88 gg.setColor(Color.lightGray);
\r
89 gg.fillRect(0, ( (i - starty) * charHeight) + ypos, getWidth(),
\r
91 gg.setColor(Color.white);
\r
95 gg.setColor(av.getSequenceColour(s));
\r
96 gg.fillRect(0, ( (i - starty) * charHeight) + ypos, getWidth(),
\r
98 gg.setColor(Color.black);
\r
101 if (av.rightAlignIds)
\r
103 xPos = panelWidth - fm.stringWidth(
\r
104 s.getDisplayId(av.getShowJVSuffix())
\r
108 gg.drawString(s.getDisplayId(av.getShowJVSuffix()),
\r
110 ( ( (i - starty + 1) * charHeight) + ypos) - (charHeight / 5));
\r
112 if (av.hasHiddenRows && av.showHiddenMarkers)
\r
114 drawMarker(i, starty, ypos);
\r
122 * @param vertical DOCUMENT ME!
\r
124 public void fastPaint(int vertical)
\r
133 gg.copyArea(0, 0, getWidth(), imgHeight, 0, -vertical * av.charHeight);
\r
135 int ss = av.startSeq;
\r
136 int es = av.endSeq;
\r
139 if (vertical > 0) // scroll down
\r
141 ss = es - vertical;
\r
143 if (ss < av.startSeq)
\r
144 { // ie scrolling too fast, more than a page at a time
\r
149 transY = imgHeight - (vertical * av.charHeight);
\r
152 else if (vertical < 0)
\r
154 es = ss - vertical;
\r
156 if (es > av.endSeq)
\r
162 gg.translate(0, transY);
\r
166 gg.translate(0, -transY);
\r
175 * @param g DOCUMENT ME!
\r
177 public void paintComponent(Graphics g)
\r
179 g.setColor(Color.white);
\r
180 g.fillRect(0, 0, getWidth(), getHeight());
\r
185 g.drawImage(image, 0, 0, this);
\r
190 int oldHeight = imgHeight;
\r
192 imgHeight = getHeight();
\r
193 imgHeight -= (imgHeight % av.charHeight);
\r
200 if (oldHeight != imgHeight || image.getWidth(this) != getWidth())
\r
202 image = new BufferedImage(getWidth(), imgHeight,
\r
203 BufferedImage.TYPE_INT_RGB);
\r
206 gg = (Graphics2D) image.getGraphics();
\r
208 //Fill in the background
\r
209 gg.setColor(Color.white);
\r
210 gg.fillRect(0, 0, getWidth(), imgHeight);
\r
212 drawIds(av.getStartSeq(), av.endSeq);
\r
214 g.drawImage(image, 0, 0, this);
\r
220 * @param starty DOCUMENT ME!
\r
221 * @param endy DOCUMENT ME!
\r
223 void drawIds(int starty, int endy)
\r
225 if (av.seqNameItalics)
\r
227 idfont = new Font(av.getFont().getName(), Font.ITALIC,
\r
228 av.getFont().getSize());
\r
232 idfont = av.getFont();
\r
235 gg.setFont(idfont);
\r
236 fm = gg.getFontMetrics();
\r
240 gg.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
\r
241 RenderingHints.VALUE_ANTIALIAS_ON);
\r
244 Color currentColor = Color.white;
\r
245 Color currentTextColor = Color.black;
\r
247 if (av.getWrapAlignment())
\r
249 int maxwidth = av.alignment.getWidth();
\r
250 int alheight = av.alignment.getHeight();
\r
252 if (av.hasHiddenColumns)
\r
254 maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1;
\r
257 int annotationHeight = 0;
\r
259 if (av.showAnnotation)
\r
263 ap = new AnnotationPanel(av);
\r
266 annotationHeight = ap.adjustPanelHeight();
\r
267 if (labels == null)
\r
269 labels = new AnnotationLabels(av);
\r
273 int hgap = av.charHeight;
\r
274 if (av.scaleAboveWrapped)
\r
276 hgap += av.charHeight;
\r
279 int cHeight = alheight * av.charHeight
\r
281 + annotationHeight;
\r
283 int rowSize = av.getEndRes() - av.getStartRes();
\r
285 // Draw the rest of the panels
\r
286 for (int ypos = hgap, row = av.startRes;
\r
287 (ypos <= getHeight()) && (row < maxwidth);
\r
288 ypos += cHeight, row += rowSize)
\r
290 for (int i = starty; i < alheight; i++)
\r
292 SequenceI s = av.alignment.getSequenceAt(i);
\r
293 if (av.hasHiddenRows)
\r
299 gg.setFont(idfont);
\r
302 drawIdString(gg, s, i, 0, ypos);
\r
305 if (labels != null && av.showAnnotation)
\r
307 gg.translate(0, ypos + (alheight * av.charHeight));
\r
308 labels.drawComponent(gg, getWidth());
\r
309 gg.translate(0, -ypos - (alheight * av.charHeight));
\r
315 //No need to hang on to labels if we're not wrapped
\r
318 //Now draw the id strings
\r
319 int panelWidth = getWidth();
\r
322 SequenceI sequence;
\r
323 //Now draw the id strings
\r
324 for (int i = starty; i < endy; i++)
\r
326 sequence = av.alignment.getSequenceAt(i);
\r
328 if (sequence == null)
\r
333 if (av.hasHiddenRows)
\r
335 setHiddenFont(sequence);
\r
338 // Selected sequence colours
\r
339 if ( (searchResults != null) &&
\r
340 searchResults.contains(sequence))
\r
342 currentColor = Color.black;
\r
343 currentTextColor = Color.white;
\r
345 else if ( (av.getSelectionGroup() != null) &&
\r
346 av.getSelectionGroup().getSequences(null).contains(
\r
349 currentColor = Color.lightGray;
\r
350 currentTextColor = Color.black;
\r
354 currentColor = av.getSequenceColour(sequence);
\r
355 currentTextColor = Color.black;
\r
358 gg.setColor(currentColor);
\r
360 gg.fillRect(0, (i - starty) * av.charHeight, getWidth(),
\r
363 gg.setColor(currentTextColor);
\r
365 String string = sequence.getDisplayId(av.getShowJVSuffix());
\r
367 if (av.rightAlignIds)
\r
369 xPos = panelWidth - fm.stringWidth(string) - 4;
\r
372 gg.drawString(string, xPos,
\r
373 ( ( (i - starty) * av.charHeight) + av.charHeight) -
\r
374 (av.charHeight / 5));
\r
376 if (av.hasHiddenRows && av.showHiddenMarkers)
\r
378 drawMarker(i, starty, 0);
\r
386 void drawMarker(int i, int starty, int yoffset)
\r
389 SequenceI[] hseqs = av.alignment.getHiddenSequences().hiddenSequences;
\r
390 //Use this method here instead of calling hiddenSeq adjust
\r
392 int hSize = hseqs.length;
\r
394 int hiddenIndex = i;
\r
395 int lastIndex = i - 1;
\r
396 int nextIndex = i + 1;
\r
398 for (int j = 0; j < hSize; j++)
\r
400 if (hseqs[j] != null)
\r
402 if (j - 1 < hiddenIndex)
\r
406 if (j - 1 < lastIndex)
\r
410 if (j - 1 < nextIndex)
\r
417 boolean below = (hiddenIndex > lastIndex + 1);
\r
418 boolean above = (nextIndex > hiddenIndex + 1);
\r
420 gg.setColor(Color.blue);
\r
423 gg.fillPolygon(new int[]
\r
424 {getWidth() - av.charHeight,
\r
425 getWidth() - av.charHeight,
\r
429 (i - starty) * av.charHeight + yoffset,
\r
430 (i - starty) * av.charHeight + yoffset + av.charHeight / 4,
\r
431 (i - starty) * av.charHeight + yoffset
\r
436 gg.fillPolygon(new int[]
\r
437 {getWidth() - av.charHeight,
\r
438 getWidth() - av.charHeight,
\r
442 (i - starty + 1) * av.charHeight + yoffset,
\r
443 (i - starty + 1) * av.charHeight + yoffset -
\r
445 (i - starty + 1) * av.charHeight + yoffset
\r
451 void setHiddenFont(SequenceI seq)
\r
453 Font bold = new Font(av.getFont().getName(), Font.BOLD,
\r
454 av.getFont().getSize());
\r
456 if (av.hiddenRepSequences != null &&
\r
457 av.hiddenRepSequences.containsKey(seq))
\r
463 gg.setFont(idfont);
\r
470 * @param found DOCUMENT ME!
\r
472 public void setHighlighted(java.util.Vector found)
\r
474 searchResults = found;
\r