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
49 * Creates a new IdCanvas object.
\r
51 * @param av DOCUMENT ME!
\r
53 public IdCanvas(AlignViewport av)
\r
55 setLayout(new BorderLayout());
\r
57 PaintRefresher.Register(this, av.getSequenceSetId());
\r
63 * @param gg DOCUMENT ME!
\r
64 * @param s DOCUMENT ME!
\r
65 * @param i DOCUMENT ME!
\r
66 * @param starty DOCUMENT ME!
\r
67 * @param ypos DOCUMENT ME!
\r
69 public void drawIdString(Graphics2D gg, SequenceI s, int i, int starty, int ypos)
\r
72 int panelWidth = getWidth();
\r
73 int charHeight = av.charHeight;
\r
75 if ((searchResults != null) && searchResults.contains(s))
\r
77 gg.setColor(Color.black);
\r
78 gg.fillRect(0, ((i - starty) * charHeight) + ypos, getWidth(),
\r
80 gg.setColor(Color.white);
\r
82 else if ((av.getSelectionGroup() != null) &&
\r
83 av.getSelectionGroup().getSequences(false).contains(s))
\r
85 gg.setColor(Color.lightGray);
\r
86 gg.fillRect(0, ((i - starty) * charHeight) + ypos, getWidth(),
\r
88 gg.setColor(Color.white);
\r
92 gg.setColor(av.getSequenceColour(s));
\r
93 gg.fillRect(0, ((i - starty) * charHeight) + ypos, getWidth(),
\r
95 gg.setColor(Color.black);
\r
98 if (av.rightAlignIds)
\r
100 xPos = panelWidth - fm.stringWidth(
\r
101 s.getDisplayId(av.getShowJVSuffix())
\r
105 gg.drawString( s.getDisplayId(av.getShowJVSuffix()),
\r
106 xPos, (((i - starty + 1) * charHeight) + ypos) - (charHeight / 5));
\r
108 if (av.hasHiddenRows && av.showHiddenMarkers)
\r
109 drawMarker(i, starty, ypos);
\r
117 * @param vertical DOCUMENT ME!
\r
119 public void fastPaint(int vertical)
\r
128 gg.copyArea(0, 0, getWidth(), imgHeight, 0, -vertical * av.charHeight);
\r
130 int ss = av.startSeq;
\r
131 int es = av.endSeq;
\r
134 if (vertical > 0) // scroll down
\r
136 ss = es - vertical;
\r
138 if (ss < av.startSeq)
\r
139 { // ie scrolling too fast, more than a page at a time
\r
144 transY = imgHeight - (vertical * av.charHeight);
\r
147 else if (vertical < 0)
\r
149 es = ss - vertical;
\r
151 if (es > av.endSeq)
\r
157 gg.translate(0, transY);
\r
161 gg.translate(0, -transY);
\r
170 * @param g DOCUMENT ME!
\r
172 public void paintComponent(Graphics g)
\r
174 g.setColor(Color.white);
\r
175 g.fillRect(0, 0, getWidth(), getHeight());
\r
180 g.drawImage(image, 0, 0, this);
\r
185 int oldHeight = imgHeight;
\r
187 imgHeight = getHeight();
\r
188 imgHeight -= (imgHeight % av.charHeight);
\r
195 if(oldHeight!=imgHeight || image.getWidth(this)!=getWidth())
\r
197 image = new BufferedImage(getWidth(), imgHeight,
\r
198 BufferedImage.TYPE_INT_RGB);
\r
201 gg = (Graphics2D) image.getGraphics();
\r
203 //Fill in the background
\r
204 gg.setColor(Color.white);
\r
205 gg.fillRect(0, 0, getWidth(), imgHeight);
\r
207 drawIds(av.getStartSeq(), av.endSeq);
\r
209 g.drawImage(image, 0, 0, this);
\r
215 * @param starty DOCUMENT ME!
\r
216 * @param endy DOCUMENT ME!
\r
218 void drawIds(int starty, int endy)
\r
220 Font italic = new Font(av.getFont().getName(), Font.ITALIC,
\r
221 av.getFont().getSize());
\r
223 gg.setFont(italic);
\r
224 fm = gg.getFontMetrics();
\r
227 gg.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
\r
228 RenderingHints.VALUE_ANTIALIAS_ON);
\r
230 Color currentColor = Color.white;
\r
231 Color currentTextColor = Color.black;
\r
233 if (av.getWrapAlignment())
\r
235 int maxwidth = av.alignment.getWidth();
\r
236 int alheight = av.alignment.getHeight();
\r
238 if (av.hasHiddenColumns)
\r
239 maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1;
\r
241 int annotationHeight = 0;
\r
242 AnnotationLabels labels = null;
\r
244 if(av.showAnnotation)
\r
246 AnnotationPanel ap = new AnnotationPanel(av);
\r
247 annotationHeight = ap.adjustPanelHeight();
\r
248 labels = new AnnotationLabels(av);
\r
251 int hgap = av.charHeight;
\r
252 if (av.scaleAboveWrapped)
\r
253 hgap += av.charHeight;
\r
255 int cHeight = alheight * av.charHeight
\r
257 + annotationHeight;
\r
259 int rowSize = av.getEndRes() - av.getStartRes();
\r
262 // Draw the rest of the panels
\r
263 for (int ypos = hgap, row = av.startRes;
\r
264 (ypos <= getHeight()) && (row < maxwidth);
\r
265 ypos += cHeight, row += rowSize)
\r
267 for (int i = starty; i < alheight; i++)
\r
269 if (av.hasHiddenRows)
\r
274 gg.setFont(italic);
\r
276 SequenceI s = av.alignment.getSequenceAt(i);
\r
277 drawIdString(gg, s, i, 0, ypos);
\r
282 gg.translate(0, ypos+(alheight * av.charHeight));
\r
283 labels.drawComponent(gg, getWidth());
\r
284 gg.translate(0, -ypos-(alheight * av.charHeight));
\r
292 //Now draw the id strings
\r
293 int panelWidth = getWidth();
\r
296 SequenceI sequence;
\r
297 //Now draw the id strings
\r
298 for (int i = starty; i < endy; i++)
\r
300 sequence = av.alignment.getSequenceAt(i);
\r
305 if (av.hasHiddenRows)
\r
310 // Selected sequence colours
\r
311 if ( (searchResults != null) &&
\r
312 searchResults.contains(sequence))
\r
314 currentColor = Color.black;
\r
315 currentTextColor = Color.white;
\r
317 else if ( (av.getSelectionGroup() != null) &&
\r
318 av.getSelectionGroup().getSequences(false).contains(
\r
321 currentColor = Color.lightGray;
\r
322 currentTextColor = Color.black;
\r
326 currentColor = av.getSequenceColour(sequence);
\r
327 currentTextColor = Color.black;
\r
330 gg.setColor(currentColor);
\r
332 gg.fillRect(0, (i - starty) * av.charHeight, getWidth(),
\r
335 gg.setColor(currentTextColor);
\r
337 String string = sequence.getDisplayId( av.getShowJVSuffix());
\r
340 if(av.rightAlignIds)
\r
342 xPos = panelWidth - fm.stringWidth(string) - 4;
\r
345 gg.drawString(string, xPos,
\r
346 (((i - starty) * av.charHeight) + av.charHeight) -
\r
347 (av.charHeight / 5));
\r
349 if(av.hasHiddenRows && av.showHiddenMarkers)
\r
350 drawMarker(i, starty, 0);
\r
357 void drawMarker(int i, int starty, int yoffset)
\r
360 SequenceI [] hseqs = av.alignment.getHiddenSequences().hiddenSequences;
\r
361 //Use this method here instead of calling hiddenSeq adjust
\r
363 int hSize = hseqs.length;
\r
365 int hiddenIndex = i;
\r
366 int lastIndex = i - 1;
\r
367 int nextIndex = i + 1;
\r
369 for(int j=0; j<hSize; j++)
\r
371 if (hseqs[j] != null)
\r
373 if(j-1<hiddenIndex)
\r
382 boolean below = (hiddenIndex > lastIndex + 1);
\r
383 boolean above = (nextIndex > hiddenIndex+1);
\r
386 gg.setColor(Color.blue);
\r
389 gg.fillPolygon(new int[]
\r
390 {getWidth()- av.charHeight,
\r
391 getWidth()- av.charHeight,
\r
395 (i - starty) * av.charHeight +yoffset,
\r
396 (i - starty) * av.charHeight +yoffset+ av.charHeight / 4,
\r
397 (i - starty) * av.charHeight+yoffset
\r
402 gg.fillPolygon(new int[]
\r
403 {getWidth()- av.charHeight,
\r
404 getWidth()- av.charHeight,
\r
408 (i - starty+1) * av.charHeight +yoffset,
\r
409 (i - starty+1) * av.charHeight +yoffset- av.charHeight / 4,
\r
410 (i - starty+1) * av.charHeight +yoffset
\r
416 void setHiddenFont(int i)
\r
418 Font italic = new Font(av.getFont().getName(), Font.ITALIC,
\r
419 av.getFont().getSize());
\r
420 Font bold = new Font(av.getFont().getName(), Font.BOLD,
\r
421 av.getFont().getSize());
\r
424 if (av.alignment.getSequenceAt(i)!=null
\r
425 && av.alignment.getSequenceAt(i).getHiddenSequences() != null)
\r
428 gg.setFont(italic);
\r
434 * @param found DOCUMENT ME!
\r
436 public void setHighlighted(java.util.Vector found)
\r
438 searchResults = found;
\r