2 * Jalview - A Sequence Alignment Editor and Viewer
\r
3 * Copyright (C) 2006 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
21 import jalview.datamodel.*;
\r
24 import java.awt.image.*;
\r
26 import javax.swing.*;
\r
33 * @version $Revision$
\r
35 public class IdCanvas extends JPanel
\r
37 protected AlignViewport av;
\r
38 protected boolean showScores = true;
\r
39 protected int maxIdLength = -1;
\r
40 protected String maxIdStr = null;
\r
41 BufferedImage image;
\r
44 boolean fastPaint = false;
\r
45 java.util.Vector searchResults;
\r
47 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, int ypos)
\r
74 int panelWidth = getWidth();
\r
75 int charHeight = av.charHeight;
\r
77 if ((searchResults != null) && searchResults.contains(s))
\r
79 gg.setColor(Color.black);
\r
80 gg.fillRect(0, ((i - starty) * charHeight) + ypos, getWidth(),
\r
82 gg.setColor(Color.white);
\r
84 else if ((av.getSelectionGroup() != null) &&
\r
85 av.getSelectionGroup().getSequences(false).contains(s))
\r
87 gg.setColor(Color.lightGray);
\r
88 gg.fillRect(0, ((i - starty) * charHeight) + ypos, getWidth(),
\r
90 gg.setColor(Color.white);
\r
94 gg.setColor(av.getSequenceColour(s));
\r
95 gg.fillRect(0, ((i - starty) * charHeight) + ypos, getWidth(),
\r
97 gg.setColor(Color.black);
\r
100 if (av.rightAlignIds)
\r
102 xPos = panelWidth - fm.stringWidth(
\r
103 s.getDisplayId(av.getShowJVSuffix())
\r
107 gg.drawString( s.getDisplayId(av.getShowJVSuffix()),
\r
108 xPos, (((i - starty + 1) * charHeight) + ypos) - (charHeight / 5));
\r
110 if (av.hasHiddenRows && av.showHiddenMarkers)
\r
111 drawMarker(i, starty, ypos);
\r
119 * @param vertical DOCUMENT ME!
\r
121 public void fastPaint(int vertical)
\r
130 gg.copyArea(0, 0, getWidth(), imgHeight, 0, -vertical * av.charHeight);
\r
132 int ss = av.startSeq;
\r
133 int es = av.endSeq;
\r
136 if (vertical > 0) // scroll down
\r
138 ss = es - vertical;
\r
140 if (ss < av.startSeq)
\r
141 { // ie scrolling too fast, more than a page at a time
\r
146 transY = imgHeight - (vertical * av.charHeight);
\r
149 else if (vertical < 0)
\r
151 es = ss - vertical;
\r
153 if (es > av.endSeq)
\r
159 gg.translate(0, transY);
\r
163 gg.translate(0, -transY);
\r
172 * @param g DOCUMENT ME!
\r
174 public void paintComponent(Graphics g)
\r
176 g.setColor(Color.white);
\r
177 g.fillRect(0, 0, getWidth(), getHeight());
\r
182 g.drawImage(image, 0, 0, this);
\r
187 int oldHeight = imgHeight;
\r
189 imgHeight = getHeight();
\r
190 imgHeight -= (imgHeight % av.charHeight);
\r
197 if(oldHeight!=imgHeight || image.getWidth(this)!=getWidth())
\r
199 image = new BufferedImage(getWidth(), imgHeight,
\r
200 BufferedImage.TYPE_INT_RGB);
\r
203 gg = (Graphics2D) image.getGraphics();
\r
205 //Fill in the background
\r
206 gg.setColor(Color.white);
\r
207 gg.fillRect(0, 0, getWidth(), imgHeight);
\r
209 drawIds(av.getStartSeq(), av.endSeq);
\r
211 g.drawImage(image, 0, 0, this);
\r
217 * @param starty DOCUMENT ME!
\r
218 * @param endy DOCUMENT ME!
\r
220 void drawIds(int starty, int endy)
\r
222 Font italic = new Font(av.getFont().getName(), Font.ITALIC,
\r
223 av.getFont().getSize());
\r
225 gg.setFont(italic);
\r
226 fm = gg.getFontMetrics();
\r
229 gg.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
\r
230 RenderingHints.VALUE_ANTIALIAS_ON);
\r
232 Color currentColor = Color.white;
\r
233 Color currentTextColor = Color.black;
\r
235 if (av.getWrapAlignment())
\r
237 int maxwidth = av.alignment.getWidth();
\r
238 int alheight = av.alignment.getHeight();
\r
240 if (av.hasHiddenColumns)
\r
241 maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1;
\r
243 int annotationHeight = 0;
\r
246 if(av.showAnnotation)
\r
249 ap = new AnnotationPanel(av);
\r
251 annotationHeight = ap.adjustPanelHeight();
\r
252 if (labels == null)
\r
253 labels = new AnnotationLabels(av);
\r
256 int hgap = av.charHeight;
\r
257 if (av.scaleAboveWrapped)
\r
258 hgap += av.charHeight;
\r
260 int cHeight = alheight * av.charHeight
\r
262 + annotationHeight;
\r
264 int rowSize = av.getEndRes() - av.getStartRes();
\r
267 // Draw the rest of the panels
\r
268 for (int ypos = hgap, row = av.startRes;
\r
269 (ypos <= getHeight()) && (row < maxwidth);
\r
270 ypos += cHeight, row += rowSize)
\r
272 for (int i = starty; i < alheight; i++)
\r
274 if (av.hasHiddenRows)
\r
279 gg.setFont(italic);
\r
281 SequenceI s = av.alignment.getSequenceAt(i);
\r
282 drawIdString(gg, s, i, 0, ypos);
\r
287 gg.translate(0, ypos+(alheight * av.charHeight));
\r
288 labels.drawComponent(gg, getWidth());
\r
289 gg.translate(0, -ypos-(alheight * av.charHeight));
\r
297 //Now draw the id strings
\r
298 int panelWidth = getWidth();
\r
301 SequenceI sequence;
\r
302 //Now draw the id strings
\r
303 for (int i = starty; i < endy; i++)
\r
305 sequence = av.alignment.getSequenceAt(i);
\r
310 if (av.hasHiddenRows)
\r
315 // Selected sequence colours
\r
316 if ( (searchResults != null) &&
\r
317 searchResults.contains(sequence))
\r
319 currentColor = Color.black;
\r
320 currentTextColor = Color.white;
\r
322 else if ( (av.getSelectionGroup() != null) &&
\r
323 av.getSelectionGroup().getSequences(false).contains(
\r
326 currentColor = Color.lightGray;
\r
327 currentTextColor = Color.black;
\r
331 currentColor = av.getSequenceColour(sequence);
\r
332 currentTextColor = Color.black;
\r
335 gg.setColor(currentColor);
\r
337 gg.fillRect(0, (i - starty) * av.charHeight, getWidth(),
\r
340 gg.setColor(currentTextColor);
\r
342 String string = sequence.getDisplayId( av.getShowJVSuffix());
\r
345 if(av.rightAlignIds)
\r
347 xPos = panelWidth - fm.stringWidth(string) - 4;
\r
350 gg.drawString(string, xPos,
\r
351 (((i - starty) * av.charHeight) + av.charHeight) -
\r
352 (av.charHeight / 5));
\r
354 if(av.hasHiddenRows && av.showHiddenMarkers)
\r
355 drawMarker(i, starty, 0);
\r
362 void drawMarker(int i, int starty, int yoffset)
\r
365 SequenceI [] hseqs = av.alignment.getHiddenSequences().hiddenSequences;
\r
366 //Use this method here instead of calling hiddenSeq adjust
\r
368 int hSize = hseqs.length;
\r
370 int hiddenIndex = i;
\r
371 int lastIndex = i - 1;
\r
372 int nextIndex = i + 1;
\r
374 for(int j=0; j<hSize; j++)
\r
376 if (hseqs[j] != null)
\r
378 if(j-1<hiddenIndex)
\r
387 boolean below = (hiddenIndex > lastIndex + 1);
\r
388 boolean above = (nextIndex > hiddenIndex+1);
\r
391 gg.setColor(Color.blue);
\r
394 gg.fillPolygon(new int[]
\r
395 {getWidth()- av.charHeight,
\r
396 getWidth()- av.charHeight,
\r
400 (i - starty) * av.charHeight +yoffset,
\r
401 (i - starty) * av.charHeight +yoffset+ av.charHeight / 4,
\r
402 (i - starty) * av.charHeight+yoffset
\r
407 gg.fillPolygon(new int[]
\r
408 {getWidth()- av.charHeight,
\r
409 getWidth()- av.charHeight,
\r
413 (i - starty+1) * av.charHeight +yoffset,
\r
414 (i - starty+1) * av.charHeight +yoffset- av.charHeight / 4,
\r
415 (i - starty+1) * av.charHeight +yoffset
\r
421 void setHiddenFont(int i)
\r
423 Font italic = new Font(av.getFont().getName(), Font.ITALIC,
\r
424 av.getFont().getSize());
\r
425 Font bold = new Font(av.getFont().getName(), Font.BOLD,
\r
426 av.getFont().getSize());
\r
429 if (av.alignment.getSequenceAt(i)!=null
\r
430 && av.alignment.getSequenceAt(i).getHiddenSequences() != null)
\r
433 gg.setFont(italic);
\r
439 * @param found DOCUMENT ME!
\r
441 public void setHighlighted(java.util.Vector found)
\r
443 searchResults = found;
\r